# amsmath “\substack”-command in section title

I do use the \substack-command in text for creating a small (2,1)-Vector. Unfortunately it does not work in the title of a section.

Here a minimal example, which does not work:

\documentclass{scrreprt}
\usepackage{amsmath}
\begin{document}
\section{$\substack{ a\\b }$}
\end{document}


To my surprise it works, if I use \section* instead of \section. I am far from understanding enough about TeX to tell why this happens, but can anyone give me an advise how I can fix it?

PS: I also tried to substitute \substack by smallmatrix, which did work for the first two times I compiled the file. After the third compilation I got the same problems.

EDIT: The Problem was solved, using the \protect-command. But now I want to use the same sectiontitle for a beamer presentation, using the beamer-class. Also using the \protect-command I receive an error. How can I solve this?

-
–  Peter Grill Mar 3 '13 at 19:49
@PeterGrill (and @Greyfox) A \protect will help: What is the difference between Fragile and Robust commands? –  Qrrbrbirlbel Mar 3 '13 at 19:52
@Qrrbrbirlbel: Oh yeah, really should try harder to not forget about \protection. :-) –  Peter Grill Mar 3 '13 at 19:53
Amazing. It works. You are a wizard. :-) Thanks a lot. –  Greyfox Mar 3 '13 at 20:13
@Greyfox -- your edit may not be noticed by many readers. it's better to enter a new question, pointing back to this one. –  barbara beeton Apr 12 '13 at 20:45

\substack is what is known as a fragile command in LaTex and needs protecting in situations like section titles and captions that get written to external files for producing tables of contents etc. See What is the difference between Fragile and Robust commands? for some more information on fragile commands.

\documentclass{scrreprt}

\usepackage{amsmath}

\begin{document}
\tableofcontents

\section{$\protect\substack{ a\\b }$}

\end{document}


If you have the hyperref package loaded then you will also need to provide a plain text version, via

\section{\texorpdfstring{$\protect\substack{ a\\b }$}{a/b}}


Finally, if using the beamer class there is an extra problem with \\ which beamer redefines. One work around in this case is to define a custom command to be used in the title:

\documentclass{beamer}

\usetheme{Warsaw}

\usepackage{amsmath}
\DeclareRobustCommand{\myfr}{\texorpdfstring{$\substack{a\\b}$}{a/b}}

\begin{document}

\section{\myfr}

\begin{frame}
Test.
\end{frame}
\end{document}


Notice here that you can make the command robust from the start.

-
Thanks a lot. This helped me very much. –  Greyfox Mar 3 '13 at 20:15
Answer extended to cover beamer question –  Andrew Swann Apr 13 '13 at 15:20
Thx, for this Extension. Using the \textorpdfstring-command, I can now solve all my problems. –  Greyfox Apr 14 '13 at 19:42