inukshuk / citeproc-ruby

A Citation Style Language (CSL) Cite Processor
101 stars 22 forks source link

Truncate authors with `, et al.` for an arbitrary length of authors #39

Closed dazza-codes closed 8 years ago

dazza-codes commented 8 years ago

When generating a Chicago style citation, we want to truncate long author lists with , et al. after 5 authors, when using the chicago-author-name style from the csl-styles gem. For example, given this citeproc-ruby input:

csl_citation_data = {"id"=>"sulpub",
 "type"=>"article-journal",
 "author"=>[{"family"=>"Sohl", "given"=>"G."}, {"family"=>"Odermatt", "given"=>"B."}, {"family"=>"Maxeiner", "given"=>"S."}, {"family"=>"Degen", "given"=>"J."}, {"family"=>"Willecke", "given"=>"K."}, {"family"=>"SecondLast", "given"=>"T."}, {"family"=>"Last", "given"=>"O."}],
 "title"=>"New insights into the expression and function of neural connexins with transgenic mouse mutants",
 "page"=>"245-259",
 "publisher"=>"ELSEVIER SCIENCE BV",
 "container-title"=>"BRAIN RESEARCH REVIEWS",
 "volume"=>"47",
 "issue"=>"1-3",
 "issued"=>{"date-parts"=>[["2004"]]}}
item = CiteProc::CitationItem.new id: 'sulpub'
item.data = CiteProc::Item.new(csl_citation_data)
csl_style = CSL::Style.load('chicago-author-date')
csl_renderer = CiteProc::Ruby::Renderer.new format: 'html'
csl_renderer.render item, csl_style.bibliography
#=> "Sohl, G., B. Odermatt, S. Maxeiner, J. Degen, K. Willecke, T. SecondLast, and O. Last. 2004. “New Insights into the Expression and Function of Neural Connexins with Transgenic Mouse Mutants.” <i>BRAIN RESEARCH REVIEWS</i> 47 (1-3). ELSEVIER SCIENCE BV: 245–59."

We want to get back a truncated author list, i.e.

expected: "Sohl, G., B. Odermatt, S. Maxeiner, J. Degen, K. Willecke, et al. 2004. ...
     got: "Sohl, G., B. Odermatt, S. Maxeiner, J. Degen, K. Willecke, T. SecondLast, and O. Last. 2004.  ... "
dazza-codes commented 8 years ago

Found a fix for this, using:

  CSL_STYLE_CHICAGO = CSL::Style.load('chicago-author-date')
  CSL_STYLE_CHICAGO_ET_AL = begin
    # Modify the bibliography attributes so it uses 'et al.' after 5 authors
    style_et_al = CSL::Style.load('chicago-author-date')
    style_et_al.bibliography.attributes['et-al-min'] = 1
    style_et_al.bibliography.attributes['et-al-use-first'] = 5
    style_et_al
  end