0

Continuing LaTeX Labels: Any Constraints on Length , are different labels also always considered different by (La)TeX? Let's assume that two labels fit into buf_size and pool size (and the corresponding lines involving the labels fit into the .aux file, too), are these labels also always considered different? Or are the differences in case ignored, as in BASIC (e.g., ABC=abc)? Or is the equality check based on only 𝑛 first or last symbols, for some natural number 𝑛?

(Background of the question: I speak from experience on programming languages.)

2
  • 2
    Different labels are, well, considered different. There are cases in the TeX ecosystem where case is disregarded, notably keys in BibTeX files (you can announce an entry as @book or @BOOK or even @BoOk; author= can also be AUTHOR= and so on). However, TeX is case sensitive and does not “truncate”. It’s perhaps interesting to know that TeX78 had a length limit on control sequence names and characters beyond that bound were ignored; this was removed in TeX82.
    – egreg
    Aug 30, 2022 at 9:16
  • @egreg Thanks! (Probably, such a limit has been hiding in the back yard of my memory since I read a document on that old TeX78 :-).)
    – user224332
    Aug 30, 2022 at 9:31

2 Answers 2

3

\label{foo} is essentially \expandafter\def\csname r@foo\endcsname and \ref{foo} is essentially \expandafter\somecommand\csname r@foo\endcsname together with some indirection via writing to the aux file so the definition survives between runs.

So the rule for labels are just the rules for csnames generally. So the same as environment names, or names of keys in keyval or ...

3
  • Thanks! Can two of these control-sequence names be considered equal (e.g., because they coincide on first/last 𝑛 symbols or because they differ just in capitalization) though they are different byte sequences?
    – user224332
    Aug 30, 2022 at 9:15
  • 2
    @GeekestGeek considered by who? I could consider \foo and \FOO to be the same, TeX would not unless I do \let\foo\FOO in which case they would have the same definition unless one of them is redefined. but nothing special about capitalisation, you could make \FOO and \BAR be the same Aug 30, 2022 at 9:20
  • I mean: considered by Plain TeX and LaTeX (with default settings). Anyway, you answered my question; thanks!!!
    – user224332
    Aug 30, 2022 at 9:29
2

From errorlog.tex (the PDF version is available in TeX Live)

enter image description here

In TeX78 there was a bound on the length of control sequence names (it's unimportant to know what the bound was), but Knuth realized that this was a big problem.

enter image description here

enter image description here

If LaTeX had been written for TeX78 (it wasn't), two different labels could have been considered equal, because the purpose of \label is to define a control sequence name. On the other hand, such task would have been impossible with TeX78, as \csname was introduced on 13 November 1982:

enter image description here

So no, labels that differ by length or by any character (including by letter case) are considered different.

TeX is generally case sensitive. This might not be the same for every program in the TeX ecosystem; for instance BibTeX is case insensitive when entry types of field names are concerned: you can type

@book{...}
@BOOK{...}
@BoOk{...}

or

author = {...},
Author = {...},
AUTHOR = ,

with no difference.

It's possible that some package considers keys that only differ by letter case as the same. This happens, for instance, with usebib, that reads .bib files and has to cope with the quirk above.

Of course, if a label is so long as it doesn't fit in buf_size or pool_size, you get a “Capacity exceeded” error and the problem is moot.

You must log in to answer this question.