# Reference undefined in \section with amsbook

I have a section that is devoted to the proof of a theorem, and hence I used

\section{Proof of Theorem~\ref{thm}}


Of course, because of the headers that are capitalized, it asks for \ref{THM} when producing the header, and I get an obvious error. What is the proper way to handle such a case? Below is a MWE:

\documentclass{amsbook}
\usepackage{lipsum}
\newtheorem{thm}{Theorem}
\begin{document}
\chapter{First Chapter}
\section{The Theorem}
\begin{thm}[Lipsum Theorem]
\label{thm}
\lipsum[1]
\end{thm}
\section{Proof of Theorem~\ref{thm}}
\lipsum[1-23]
\end{document}


When compiling I get:

LaTeX Warning: Reference THM' on page 3 undefined on input line 14.


2. PROOF OF THEOREM ??'

• I would say, it's a bug in amsbook. – Michael Ummels Mar 19 '11 at 16:06
• Sorry -- I was looking for a literal error message. I can see the problem now. – lockstep Mar 19 '11 at 16:08
• if the textcase package is loaded, amsmath uses its \MakeTextUppercase. This could be used to work out a solution, since textcase respects \ref, and it further provides a \NoCaseChange macro. – Stefan Kottwitz Mar 19 '11 at 16:45

If you don't feel like hacking around and don't mind just circumventing your problem: a theorem can have multiple labels, so give it \label{THM} as well.

• Just an idea: would it be possible to re-define \label such that it defines a label both in the given form and additionally in uppercase form? Once the bug is fixed one could get rid of this hack. – Christian Lindig Mar 19 '11 at 17:17
• @Christian Lindig -- creating a "double label" will most likely fail in hyperref; at least, if two explicit instances of \label are attached to a single node, hyperref will report that one of them is being ignored. using an uppercase value for the label will always work. – barbara beeton Mar 19 '11 at 20:29
• @barbara beeton: what about having \label (and \ref) uppercase their argument before using it, going for a fully uppercase version (the user can still type in lowercase). – Bruno Le Floch Mar 20 '11 at 1:31

A workaround is to define a new macro that contains the expanded reference and use this macro in the section title:

\edef\mythmref{\ref{thm}}
\section{Proof of Theorem~\mythmref}

• Thanks for your answer. That's what I'm actually already using as a temporary work around, but I'm not entirely satisfied to have some random \edef's in my document. So there doesn't seem to be a native amsbook way to do this? need for a patch? – gniourf_gniourf Mar 19 '11 at 16:16
• @gniourf-gniourf As I said, I think it's a bug. I guess Barbara Beeton can say more on this. – Michael Ummels Mar 19 '11 at 16:18
• @gniourf-gniourf: If this is really a bug and you don't like the \edef-ing, would using uppercase labels from the beginning be an acceptable workaround? – Christian Lindig Mar 19 '11 at 16:29
• @gniourf-gniourf -- the uppercasing of labels in running heads in ams document classes is certainly a weakness; we are aware of it, and the workaround we suggest is indeed to use all-uppercase labels in situations when a label is in a section heading or other text that will go into a running head. so using uppercase labels from the start is acceptable. we will look into the problem during the next review and upgrade, but there are many other problems that are more important, in the sense that there is no simple workaround. – barbara beeton Mar 19 '11 at 20:23

Since amsbook uses a macro \uppercasenonmath, which doesn't capitalize math expressions, you could use the trick to enter math mode for the reference:

\section{Proof of Theorem~$\text{\ref{thm}}$}


• @Stephan: Thanks for your answer. It's a cool trick, but as I also use the hyperref package, this method would force me to also wrap this with a \texorpdfstring command... which seems a bit too clumsy! – gniourf_gniourf Mar 19 '11 at 16:13
• @Stefan, sorry I mispelled your name! – gniourf_gniourf Mar 19 '11 at 16:20
• @gniourf_gniourf: comments can be edited. ;-) – Stefan Kottwitz Mar 19 '11 at 16:24
• @Stefan: But only by mods! – Caramdir Mar 19 '11 at 16:38
• Would be it sufficient to change it to \lowercase{\ref{thm}}? However, this still doesn't allow for arbitrary reference labels. – Martin Scharrer Mar 19 '11 at 22:56

You could define \label and \ref to lowercase their argument before using it, as follows:

\expandafter\def\expandafter\label\expandafter#\expandafter1\expandafter{\expandafter\lowercase\expandafter{\label{#1}}}
\expandafter\def\expandafter\ref\expandafter#\expandafter1\expandafter{\expandafter\lowercase\expandafter{\ref{#1}}}
\expandafter\def\expandafter\eqref\expandafter#\expandafter1\expandafter{\expandafter\lowercase\expandafter{\eqref{#1}}}


Then, label names become case insensitive.

• this can work just fine for one user, but it's a non-starter for repairing the document class. too many authors use "camel case" labels with variations on the same underlying spelling. until authors learn to be more sensible, there's no hope in this direction. – barbara beeton Sep 30 '12 at 21:15
• @barbarabeeton You are right. One thing that could be done is to check that label names which appear in are fully uppercase when using them in headers. So \section would set \@inheadertrue while processing the text, and \ref would check that \if@inheader`, its argument should be entirely uppercase, lest there be a warning explaining to the user what to do. – Bruno Le Floch Oct 6 '12 at 5:46