booxdown 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. IFS=$'\n\t'
  4. if [ $# -lt 1 ] ; then
  5. echo "$(basename $0) MARKDOWN-FILE" >&2
  6. exit 1
  7. fi
  8. MDFILE=$1
  9. PDFFILE=$(basename $MDFILE .md).pdf
  10. FILE=$(mktemp XXXXXXXXXX-${MDFILE})
  11. HAS_METADATA=0
  12. if head -n 1 ${MDFILE} | grep -- '---' > /dev/null ; then
  13. echo "Metadata Block Found"
  14. HAS_METADATA=1
  15. fi
  16. cat <<EOF >> $FILE
  17. ---
  18. documentclass: scrartcl
  19. classoption:
  20. - DIV=14
  21. papersize: a5
  22. fontsize: 10pt
  23. mainfont: LucidaBrightOT
  24. mainFontOptions:
  25. - Numbers=OldStyle
  26. sansfont: LucidaSansOT
  27. mathFont: LucidaBrightMathOT
  28. monofont: IBMPlexMono
  29. monofontoptions:
  30. - Scale=MatchLowercase
  31. - StylisticSet=3
  32. csquotes: true
  33. links-as-notes: true
  34. highlight-style: monochrome
  35. citemethod: biblatex
  36. pdfa: true
  37. hyperrefoptions:
  38. - breaklinks=true
  39. - bookmarks=true
  40. EOF
  41. if [ $HAS_METADATA -eq 1 ] ; then
  42. cat $MDFILE | sed '1 d' >> $FILE
  43. else
  44. echo "..." >> $FILE
  45. cat $MDFILE >> $FILE
  46. fi
  47. echo "Processing file to PDF."
  48. pandoc -f markdown \
  49. -s -t pdf \
  50. --highlight-style monochrome \
  51. --pdf-engine='lualatex' \
  52. -o $PDFFILE \
  53. $FILE
  54. echo "Done."
  55. rm $FILE