larsgw / citation.js

Citation.js converts formats like BibTeX, Wikidata JSON and ContentMine JSON to CSL-JSON to convert to other formats like APA, Vancouver and back to BibTeX.
https://citation.js.org/
MIT License
226 stars 30 forks source link

(optionally) Use CSL object ID as bibtex citation key #181

Closed clbarnes closed 5 years ago

clbarnes commented 5 years ago

The current default {author}{year}{title} scheme doesn't work well with e.g. literal names, and we've got an ID just sitting there not doing anything.

larsgw commented 5 years ago

Are literal names a problem because of reserved characters (like spaces), or are they processed wrong? Either way, would something like this work for you?

plugins.config.get('@bibtex').generateLabels = false // and get them from `id` instead

That's easy for me because it wouldn't be a breaking change then, but I don't know how you're using Citation.js so I don't know if that would work for you.

clbarnes commented 5 years ago

My use case is a tool called citepy which fetches citation data from the python package index and dumps it out as CSL-data JSON, but can obviously only get a raw string for the author (as it might be multiple people, an organisation, etc). I'm then recommending people use citation-js as a command line utility (so not much I can do on the js end) to convert the CSL-data JSON into bibtex/citations.

From what I can tell, the default when the only name is literal is to use nameyeartitle, but that means I end up with e.g.

"Travis Oliphant et al.2019numpy"

As the citation key in my bibtex output, which is unwieldy. But I've already defined what I want the ID to be in the CSL-data's ID field - a command line switch to use it would be great!

larsgw commented 5 years ago

Available in the next update:

citation-js -i INPUT -s bibtex --formatter-options generateLabel=false

Also, I will include a fix which should make the author names, and not just the title, safe for usage as a BibTeX key.