9

I usually work with LyX, and when I want to label a section (in order to reference it later), I put the label inside the section heading. This usually works, but recently I tried to create an article using the "Econometrica article" layout, and got a compilation error:

! Missing control sequence inserted.
<inserted text> 
                \inaccessible 
l.4 \section{\label{sec:The-Model}The Model}

Here is a MWE:

\documentclass[english]{ectaart}
\usepackage{babel}
\begin{document}
\section{\label{sec:The-Model}The Model}
\end{document}

(Note: the Econometrica layout comes with LyX installation in an Unavailable status, until one installs the ectaart.cls file).

  • I had an identical problem, and following David Carlisle below updated my labels to ALLCAPS, like \section{The Title\label{SEC:TITLE}}. Of course it's only necessary to do this for the references, but this way LyX doesn't complain about broken refs. – Sean D Nov 7 '17 at 16:19
9

It is actually failing in the \MakeUppercase in the page head. If you add

\usepackage[overload]{textcase}

then \label is safe in such contexts.

| improve this answer | |
  • would this work with \MakeTextUppercase and \uppercasenonmath? unless both of those work without side effects, i can't recommend embedding \label within any heading, from \title on down through `\section', at least not if ams document classes are involved. similarly with the headings of theorem-class objects. – barbara beeton Oct 13 '13 at 16:28
  • @barbarabeeton MakeTeXuppercase works (the overload option mentioned just defines MakeUppercase to be MaketextUppercase) by default \uppercasenomath would not but it looks like that redefines itself if maketextuppercase is available \AtBeginDocument{% \@ifundefined{MakeTextUppercase}{}{\let\uppercasenonmath\altucnm}% } – David Carlisle Oct 13 '13 at 16:35
  • Thanks, this also worked, but, I could not understand why it worked... can you add some explanation? – Erel Segal-Halevi Oct 14 '13 at 7:42
5

You should not use the \label command inside the \section command. Instead you should place the \label command within the section itself.

It doesn't matter where in the section you place it but to avoid confusion it is better to place just after the \section{<title>} command.

Here is a MWE with which you can play (uncomment one of the \label{foo} and comment the other) and see that it doesn't matter where the \label is, the output is always the same.

\documentclass{article}

\usepackage{float}
\usepackage{lipsum}
\begin{document}

\section{First section}
label{foo}

\lipsum[1]
\begin{figure}[H]
\caption{\label{bar}This is a figure}
\end{figure}

%\label{foo}

\lipsum[2]
{\Huge\bfseries This is section~\ref{bar}.}

%\label{foo}

\section{Second section}

\end{document}

The output is the following:

Output

NOTE I know I did not use the etcaart class for the example but the considerations presented above are sort of class independent, and should also work with the etcaart class (even though I haven't tried it).

| improve this answer | |
  • Thanks, this solved the problem. I still wonder, though, why it worked when I used the article class. – Erel Segal-Halevi Oct 13 '13 at 15:20
  • 6
    Putting \label in the section head is supposed to work, just as putting in the \caption is. Placing it after either construct can complicate getting the vertical spacing right in some layouts. – David Carlisle Oct 13 '13 at 15:38

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.