📄 Pandoc - Markdown to PDF on Save
1 min read

📄 Pandoc - Markdown to PDF on Save

📄 Pandoc - Markdown to PDF on Save

Winter is coming. The days are getting shorter and the semester is drawing to a close. Obviously, instead of studying and preparing for my exams, I am wasting my time on optimizing my workflow to write lecture summaries. I write my summaries in Markdown and convert them with Pandoc to LaTex styled PDFs. This has the benefit that I can write down mathematical formulas and code with syntax highlighting seamlessly. Also, I don't need to rely on Microsoft Word which becomes sluggish and unresponsive when editing large documents.

The only drawback is that there are no WYSIWYG Markdown editors which can render the document as the final Pandoc PDF would look like. It is troublesome when you only notice after long writing that the document contains a equation with syntax error and cannot be converted into a PDF.

By using fswatch one can trigger commands when the contents of the specified files or directories are modified.

This means we can trigger Pandoc to converts the Markdown document to PDF after every modification automatically and build a nearly live editor! Here's how to set it up on MacOS:

  1. brew install fswatch
  2. brew cask install skim: A PDF Reader that can reload automatically
  3. Open Skim.app, In preferences under the tab sync, check 'check for file changes' and 'Reload automatically'
  4. Run fswatch:
fswatch -v NMIT2.md | \
xargs -n1 -I{} \
pandoc NMIT2.md -o NMIT2.pdf

4. Open the PDF-File with skim