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
219 stars 30 forks source link

Ability to output only citation as such, e.g. [ABC99], [Tao03] #182

Closed ComFreek closed 5 years ago

ComFreek commented 5 years ago

Is this library also able to output the pure citation, i.e. not the entry in the bibliography, but the citation in the text? E.g. with alphabetical style, it could produce [ABC99] or [Tao03].

I couldn't find related information in the docs or in the issue list. (Admittedly, I didn't quite know what to search for in the issue list. Searching for citation was not restrictice enough as you can imagine :smile:)

larsgw commented 5 years ago

True :slightly_smiling_face:

TL;DR: (docs)

const cite = new Cite(data)

cite.format('citation', { template, ...options })

Story: Before v0.4.0, the output format for bibliographies was named citation-STYLE (where style is the template). With the transition from Cite#get() to Cite#format() there was the possibility to fix that, so now

cite.get({ style: 'citation-apa' })

became

cite.format('bibliography', { template: 'apa' })

which freed up the namespace to add

cite.format('citation', { template: 'apa', entry: [id1, id2] })

Not entirely sure what template that would be though.

ComFreek commented 5 years ago

@larsgw Thanks for your answer! It seems like a simple plugin with a single output would do the job. I am not entirely sure whether I pursue to use citation.js. For my prototype application where I needed such functionality I hacked something together. Let's see if the prototype survives anyway :smile: (So anyone desiring this functionality, don't wait for me, go ahead yourself, I guess.)

PS: I was heavily confused not to find the sources in this repository (https://github.com/larsgw/citation.js) and then the apparent duplicate (?) repository https://github.com/citation-js/citation-js :smile:

larsgw commented 5 years ago

No problem, for just citation output it may be better to use citeproc-js directly (or something else, if that works for you).

PS: I was heavily confused not to find the sources in this repository (https://github.com/larsgw/citation.js) and then the apparent duplicate (?) repository https://github.com/citation-js/citation-js smile

Yeah, sorry, it's a mess. I intended to move from larsgw/citation.js to citation-js/citation-js but decided to keep this one for compatibility, which only made things more confusing. I'm thinking of coupling the two repositories more tightly, maybe with git submodules?