Search code examples
pandoccslpandoc-citeproc

Pandoc citeproc bibliography entries sorting follows the order of entries in bib file


When I convert the markdown file to pdf the order of references in the bibliography is the same as in the .bib file. As a result, the references in the text appear in the wrong order. As a result, I can have in the text sentences like ... reported in [2] after [1] ... while I would like the references to be sorted in the bibliography as they appear in the text, as it would be using unsrt.bib.

The question is: how do I achieve sorting of entries in the bibliography section in order of their appearance in the text?

MWE, compiled using pandoc -C -f markdown testing.md -o testing.pdf

testing.md:

---
bibliography: test.bib
csl: aps.csl
---

The first reference [@second_title_2015]

The second reference [@author_title_2014]

test.bib

@article{author_title_2014,
  title = {The title},
  author = {Author, A. B. and Other, C. D.},
  year = {2014},
}

@article{second_title_2015,
  title = {The other title},
  author = {Second, T. A. and First, F. G.},
  year = {2015},
}

The output

Illustration of the order of the references

Changing the order of @article's in test.bib results in the desired output: The first reference [1] the second reference [2].

I am using the aps.csl taken from zotero style repository: https://www.zotero.org/styles/american-physics-society?source=1

cause of the problem:

I had an outdated pandoc installed by conda (pandoc is a prerequisite for some important packages I needed), and this version took precedence over the default arch installation because of conda's executables dir being in $PATH before /bin/.


Solution

  • Did you use outdated pandoc? I tested your code with pandoc 2.13, which produced the correct output. You can get the latest release here.

    pandoc --version
    pandoc 2.13
    Compiled with pandoc-types 1.22, texmath 0.12.2, skylighting 0.10.5,
    citeproc 0.3.0.9, ipynb 0.1.0.1
    
    pandoc -C -f markdown testing.md -o testing.pdf
    

    enter image description here