BC Wiki - Pandoc Text Converter

Category: software


Overview

Pandoc is a command line tool for interconverting between markup languages. Pandoc supports common languages like HTML, Markdown, and LaTeX, common document formats like docx and epub, and lots of weird stuff I’ve never heard of before.

For example, Pandoc can convert Markdown with inline $\LaTeX$ into a PDF:

pandoc pandoc.md -f markdown -t latex -s -o pandoc.pdf

You can generate an intermediate .tex file, customize it, then convert it to a PDF in a separate step:

pandoc pandoc.md -f markdown -t latex -s -o pandoc.tex
pdflatex pandoc.tex

To roll right through errors and clean up the $\LaTeX$ build files after generating the PDF, I created this script:

#!/bin/bash
mymd="$1"
mytex="$(echo "$mymd" | sed s/.md/.tex/)"
pandoc "$mymd" -s -f markdown -t latex -o "$mytex"
latexmk -pdf -f -interaction=nonstopmode "$mytex"
latexmk -pdf -f -c