Closed Brixy closed 10 years ago
This the syntax from the 0.x branch. Starting with the 1.0 release this does not work anymore. Please see the Readme for a more current example. Something like this should work:
cp = CiteProc::Processor.new
cp.import b.to_citeproc
cp.render :bibliography, id: 'sample1'
Thank you very much indeed @inukshuk for answering my silly question!
Unfortunately, I am not familiar enough with ruby and helplessly trying to render
/ruby/
in alphabetical order.
This is my start:
out = BibTeX.parse(bib).map do |b|
if b.respond_to?(:to_citeproc)
array = b[:bibtexkey] # no luck with `bibtexkey`, `key`, `id`
cp = CiteProc::Processor.new style: 'my_style', locale: 'de-DE', format: 'html'
bib_open.convert :latex
cp.import bib_open.to_citeproc
cp.render :bibliography , id: 'test_id' # can’t skip id(?)
else
b.is_a?(BibTeX::MetaContent) ? b.to_s : ''
end
end
out
If anyone could help me, I’d be super-happy :-) Thank you!
The idea is to create a CiteProc::Processor and import all your references. Then you can cite individual references or compile a full bibliography.
cp = CiteProc::Processor.new style: 'apa', format: 'html', locale: 'en'
cp.import BibTeX.open('your.bib').to_citeproc
# one off references
cp.render :bibliography, id: 'x'
# one off citation
cp.render :citation, id: 'x', page: 42
# full bibliography (sorting etc. according to style rules)
bib = cp.bibliography
puts bib.join
Thanks a lot again. I don’t want to be bothersome, really. Hopefully a last question from a ruby newby.
How/where can you include BibTeX-Ruby searches.
Something simple like this will not work:
bib = BibTeX.open('your.bib')[/ruby/]
cp = CiteProc::Processor.new style: 'apa', format: 'html', locale: 'en'
cp.import bib.to_citeproc
Background: The .bib file is just huge but organized with key words. This way I would like to handle all my bibliographies (instead of creating .bib files for each publication).
You could do something like this:
Now your processor 'knows' about every item in your bibliography; you can render an item using the item's id. You can then use queries on the BibTeX library and map the result to a list of ids (you may want to apply sorting before you do that). Finally, use the cite processor to render each item using its id.
Note that this assumes your bibliography does not change anymore after you parsed it.
Strangely, to_citeproc
seemed to be the problem.
Now, here is my very simple solution (citations are treated seperately)
bib = BibTeX.open('your.bib').convert :latex
bib = bib[/my_search_term/]
cp = CiteProc::Processor.new style: 'apa', format: 'html', locale: 'en'
cp.import bib# do not use ´.to_citeproc´ here!
cp = cp.bibliography
cp.join
Thanks a lot for your help and patience, @inukshuk
Ok, my last comment to this issue ;-)
Just learned about $stdout
and this makes everything so easy.
The following code works perfectly. Maybe helpful for someone.
bib = BibTeX.open('your.bib').convert :latex
query_results = bib.query(/my_keyword/)
$stdout = StringIO.new
puts query_results
bib = BibTeX.parse(bib).convert :latex
cp = CiteProc::Processor.new style: 'apa', format: 'html', locale: 'en'
cp.import bib.to_citeproc
cp = cp.bibliography
Dear all!
I am experiencing problems with CiteProc.process.
The following code works like a charme:
With
CiteProc.process
nothing “happens” at all:Hope, anyone can help me! Thank you very much. (Sorry: I don’t know, whether this really is an issue.)