Chris Bissette's Blog

Updated Markdown Workflow

A couple of years ago I posted a few things about my experiments using Markdown and Pandoc to produce quick PDFs that share styling with the properly typeset products I release for A Dungeon Game. That workflow hasn't really changed at all over the past two years, and while I'm happy with the results, I've never been particularly pleased with the actual process of making these things. I'm not a coder and I'm not comfortable in the command line, and I've had a sticky note on my monitor for two years containing my (very simple) Pandoc command because I regularly forget it. I also have my LaTeX template duplicated in every single project folder from the past two years, which is just annoying. (In hindsight I should have set up an export folder that I always use, but it's far too late for that now).

Over the past year or so I've been hunting for a minimal, distraction-free writing solution. I've been looking at things like AlphaSmarts, FreeWrites, the recently-crowdfunded BYOK, etc., but they've all been either out of budget or very hard to get hold of, and really I know in my heart that while I want something with the job of Just Writing and no distractions, I prefer to have a larger screen than any of those devices offer.

This week I realised that what I want is, effectively, a laptop that will boot immediately into a Markdown editor, that will let me sync files using GDrive (or Dropbox, or whatever), and that will do nothing else at all. And what seemed to be the best option to make that happen was to buy an old laptop and put a very minimal Linux distro on it. Having found a laptop that looked suitable on eBay for a very low price this week, I started researching Markdown editors.

Over the past year I've been using Deepdwn as my Markdown editor of choice. I like it a lot and it does almost everything I need it to do, but I was still annoyed by how finnicky exporting things can be (plus having to remember to type my YAML header into every new document). I was 90% sure I'd stick with Deepdwn once I get the Linux machine up and running, but yesterday I decided to look into alternatives.

Enter Zettlr, which has immediately become my editor of choice for the foreseeable future. Super light Markdown editor? Check. Sidebars showing my folders and files so I don't have to navigate away when I'm writing? Check. Actually useful tagging system, unlike Deepdwn? Check.

And then I read the documentation, and realised it has built-in Pandoc support.

I've spent this morning figuring out how to modify the export templates to match what I've been doing with Pandoc and LaTeX, and I now have a one-click export for both PDFs and epubs. It was a bit fiddly to get it working exactly as I wanted, so this is me sharing what I've done in case it's useful to anybody else - especially people like me who aren't particularly good at working this stuff out. For reference, my original YAML headers looked like this:

---
title: 
subtitle: 
author: 
mainfont: Roslindale
sansfont: ITCAvantGardePro-Bold
classoption: table
geometry:
			margin=1in
papersize: b5
linkcolor: blue
output: pdf_document
---

I also have a .tex file that I include in the YAML header in my Pandoc command (rather than a full LaTeX template, which I never managed to get working as I would have liked):

\usepackage{float}
\let\origfigure\figure
\let\endorigfigure\endfigure
\renewenvironment{figure}[1][2] {
    \expandafter\origfigure\expandafter[H]
} {
    \endorigfigure
}

\usepackage{sectsty}
\allsectionsfont{\sffamily\centering}
\subsectionfont{\sffamily\raggedright}
\subsubsectionfont{\sffamily\raggedright}

\rowcolors{2}{gray!25}{gray!0}

Then I run this Pandoc command to make my PDFs:

pandoc -H tex-template.tex InputFile.md -o OutputFile.pdf --pdf-engine=lualatex

As I say, this has been working perfectly for years, it's just a bit of a faff. I also regularly forget to change the output format in my YAML header to epub (or vice versa), which creates some issues with the output.

The first issue I ran into with Zettlr was that I couldn't create new export templates. The functionality is there - if you go to File > Preferences > Asset Manager you'll see a list of all the export template and a pair of + - buttons that imply you should be able to add and delete new templates, but these did nothing when I clicked them. My solution was to navigate to the folder where they're stored (click "Open defaults folder") then duplicate one of the exiting templates. Then I could jump back into Zettlr to edit it.

I only needed to make a couple of changes to the default XeLaTeX PDF template to make everything work.

  1. In the line include-in-header: I added the path to my .tex file.
  2. Under variables:I added the information from my YAML header
  papersize: b5 # Possible values: a0-a6, b0-b6, c0-c6,b0j, letter, executive, legal
  mainfont: Roslindale
  sansfont: ITCAvantGardePro-Bold
  classoption: table
  geometry: margin=1in
  linkcolor: blue

My YAML header (which I have set up as a snippet in Zettlr, so I can automatically insert it into every document) now looks like this:

---
title:
subtitle:
author:
---

Then I set up an export template for reflowable epubs, too. It's always bothered me that I have to edit my YAML header for epubs, both to change the output format and to strip out the font information (since the whole point of epubs is that readers can choose their own fonts). I made a new Export Defaults File in Zettlr, copying and pasting a pre-existing one again as above and simply deleting everything in it before replacing it with this:

reader: markdown
writer: epub
epub-chapter-level: 1
toc: true
toc-depth: 2

And that's it. As of this morning it's all working perfectly and I hopefully never need to type a Pandoc command ever again.

#markdown #pandoc #workflow #zettlr