Search code examples
pdflatexmarkdownpandocbibtex

LaTeX math in BibTeX citations not working with pandoc


Background

I am using pandoc to convert Markdown → PDF with references incorporated from a BibTeX citation database. I would like a citation in my bibliography to match the typographical conventions in the original article, namely italics and subscripts. The citation in the bibliography should look like this:

enter image description here

I have the following citation exported from Zotero as BibTeX.

@article{stanley_restrictions_1969,
    title = {Restrictions on the Possible Values of $r_{12}$, Given $r_{13}$ and $r_{23}$},
    volume = {29},
    issn = {0013-1644},
    url = {http://dx.doi.org/10.1177/001316446902900304},
    doi = {10.1177/001316446902900304},
    number = {3},
    urldate = {2013-01-04},
    journal = {Educational and Psychological Measurement},
    author = {Stanley, J. C. and Wang, M. D.},
    month = oct,
    year = {1969},
    pages = {579--581}
}

Zotero escapes the dollar signs, brackets, and underscores (\$r\_\{12\}\$) when I export to BibTeX format, but I just use sed to take them out before invoking pandoc. But then pandoc escapes them again. If I convert from Markdown → LaTeX, pandoc produces:

Stanley, J. C., \& Wang, M. D. (1969). Restrictions on the Possible
Values of \$r\_12\$, Given \$r\_13\$ and \$r\_23\$. \emph{Educational
and Psychological Measurement}, \emph{29}(3), 579--581.
doi:10.1177/001316446902900304

which means I get:

enter image description here

Question

How can one include LaTeX math in the BibTeX citations used by pandoc when converting from Markdown → PDF?


Solution

  • It's not supported. Here's an issue on the pandoc bug tracker. Pandoc uses bibutils to read bibtex databases, converting them to MODS XML which is then read by citeproc-hs. Unfortunately, MODS doesn't have any way of representing math. And bibutils doesn't recognize math in bibtex. So there's no clear solution at the moment -- short of writing a bibtex parser from scratch that uses pandoc to convert LaTeX in fields -- maybe not a bad idea!

    The upcoming 1.12 release of pandoc will allow you to include your citation database in a YAML form inside the document itself (or in a separate file). When citations are included this way, simple math will be supported, as well as some other kinds of markup. There will be a tool for converting an existing bibtex database to the YAML form, though because tool, like pandoc, uses bibutils, it won't convert math, and you'll have to modify that later.