inukshuk / citeproc-ruby

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

Support the citation-label standard variable #26

Closed gousiosg closed 9 years ago

gousiosg commented 9 years ago

This will output the processed item's :id when a citation-label variable value is requested in a CSL style.

inukshuk commented 9 years ago

Thanks for this! Could you add a test case for this as well?

inukshuk commented 9 years ago

Having consulted the CSL spec I wonder if we should not go about this in a different way. We could make teh CiteProc Engine add the id as citation-label to each item by default for now, for example. This would then eliminate the need to test for this when rendering text elements -- what do you think?

inukshuk commented 9 years ago

Having thought about this further, I think we should investigate what Zotero and others do to compute the citation-label (if at all); we could then add this behavior to the processor engine, but I'd rather keep it out of the renderer.

Just defaulting to the id only works when your ids actually make sense as labels. If this is the case, then it would be easy to simply set the citation-label of each item to its id prior to importing it into the processor. Does that work for your use case?

rmzelle commented 9 years ago

citeprojc-js generates a "trigraph" type of citation marker for the "citation-label" CSL variable. See e.g. https://forums.zotero.org/discussion/5239/first-letter-of-author-as-citation/?Focus=111233#Comment_111233 . Frank Bennett would know the full details.

gousiosg commented 9 years ago

@inukshuk I am not fully aware of the implementation details of the citeproc, or its uses other than formatting Bibtex citations. In the particular case of Bibtex, the citation key is by definition unique and makes sense as a label.

However, I do not know if this is a generic solution. Feel free to reject this PR (it is a 5 min hack anyway), I can just include my repo in my Gem list until a generic solution is implemented in citeproc.

inukshuk commented 9 years ago

@rmzelle thanks for the pointer!

@gousiosg I would actually suggest that when you convert your BibTeX items for use with the citeproc you simply add the id as the citation-label. I'm assuming that you use BibTeX-Ruby, so you could do something like this to convert your bibliography:

def to_citeproc(bib)
  bib.to_citeproc.map { |item|
    item['citation-label'] = item['id']
    item
  end
end

Alternatively, you could patch the conversion method like this:

class BibTeX::Entry::CiteProcConverter
  def key
    hash['id'] = hash['citation-label'] = bibtex.key.to_s
  end
end

This would ensure that when you use #to_citeproc the citation-label is always set to the item's BibTeX key.

gousiosg commented 9 years ago

@inukshuk Thanks for the tips!