I'm trying to use the mathsf font in a section title and it wont compile. Here is a MWE:
\documentclass{amsart}
\usepackage{verbatim, rotating, stmaryrd, bbm, pict2e, ytableau, mathrsfs, amssymb, mathtools}
\newcommand{\Dsg}[1]{{\mathsf{D}^b_\mathsf{sg}(#1)}}
\newcommand{\APC}[1]{{\underline{\mathsf{APC}}(#1)}}
\begin{document}
\tableofcontents
\section{$\APC{S} \simeq \Dsg{S}$}
hi
\end{document}
It works without the table of contents tag, but with it when I compile this I get an error:
Latex Error: ./temp.toc:1 \mathsf allowed only in math mode.
The ./temp.toc file consists of just one line:
\contentsline {section}{\tocsection {}{1}{${\relax $\@@underline {\hbox {\mathsf {APC}}}\mathsurround \z@ $\relax (S)} \simeq {\mathsf {D}^b_\mathsf {sg}(S)}$}}{1}
I'm not sure how to parse that to figure out what's wrong. Why can't I use \mathsf in math mode in a section title?
\mathsfbut\underline. This should work:\newcommand{\APC}[1]{{\protect\underline{\mathsf{APC}}(#1)}}. Or\DeclareRobustCommand{\APC}[1]{{\underline{\mathsf{APC}}(#1)}}– cgnieder Oct 27 '13 at 19:46\protectdoes, is there a short explanation of why\underlinewas causing problems and\protectfixes it? – Jim Oct 27 '13 at 20:01.tocfile expandable macros get expanded. Sometimes this breaks things like in this case.\protectprevents the unwanted expansion (actually it does something else and very clever... :) Defining\APSas a robust command prevents its expansion in such contexts (through something similarly clever) so\underlinedoesn't even get to be expanded then. – cgnieder Oct 27 '13 at 20:17