16

I am trying to use the acronym package to create an acronym list. The problem is that one of the acronyms I need to use contains an ampersand ('&').

But when I try to compile the .tex file I get this error:

! Missing \endcsname inserted.
<to be read again> 
                   \&
l.2 ...&M}[\AC@hyperlink{M\&M}{M\&M}]{I like them}

Here is an example:

\usepackage{amsmath}
\usepackage{acronym}

\begin{document}

\begin{acronym}
\acro{M\&M}{I like them}
\end{acronym}

\end{document}

So how do I use an ampersand in an acronym using the acronym package?

More generally, how is it possible to apply special formatting to a single acronym? For example

\acro{\textit{IAF}}{Italic acronym frenzy}
egreg
  • 1,121,712
Fred
  • 305
  • 2
  • 8

3 Answers3

17

Completely different way than in my previous answer, is reading the package documentation, for example here.

\documentclass{article}

\usepackage{amsmath}
\usepackage{acronym}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\begin{document}

\begin{acronym}
\acro{FoobAR(tm)}[FoobAR™]{Copyrighted}
\end{acronym}

\begin{acronym}
\acro{MM}[M\&M]{I like them}

\acro{IAF}[\textit{IAF}]{Italic acronym frenzy}
\end{acronym}

\end{document}
egreg
  • 1,121,712
yo'
  • 51,322
9

Perhaps not the best way to input it, but this works:

\acro{M\string&M}{I like them}
egreg
  • 1,121,712
2

You can define macros \makeampletter and \makeampcolsep similar to \makeatletter and \makeatother. This makes & to locally behave like a letter.

\documentclass{article}

\usepackage{amsmath}
\usepackage{acronym}

\def\makeampletter{\catcode`\&11\relax} % <-- HERE
\def\makeampcolsep{\catcode`\&4\relax} % <-- HERE

\begin{document}

\tracingmacros=1
\begin{acronym}
\makeampletter % <-- HERE
\acro{M&M}{I like them}
\makeampcolsep % <-- HERE
\end{acronym}

\begin{tabular}{cc}
Just to test & that ampersand works
\end{tabular}

\end{document}
yo'
  • 51,322
  • Will this work on the registered trademark symbol? – Fred Mar 08 '12 at 22:11
  • At first I was sure it will work with \usepackage[utf8]{inputenc}. But I tried and unsuccessfully. I'm unable to make it work, neither via unicode nor via command definition. – yo' Mar 08 '12 at 23:33