Porting Word citations to latex with \cite{}

  • There is no way to access BBT citekeys via Zotero's server API that I know of (though this is the part that I may be wrong about)
    You can sometimes sorta get them -- if they are "pinned", that is, they're in the extra field as

    Citation Key: thePinnedKey

    then the stock bib(la)tex exporter will pick that up as the citekey, and if I'm not mistaken, the Zotero server API uses the stock exporters.

    These are not technically BBTs keys, but BBT will generate that line in the extra field if you request the citekey to be pinned, and will use that citekey instead of generating one itself.
  • Going to BibTeX will work okay with journal articles and most books/chapters, but most other item types will have some pretty serious loss of information in the CSL—BibTeX—CSL loop, so if your plan is to work with pandoc, I recommend sticking with CSL-JSON data.
  • Plus you forego the problems of sentence-case vs title-case.
  • In case not using LaTeX is not an option here, could Zotero Better BibTeX (BBT), or some spin-off, be used to convert a CSL JSON file to a Bib(La)TeX file, possibly via the command line?

    As far as I know, BBT and pandoc-citeproc are the only biblio database conversion tools that actually offer title case conversion between Bib(La)TeX to CSL JSON (and pandoc-citeproc only from Bib(La)TeX to CSL JSON, so not helpful in the present context).

    I have not tested citation-js so far either (actually, could not; it errors out with “TypeError: Cannot read property 'toLowerCase' of undefined”; haven’t found time to investigate), but from what I’ve read in its documentation, I very much doubt it attempts to do title case conversion. Besides, it does not seem to include any support for BibLaTeX - which I consider a serious drawback.
  • It depends on what you mean by "from the command line". BBT can be driven using HTTP; my python test setup uses this to run the test suite, but it requires Zotero to be running, and that's not what people usually mean by command line.

    Since 5.2 it should actually be somewhat feasible to run BBT outside Zotero; translators/workers/zotero.ts shows what should be shimmed. But it'd not be trivial. It's not a route I would recommend unless you're primarily curious whether it can be done. It's very likely saner to try to get pandoc csl to bibtex conversion done.
  • I meant “command line” in a very broad sense (like, for example, the pandoc-zotxt filter, which requires a running instance of Zotero, too).

    And you’re right, I’m primarily curious whether it can be done at all.

    For merely testing whether bib(la)tex files generated by ref-extractor → CSL JSON → BBT → bib(la)tex work better than bibtex from ref-extractor → citation-js → bibtex, the OP wouldn’t need a command line prog; they’d just have to import the former into Zotero, and reexport using BBT. Only if they wanted to do the former on a regular basis, a CLI might be an improvement worth thinking about.
  • Oh yeah, for one-offs you could just use Zotero manually.

    If it's not too high-volume, you can automate the import-export using the stuff I use for my test suite (https://github.com/retorquere/zotero-better-bibtex/tree/master/test/fixtures/debug-bridge). If you put the import CSL-JSON into a unique filename (let's say you rename it to {GUID}.json, you can import it, recognize the imported collection, re-export it and delete the collection from a script to drive the debug-bridge (I happen to use python).

    This is much easier than running BBT outside Zotero.
  • edited September 8, 2021
    Similar to original author of this thread, I am trying to transfer content of my Word doc to LaTex document. I also read another similar thread here https://forums.zotero.org/discussion/56462/in-line-citation-with-as-citekey-for-easier-latex-conversion/.

    I have a word document which contains references managed my Zotero. I want my inline citation to appear as \cite{someCiteKey1, anthorCiteKey2} because I am basically copying and pasting the content of the Word doc into my LaTex document. I change the value of citeprocNoteCitekey to True and installed th custom CSL as suggested in the BBT docs https://retorque.re/zotero-better-bibtex/installation/preferences/hidden-preferences/#citeprocnotecitekey. Now the Word document shows the cite keys but not in the format I expected. The inline cite keys appear as [@someCiteKey1; @anthorCiteKey2]. How do I make the inline cite keys use the \cite{...} command so I can just copy and paste the Word doc to the LaTex doc.

  • That would be the layout line on line 51 if I'd have to guess. I don't know much about CSL styles though. This one was butchered up from an existing style.
  • edited September 8, 2021
    @emilianoheyns Thanks for the quick response and pointing me to the correct section of the code I need to modify. I drafted a modification to your posted custom CSL. I modified line 51 and 53. Can you please confirm if this code is correct: https://pastebin.com/raw/3LDMmkk3 https://pastebin.com/raw/XdwL4Vq3
  • That's what I would do, but I don't really know.

    There's no need to @ me BTW, I already get a notification mail because the forum auto-subscribes one to a thread if you've posted in it. I currently get 2 mails when I'm @-ed.
  • emilianoeheyns: Super sorry for doing @ to you.

    In case anyone is interested, the modified CSL (link below) will insert the \cite command to the inline cite keys.
  • I currently get 2 mails when I'm @-ed.
    (Just to clarify, this would only happen when people @ your other account.)
  • Ah, I see. My main account on the forums is @emilianoeheyns. The other one I screwed up at some point messing with my database, and I'm now using it as a secondary account.
  • Thanks @01baftb, this actually makes it easy to copy text also from Google Docs over to overleaf.

    I was looking into creating a CSL style this week but didn't have the time to dive deep and today I find this thread.


    If I have time I will investigate how we could get this to work with pandoc, because the \cite will be commented out. Maybe the original CSL and then batch replace the [@ would work.
  • It seems the previous modded script I posted no longer works. Maybe it stopped working after upgrading to Zotero 6? I am getting errors like below:
    \cite{[CSL STYLE ERROR: reference with no printed form.]}
  • Are you sure you have the citekey in Extra?
  • I got the script working on. It seems there were some new changes introduced after reading this, https://retorque.re/zotero-better-bibtex/citing/migrating/.

    The new modified script: https://gist.githubusercontent.com/01baftb/dc769574b29891263588a89c62bc2476/raw/67035b0efef81c8633d99e0ddbf4f493c5f79af6/better-bibtex-citekeys-modded-to-use-cite-latex-command.csl

    For those in future that want to convert your Zotero citations in Word into inline LaTex format, e.g. \cite{someCiteKey1, anthorCiteKey2}, then install the above modified CSL script to Zotero.
Sign In or Register to comment.