In line citation with as citekey for easier latex conversion

2»
  • The link to the hidden prefs should describe how it works for standalone (I use FF, sorry). Yes, citation-label is the var you're looking for.
  • I got the variable changed, thanks. I know you can't help so much on the CSL side, Emiliano, so thanks so much for what you've done so far. I'll keep working/asking for help to get this tested. Been trying for a few minutes to change variable names in a CSL file to "citation-label" but I'm unable to produce the cite key in a word document yet. I'll keep at it! (And probably eventually actually read the guide to editing CSL, haha!)

    If anyone can help with testing this, I have so far just downloaded a test style from the repository, and replaced the author variable with citation-label, but it is not working. Thanks to Emiliano and to all who can help with testing!
  • I could use a different variable if you want, at least for testing.
  • It's likely something I'm doing wrong in the CSL, but Zotero is giving me "[CSL STYLE ERROR: reference with no printed form.]" in Word when I try to insert a citation with the variable set to citation-label.

    If anyone is curious I'm using the "BibTeX generic citation style" as a template. This thing just calls the author's last name, adds an underscore delimiter, then adds the year. I've tried to edit this by telling it to call the citation-label instead of the author-short variable.
  • Different variable? Not sure exactly what you mean. It shouldn't really matter which variable is used, should it? Just so long as it's called properly, no? I'll keep playing with this. I think I have some idea what's going on in the CSl file. I can change the prefix, suffix, item delimiter, and remove the year field. So I assumed just changing the variable author-short to citation-label might do the trick. But apparently not...
  • I mean I could inject the citekey into author-short if you want if that helps with testing.
  • Oh let's try this!
  • I can see that error in the citeproc source, but I can't readily tell what the conditions are that trigger it. Citeproc is some voodoo man.
  • Haha, I'll take your word for it. Well, let's hope there are some citation style experts lurking around that will be able to help actually make something usable out of this! I really think there will be interest in this. Once working, Zotero+BBT+pandoc will be essentially the holy grail of word to latex conversion, and it'll be open source!
  • You can fetch a new build at https://s3.eu-central-1.amazonaws.com/zotplus-builds/zotero-better-bibtex-1.6.36-travis-2446.xpi, but wouldn't it be easier to use http://editor.citationstyles.org/visualEditor/ ? You can add your own csl-json as you wish under "Example Citations/Citations 1/Advanced" and tweak until it works.
  • (BTW there's a lot more to Word to LaTeX conversion, unfortunately; not only must the bibliography be changed to the appropriate \cite and \printbibliography calls, there's also the matter of quote blocks, acronyms, theorems, you name it --- I'd love there to be a good converter, but I haven't come across anything that really does a good job, yet)
  • Awesome. Have to run out for a bit, but will be testing this tonight. Not sure what you mean by add my own csl-json, though. I know you mean in the online CSL editor, right? I had just been editing the CSL file locally on my computer and reinstalling the style in Zotero to test it live in Word.
  • You should be able to import that CSL file into the editor, but with CSL-JSON I mean the references that you want to put through that CSL configuration. The visual editor has a few sample references included, but you can paste raw CSL-JSON in there under advanced; if you want a starter, just export any reference to CSL-JSON using Zotero. It'll yield a JSON file, which is just rigidly formatted plain-text; you can edit it (e.g. to change variable names) and the editor will use that.
  • I've been toying with the visual editor and it picks up the citation-label without issue.

    I get the same "[CSL STYLE ERROR: reference with no printed form.]" if I delete the bibliography section from the style. It looks like citeproc doesn't like it if you output nothing for a reference. And since this is javascript, an empty string very likely counts as nothing. So you can have it produce \printbibliography, but it looks like you must output *something* per-reference, but it can be a fixed string such as "%".
  • yes -- empty strings in Word fields are dangerous as they produce inivisble fields which are a bad idea. That's why citeproc throws that error message on an emptry string. I'd test this in the style editor in Zotero and not the visual editor: https://www.zotero.org/support/dev/citation_styles/reference_test_pane

    I think that would also directly reflect BBTs changes.
  • OK so exporting the CSL JSON and the Better CSL JSON both include:

    "citation-label": "aas_borders_2013"

    (the recent version also includes)
    "author-short": "aas_borders_2013"

    And the citation-label does show up where author-short is being called in the in-line citation! So that's great! Now I can play around with the formatting a bit to make it closer to what I want, but obviously this mapping must change in the final version, right, since we can't have the cite key mapped to the variable author-short?

    Let me play in the online editor a bit and see what comes of it. I'll try to edit the citation style so that I'm calling citation-label instead of author-short, and see if it still displays the citekey as intended.

    OK so a bit of an update. I can get the citekey to display in the online editor after editing the citation style variable to citation-label (changed from author-short). But I don't have it working yet in word, after downloading the style and trying it. Hm... Would love it if a CSL expert could step in right about now! Thanks!!

    Thanks so much Emiliano!
  • edited March 1, 2016
    So just a few thoughts about implementation:

    1. Bibliography is not required. I don't see any reason to include a \printbibliography command, as this will be easily provided by the LaTeX code. Some of us will be using biblatex, and others bibtex. It's easiest to leave this kind of thing in a latex template. For our purposes, we should create a minimum of two citation styles, the first one with \autocite commands for biblatex users, and a second with \citep and \citeyearpar for bibtex users.

    I'm not an expert, but I would think that the citation-label should be wrapped with {} as prefix and suffix, and the locator variable wrapped with [], and placed BEFORE the citation-label.

    One thing complicating this is if there are multiple citations, and if those citations do or do not have page numbers.

    Multiple citations without page numbers look like this:
    \autocite{key1,key2,key3}

    Multiple citations with page numbers look like:

    \autocite[locator]{key1}[locator]{key2} *(actually this probably isn't right, sorry)

    Finally, the commands need to be set as IF statments, with \autocite (or \citep) used as a prefix to the entire entry if author is not suppressed, and \autocite* (or \citeyearpar) if author is suppressed. This is really all that's needed to have a minimally functioning style. In fact, this should actually be quite sufficient for most users! I know there are a ton of other options that biblatex allows for, but this would be an awesome start, just to have what I have described working. I'll try my best...
  • Emiliano, I've been testing with the first test build (2445) and it seems to be working fine in terms of creating the variable "citation-label" and assigning the correct value. Do we need to do anything specific to have this merged to the main branch (hope my github terminology is accurate here, I'm not too familiar with these terms), because it seems to be working great as far as I can tell.
  • just as a note: you can't test for authors being suppressed in CSL. That's not something that CSL defines currently (it's just something that reference managers do).

    Getting the outer delimiters of a citation to be different depending on the presence of locators is also going to be tricky.
  • I can merge the former behavior (only citation-label) preferably as soon as you have something that works to your satisfaction. I'd rather hold off merge/release for another few days to see if you need anything else. A BBT release causes a BBT cache drop, so I've grown a little more cautious about my release-every-day approach I used to have.
  • @adamsmith that's interesting; does Zotero hand the label to citeproc-js? How else would author suppression work if it's not handled by citeproc-js? I'm caught up in my bibtex frame of mind, where the citation processor does this kind of thing, not the reference manager, so my intuitions will be off on this.
  • Emiliano,

    Unfortunately I have some bad news for this project. Everything works PERFECTLY in the online editor. However, in the actual Word plugin, we are not able to access the CLS JSON containing the variable you created! If you look at the zotero plugin on github, you will not find the string
    CSL.Engine.prototype.getCitationLabel. There is no way to get our variable into the "item-data." This basically stops us dead in the water. You can see in the field code that your variable is totally non-existent in the code the Word plugin generates, and there is no way to pull it in without going deep into Zotero itself, as far as I can tell. If anyone has any suggestions (and I'd like to talk to the Zotero devs about this) -- please leave a message.
  • CSL.Engine.prototype.getCitationLabel lives at https://github.com/zotero/zotero/blob/4.0/chrome/content/zotero/xpcom/citeproc.js#L2145 , but I really have no idea how the word plugin works; I always thought it just talked to Zotero and had it do the work of generating labels & bibliographies.

    This forum is more for user-oriented stuff I think; the zotero devs more usually talk about devvy stuff at https://groups.google.com/forum/#!forum/zotero-dev .
  • Hi,

    I know that this is an old series of posts, but I was wondering where this stood. I was trying to include the citation key in a CSL file for use in LibreOffice/Word, but I don't see any way to currently do it and I can't find the option mentioned above, presumably because it was removed as ineffective?

    Thanks,
    David
Sign In or Register to comment.