\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 &?

\ifmmodeinsidealign*? – egreg Sep 07 '20 at 12:57\relaxbefore\ifmmode, explanation: https://tex.stackexchange.com/a/82656/3929 (founf via a simple google search onlatex ifmmode align– daleif Sep 07 '20 at 12:59\ifmmodepart is from a macro\Cinfthat's supposed to ensure math mode. This way, when I have to say a function is smooth, I can just type\Cinfwithout dollars. – MickG Sep 07 '20 at 14:43