This repository has been archived on 2023-03-02. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/.local/bin/texer

86 lines
3.0 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env sh
######################################################################
2021-02-14 19:07:45 +01:00
# @author : swytch
# @file : texer
# @license : MIT
# @created : Wednesday May 20, 2020 18:26:30 CEST
#
2021-02-14 19:07:45 +01:00
# @description : create a LaTeX doc with generic metadata
# open it with (neo)vim
######################################################################
2020-05-06 03:20:19 +02:00
if [ -z "$1" ]; then
printf "Please provide a name for your file\n"
2020-05-06 03:20:19 +02:00
elif [ -e $1 ]; then
printf "This filename is already taken, please provide a different name\n"
2020-05-06 03:20:19 +02:00
else
touch "$1"
printf '%%metadata' >> "$1"
2020-05-06 03:20:19 +02:00
read -p "Which type is your document? (def: article) " class
if [ -z "$class" ]; then
class='article'
fi
printf "\n\\documentclass[a4paper, 12pt]{$class}" >> "$1"
printf '\n' >> "$1"
2020-05-06 03:20:19 +02:00
read -p "Do you want colors?(y/N) " colors
if [ "$colors" = "y" ]; then
printf '\n\usepackage[dvipsname]{xcolor}' >> "$1"
2020-05-06 03:20:19 +02:00
fi
read -p "Do you want hyperlinks management?(y/N) " links
if [ "$links" = "y" ]; then
if [ "$colors" != "y" ]; then
printf '\n\usepackage[dvipsname]{xcolor}' >> "$1"
2020-05-06 03:20:19 +02:00
fi
printf '\n\usepackage[colorlinks=true, urlcolor=BrickRed]{hyperref}' >> "$1"
2020-05-06 03:20:19 +02:00
fi
read -p "Do you want bibliography management?(y/N) " bibliography
if [ "$bibliography" = "y" ]; then
read -p "Do you want to use apacite?(y/N) " apacite
if [ $apacite = "y" ]; then
printf '\n\usepackage{apacite}' >> "$1"
2020-05-06 03:20:19 +02:00
bibstyle="apacite"
else
bibstyle="unsrt"
printf '\nThe default style is _unsrt_ (you may change it at the end of the document)'
2020-05-06 03:20:19 +02:00
fi
bibfile="$(basename "$(find $HOME/documents/bibliographies/ -type f -not -path '*/\.*' | dmenu -l 20 -p "which bibliography?")")" # the -not -path allows find to ignore hidden files
if [ -z "$bibfile" ]; then
printf '\n'
printf '\n##################################################'
printf "\nDon't forget to specify the .bib file (\\bibliography{.bib}) at the end of the file " | fold -w 46 | sed "s/$/\ \#/g" | sed "s/^/\#\ /g"
printf '\n##################################################'
printf '\n'
2020-05-06 03:20:19 +02:00
fi
fi
read -p "Do you want to use another package? If so, please provide a package name; else, just press <Enter>: " package
while [ -n "$package" ]; do
printf "\n\usepackage{"$package"}" >> "$1"
2020-05-06 03:20:19 +02:00
package=''
read -p "Do you want to use another package? If so, please provide a package name: " package
done
printf '\n' >> "$1"
printf '\n\\author{David JULIEN}' >> "$1"
2020-05-06 03:20:19 +02:00
read -p "What is the title of the document? " title
printf '\n\\title{"$title"}' >> "$1"
printf '\n' >> "$1"
printf '\n%%document' >> "$1"
printf '\n\\begin{document}' >> "$1"
printf '\n' >> "$1"
printf '\n\\maketitle' >> "$1"
printf '\n' >> "$1"
2020-05-06 03:20:19 +02:00
if [ "$bibliography" = "y" ]; then
printf '\n\bibliographystyle{$bibstyle}' >> "$1"
printf '\n\bibliography{$HOME/documents/bibliographies/$bibfile}' >> "$1"
2020-05-06 03:20:19 +02:00
fi
printf '\n\end{document}' >> "$1"
2020-05-06 03:20:19 +02:00
# check if neovim is installed
if command -v nvim > /dev/null 2>&1; then
2020-05-06 03:20:19 +02:00
nvim "$1"
else
vim "$1"
fi
fi