[Tex/LaTex] Bibtex’s formal format for citation key field

bibtexbibtool

I have seen multiple posts what "nice" formats one might use for bibtex citation keys as in

@ARTICLE{ FormatInQuestion,
   author = {XXX},
    title = {YYY},
}

My question is different, and arises when doing

bibtool --preserve.key.case=on --preserve.keys=on refs.bib > refs_new.bib

where I get

@article{ doi:10.1016/s0012-365x(97)00126-x,
_________________________________^
*** BibTool ERROR:  (line 2101 in ./references.bib): Unexpected character encountered

so even though I ask bibtool to not change the citations keys whatsoever, it complains about having an opening parenthesis ( in the key.

My question is

What format is formally allowed to be used for the citation key "FormatInQuestion"?

As an example, I expect that only a closing parenthesis FormatInQuestion = } is probably not allowed. Is that correct?

Best Answer

I've made a few experiments.

  1. Braces are not allowed. If in initial position they're dropped by the LaTeX argument scanner, in middle position they cause BibTeX to fail

    Stuff after "}"---line 2 of file bibstump.aux
     : \citation{b{ra
     :               }ces}
    I'm skipping whatever remains of this command
    
  2. A comma is obviously disallowed, being the field separator.

  3. The backslash, even escaped, is not allowed because of obvious TeXnical issues.

  4. The percent is not allowed for similar reasons.

  5. Other characters might be dangerous in LaTeX contexts, like double punctuation when French babel is active or straight quotes for several babel languages.

  6. The citation key should consist of printable ASCII characters (with the above mentioned exceptions).

The following .bib file

@article{quo"tes,
  author={A B},
  title={T},
  journal={J},
  year=2000,
}
@article{(paren),
  author={A B},
  title={T},
  journal={J},
  year=2000,
}
@article{o@th[;]er,
  author={A B},
  title={T},
  journal={J},
  year=2000,
}

in a non babel document produces the following .bbl file

\begin{thebibliography}{1}

\bibitem{quo"tes}
A~B.
\newblock T.
\newblock {\em J}, 2000.

\bibitem{(paren)}
A~B.
\newblock T.
\newblock {\em J}, 2000.

\bibitem{o@th[;]er}
A~B.
\newblock T.
\newblock {\em J}, 2000.

\end{thebibliography}

On the other hand, running bibtool on the .bib file with the same options as you have in the question produces

@article{quo"tes,
_____________^
*** BibTool ERROR:  (line 1 in ./bibstump.bib): Unexpected character encountered

*** BibTool WARNING: Skipping to next '@'

*** BibTool WARNING:  (line 7 in ./bibstump.bib): 49 non-space characters ignored.

@article{(paren),
________________^
*** BibTool ERROR:  (line 7 in ./bibstump.bib): Unexpected character encountered

*** BibTool WARNING: Skipping to next '@'

*** BibTool WARNING:  (line 13 in ./bibstump.bib): 46 non-space characters ignored.

So I conclude that the error raised by BibTool is a decision by the programmer (possibly induced by the usage of Perl for the string management).

Related Question