Skip to content

Instantly share code, notes, and snippets.

Created May 23, 2016 20:28
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save anonymous/2f0b993190fd95e9749454903fc89931 to your computer and use it in GitHub Desktop.
Save anonymous/2f0b993190fd95e9749454903fc89931 to your computer and use it in GitHub Desktop.
an easy way to turn formatted text files into PDFs.
#!/bin/bash
# a pandoc script to easily turn formatted text files into PDFs - May 2016.
# based on a script by @pdfkungfoo, minor changes by Ange Albertini
# requires pandoc http://pandoc.org/
# and either XeTeX http://xetex.sourceforge.net/ or LuaTeX http://www.luatex.org/
# Xelatex supports all system fonts by default, and UTF8.
# standard PDFLateX doesn't. LuaLaTex also does but is slower.
# warning: you may have to change manually EOLs to match your OS.
in="${1}"
out="${in}".pdf
fontname="Ubuntu Mono"
paperwidth="11.5 cm"
paperheight="15 cm"
# 1- declare your favorite monospace font
# 2- tweak paperwidth (and paperheight? see below) according to your font
# example:
# for an 40 columns Apple II style output for an E-book screen
# fontname="Print Char 21"
# paperwidth="9cm"
# paperheight="125mm"
# if you are are not sure which exact font name
# to use for XeLaTeX or LuaLaTeX,
# you can use `luaotfload-tool` like this:
# luaotfload-tool --find "Similar Fontname" --fuzzy
# wrap the text file around code marker
echo '~~~' > fence.txt
echo "" >> fence.txt
# you can give paperheight a very big value
# to read with 'fit width' and minimize page changes.
pandoc \
-o "${out}" \
-f markdown \
fence.txt \
"${1}" \
fence.txt \
--latex-engine=xelatex \
-V monofont="${fontname}" \
-V geometry:"paperwidth=${paperwidth}, paperheight=${paperheight}, margin=3mm"
# recommended URLs about programming and old-school fonts:
# http://www.slant.co/topics/67/~programming-fonts
# http://int10h.org/oldschool-pc-fonts/fontlist/
# https://damieng.com/blog/2011/02/20/typography-in-8-bits-system-fonts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment