Various characters are forbidden for various reasons, but it is tricky to come up with a simple list that works for all possible tools (not all .bib-file related tools use the same library to parse .bib files, most notably Biber has much stricter requirements than BibTeX, but there are many other tools out there with who knows which restrictions).
BibTeX
On the BibTeX side the only characters that seem to be forbidden in an entry key are the space , } and , due to the syntax of a .bib entry
@<type>{<entry key>,
<field> = {<contents>},
}
Generally, non-US-ASCII characters are not guaranteed to be processed properly, but since they are generally passed through as is, things mostly work on the BibTeX side.
Biber
Biber is a bit more fussy about entry keys and disallows
" # ' ( ) , = { } %
See Using BibTeX keys containing parentheses with Biber.
LaTeX
Many characters are disallowed on the LaTeX side either when the processed .bib data is passed back to LaTeX or when LaTeX needs to tell BibTeX which entries to fetch. Note that the exact characters that are forbidden may very well depend on the exact citation/bibliography packages you load.
For example BibTeX accepts { in an entry key, but this will very likely error on the LaTeX side since the { would open a group that would not be closed properly.
Similarly, # has a special meaning for LaTeX and can in general not appear outside of macro definitions.
% starts a comment and is therefore problematic.
Since \ starts command sequences it is also dangerous
This gives us
{ } # % \
Another possible source of issues are active characters like ~, since they might expand to something that cannot be written out cleanly into the .aux file.
The way pdfLaTeX works means that non-US-ASCII characters are also implemented via active characters and so with pdfLaTeX it is best to stay clear of non-US-ASCII characters as well.
All of this suggests that on the LaTeX side A-Za-z0-9 as well as safe punctuation like .:;-_!?"'+=*/ might be acceptable. Some punctuation is made active by some babel language modules. Often this happens in a way that still allows these punctuation characters to be used in entry keys.
But there is no guarantee. babel-german makes the " active, so it can be used as a shorthand (e.g. "a for ä). Then the behaviour of " depends on the following character.
\documentclass[ngerman]{article}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{natbib}
\begin{filecontents}{\jobname.bib}
@book{".,
author = {Anne Elk},
title = {A Theory on Brontosauruses},
year = {1972},
publisher = {Monthy & Co.},
location = {London},
}
\end{filecontents}
\begin{document}
Lorem \citep{".}
\bibliographystyle{plainnat}
\bibliography{\jobname}
\end{document}
works, but
\documentclass[ngerman]{article}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{natbib}
\begin{filecontents}{\jobname.bib}
@book{"',
author = {Anne Elk},
title = {A Theory on Brontosauruses},
year = {1972},
publisher = {Monthy & Co.},
location = {London},
}
\end{filecontents}
\begin{document}
Lorem \citep{"'}
\bibliographystyle{plainnat}
\bibliography{\jobname}
\end{document}
doesn't.
A popular character in labels is :, which does not work with babel-french if you don't listen to the warning produced by natbib
\documentclass[french]{article}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{natbib}
\begin{filecontents}{\jobname.bib}
@book{elk:bronto,
author = {Anne Elk},
title = {A Theory on Brontosauruses},
year = {1972},
publisher = {Monthy & Co.},
location = {London},
}
\end{filecontents}
\begin{document}
Lorem \citep{elk:bronto}
\bibliographystyle{plainnat}
\bibliography{\jobname}
\end{document}
: works if you load natbib before babel as recommended by the warning.
LaTeX offers you a great many ways to shoot yourself in the foot. For example in the following MWE k is no longer allowed in entry keys
\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage{babel}
\begin{filecontents}{\jobname.bib}
@book{elk,
author = {Anne Elk},
title = {A Theory on Brontosauruses},
year = {1972},
publisher = {Monthy & Co.},
location = {London},
}
\end{filecontents}
\begin{document}
{\catcode`k=\active
\def k{_}
Lorem \cite{elk}}
\bibliographystyle{plain}
\bibliography{\jobname}
\end{document}
Other tools
As mentioned in the beginning there are several tools out there that operate on .bib files and depending on the library or method they use to parse .bib entries they might come with their own restrictions.
OK, tell me which characters are safe already
Even though there are contrived examples to the contrary, if you want a list of safe characters, I'd definitely include
A-Za-z0-9
because LaTeX would become almost unusable in case those characters were made active.
I prefer to use only lowercase characters, because I don't trust case sensitivity, but that is just me being weird. I believe a-z0-9 already get you very far, though I think that at least one additional character for visual separation might be useful.
But then it already becomes tricky. . seems pretty safe, since I don't think it is usually made active. Many other punctuation commands could end up active and could break.
()in citation keys, whereasbibtexdoes. This is listed for example in the explanation ofentrykeyin thebiblatexmanual. – daleif Feb 04 '21 at 09:34biblatex+Biber^$&[]+`@is a valid entry key, not that I would ever recommend using it, but it works: https://gist.github.com/moewew/d1aecb41d809ca285f3142260c06d0ff – moewe Feb 04 '21 at 17:18