0

Here is a MWE to illustrate a problem I encounter when I try to include an & in a label. Any ideas how to fix this?

\documentclass[14pt,a4paper]{extreport}
\usepackage[latin9]{inputenc}

\newcounter{SlideCounter}
\newcommand{\slide}[1]{%
\stepcounter{SlideCounter}%
\paragraph{\newline Slide \arabic{SlideCounter}) #1}
\paragraph{\newline}}

\begin{document}
I have a document in which I refer to numbered `slides' and I want to label 
the slides to help navigate the document in TeXstudio. TeXstudio has a
document structure window which shows the labels. However, if I include
\& in the label, as in:

\begin{verbatim}
\label{Alvarado Rudy \& design and procedure}
\end{verbatim} 

I get the message: \\

\begin{verbatim}
! Missing \endcsname inserted.
<to be read again> 
\&
l.3 ...varado \& Rudy design and procedure}{{}{1}}

The control sequence marked <to be read again> should
not appear between \csname and \endcsname.

LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right.
\end{verbatim}

\slide{Alvarado \& Rudy design and procedure}
\label{Alvarado Rudy design and procedure}

\slide{Next Slide}
\label{Next Slide}
\end{document}
  • 1
    Information on which characters are allowed in a label can be found here: What are the valid names as labels? – leandriis Apr 25 '18 at 19:25
  • 1
    labels should be treated like identifiers in html or programming languages, short unique internal strings with no spaces or special characters. latex doesn't check and sometimes you can use more characters without error but it is not a good idea to rely on that. – David Carlisle Apr 25 '18 at 20:30
  • 1
    The label is like the barcode on store items. It needs to be unique, but doesn't matter how it is called. – Johannes_B Apr 26 '18 at 5:21
0

OK, the comment from leandriis helped me solve the problem. Using "&" alone, instead of "\&" worked. I had actually tried that previously but got the same error until, after the comment above, I tried clearing the aux file which for some reason was not updated.

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.