inukshuk / citeproc-ruby

A Citation Style Language (CSL) Cite Processor
103 stars 23 forks source link

Rendering verbatim author strings with `{}` #77

Open mjy opened 3 years ago

mjy commented 3 years ago

Checking to see if I'm missing something obvious.

When I want to render a verbatim author string (e.g. Consortium of Grand Poobahs), then the author string is parsed.

Code is a wrapper, not native, but you can see what I'm getting at here:

a.author = 'Consortium of Grand Poobahs'
ap a.render_with_style('vancouver', 'text', false)
# => "Grand Poobahs C of. TaxonWorks - Codebase [Internet]. d: c; 2021. Available from: https://taxonworks.org"

vs.

a.author = '{Consortium of Grand Poobahs}'
ap a.render_with_style('vancouver', 'text', false)
"{Consortium of Grand Poobahs}. TaxonWorks - Codebase [Internet]. d: c; 2021. Available from: https://taxonworks.org"

I note that {} in author is being assigned in to_citeproc as "author"=>[{"family"=>"{Consortium of Grand Poobahs}"}, this is probably why it renders "cleanly".

Questions:

Thanks!

inukshuk commented 3 years ago

If you pass the author as a single string, it will try to parse it. The {} cause the parsing to fail, so it falls back to the literal input instead. So this behavior is incidental, the brackets do not preserve the string by definition.

In order to by-pass name passing you can pass the author as an object. Since this is a literal name and not a personal name with family/given parts you would want to set it to: { "literal" => "Consortium of Grand Poobahs" }.

mjy commented 3 years ago

Wonderful, thanks.

A followup, we're getting to citeproc form using the BibTeX::Entry.new(bibtex_type: bibtex_type).to_citeproc pattern. Is there a similar convention for BibTeX::Entry for literals that could be used so that I won't have to tweak the to_citeproc return?

E.g. this transition:

b.author = {literal: 'foo and the bar'}
 => {:literal=>"foo and the bar"} 
2.7.4 :028 > b.to_citeproc
 => {"publisher-place"=>"d", "author"=>[{"family"=>"{:literal=>\"foo and the bar\"}"}], 
inukshuk commented 3 years ago

I don't think bibtex-ruby has the concept of literal names, so you'll likely need to implement or tweak the conversion to CSL-JSON.