Closed tfwright closed 11 years ago
You can generate citations in 0.6 using the :citation mode. For instance:
require 'bibtex'
require 'citeproc'
bib = BibTeX.parse(DATA).to_citeproc
puts CiteProc.process bib[0], :style => :apa, :mode => :citation
#=> (Derrida, 1967)
bib[0]['locator'] = 42
puts CiteProc.process bib[0], :style => :apa, :mode => :citation
#=> (Derrida, 1967, 42)
__END__
@book{grammatology,
author = { Jacques Derrida },
title = { De la Grammatologie },
year = 1967,
publisher = { Les Editions de Minuit }
}
Please note that the 0.x branch is deprecated as we are currently in middle of a complete re-write of the processor engine. In 0.6 some features that will be in the new version (like disambiguation) have not been implemented.
Thanks a lot!
Just one question, when I follow your example CiteProc.process with the mode option, it returns an array rather than a string. Is that expected?
014:0> BibTeX::Entry.parse(bib).first.to_citeproc
{"id"=>"grammatology", "type"=>"book", "author"=>[{"family"=>"Derrida", "given"=>"Jacques"}], "title"=>" De la Grammatologie ", "publisher"=>" Les Editions de Minuit ", "issued"=>{"date-parts"=>[[1967]]}}
015:0> CiteProc.process BibTeX::Entry.parse(bib).first.to_citeproc
"Derrida, J. (1967). De la Grammatologie . Les Editions de Minuit."
016:0> CiteProc.process BibTeX::Entry.parse(bib).first.to_citeproc, mode: :citation
["(Derrida, 1967)"]
Oh, there's a formatting error there as well: De la Grammatologie .
:-(
Regarding the array output, if I remember correctly this was done because the processor may want to include previous citations that have changed because of the current one. For example, if you quoted another text by Derrida previously and the book was published in 1967, too, the processor may want to return the updated old citation. Having said that, the citation mode is far from finished in 0.6 so there may be another reason for this.
The cite processor API for citation mode is something that we have yet to address in the citeproc ruby re-write as well, so your input on this would be much appreciated (e.g., what are your use-cases, what kind of functionality would you expect from the processor).
That reasoning makes sense, but it seems like a good way to detect that automatically would be to check if the argument is an array.
For my specific use case, I'm trying to represent sources (articles, books etc) as bibliography entries and citations (specific page references, possibly with annotations) in various formats (mla, chicago, apa) and various markup (html, rtf) to facilitate an online collaborative research project.
I had started implementing it a few years back before this project existed that achieved this on a very limited scale with pure ruby, but CSL is much more powerful. Let me know if there's anything I can contribute.
Is there support for generating citation styles? Right now the output for an entry always appears to be formatted for a bibliography.