blob: c9a35d79a6810db87b384d73bcb636d31e945637 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
#!/bin/sh
#
# toPDF.sh
#
# Usage: toPDF.sh [-o] INPUTFILE
#
# Compiles a file to a temporal PDF using pandoc, updating the temporal file if
# it already exists.
# Opens the file with $READER if -o option is given.
open=""
if [ "$1" = "-o" ]; then
open="1"
shift
fi
[ -z "$1" ] && exit 1
targetDir="/tmp/toPDF"
sourceFile="$1"
targetFile="${targetDir}/${sourceFile##*/}"
targetFile="${targetFile%.*}.pdf"
extension="${sourceFile##*.}"
texengine="xelatex"
pandocLuaScriptsFolder="$XDG_CONFIG_HOME/pandoc/luascripts"
pandocPlantUmlLuaScript="diagram-generator.lua"
[ -d "$targetDir" ] || mkdir -p "$targetDir"
case "$extension" in
"tex")
"$texengine" -output-directory "$targetDir" "$sourceFile"
;;
*)
plantUmlCode=""
plantUmlScriptPath="${pandocLuaScriptsFolder}/${pandocPlantUmlLuaScript}"
[ -f "$plantUmlScriptPath" ] &&
[ -n "$PLANTUML" ] &&
grep -q '```{\.plantuml' "$sourceFile" &&
plantUmlCode="--lua-filter $plantUmlScriptPath"
pandoc --pdf-engine="$texengine" "$sourceFile" $plantUmlCode -o "$targetFile" > ~/logs/toPDF.log
;;
esac
[ -n "$open" ] && "$READER" "$targetFile" &
|