Search code examples
markdownpandocpdflatexbibtexcitations

Pandoc(md, latex) should generate bibitem in Bibliography


With pandoc I am trying to produce a .tex file by combining a .md and a .bib file. In the resulting latex file, Pandoc already formatted as plain text the inline reference as well as the full reference in the bibliography. However, I like to have the references in \cite and \bibitem format, respectively.

example.md

---
title: Plain Text Workflow
author: Dennis Tenen, Grant Wythoff
date: January 20, 2014
bibliography: example.bib
---

# Section 1

Some sentence that needs citation [@fyfe_digital_2011 argues that too].

# Bibliography

example.bib

@article{fyfe_digital_2011,
    title = {Digital Pedagogy Unplugged},
    volume = {5},
    url = {http://digitalhumanities.org/dhq/vol/5/3/000106/000106.html},
    number = {3},
    urldate = {2013-09-28},
    author = {Fyfe, Paul},
    year = {2011},
    file = {fyfe_digital_pedagogy_unplugged_2011.pdf}
}

Pandoc command

pandoc example.md -t latex -s -S --filter pandoc-citeproc -o example.tex

example.tex (excerpt)

Some sentence that needs citation (Fyfe 2011 argues that too).

\section*{Bibliography}\label{bibliography}
\addcontentsline{toc}{section}{Bibliography}

Fyfe, Paul. 2011. ``Digital Pedagogy Unplugged'' 5 (3).
\url{http://digitalhumanities.org/dhq/vol/5/3/000106/000106.html}.

However, what I want to have is this (essentially what would be in the .bbl file generated by bibtex):

Some sentence that needs citation \citep[ argues that  too]{fyfe_digital_2011}.

\begin{thebibliography}{1}
\providecommand{\natexlab}[1]{#1}
\providecommand{\url}[1]{\texttt{#1}}
\expandafter\ifx\csname urlstyle\endcsname\relax
  \providecommand{\doi}[1]{doi: #1}\else
  \providecommand{\doi}{doi: \begingroup \urlstyle{rm}\Url}\fi

\bibitem[Fyfe(2011)]{fyfe_digital_2011}
Paul Fyfe.
\newblock Digital pedagogy unplugged.
\newblock 5\penalty0 (3), 2011.
\newblock URL
  \url{http://digitalhumanities.org/dhq/vol/5/3/000106/000106.html}.

\end{thebibliography}

I know that I could run pandoc with --natbib --bibliography=example.bib, then compile with pdflatex and bibtex, and make use of \input{example.bbl}. But is there a way to do it properly with pandoc without having bibtex (manually or piped) in between?

By the way, how is pandoc doing it internally when it generates a pdf directly with --filter pandoc-citeproc? If it also just uses these preformatted plain text references, I would be deeply disappointed. Because it looks like that individual styles defined in the preamble of a latex template do not apply in this case.


Solution

  • 1) You cannot. Either you

    • have pandoc generate the reference and bibliography for you (pandoc-citeproc, see point 2) or
    • have it format them for natbib (--natbib) or biblatex (--biblatex), but you have to rely on an external bibtex file (or another compatible format). You will then need bibtex or biber to format your citations.

    2) pandoc-citeproc relies on csl styles. You can find some here and here and you can easily customize them here. Pass it to your pandoc command with --csl= or with a csl: line in the YAML title block. Pandoc looks for files in ~/.csl, you have to give the full path if it's not there or in the same directory as your markdown file.