Prevent extra braces in BibTeX export

Hello!

I'm using Zotero to generate BibTeX files and I would like to change the way that braces in the title field are handled. For now Zotero puts Braces around every capitalized word in the Title in order to preserve the capitalization. I'm trying to turn off that behavior as I believe it's not the optimal way of doing it.
Most BibTeX and BibLaTeX are able to properly convert titles to lower case but not to convert them to title case. Therefore I am storing all titles in title case (that's also how most get automatically imported via the browser plugin) and put braces around those words that should not be converted in case a style requires lowercase.
Thus for those styles requiring Title case, proper capitalization is already achieved, and for those requiring lowercase it is easy to automatically convert as proper names are protected and will remain as they should be.

For example, this is how a title is stored in Zotero:
Dual Language Education in {Canada} and the {USA}

And when exporting to a .bib file it should produce.
Title = {Dual Language Education in {Canada} and the {USA}},

Unfortunately as of now the words "Language" and "Education" also get braces and I have no idea how to turn that off.
Any help much appreciated!
«1
  • Contrary to what you say, Zotero tends to import titles in sentence case and assumes this is how they're stored for many citation and export formats. BibTeX, lime CSL can transform sentence case into the preferred casing scheme. Zotero is designed to be agnostic to format so does not use BibTeXisms such as adding braces manually.

    I'd this urge you to use sentence casing and edit your BST styles if needed.

    If you'd prefer to use the more idiosyncratic method, you'd need to edit BibTeX.js (or possibly use the better bibtex extension) and put up with the breakage when using anything other than bibtex export (e.g. sharing data with others and the word processor plugins).
  • Thank you, noksagt, for your quick reply!

    Would you be able to let me know how to edit BibTeX.js?
    I'm not using a word processor plugin or sharing so it should be fine,
    I only need the BibTeX export to be tweaked.

    I'm already using the Better BibTeX extension but I couldn't find any option to control the braces.

    You wrote that Zotero tends to import titles in sentence case, but I don't seem to get that behavior on my system (I'm using the Firefox integrated version of Zotero). It seems to respect whatever the format is on the website that it imports the titles from. Google books for example has the books in Title case whereas Google scholar uses sentence case, who knows why. And that's how they end up in my Zotero.
    Or is there a setting how to control this?
  • There is no setting for casing on import. In some cases, Zotero does import whatever the website serves. On some sites where this case is not sentence case, Zotero will try to perform the conversion. Most journal articles should be imported with sentence case from most sources, but this isn't perfect. We may wish to look at fixing the Google books translator...

    If you use Better Bibtex's styles, you will need to consult with their support services for how to do it. They do seem to have settings to control title casing: https://github.com/retorquere/zotero-better-bibtex/wiki/Configuration

    If you use Zotero's style, you may first try to use the hidden BibTeX.export.dontProtectInitialCase preference. If this is insufficient, you'd need to modify the translator.
  • (FWIW, I don't try to force to sentence case in translators, because it can't be done properly because of proper nouns. That's not necessarily the right way to go. Aurimas, when he was still around, suggested forcing sentence case consistently to get users to save in sentence case; that's a larger discussion, though.

    I would suggest manually correcting to sentence case after import where it is in title case so that you get correctly protected proper nouns in Bibtex.
  • @noksagt Thank you for that hint! I had no clue about the hidden prefs, that's a very easy and straightforward solution. Does exactly what I want.

    And it works not only for the BibTeX translator, but also for Better BibTeX!


    @adamsmith I spent some time trying to figure out what the best practice would be for storing titles, and the way that I described above seems to me still the best solution for BibTeX users, although for those using Zotero for export to other formats that's obviously not the case.

    Storing everything in Sentence case and then having it convert to Title Case for those bib styles that require it might work if all titles are in English. But if there's a lot of foreign language stuff, which has different rules then it gets messy, as one would have to keep a language ID field always up to date so that BibTeX or BibLaTeX know how to render each title. Therefore I prefer to store them in Title case, while protecting uppercase words, for English titles or, for other languages I store them in whatever the language demands, in which case I usually protect the entire string. Thus it's easy for BibTeX to convert titles to lower case if required.

    Don't know if there's any better way of doing it?
  • the way that I described above seems to me still the best solution for BibTeX users
    Just to be clear: I use Zotero to produce BibTeX & disagree with this. I suspect I'm not alone or the default settings of Better BibTeX would likely also be different. But I don't use many foreign titles & so autonomous conversion works well for me.

    In any case, this seems like it shouldn't be limited to BibTeX. If the CSL processors are handling casing appropriately, I'd expect some BibTeX-like toolchain should be able to handle it as well.

    If not, it seems like a much better way to go would be to have Zotero store entries in sentence case and fix on export to Bib(La)Tex. The translator could first preserve capitalization using brackets and then perform a sentence-to-title-case conversion for you.
  • If not, it seems like a much better way to go would be to have Zotero store entries in sentence case and fix on export to Bib(La)Tex. The translator could first preserve capitalization using brackets and then perform a sentence-to-title-case conversion for you.
    Without being an expert on this, this sounds right to me. But yes, in Zotero you also do need to use the language field to make sure non-English titles aren't faux-title-cased.
  • edited February 25, 2017
    The rules for capitalization in BibLaTeX as insanely complicated (https://github.com/retorquere/zotero-better-bibtex/issues/541), and it is prudent to brace-protect even words that would seem otherwise OK (e.g. try "The {{U}}.{{S}}. vs {{U.S}}. vs {{U.S.}} VS {U.S.} VS U.S., {I} vs I").

    It is true that the BibTeX importer doesn't undo the titlecasing, but that's a right-click away after import in the Zotero interface.

    Fully agreed with @adamsmith, the way to go is to have references in sentence case in Zotero and let the BibTeX translator deal with Title Casing. That way, you don't have the extra braces (which ought to do no harm BTW), but the rule for the BibTeX exporters is, as it should be, "if you have capitals in your text other than at the start, I must assume you want them there", which is only achievable using braces. The single-wrap braces don't always achieve that BTW for reasons that could drive a man to drink.

    Capitalization is only needed for references that are in English(ish) languages, BTW. I don't know how the stock BibTeX translator does it (I've looked, but I can't find where it would be doing the title casing), but BBT will only do it to English(ish) references. Refs without language specified are assumed to be English.
  • Not sure if this discussion is still open but this is not just about protecting capitals. Take the (English) title:

    "Design of a new 680 nm laser". Here "nm" stands for the nanometer unit, and should be kept in lowercase all the time, even if converted to Title Case:

    "Design of a New 680 nm Laser".

    It doesn't look like Zotero can handle such a case. Of course, in BibTeX, you would protect the case with braces {nm} and everything would be easy.

    Note this is not a BibTeX/LaTeX issue. Exporting to Word or whatever wouldn't work either for cases such as above.

    Also I'm not sure I would agree that this casing issue should be fully handled at the export phase. When using BibTeX, the casing is normally handled by the style file (the BST), and the BIB file should have the data in such a way as it can lead to both correct Title and Sentence case, depending on the style you use. If you export with correct sentence case in the BIB file, and no protection, then use a style that generates title case, you are in trouble for titles like above. Therefore the exporter shouldn't just output whatever case is deemed correct, it should also protect special cases so a conversion down the track is still possible.

    Anyway, irrespective of this later point, if Zotero provides a way to handle my "680 nm laser" case, that would already be a big plus.
  • The following, if entered into a Zotero title field, works with both citeproc-js and Better BibTeX or Better BibLaTeX:

    Design of a new 680 <span class="nocase">nm</span> laser

    Documentation: https://citeproc-js.readthedocs.io/en/latest/csl-json/markup.html#html-like-formatting-tags

    The export via the standard BibTeX or BibLaTeX exporter however is broken and should be fixed:

    title = {Design of a new 680 {\textless}span class="nocase"{\textgreater}nm{\textless}/span{\textgreater} laser},
  • edited February 27, 2017
    I find it interesting that for a long time there was some resistance from the Zotero developers to introduce any kind of markup, especially anything that might look like LaTeX. The (fair) goal was of course not to give special treatment to LaTeX/BibTeX.

    However, if there has to be markup, I can't see why

    Design of a new 680 .span class="nocase".nm./span. laser (using "." for "<" and ">")

    is better than

    Design of a new 680 {nm} laser

    ?? I guess the HTML is more general, but seriously that's a lot of markup to protect one letter. Anyway, happy it can be done. And I think better-bibtex handles it properly.

    Thanks
  • yeah, that's not official Zotero mark-up for just that reason; it just works in the citation processor Zotero uses and is almost certain to keep working there. I'm not liking it much, either. (though html does have the advantage that we can filter it out more easily on export to other formats that curly braces).
  • I don't know what counts as official, but HTML(ish) markup is in the Zotero knowledge base (https://www.zotero.org/support/kb/rich_text_bibliography) even if this particular case isn't. I think it's a pretty sensible choice from the POV of the citation processor. If anything ought to change, I'd say that it would need to be pushed all the way through and the input format would just be a (perhaps limited subset of) xhtml, where even `<` would have to be encoded as `&lt;`, and it'd be up to the editing interface to present it to the user in an intuitive way. At least with HTML(ish) that path is still open, it'd get pretty funky pretty fast with braces.
  • right, the ones in the kb article are officially endorsed by Zotero (and also standard html). The no-case span class is neither. I don't mean to be too negative about it -- it's there for a reason and people find it useful -- just to clarify the different status. It might not matter in the end, but Zotero's firm commitment is only to the html markup listed in the link that Emiliano posted.
    There's long been the desire to implement this more elegantly, i.e. don't display the tags in the field and don't require manual marking up, and when that's implemented, I think we should include a proper solution for no-case tagging (which may well just use the same syntax behind the scenes).
  • We could ask Frank whether he could add < span style="text-transform: none;" > in addition to class="nocase" (and perhaps in time to replace it). That's standard HTML (or rather CSS, but it's standard HTML in the same sense that font-variant:small-caps; is), and shouldn't be hard to add.
  • Hello,

    I'm having trouble getting the tweaks described above in this threat to work again after updating to Zotero 5 (I had been using the Firefox extension prior to Quantum).

    I am trying to suppress adding extra braces for capitalized words in titles upon BibTeX export.
    I have added
    user_pref("extensions.zotero.BibTeX.export.dontProtectInitialCase", true);
    to
    /Users/[name]/Library/Application Support/Zotero/Profiles/[string]/prefs.js
    but to no avail.

    (I'm also using Better BibTeX, not sure if that makes a difference)

    Any hints much appreciated.
  • Better Bibtex has separate preferences and you probably want to use those. They're more flexible.
  • I looked at Better Bibtex preferences, but I couldn't find anything that would do what I need.
    According to
    https://retorquere.github.io/zotero-better-bibtex/configuration/
    there seems to be a hidden pref
    suppressTitleCase
    so now I've tried to add
    user_pref("extensions.zotero.translators.better-bibtex.suppressTitleCase", true);
    to the same
    /Users/[name]/Library/Application Support/Zotero/Profiles/[string]/prefs.js
    but that doesn't do anything either (and that line is also deleted again upon restarting Zotero).
    Any further ideas?
  • edited February 2, 2018
    you set hidden prefs in about:config, accessible from the advanced tab of the prefs. Don't mess with prefs.js (where did that idea come from? I've never seen that recommended here).

    Edit: also, make sure you're using the right translator. BBT preferences affect BBT BibTeX, the other ones the regular one. Finally, what exactly are you after -- this is a pretty complex thread, so it's not entirely clear what behavior specifically you want to prevent.
  • OK, sorry for not providing all the details:

    Essentially:
    I'm trying to prevent the addition of extra {braces} to protect capitalized words in title fields when exporting form Zotero to BibTeX formats.
    I've been storing titles in title case in Zotero and manually protected proper names and words in all caps (I know I'm not following established best practices :/ but there's a few reasons for this: (a) I have lots of foreign language titles where I'd like to keep the original casing, (b) I mostly use Chicago which wants title case anyways, (c) conversion to sentence case is fairly easy in LaTeX but not the other way round.)

    In the previous Firefox Zotero it was working fine, I had Better Bibtex installed and then "extensions.zotero.BibTeX.export.dontProtectInitialCase" to true and all was fine.
    But not any more after updating ...

    Any help?

    PS: I did choose "Better BibTeX" under Export.




  • do you see extensions.zotero.translators.better-bibtex.suppressTitleCase in the configuration editor in Zotero? Have you tried toggling it there?
  • (sorry, I didn't realize you were the same person who originally started the thread)
  • Yes in about:config there's both suppressTitleCase and dontProtectInitialCase and both are set to "true".
  • The name of the Zotero hidden preference should be
    extensions.zotero.translators.BibTeX.export.dontProtectInitialCase

    and with that it works for the stock BibTeX export. You should post to the Better BibTeX issue tracker with the problem with the BBT export not taking that preference (which I can replicate)
  • Ok, great, that was it then. It was "extensions.zotero.BibTeX.export.dontProtectInitialCase"
    without "translators". I've changed it and it works now, although only without Better BibTeX. Thank you for your help!
  • I don't understand what is meant by "only without BBT". Do you mean that the pref for the stock translator doesn't work when you have BBT installed?

    The suppressTitleCase preference ought to work for BBT, if it doesn't I'd appreciate a bug report on the github issue tracker.
  • setting suppressTitleCase to true doesn't work for me with BBT BibTeX (i.e. I still get the same braces). I'm in a rush until tonight, will report properly then.
  • Oops. 5.0.87 should have suppressTitleCase re-enabled.
  • I'm a new user of Zotero. I've also installed BetterBibTeX (BBT).

    I already have "correct" bib files. When I import one of them into Zotero under BBT and export it to a bib file using BBT, it's converted to a "wrong" bib file. By "wrong", I mean a wrong brace protection. For example, when the original was

    Coastal-Trapped Waves and Wind-Driven Currents Over the Continental Shelf

    the converted result was

    Coastal-{{Trapped Waves}} and {{Wind}}-{{Driven Currents Over}} the {{Continental Shelf}}

    Bibtex or biber converts the original correctly to sentence case or title case depending on the style but the braces in the latter prevents that conversion from happening.

    In terms of sentence or title casing, my bib files are inconsistent because the entries are from various sources or from copy-and-pasting from manuscripts and papers. Nevertheless the cases are correctly protected by braces in my bib files.

    So, I'm interested in what's happened to this discussion.
  • The export is correct, it's the import that's wrong - Zotero expects titles to be sentence-cased, not Title Cased. Given the assumption that titles in Zotero are sentence cased, brace-protecting on export this way is the correct thing to do.

    If you right-click the title and convert it to sentence case, the export will change appropriately. I could look at sentence-casing on import, but that's bound to have nasty edge cases, and it would require extensive changes to the parser. I can't make any commitments on this one.

    More generally, a) BBT does not (cannot) guarantee damageless round-tripping of bibtex because of the many subtle and not so subtle differences between the reference model of bib(la)tex and zotero, and b) support for BBT happens on github. I happened to catch this because I posted on this thread before but that's not always going to happen.
Sign In or Register to comment.