paleolimbot / rbbt

R Interface to the Better BiBTex Zotero Connector
145 stars 26 forks source link

New function: Generate .json/.bib file from cited citekeys #4

Closed bwiernik closed 4 years ago

bwiernik commented 4 years ago

The BBT developer has added an endpoint to generate a bibliography file from a list of citekeys. Within this, rbbt could generate a bibliography file from the citekeys that are inserted into a document.

This is the API:

curl http://localhost:23119/better-bibtex/json-rpc -X POST -H "Content-Type: application/json" -H "Accept: application/json" --data-binary '{"jsonrpc": "2.0", "method": "items.export", "params": [[<list of citekeys>], "<format>"] }'

In format you can specify either a name (better at the start not necessary) to get one of the BBT formats, or a translator GUID to get any one that's available at that moment in Zotero.

Could you possibly add a function like rbbt::bbt_bib_file() to extract the citekeys from a document (e.g., using a simple @ regex) and pass these to this endpoint and save the output to a file? Something like:

bbt_bib_file <- function(x, file = "references.bib", format = c("csljson", "biblatex", "bibtex", output_dir = NULL)) {
   ...
}

x here is the path to a file from which to extract the citekeys or the current document in the editor if using the RStudio add-in. file is the filename to save to, format is what format to request from BBT ("csljson" should be the default format because it it pandoc-citeproc's native format and it will yield the highest quality citations).

paleolimbot commented 4 years ago

This is the best news I've heard all day! I'll get it in rbbt in the next few days.

paleolimbot commented 4 years ago

What version? I get

curl http://localhost:23119/better-bibtex/json-rpc -X POST -H "Content-Type: application/json" -H "Accept: application/json" --data-binary '{"jsonrpc": "2.0", "method": "item.export", "params": [["dunnington_etal19"], "csl_json"] }'
{"jsonrpc":"2.0","error":{"code":-32601,"message":"Method not found: item.export"},"id":null}
bwiernik commented 4 years ago

https://github.com/retorquere/zotero-better-bibtex/issues/1503

Should be in the release of BBT within a few days.

paleolimbot commented 4 years ago

Still experimental, but give it a go! I updated the README with instructions. The new bbt_detect_citations() and bbt_write_bib() power most of it.

bwiernik commented 4 years ago

This looks great!

The default translator should probably be csljson. I've mentioned this a few places, but people using pandoc/RMarkdown will only get accurate citations for journal articles and books/chapters when biblatex. Anything else (software, reports, multimedia items) is going to lose information and generate inaccurate citations. Internally, pandoc converts bibtext back to csljson, but fields like "Report type" and "Format" will get lost in the trip.