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
2021-02-16 00:37:44 +01:00

86 lines
3.0 KiB
Bash
Executable File

#!/usr/bin/env sh
######################################################################
# @author : swytch
# @file : texer
# @license : MIT
# @created : Wednesday May 20, 2020 18:26:30 CEST
#
# @description : create a LaTeX doc with generic metadata
# open it with (neo)vim
######################################################################
if [ -z "$1" ]; then
printf "Please provide a name for your file\n"
elif [ -e $1 ]; then
printf "This filename is already taken, please provide a different name\n"
else
touch "$1"
printf '%%metadata' >> "$1"
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"
read -p "Do you want colors?(y/N) " colors
if [ "$colors" = "y" ]; then
printf '\n\usepackage[dvipsname]{xcolor}' >> "$1"
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"
fi
printf '\n\usepackage[colorlinks=true, urlcolor=BrickRed]{hyperref}' >> "$1"
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"
bibstyle="apacite"
else
bibstyle="unsrt"
printf '\nThe default style is _unsrt_ (you may change it at the end of the document)'
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'
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"
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"
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"
if [ "$bibliography" = "y" ]; then
printf '\n\bibliographystyle{$bibstyle}' >> "$1"
printf '\n\bibliography{$HOME/documents/bibliographies/$bibfile}' >> "$1"
fi
printf '\n\end{document}' >> "$1"
# check if neovim is installed
if command -v nvim > /dev/null 2>&1; then
nvim "$1"
else
vim "$1"
fi
fi