7

I have a Markdown document with pandoc-style citations such as [@johndoe2014]. This documents needs to be converted to LaTeX for submission to a scientific journal. The LaTeX template of the journal stipulates the use of the cite package, and asks to avoid using additional packages for compatibility purposes.

I am aware that using --biblatex or --natbib options with pandoc, one can convert pandoc-style citations to one of these styles, in our example to \autocites{johndoe2014}.

Would it be possible to automatically convert pandoc-style citations to the cite format, e.g. \cite{johndoe2014}? Thank you.

  • 1
    Maybe I misunderstand the problem, but what's stopping you from doing a 'replace all' autocites->cite in your editor or writing a script to do the same? – Mass Jul 22 '14 at 14:09
  • 1
    ...or you could simply put \let\autocites=\cite into your preamble and don't worry about doing a replace-all. – Andrew Jul 22 '14 at 14:30
  • Can you present a small example? – egreg Jul 22 '14 at 14:52
  • It is highly unlikely that the --natbib option produces \autocites{<key>} since that is not a natbib command. Can you be more precise about how you are calling pandoc? – jon Jul 22 '14 at 17:46
  • @jon \autocites pertains to biblatex, of course, which I have mentioned along with natbib. – Maxim.K Jul 23 '14 at 7:31
5

There is no built-in feature in pandoc that compiles pandoc-style citations to the cite package format. A quick workaround would be to first use the --natbib flag in pandoc to convert to natbib:

pandoc article.md -s --natbib -o article.tex

and then use the following sed commands to rename all the citations from \citet and \citep to \cite as well as change the natbib package in the preamble to cite:

sed -i 's/\\cite[t,p]{/\\cite{/g' article.tex
sed -i 's/{natbib}/{cite}/' article.tex

If you want to avoid overwriting your original .tex file, you can pipe successive sed calls and save to a new file:

sed 's/\\cite[t,p]{/\\cite{/g' article.tex | sed 's/{natbib}/{cite}/' > article-new.tex 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.