#!/usr/bin/env bash # HEADER #======================================================================= # # panpdf -- Get a quick access to generate PDF from text files. # # SYNOPSIS # panpdf [options] [infile] # # DESCRIPTION # Shell script to get PDF from markdown or text files. # # OPTIONS # -h|--help display this help and exit # 10pt|12pt font size # a5|A5 format on A5 paper # a5l|A5L format as landscape on A5 paper # en babel in english # fr babel in french (default) # --no-num unumbered sections # --toc print table of contents # # EXAMPLES # $ panpdf # $ pdfprint --no-num # $ pdfprint --toc # # DEPENDENCIES # - pandoc >= 1.17.2 # - pdflatex # - GNU coreutils # # INSTALLATION # - copy "latex.template" to "/home/$(whoami)/.pandoc/" # - copy file to "/home/$(whoami)/bin" # - add line "complete -f -X '!*.md' panpdf # to "/home/$(whoami)/.bashrc" # # # Copyright (C) 2019-2021 Nicolas Mesnier # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License version 3 or # above as published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # #======================================================================= # END_OF_HEADER #----------------------------------------------------------------------- #----------------------------------------------------------------------- # *** read this header to display help #----------------------------------------------------------------------- BOH=$(head -200 ${0} | grep -n "^# HEADER" | cut -f1 -d:) EOH=$(head -200 ${0} | grep -n "^# END_OF_HEADER" | cut -f1 -d:) function Help(){ head -$(($EOH-1)) ${0} | tail -$(($EOH-$BOH-1)) \ | grep -e "^#$" -e "^# " | sed -e "s/^#=*//g" } #----------------------------------------------------------------------- # *** default options GEOM="--variable geometry:a4paper,textwidth=160mm,textheight=247mm," GEOM+="centering,includefoot" FONT=" --variable fontsize:11pt" LANG="--variable lang:fr-FR --variable babel-lang:frenchb" NUM="--variable numbersections:true" TOC="" infile="" # *** read options while [[ ${1} ]]; do case "${1}" in -h|--help ) Help exit 0 ;; 10pt) FONT=" --variable fontsize:10pt" ;; 12pt) FONT=" --variable fontsize:12pt" ;; A5L|a5l) GEOM="--variable geometry:a5paper,landscape," GEOM+="textwidth=160mm,textheight=123mm,centering," GEOM+="includefoot" ;; A5|a5) GEOM="--variable geometry:a5paper," GEOM+="textwidth=120mm,textheight=160mm,centering," GEOM+="includefoot" ;; en) LANG="--variable lang:en --variable babel-lang:english" ;; fr) LANG="--variable lang:fr --variable babel-lang:french" ;; --no-num) NUM="" ;; --toc) TOC="--variable toc:true --variable toccolor:red" TOC+=" --toc-depth=2" ;; *) if [ -f ${1} ];then infile=${1} else echo "File \"${1}\" does not exists." >&2 exit 1 fi ;; esac if ! shift; then echo 'Missing parameter argument.' >&2 exit 1 fi done # filename filename=$(basename $infile .${infile##*.}) # use pandoc for markdow conversion to tex pandoc $infile \ --variable documentclass:article \ ${GEOM} ${FONT} ${LANG} ${NUM} ${TOC}\ --highlight-style haddock \ --variable colorlinks:true \ --variable linkcolor:red \ --variable urlcolor:blue \ --variable filecolor:blue \ --template=/home/$(whoami)/.pandoc/latex.template \ -s -o $filename.tex # remove option for french spaces sed -i 's/shorthands=off,//g' $filename.tex # compile tex (quietly) for i in $(seq 1 3);do pdflatex $filename.tex 2>&1 1>/dev/null done # purge extensions=(".aux" ".bbl" ".blg" ".dvi" ".log" ".mtc*" ".nav" \ ".out" ".ptc*" ".snm" ".spl" ".toc" ".tex") for extension in "${extensions[@]}";do find -maxdepth 1 -type f -name "${filename}${extension}" -delete done #====================================================================eof # vim: set tw=72 ts=4 sw=4 nu: