Skip to content

Instantly share code, notes, and snippets.

@mxpiotrowski
Created April 20, 2024 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mxpiotrowski/0e7d26980db8554b62ca61a476adc958 to your computer and use it in GitHub Desktop.
Save mxpiotrowski/0e7d26980db8554b62ca61a476adc958 to your computer and use it in GitHub Desktop.
-- Time-stamp: <2024-04-20T21:07:41+0200 mpiotrow>
--[[ When converting from biblatex to bibtex, Pandoc only considers
URL fields: DOIs get lost in the conversion (see
<https://github.com/jgm/pandoc/blob/main/src/Text/Pandoc/Citeproc/BibTeX.hs>).
This filter copies the values of DOI fields to URL fields, so that
they are output to bibtex. ]]
function Pandoc(d)
refs = pandoc.utils.references(d)
local i, entry = next(refs, nil)
while i do
if refs[i].DOI then
refs[i].URL = "https://doi.org/" .. refs[i].DOI
end
i, entry = next(refs, i) -- get next index
end
d.meta.references = refs
return d
end
@mxpiotrowski
Copy link
Author

Usage:

pandoc -f biblatex -t bibtex -L doi2url.lua bibliography.bib

I’m using this filter in conjunction with getbib.lua to extract the references cited in a document from the main database (in biblatex format) into a BibTeX file, approximately like this:

pandoc -t bibtex -L getbib.lua -L doi2url.lua --bibliography=bibliography.bib -o references.bib *.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment