Printing Markdown Files
Recently I had the need to print the content of one of my Markdown files. I had some notes that I wanted to take with me in physical form. However, the notes were mostly in bullet-point form, so it was terrible for printing. There would be tons of dead space. My goal is to print it in two columns so that the many short lines wouldn’t leave a lot of dead space. I also wanted relatively small text size so that I wouldn’t have a lot of pages to flip through when looking for something.
The tool I’m familiar with to handle this is pandoc. It’s a great tool for converting between different document formats. That includes LaTeX and PDF generation.
The basic format of the pandoc command is as follows. In this case I have a half-inch margin, two columns, 8-point font and am using the FreeSerif font. I’m using the Tectonic PDF engine.
pandoc input.md \
-o Downloads/Rules.pdf \
--pdf-engine=tectonic \
-V classoption=twocolumn \
-V fontsize=8pt \
-V geometry:margin=0.5in \
-V mainfont="FreeSerif"
Fonts
Getting the right font can be tricky. Listing the font names that are available can be accomplished with a quick command. What we are looking for is just the font family name.
fc-list : family | sort -u | less
Running it in Nix
The whole command can be run in Nix without having to install anything by using nix shell. I use the new nix-commands instead of the old nix-shell. pandoc does not come with a PDF backend, I must include tectonic as well.
nix shell 'nixpkgs#pandoc' 'nixpkgs#tectonic' -c \
pandoc input.md \
-o Downloads/Rules.pdf \
--pdf-engine=tectonic \
-V classoption=twocolumn \
-V fontsize=8pt \
-V geometry:margin=0.5in \
-V mainfont="FreeSerif"