This question is inspired by Umlauts in label and a quote from an answer to How to automatically add \! in subscripts?

However the best is to avoid _ in labels.

I already name all my labels with a "namespace" (like fig:, eq:, tab: and so on) and avoid umlauts (and Unicode characters anyway), but was wondering if there are more things to consider to avoid compilation errors and conflicts with loaded packages.

What rules and advises exist for naming labels to prevent errors and conflicts?


It is safest to stick to a-zA-Z0-9. Punctuation characters like " and : are subject to being made active by babel. Babel goes to some effort to make things safe even if active but you depend on the individual definitions in the individual language files. Basically the internal key is a macro name and it's a good idea to stick to things that can easily be made into macro names, so (ascii) letters but digits are OK as well.


This is sort of a subjective question, but the usual advice applies: don't use any character that has special meaning to TeX (i.e. catcode other than "letter" or "other"). There may be exceptions but it's annoying to rely on them if you don't understand what they are, and who can really understand what TeX is thinking, or wants to when just making some metadata that is for purely personal convenience? One exception that I do find useful (and memorable) is that spaces are allowed. This allows me to write legible long labels such as \ref{thm:fermat's last theorem}.


Here's my five cent's worth: letters and digits from the standards ASCII character set are safe. Spaces are ok, too, but I have taken up the habit to use _ instead, like in naming files, to make them as portable as possible.

Another thing I can suggest is to use Hungarian notation, as in programming, if you are familiar with it.

Also, a little extra (something I quite regularly stumble over): careful with copy-pasting and modifying equations, you need to modify the label, too!... (Okay, that merely produces a warning on compile, but still...)

  • I was also using underscores in my labels but recently I stumbled upon this answer. Although the usage of underscores is allowed, to be completely safe one should try to prevent using them: tex.stackexchange.com/questions/18311/… – Calvin Kent Jan 19 '19 at 17:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.