YAML-embedded BibTeX files in Pandoc
hannah
Recently I’ve been writing documents with LaTeX again. It’s a lot of fun, and very rewarding — I highly recommend it. LaTeX doesn’t lend itself to editing on a smartphone, however, and that’s where I do a lot of note-taking. But Markdown is perfect for the task.
Inspired by John Godlee’s post (Godlee 2019), I’ve created a build
file that reads in a regular old .md note and uses a
combination of xelatex, pandoc and some
templates to create PDF and HTML copies. Titles, authors, and
bibliographies are all specified in a YAML block at the top, e.g.
---
title: Some very important note
author: hannah
date: 2024-09-26
bib: references.bib
---
This is some other important note [@hannah20240925].
Pandoc has a few ways to handle citations:
--citeprocworks, but the resulting.texfile uses\citepsequences: I’d rather use vanilla\cite, right?1The
citationsextension to Markdown also works, but I would have to pass in the bibliography as a parameter to Pandoc. I could do that with somegrepmagic, but it seems fragile
My ideal workflow is that Pandoc converts
[@hannah20240925]
to \cite{hannah20240925}, with my LaTeX template handling
the actual citation process. And I found it: --biblatex
does exactly that. My build file contains the line
pandoc -o $OUTPUT --biblatex -s --template=$TEMPLATES/template.tex $INPUT
and the LaTeX template handles citations like so:
[...]
$if(bib)$
\usepackage{biblatex}
\addbibresource($bib$)
$endif$
[...]
$if(bib)$
\printbibliography
$endif$
\end{document}
My Markdown notes are converted into LaTeX, and from there into a PDF2, a standalone HTML file and a partial “bare” file for HD-DN.