Export 'LaTeX' Form

edited May 11, 2018
I have a title, say "Emergence of a $k$-Core", and I would like Zotero to export precisely this, not escape the $-s to give "Emergence of a \$k\$-Core". In this discussion [https://github.com/retorquere/zotero-better-bibtex/issues/124] someone explains that this can be done by tagging the item "#LaTeX". However, I don't want to have to do this for every item. (Other discussions suggest that you can tag multiple items at the same time using the "tag selector" in the bottom-left of the window... no such thing exists on my screen.) In the above referenced discussion, the person also says "As a matter of fact, if you prefer things this way, you can enable "retain LaTeX on import" in the settings and it will auto-generated any future bibtex imports." However, I cannot find this anywhere in the settings.

So I guess my question is to have (at least) one of the following answered: how do I find the tag selector, so as to be able to tag all my items at once? and where is the "retain LaTeX on import" setting?

Thanks,
Sam
  • If the tag selection is not showing in the client, you can reveal it by clicking at the bottom edge of the client pane below the left-side column.
  • I don't see where to click... I've tried clicking basically everywhere at the bottom left. See this picture (hosted by StackExchange): https://i.stack.imgur.com/RcNqp.png
  • There is also a hotkey to reveal the tag selector. On Linux it's Ctrl-Shift-T. You can check the key combination via Preferences -> Advanced -> Shortcuts.

    (If the hotkey won't bring it up, it will be one for the developers.)
  • That has brought it up :)

    Just for interest's sake, I'd like to know how to do the "retain LaTeX on import" also, if you know about that? (I couldn't find any reference to this via Google other than the link above.)
  • The discussion about it is in the Better BibTeX tracker, so it would be an option supplied by BBT.
  • Are you able to give me a screenshot? I'm not able to find it... thanks :)
  • Sorry, I don't have Better BibTeX installed. Best would be to post a question to BBT support.
  • edited May 11, 2018
    Ok, no problem, thanks. I have come across an issue, however: when I tag everything #LaTeX, this then outputs various &-s, which cause errors. Do you know if there's some way that I can get "&" to output as "\&" (but the rest as they appear?)

    --

    Edit: the same goes for #
  • I'm not clear -- do you actually have the BetterBibTeX add-on installed?
  • With BBT installed, you can do this in 3 ways:

    1. Tag the item with "#LaTeX" (case sensitive)

    2. Enter the title as "Emergence of a <pre>$k$</pre>-Core" (this is BBT-specific, and the "pre" stuff will end up in your bibliography if you're generating the bibliography in e.g. Word)

    3. Using a postscript: https://retorque.re/zotero-better-bibtex/scripting/#detect-and-protect-latex-math-formulas
  • Yes, I do have BetterBibTeX installed. I've been doing option 1 above. The issue is that journals sometimes have an & in them, and this causes errors. Option 3 seems optimal; I don't understand exactly what all the icons /(\$.*?\$)/g mean -- are they all individual? if so why do / and \ appear twice? -- but I think it's what I want. The issue is, I have no idea how to run that script...
  • edited May 11, 2018
    It's in the BBT prefs; see the top of https://retorque.re/zotero-better-bibtex/scripting/

    /(\$.*?\$)/g is a regular expression which, broken down, means:

    1. /( = find and remember

    2. \$ = a literal dollar sign (the backslash means literal)

    3. .*? = any stretch of characters that is not like the next term (. means any, * means zero or more, ? means "but not the next term")

    4. \$ = again a literal dollar sign (so the stretch of characters cannot consume the dollar sign)

    5. )/ = done

    So that finds anything that looks like "$....$". The next part just replaces that with "<pre>$....$</pre>". "<pre>" means "literal latex, do not touch" to BBT.

    It's a heuristic and I'm sure examples can be found where it fails, but a simple synthetic example would be the title "Any price between $4.00 and $5.00".

    (on an entirely unrelated note, it would be really nice if the forum supported github-flavored markdown)
  • (a proper solution would likely involve something like citeproc supporting mathjax, but that's not trivial to do I'd venture to guess)
  • Thanks for your response. It says that I should check which translator my postscript is using, but I have no idea how to do this, really, and the linked page doesn't say how to. It just says to "run something like...", but I don't know how to run anything =P

    I've tried adding the code for the LaTeX formula to the box, but to no avail, unfortunately: the file that is outputted (using Better BibLaTeX) looks exactly the same as without it. I consider myself pretty handy with computers, eg knowing some programming and quite a lot of in-depth troubleshooting, but I can't understand how to do this :/
  • edited May 11, 2018
    Documentation is a bit sparse because it's really just standard javascript. If you know javascript, this should be pretty clear, e.g.
    if (Translator.BetterBibLaTeX) {
    ...
    }
    is a standard javascript snippet to test whether you're running BetterBibLaTeX as the translator.

    If you don't know javascript, that's probably out of scope for a humble documentation page to explain.

    (in which case option 2 is probably the better bet)
  • Does one keep the "..."?

    I could do option 2, but option 3 seems far preferable. It looks very basic, just the documentation doesn't say enough if you don't know javascript. By the look of it though, it just a few easy things...

    Do I need to be using BetterBibTeX (rather than BetterBibLaTeX) for it to work? And if so, do I just choose Better BibTeX (rather than Better BibLateX) from the drop-down export list?

    Thanks :)
  • edited May 12, 2018
    sorry, I didn't see that Emiliano actually has the code you need on the page.
    if (Translator.BetterBibTeX && this.has.title) {
    this.add({ name: 'title', value: item.title.replace(/(\$.*?\$)/g, '<pre>$1</pre>'), replace: true });
    }


    is all you need, just use copy&paste. That includes the translator test. If you want to use it with BetterBibLaTeX, use
    if (Translator.BetterBibLaTeX && this.has.title) {
    as the first line.
  • It can work for either, that's up to your preference. To have it work for both, you'd do

    if ((Translator.BetterBibTeX || Translator.BetterBibLaTeX) && this.has.title) {
    this.add({ name: 'title', value: item.title.replace(/(\$.*?\$)/g, '<pre>$1</pre>'), replace: true });
    }
    you just go into preferences - BBT - Advanced - Postscript and paste this into the text field.

    It is indeed plain javascript. You don't need to understand javascript; the BBT page mentions "but usually you can just open a new issue and ask me to write it, and I’ll add it here".
  • That's perfect, thank you :) -- for some reason, when I saw that the code snippet only had Translator.BetterBibTeX, I assumed that it only worked for BetterBibTeX, not BetterBibLaTeX... I know you're thinking it, and I agree, that's an incredibly stupid assumption! (And yeah, the documentation is plenty... providing you don't have a brain-meltdown as I apparently did!)

    It's working now perfectly, thank you :)
  • Not stupid at all. The postscript facility is both the most complex and the least adequately documented part of BBT.
  • I mean, I don't know javascript, but I've learnt python (or, rather, I had learnt python) and do a fair amount of Matlab. Simply adding in "La" wouldn't have been too much of a stretch =P

    It might be worth making this feature more obvious. For someone using Zotero for maths stuff, it's really vital. Otherwise the output looks terrible, eg $L^2$ becomes \$L^2\$ which prints out as $L(2 with a hat)$. The postscript facility rectifies this completely, and is very simply to implement :)
  • edited May 14, 2018
    I'm not sure how to make it more obvious that wouldn't be really pushy, and it's also a method of last resort. I promote its use for those instances where what the user wants is not a safe universal assumption; changing $ into <pre>$;</pre> is not a behavior I want to make the built-in standard. A lot of times people come with questions on how to do things and it just identifies a change I should make in BBT.
  • So I spent quite a while looking to see how to do it, and only found it when you gave me the link above -- I didn't look into the scripting documentation.

    Hopefully this discussion will be a useful resource in of itself :)
Sign In or Register to comment.