10

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?

Mico
  • 506,678
Christian
  • 515
  • I don't think there are illegal characters for the key, except for (unbalanced) braces, % and backslash. I guess that BibTool is adding some checks on its own. – egreg Oct 22 '16 at 08:04
  • Once more thanks for your quick responce! So @ARTICLE{{}(97), author = {XXX}, title = {YYY} } with key {}(97) is an acceptable format? Do you happen to have any reference to some documentation specifying this? – Christian Oct 22 '16 at 08:09
  • I'm not sure what the legal characters are. I tried looking in the standard sources and found nothing. Oh, obviously the comma! – egreg Oct 22 '16 at 08:10
  • So, any idea how to make bibtool completely ignoring citation keys? – Christian Oct 22 '16 at 08:31
  • Ask the author of BibTool. It's not even distributed in TeX Live, so I can't do experiments; I tried to compile it on my machine, but the instructions are not helpful. – egreg Oct 22 '16 at 08:37
  • I managed to install bibtool and got a few surprises. – egreg Oct 22 '16 at 08:48

1 Answers1

10

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).

egreg
  • 1,121,712
  • 1
    Perhaps note that BibTeX(8) requires the key to be 7-bit, even though other parts of the file can be 'passed through' as UTF-8 or whatever (if not processed by BibTeX). – Joseph Wright Oct 22 '16 at 09:18
  • @JosephWright I considered that as obvious, but I'll add it. – egreg Oct 22 '16 at 09:21
  • Don't think it is, as like I say you can use UTF-8 happily in the bulk of a file if there is no case-changing or whatever in the .bst. – Joseph Wright Oct 22 '16 at 09:22
  • Can you refer to an "official" source where the bibtex format is described? I am not sure what these observations are based on and where the official format is documented. – Sybille Peters Dec 20 '22 at 16:15
  • @SybillePeters You can consult “Tame the BeaST” on your system with texdoc tamethebeast or online at https://texdoc.org/index.html, which would point to https://texdoc.org/serve/tamethebeast/0 – egreg Dec 20 '22 at 16:39
  • @egreg Thanks, I looked in https://texdoc.org/serve/tamethebeast/0 Unfortunately, this also does not seem to give the information what characters can be used for citation key aka internal_key, for example. When writing / evaluating / testing libraries for parsing bibtex etc. I am looking for a more formal description. – Sybille Peters Dec 20 '22 at 16:59
  • @SybillePeters Use alphanumeric characters and you're on the safe side. – egreg Dec 20 '22 at 17:12