Pages

Friday, December 28, 2018

Replacing BibTeX with Citation.js

As part of replacing LaTeX with Markdown for my Groovy Cheminformatics book (now Open Access), I also needed to replace BibTex. Fortunately, Citation.js supports Wikidata and the solution by Lars was simpler than I hoped. Similar to LaTeX, I have citations annotated in the Markdown, but the reference code does not refer to a BibTeX file entry, but to Wikidata (see also Wikidata-powered citation lists with citation.js).

The set up is as follows:
  1. extract the Wikidata Q-codes (which creates references.qids)
  2. using Citation.js to format the reference as plain text
  3. number of the citations and create the bibliography
The first step uses a Groovy script, and the second a very short JavaScript script:

fs.readFile('references.qids', 'utf8',
            async function (err, file) {
  const data = Array.from(await Cite.async(file)).map(
    item => item.id + '=' + Cite(item).format(
      'bibliography', {template: 'vancouver'}
    )
  )
  fs.writeFile('references.dat', data.join(''),
    function() {}
  )
})

The result looks like:



I have yet some things left to do, like add the DOI, and add some Markdown formatting. But the toolkit allows that but also is not urgent.

No comments:

Post a Comment