1 #!/bin/sh 2 3 usage() { 4 printf "$(basename $0) [OPTIONS] <input>.md\n" 5 printf "OPTIONS:\n" 6 printf " -H, --style <file>.tex\n" 7 printf " -l, --lua-filter <file>.lua\n" 8 printf " -o, --output <file>\n" 9 printf " -tc, --two-column\n" 10 } 11 12 md2pdf_path=$(dirname $(readlink -f $0)) 13 style_path=$md2pdf_path"/style.tex" 14 highlight_style_path="$md2pdf_path/tango-grey-bg.theme" 15 # highlight_style_path="$HOME/.local/bin/pygments.theme" 16 cmd="" 17 18 while [ $# -gt 1 ]; do 19 case "$1" in 20 --style-file|-H) 21 shift 22 style_path="$(readlink -f "$1")" 23 shift 24 ;; 25 --lua-filter|-l) 26 shift 27 lua_filter_path="$(readlink -f "$1")" 28 cmd="$cmd --lua-filter $lua_filter_path" 29 shift 30 ;; 31 --output|-o) 32 shift 33 output="$1" 34 shift 35 ;; 36 --two-column|-tc) 37 shift 38 cmd="$cmd -V classoption=twocolumn" 39 ;; 40 *) 41 shift 42 ;; 43 esac 44 done 45 46 [ -z "$1" ] && usage && exit 1 47 48 filename=$(echo "$1" | sed 's/\.[^.]*$//') 49 extension=$(echo "$1" | sed 's/^.*\.//') 50 51 echo "* input file: \`$(realpath --relative-to=$HOME $1)\`" 52 echo "* style file: \`$(realpath --relative-to=$HOME $style_path)\`" 53 [ ! -z "$lua_filter_path" ] && echo "* lua filter: \`$(realpath --relative-to=$HOME $lua_filter_path)\`" &&\ 54 lua_filter="--lua-filter=$lua_filter_path" 55 echo "* highlight style file: \`$(realpath --relative-to=$HOME $highlight_style_path)\`" 56 57 # lua_fiter=$HOME/dox/sync/sync/md2pdf/tables-rules.lua 58 # --lua-filter $lua_fiter \ 59 [ -z "$output" ] && output="$filename.pdf" 60 input_format="markdown+startnum+tex_math_dollars+implicit_figures"\ 61 "+grid_tables+backtick_code_blocks" 62 63 [ "$extension" != "md" ] && \ 64 echo "Input file not markdown" && \ 65 usage && exit 2 66 67 # -V fontsize:12pt \ 68 # --listings \ 69 pandoc --pdf-engine=xelatex \ 70 -V colorlinks=false \ 71 -V linkcolor=black \ 72 -V urlcolor=blue \ 73 -V tables=false \ 74 $cmd \ 75 -H $style_path \ 76 -f $input_format+implicit_figures+raw_tex \ 77 --highlight-style "$highlight_style_path" \ 78 --shift-heading-level-by=-1 \ 79 -o "$output" \ 80 $lua_filter \ 81 "$filename".md 82 83 [ $? -ne 0 ] && exit 3 84 85 printf "\`$output\` generated successfully\n"
