In line citation with as citekey for easier latex conversion


I want to create a custom citation style, where the in line citation are expressed using the citation key. In the "search by example" it provide many examples, however, I am not sure how to reference bibtex citation key.

The result should look like " as mentioned by \cite{somekey}"

Thank you,
  • Check out the Better Bibtex plugin for Zotero ( It can do this and a lot more for making it easier to work with Zotero in LaTeX.
  • edited March 1, 2016
    Hi there,

    I am also very interested in what OP is asking about. I made a post here about it:

    bwiernik, can you please give some more specific information because I can't find what you are referring to on the BBT website. I think the goal should be to create a Zotero Style in CSL so one can easily switch between say APA, and BIB citation key. Just the press of a button to go from (Author, 2016) to \autocite{Author_2016} and back again!

    Here is the text of the github post:

    Hello all,

    I would like to discuss a possibility for BBT which I hope will be of interest to a few people out there. My sincere apologies if posting here is not the correct way to go about this, but I saw a note saying to leave any ideas in the issue tracker.

    I would like very much to be able to call the citation key defined by BBT in an in-line citation using the Word (or other) plugin. I write my documents using Word and then use pandoc to convert the docx to a tex file, which pandoc does beautifully. I then drop this converted tex output into one of my latex templates. The only thing left for me to do is manually change all of the (Author, 2016) in-line citations to \autocite{author_2016} or \autocite*{author_2016} so biblatex and hyperref can do their thing. I think it is possible to use the Zotero CSL Editor to make a citation style that will give me the desired output, so I won't have to manually type the autocite commands anymore.

    Using the CSL editor, I see that it is relatively straightforward to change the prefix and suffix of an in-line citation. This can be \autocite{ for the prefix and } for the suffix. Now all that's left is to call the citation key set by BBT in the middle! Obviously, the full solution here would require the prefix to be \autocite* when the author name is suppressed in the Zotero Word add-in, and page/section/chapter numbers should also show ( eg. \autocite*[1]{author_2016} ). The astrix should be set by using the suppress author command, and the page number should format as shown by just typing the page number in the Word plugin popup. Citation keys for citations with more than one source should be separated by commas, as biblatex requires. It seems like a bit of a task when I think about it, but I'm really hoping that this project could see some progress, as it would I think make some real strides toward the fastest Word-->LaTex conversion possible. Once complete, a few versions of what I've outlined above could be added to the Zotero citation repository (for people who use cite commands beside autocite).

    The most basic question that I need to know the answer to to get started is how to call the "Citation Key" field generated by BBT in the CSL editor, so the key will show in an in-line citation in Word. I believe this is a "macro," correct? What is the macro name so I can call it in the CSL editor?

    The rest of the workflow is pretty straightforward. Just export the biblatex to a .bib file as usual, copy the pandoc generated latex into a template, and compile. The result is a fully typeset document with about zero conversion work!

    Anyway, I'm not a programming whiz, but I'm willing to learn, so if anyone finds this an interesting possibility and is willing to help me, I'm sure it would be of great use to quite a few people, who work/collaborate in Word, and then typeset with LaTeX and BBT. Thanks everyone!
  • I don't think that's possible. You'd need Zotero to map the citekey to a CSL variable -- likely citation-label. Zotero certainly doesn't do that and I don't think BBT does (or even can, though Emiliano can work magic, so who knows).

    bwiernik, I'm pretty sure, is just referring to BBT's ability to allow drag&drop citekeys on shift+drag
  • Thanks for your comment adamsmith. Is there some way we can check the CSL variable name for the citekey generated by BBT? Perhaps opening the database file in an editor? This is just a matter of getting the BBT and the Zotero devs to talk to each other. Is Emiliano a Zotero dev?
  • Emiliano develops BBT, and he is the only one who would be able to say. The mappings to CSL aren't in the database, BBT would have to actually implement that specifically, and as I said, I'm not even sure that's possible in an add-on.
  • edited March 1, 2016
    Offhand I know three avenues of attack for this; there will likely be more:

    * Monkey-patch CSL.Engine.prototype.getCitationLabel to return the citation key. Doable, but tricky, as I am not even close to understanding how citeproc hangs together internally. Probably allows detection of author-suppression. Oddly enough, the current implementation looks like it's hard-wired for author-year citation style, which more likely than not means I misunderstand either how it's called or what it does.

    * Monkey-patch (replace, really), the CSL.Output.Formats.prototype.rtf."@cite/entry" (since the Word plugin support hard-codes the rtf formatter; BTW, this entry is specified twice in Zotero, so it could be random which is picked). Fairly easy to do; I already have a markdown formatter that accesses the BBT cite keys. There may be enough information to infer author-suppression, but I think at the point the formatter is involved, citeproc has already done most of the work and is likely to have discarded information that specifies this clearly.

    * Inject (through monkey-patching, natch) the citation key into an existing CSL variable, e.g. citation-number. Obvious downside: you lose the legitimate use of an existing CSL variable. Upside: all the rest can probably be handled much more cleanly by creating a new CSL style built on the assumption of availability of this variable. And the CSL style ought to be able to do author suppression cleanly.

    Thoughts, preferences?
  • edited March 1, 2016

    Thanks so much, these are all great ideas. Honestly, the third option sounds closest to what I envisioned, although you are clearly more qualified than me to judge if this is the most feasible way. The benefit of clean author suppression is a big plus here.

    I get that there is a downside in the loss of an existing CSL variable, but, if you think about it, do we really lose any practical value by losing the variable citation-number, for example? I don't see any use cases for this citation style that would require the use of CSL variables besides the one we are monkey-patching with the citation key. Does that seem fair? We really just want the two alternate prefixes: "\autocite{" and "\autocite*{" for author suppression, one suffix "}" The page number is a bit trickier given its required position, but it at least needs its own prefix and suffix "[" and "]" and to have its location changed to between the word autocite and the "{" or the "*" and the "{". I imagine an existing citation style which included the addition of "p." and "chap." etc. could be borrowed for that aspect of the formatting.

    Please let me know if there's anything I can help with! As I said, I'm willing to learn. Thanks so much for your interest in this. I know I'm not the only one who would love to have this!
  • generally I'm fine with 3 (and I'm happy with whatever is easiest for you), but please use a variable not used by Zotero. citation-label is actually CSL, and citeproc-js will handle it. citation-number is used a gazillion of citation styles, so please don't mess with it ;)
  • You mean I could validly set citation-label and the rest would pretty much work? That sounds about as clean as something like this could possibly get.
  • I'm pretty sure that's the case, yes -- no promises, though.
  • Emiliano, just so I understand, when you say "validly set citation-label" how does that work exactly? Are you just reading the citation-label set by BBT and assigning that value to the variable citation-label? Does this all take place in the CSL code?

    I was thinking about two possibilities, of which I am not sure which would be best overall. The first is to do as I have been suggesting, which is read the BBT set citekeys and just use them as variables in the citation style -- and I assume that is what you're thinking of doing. The other would be to tap into the way that Zotero generates citekeys itself (if BBT is not installed). I don't know how it works in Zotero, but obviously it has the ability to generate citekeys (as it does when you export a collection to a .bib). Perhaps this solution would be better in some way because it wouldn't require the use of BBT? Personally, I like BBT and I like to see my citekeys in Zotero, so I prefer a solution which uses the BBT citekeys. Just a thought though, in case this was actually a preferable solution - or easier to implement for some reason.
  • no, this currently requires BBT -- I don't think Zotero will want to map citekeys to CSL before it has a proper citekey field (as the BBT readme explains, currently the citekeys in Zotero are generated on the fly and thus not 100% stable).
  • I gotcha. This is what I thought, but I just wanted to make sure I understood it correctly.
  • edited March 1, 2016
    Well that, and:

    * Re-implementing the BBT key generator means you're re-creating half of BBT. I have no objections, but I don't think you want to go all that baroque if you want to go BBT-less.

    * Even the Zotero citekeys cannot be easily recreated inside itemToCSLJSON (which is the place where I think this should happen) since Zotero citekeys are export-session-unique, not globally unique, and itemToCSLJSON isn't aware of the session it is used in.

    What I could do (what I am halfway done with) is a run-time (aka monkey) patch that simply replaces the citation-label with the BBT citekey after itemToCSLJSON is done. It's a 3-line job, but I'm running into an unrelated error right now that I need to fix first.

    Since this is without a doubt the easiest thing for me to do, I vote option #3, and proceed with the discussion at

    Can't help you with the CSL though. That is some deep voodoo right there.
  • CSL entries have an element called "uri" which (in some instances at least) looks like . I know some parts of this url point towards the library and reference key, but I forgot which. Can someone enlighten me?
  • if I understand the question correctly, the last part i.e. HMF2DP9I , is the item key. Where the URL contains "local" this is always a personal library, since this is an unsynced version of Zotero. After the first sync, URIs contain a library/group ID
  • And if synced, "local" would be replaced by the key of the library? What does the um9cmTFA stand for?
  • the um9cmTFA is a random placeholder (don't ask me why it's there, that part of the schema is pretty old and was never touched).
    Synced URIs look like this:
    Peronsal Library

    Where, obviously, the numbers in the middle are the user/group ID and the code at the end the item key.
  • (note that the actual item doesn't have to be synced -- all URIs look this way once the library has synced once).
  • So would I be correct in interpreting this as

    *<library ID>/items/<reference key>

    means item in personal library; I can see whether it has been synced (because it will have a number instead of "local"), but all I need to know to resolve this item is that it's in library 0/null/1/you know what I mean.

    *<library ID>/items/<reference key>

    means item in group library, and in this case I need that ID to look up the reference.
  • yup that looks exactly right to me.
  • I don't quite follow the last few comments, but no problem. I am curious if you can explain how this will be implemented. Am I correct that Emiliano, you are working on mapping the citekey to a CSL varibable? This will require users to update BBT, no? Sounds great.

    If that's right, I hope to make some progress on the CSL editing to make a viable citation style for the repository. I think it would be relatively straightforward to make several variants, for people who use different cite commands. If anyone is watching this thread and can offer help in this regard, please join in. I think most users would not be concerned about defining bibliography styles for these citation styles, as those will be defined in the tex code. The main goal is jut the in-line citations. Is there any particular style that might be best to start with as a base? I would think any style that supports page/section/chapter abbreviations should work fine.
  • Yes, it will map the citekey to a CSL variable, and yes, it would require people to upgrade BBT. There's a test build at you can try; after installing it, you'll have to go into "about:config" and enable "citekeyInCSLJSON". When you've done this you can export a reference with the standard Zotero CSL-JSON exporter to see if the citation-label shows up; it uses the same method to generate the CSL-JSON objects that are handed to the embedded citeproc. The test build stays up for a week I think.

    WRT how this was implemented: I wrap the Zotero function that usually converts Zotero references to their CSL equivalent; I let it do it's thing, and just add my citation key to the result after its done. Source code is the nine lines starting at One of the simpler ones as far as monkey-patching goes.

    As far as creating CSL styles go, braver souls than me will have to be involved.
  • So awesome! I will test this right now. I just need a little direction, how do I open the about:config? Where do I find this? (Sorry for the easy question).
  • No worries. Depends on whether you use Firefox or Standalone; in Firefox, you just type "about:config" where you would usually type the URL you want to go to. It will give you a stern warning before you're allowed in.
  • Do you mean just open BetterBibTeX JSON.js in a text editor and change false to true for "citekeyinCSLJSON"?
  • I am using standalone.
  • Ah no, the "BetterBibTeX JSON.js" translator is the debug translator from BBT. citekeyinCSLJSON is what they call a "hidden preference"; it's a normal Firefox preference, but I haven't created an UI for it, so you have to go through some hoops to enable it right now. No text editing involved though, this is all inside FF; you find the preference in about:config, double-click it to toggle it from false to true, and you should be good to go.
  • edited March 1, 2016
    Is there a way to do this in standalone? Oh and also, the variable I want to call is "citation-label" is that correct?
Sign In or Register to comment.