Generating citekeys for your references

The BibTeX citations keys generated by the standard Zotero exporters are fully auto-generated, using an algorithm that usually generates unique keys. For serious LaTeX users, “usually” presents the following problems:

  • If a non-unique key is generated, which one gets postfixed with a distinguishing character is essentially non-deterministic.
  • The keys are always auto-generated, so if you correct a typo in the author name or title, the key will change
  • You can’t see the citation keys until you export them

For a LaTeX author, the citation keys have their own meaning, fully separate from the other reference data, even if people usually pick a naming scheme related to them. As the citation key is the piece of data that connects your bibliography, this is a piece of data you want to have control over. BBT offers you this control:

  • Set your own, fixed citation keys
  • Stable citation keys, without key clashes. BBT generates citation keys that take into account other existing keys in your library in a deterministic way, regardless of what part of your library you export, or the order in which you do it.
  • Generate citation keys from JabRef patterns

You can also

  • Drag and drop LaTeX citations to your favorite LaTeX editor
  • Show both pinned (fixed) citation keys and dynamically generated ones in the reference list view
  • Search for citation keys (if you select “All fields and tags” in the search box)

Set your own, fixed citation keys

You can fix the citation key for a reference by adding the text “bibtex: [your citekey]” (sans quotes) anywhere in the “extra” field of the reference, or by using biblatexcitekey[my_key]. You can generate a fixed citation key by selecting references, right-clicking, and selecting “Generate BibTeX key”.

Drag and drop/hotkey citations

