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.
  • @01baftb thanks for the heads up and the modified script.
    I am attempting similar conversion work - I had originally written the document in word using standard APA 7th ed reference style, and am now editing the in-line citations using the modified csl \cite{ script. I also added parentheses to the csl script. This is working in part, but I am running into issues when the citation field in word is not simply (author, date). I.e. when:
    1. more than one reference is used in the citation field, the printed citekey becomes only the first reference, omitting the remaining references in the string.
    2. the citation field had been modified to fit as part of a textual narrative, e.g. ' O'Rourke et al (2020: 188) defined such and such as ... '

    Any help on this is appreciated!
  • Hi guys!

    Any progress here in the topic?
    I was trying to use the CSL style for \cite but all I get is only:

    "\cite{[CSL STYLE ERROR: reference with no printed form.]}"

    Any idea what to do with it?
  • which style exactly are you using?
  • Like Sebex, most of my citations show with

    [CSL STYLE ERROR: reference with no printed form.]

    I am using the style shared by 01baftb, but i have tried modifiying others with the same result and not recognizing the "citation-key" variable.

    When I update the document I can see that some items include the "citation-key" in the "citationItems" and others no. https://pastebin.com/VXKFCats

    If I edit the citation on word and find the same citation on the classic menu it will then correctly show the citation otherwise it gets the same error.

    Using Zotero 6 and the latest BBT plugin on a windows computer. Any advice will be greatly appreciated.

  • Hi all,
    made a new CSL file based on 01baftb script. However I get an error when trying to import/install the style In zotero (using version 6.0.26). Does anybody have any idea?
  • That style requires that you have citation keys defined for all of your items in Extra like this:
    Citation key: Abc123

    The easiest way to have that data entered is to pin the keys using BetterBibTeX
  • Please check here - you need better bitex on zotero, enable ciation keys and install the style in this link, the style will convert citations to keys. https://retorque.re/zotero-better-bibtex/citing/migrating/
Sign In or Register to comment.