\documentclass[a4paper]{article}
\usepackage{amsmath,amssymb,amsfonts}
\begin{document}
\begin{align*}
\eta_i\in{}&\ifmmode\mathcal C^\infty\else$\mathcal C^\infty$\fi
\end{align*}
\end{document}
Typing pdflatex in the command line and running this, I would expect it to work. align*
is a math mode environment, so the \ifmmode
should take the YES branch, and just produce \mathcal C^\infty
. However, that is not the case. The result of the above is Missing } inserted
, and if I add \show\mathcal
right after the \else
, the \show
gets executed, meaning it's going into the NO branch as if it weren't in math mode. If I remove the &
, however, everything works fine, and the result is:
Same goes with xelatex
.
What is going on here? Why is it not in math mode after the &
?
\ifmmode
insidealign*
?\relax
before\ifmmode
, explanation: tex.stackexchange.com/a/82656/3929 (founf via a simple google search onlatex ifmmode align
\ifmmode
part is from a macro\Cinf
that's supposed to ensure math mode. This way, when I have to say a function is smooth, I can just type\Cinf
without dollars.