2021-02-12 23:20:57 +01:00
|
|
|
#!/usr/bin/env sh
|
2020-05-20 18:34:34 +02:00
|
|
|
|
|
|
|
######################################################################
|
2021-02-14 19:07:45 +01:00
|
|
|
# @author : swytch
|
|
|
|
# @file : texer
|
|
|
|
# @license : MIT
|
|
|
|
# @created : Wednesday May 20, 2020 18:26:30 CEST
|
2020-05-20 18:34:34 +02:00
|
|
|
#
|
2021-02-14 19:07:45 +01:00
|
|
|
# @description : create a LaTeX doc with generic metadata
|
|
|
|
# open it with (neo)vim
|
2020-05-20 18:34:34 +02:00
|
|
|
######################################################################
|
2020-05-06 03:20:19 +02:00
|
|
|
|
|
|
|
|
|
|
|
if [ -z "$1" ]; then
|
2020-05-25 15:04:16 +02:00
|
|
|
printf "Please provide a name for your file\n"
|
2020-05-06 03:20:19 +02:00
|
|
|
elif [ -e $1 ]; then
|
2020-05-25 15:04:16 +02:00
|
|
|
printf "This filename is already taken, please provide a different name\n"
|
2020-05-06 03:20:19 +02:00
|
|
|
else
|
|
|
|
touch "$1"
|
2020-05-25 15:04:16 +02:00
|
|
|
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
|
2020-05-25 15:04:16 +02:00
|
|
|
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
|
2020-05-25 15:04:16 +02:00
|
|
|
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
|
2020-05-25 15:04:16 +02:00
|
|
|
printf '\n\usepackage[dvipsname]{xcolor}' >> "$1"
|
2020-05-06 03:20:19 +02:00
|
|
|
fi
|
2020-05-25 15:04:16 +02:00
|
|
|
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
|
2020-05-25 15:04:16 +02:00
|
|
|
printf '\n\usepackage{apacite}' >> "$1"
|
2020-05-06 03:20:19 +02:00
|
|
|
bibstyle="apacite"
|
|
|
|
else
|
|
|
|
bibstyle="unsrt"
|
2020-05-25 15:04:16 +02:00
|
|
|
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
|
2020-05-25 15:04:16 +02:00
|
|
|
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
|
2020-05-25 15:04:16 +02:00
|
|
|
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
|
2020-05-25 15:04:16 +02:00
|
|
|
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
|
2020-05-25 15:04:16 +02:00
|
|
|
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
|
2020-05-25 15:04:16 +02:00
|
|
|
printf '\n\bibliographystyle{$bibstyle}' >> "$1"
|
|
|
|
printf '\n\bibliography{$HOME/documents/bibliographies/$bibfile}' >> "$1"
|
2020-05-06 03:20:19 +02:00
|
|
|
fi
|
2020-05-25 15:04:16 +02:00
|
|
|
printf '\n\end{document}' >> "$1"
|
2020-05-06 03:20:19 +02:00
|
|
|
|
|
|
|
# check if neovim is installed
|
2020-05-25 03:59:22 +02:00
|
|
|
if command -v nvim > /dev/null 2>&1; then
|
2020-05-06 03:20:19 +02:00
|
|
|
nvim "$1"
|
|
|
|
else
|
|
|
|
vim "$1"
|
|
|
|
fi
|
|
|
|
fi
|