[Tex/LaTex] What characters are allowed to use as delimiters for BibTeX keys

biberbiblatexbibliographiescodesymbols

Surprisingly, I wasn't able to find the list of symbols which can be used for separating fields in BibTeX keys. Many programming languages have their own lists of exceptions, but it seems there is none, neither for BibLaTeX, nor for Biber.

Consider the following example:

@article{Doe1970,
  author = {Doe, John},
  title = {Lorem ipsum},
  volume = {42},
  date = {1970-01-01},
  pages = {123--456},
}

Common and widely used pattern is [auth][year] (e.g. Doe1970), but what if I would like to include a sequence of homogeneous descriptors (text or numerical fields following one another)? For example, [auth][year][volume][firstpage] would result in Doe197042123, which looks clunky and hard to read; or [auth][shorttitle][year] DoeLoremipsum1970, which also doesn't look great. Can I use something like Doe+1970-42:123 or Doe_Loremipsum;1970 instead?

From what I understand, non-ASCII symbols, white spaces and commas are not allowed, and even though Biber can handle non-ASCII characters, those are usually omitted for better compatibility. However, it would be nice to have a list of characters which are not permitted at all, and a list of recommended symbols which are safe to use and won't cause any troubles upon compilation.

Best Answer

First of all, spaces are not allowed in key names, so we can concentrate on other special characters.

BibTeX

I have prepared the following test file:

@article{a{}b$,
  author={A. Uthor},
  title={With curly braces and dollar},
  journal={Journal},
  year=2011,
}
@article{a-b;^,
  author={A. Uthor},
  title={With hyphen and caret},
  journal={Journal},
  year=2012,
}
@article{a&#,
  author={A. Uthor},
  title={With ampersand and hashmark},
  journal={Journal},
  year=2013,
}
@article{a@_,
  author={A. Uthor},
  title={With at and underscore},
  journal={Journal},
  year=2014,
}
@article{a;:",
  author={A. Uthor},
  title={With semicolon, colon and double quote},
  journal={Journal},
  year=2015,
}
@article{a?!,
  author={A. Uthor},
  title={With question and exclamation marks},
  journal={Journal},
  year=2016,
}
@article{a([)/*],
  author={A. Uthor},
  title={With parentheses, brackets, slash and asterisk},
  journal={Journal},
  year=2017,
}
@article{a+='`,
  author={A. Uthor},
  title={With plus, equals and quotes},
  journal={Journal},
  year=2018,
}
@article{a.<>,
  author={A. Uthor},
  title={With period, less and greater},
  journal={Journal},
  year=2019,
}

and a small test file with a \cite for each entry. Compiling with LaTeX shows problems for a&# because of

! Illegal parameter number in definition of \@fortmp.
<to be read again> 
                   }
l.7 \cite{a&#}

which is not really surprising. Going past the two related errors and running BibTeX shows

Stuff after "}"---line 2 of file strange.aux
 : \citation{a{
 :             }b$}

and

Warning--I didn't find a database entry for "a&##"

again not really unexpected. So I conclude that curly braces, even if balanced, and # are not allowed (but if # was made of category code 12 in the LaTeX document it would go through).

Now I removed the curly braces and the # from the relevant keys. The compilation was successful.

Next experiment is to add \usepackage[czech,turkish,ngerman,french]{babel} to the LaTeX document, which would make several of the characters active, but I got no problem. Note that the .aux file contains

\catcode `"\active 
\catcode `-\active 
\catcode `:\active 
\catcode `!\active 
\catcode `=\active 
\catcode `;\active 
\catcode `?\active 

Next experiment is to have the \cite commands in the argument to another command, I used \emph. Again no problem.

Conclusion

The forbidden characters in the seven bit ASCII range are { } , ~ # % \. I didn't text comma, percent and backslash because they're obviously not acceptable: the first on the BibTeX side, the other two on the LaTeX side.

Also ~ is disallowed (do yourself a test).

Biber

See https://tex.stackexchange.com/a/96918/2388 where it is specified that

" # ' ( ) , = { } %

are disallowed. I guess that also ~ cannot be used (for problems on the LaTeX side like for BibTeX). It goes without saying that the backslash is also out of the question.

Related Question