You can drag and drop citations into your LaTeX/Markdown/Orgmode editor, and it will add a proper \cite{citekey}/[@citekey]/[[zotero://select...][@citekey]. The cite command is configurable for LaTeX by setting the config option in the [[Preferences|Configuration]]. Do not include the leading backslash. This feature requires a one-time setup: go to Zotero preferences, tab Export, under Default Output Format, select “Better BibTeX Quick Copy”, and choose the Quick Copy format under the Citation keys preferences for BBT.

Find duplicate keys through integration with Report Customizer

The plugin will generate BibTeX comments to show whether a key conflicts and with which entry. BBT integrates with Zotero: Report Customizer to display the BibTeX key plus any conflicts between them in the zotero report.

Configurable citekey generator

BBT also implements a new citekey generator for those entries that don’t have one set explicitly; the formatter pattern language mostly follows the JabRef key formatting syntax in the Better BibTeX preferences (you can get there via the Zotero preferences, or by clicking the Better BibTeX “Preferences” button in the addons pane.

The default key pattern is ​[auth:lower][shorttitle3_3][year]; if you have papers that use keys which were generated by the key generator of the standard Bib(La)TeX exporters of Zotero you may want to use [zotero:clean] instead in order to ease migration from existing exports for people who previously used the standard Zotero Bib(La)TeX exports. You will be offered this choice on first run of BBT.

A common pattern is [auth:lower][year], which means

  1. last name of first author without spaces, in lowercase
  2. year of publication if any,
  3. a letter postfix in case of a clash (this part is always added, you can’t disable it)

note that changing the pattern used to cause all your non-fixed keys to be regenerated in Zotero 4. In Zotero 5, this is no longer the case; changing a pattern will only affect references being created/changed after you changed the pattern. If you want your keys to update after a pattern change you will have to select your references, right-click, and select Refresh. This will not affect keys you have pinned.

If you want to get fancy, you can set multiple patterns separated by a vertical bar, of which the first will be applied that yields a non-empty string. If all return a empty string, a random key will be generated.

Generating citekeys

The full list of functions (extract data from your reference into your citekey) and filters (change the extracted data) is:

Functions

  • authN_M / edtrN_M: The first N (default: all) characters of the Mth (default: first) author’s last name.

  • authEtAl / edtrEtAl: The last name of the first author, and the last name of the second author if there are two authors or “EtAl” if there are more than two. This is similar to auth.etal. The difference is that the authors are not separated by “.” and in case of more than 2 authors “EtAl” instead of “.etal” is appended.

  • authForeIni / edtrForeIni: The forename initial of the first author.

  • authIniN / edtrIniN: The beginning of each author’s last name, using no more than N characters.

  • auth.auth.ea / edtr.edtr.ea: The last name of the first two authors, and “.ea” if there are more than two.

  • auth.etal / edtr.etal: The last name of the first author, and the last name of the second author if there are two authors or “.etal” if there are more than two.

  • authorIni / editorIni: The first 5 characters of the first author’s last name, and the last name initials of the remaining authors.

  • authorLast / editorLast: The last name of the last author

  • authorLastForeIni / editorLastForeIni: The forename initial of the last author.

  • authorsN / editorsN: The last name of up to N authors. If there are more authors, “EtAl” is appended.

  • authorsAlpha / editorsAlpha: Corresponds to the BibTeX style “alpha”. One author: First three letters of the last name. Two to four authors: First letters of last names concatenated. More than four authors: First letters of last names of first three authors concatenated. “+” at the end.

  • authshort / edtrshort: The last name if one author is given; the first character of up to three authors’ last names if more than one author is given. A plus character is added, if there are more than three authors.

  • firstpage: The number of the first page of the publication (Caution: this will return the lowest number found in the pages field, since BibTeX allows 7,41,73--97 or 43+.)

  • journal: returns the journal abbreviation, or, if not found, the journal title, If ‘automatic journal abbreviation’ is enabled in the BBT settings, it will use the same abbreviation filter Zotero uses in the wordprocessor integration. You might want to use the abbr filter on this.

  • keywordN: Tag number N. Note that the tag order is just as Zotero hands it to BBT – no guarantees

  • lastpage: The number of the last page of the publication (See the remark on firstpage)

  • library: returns the name of the shared group library, or nothing if the reference is in your personal library

  • month: the month of the publication

  • origyear: the original year of the publication

  • shorttitleN_M: The first N (default: 3) words of the title, first M (default: 0) capitalized

  • shortyear: The last 2 digits of the publication year

  • title: Capitalize all the significant words of the title, and concatenate them. For example, An awesome paper on JabRef will become AnAwesomePaperonJabref

  • veryshorttitleN_M: The first N (default: 1) words of the title, first M (default: 0) capitalized

  • year: The year of the publication

  • zotero: Generates citation keys as the stock Zotero Bib(La)TeX export does

  • 0: a pseudo-function that sets the citekey disambiguation postfix to numeric (-1, -2, etc, like the standard Zotero Bib(La)TeX translators do) rather than alphabetic (a, b, c). Does not add any text to the citekey otherwise.
  • >X: a pseudo-function which aborts the current pattern generation if what came before it is X characters or less ([>0] is a typical use. You’d typically use this with something like [auth][>0][year]|[title][year] which means if there’s no author you get title-year rather than just year.
  • =typeName: a pseudo-function that aborts the current pattern generation if the Zotero reference type != typeName. You can test for multiple typenames at once by separating them with slashes ([=journalArticle/report]). Valid typeNames are: artwork, attachment, audioRecording, bill, blogPost, book, bookSection, case, classic**, computerProgram, conferencePaper, dictionaryEntry, document, email, encyclopediaArticle, film, forumPost, gazette**, hearing, instantMessage, interview, journalArticle, letter, magazineArticle, manuscript, map, newspaperArticle, note, patent, podcast, presentation, radioBroadcast, regulation**, report, standard**, statute, thesis, treaty**, tvBroadcast, videoRecording, webpage.

Note: the functions above all have the clean filter (see below) automatically applied to them. If you want more control, auth, authIni, edtr, … and all the author-related fields that mimic the JabRef equivalents also have capitalized versions (so Auth, AuthIni, Edtr, …) which follow the same algorithm but do not have any cleaning (diacritic folding, space removal, stripping of invalid citekey characters) applied. These can be used to pass through the filters specified below much like the fields from the table above. See also “usage note” below. For all the non-author fields, you can use the reference fields directly. The possible fields are:

AbstractNote AccessDate AdoptionDate** ApplicationNumber
Archive ArchiveLocation ArtworkSize AssemblyNumber**
Assignee CallNumber Code CodeNumber
Committee ConferenceDate** ConferenceName Country
Court DOI Date DateAmended**
DocumentName** Edition Extra FilingDate
GazetteFlag** Genre** History ISBN
ISSN Institution** Issue IssuingAuthority
JournalAbbreviation Jurisdiction** Language LegalStatus
LegislativeBody LibraryCatalog Medium MeetingName
MeetingNumber** NewsCaseDate** NumPages Number
NumberOfVolumes OpeningDate** Opus** OriginalDate**
Pages ParentTreaty** Place PriorityDate**
PriorityNumbers ProgrammingLanguage PublicationDate** PublicationNumber**
PublicationTitle Publisher References RegnalYear**
Reign** Reporter ResolutionLabel** Rights
RunningTime Scale Section Series
SeriesNumber SeriesText SeriesTitle Session
ShortTitle SigningDate** Status** SupplementName**
System Title Type Url
VersionNumber Volume VolumeTitle** WebsiteTitle**
YearAsVolume**

Flags

  • +initials adds initials to any author name function. Specify using e.g. [auth+initials]

Filters

  • abbr: Abbreviates the text. Only the first character and subsequent characters following white space will be included.

  • alphanum: clears out everything but unicode alphanumeric characters (unicode character classes L and N)

  • ascii: removes all non-ascii characters

  • capitalize: uppercases the first letter of each word

  • clean: transliterates the citation keys and removes unsafe characters

  • condense: this replaces spaces in the value passed in. You can specify what to replace it with by adding it as a parameter, e.g condense=_ will replace spaces with underscores. Parameters should not contain spaces unless you want the spaces in the value passed in to be replaced with those spaces in the parameter

  • fold: tries to replace diacritics with ascii look-alikes. Removes non-ascii characters it cannot match

  • lower: Forces the text inserted by the field marker to be in lowercase. For example, [auth:lower] expands the last name of the first author in lowercase.

  • nopunct: Removes punctuation

  • nopunctordash: Removes punctuation and word-connecting dashes

  • postfix: postfixes with its parameter, so postfix=_ will add an underscore to the end if, and only if, the value it is supposed to postfix isn’t empty

  • prefix: prefixes with its parameter, so prefix=_ will add an underscore to the front if, and only if, the value it is supposed to prefix isn’t empty. If you want to use a reserved character (such as : or \), you’ll need to add a backslash (\) in front of it.

  • replace: replaces text, case insensitive; :replace=.etal,&etal will replace .EtAl with &etal

  • select: selects words from the value passed in. The format is select=start,number (1-based), so select=1,4 would select the first four words. If number is not given, all words from start to the end of the list are selected. It is important to note that `select’ works only on values that have the words separated by whitespace, so the caveat below applies.

  • skipwords: filters out common words like ‘of’, ‘the’, … the list of words can be seen and changed by going into about:config under the key extensions.zotero.translators.better-bibtex.skipWords as a comma-separated, case-insensitive list of words.

  • substring: (substring=start,n) selects n (default: all) characters starting at start (default: 1)

  • upper: Forces the text inserted by the field marker to be in uppercase. For example, [auth:upper] expands the last name of the first author in uppercase.

  • (x): The string between the parentheses will be inserted if the field marker preceding this modifier resolves to an empty value. The placeholder x may be any string. For instance, the marker [volume:(unknown)] will return the entry’s volume if set, and the string unknown if the entry’s volume field is not set.

Usage note: the functions condense, skipwords, capitalize and select rely on whitespaces for word handling. The JabRef functions strip whitespace and thereby make these filter functions sort of useless. You will in general want to use the fields from the table above, which give you the values from Zotero without any changes.


This site is open source. Improve this page