I'm having a really strange problem with the align* environment from amsmath (it happens with align, aligned, gather, etc. as well). For some reason, the first character is not in math mode, but the rest are. The following code:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
\ifmmode t \else f \fi
\ifmmode t \else f \fi & =
\ifmmode t \else f \fi
\end{align}
\end{document}
This is obviously a simplified version of what I'm actually trying to do, but I'm wondering what causes this behavior?

\leavevmode\ifmmode .... – Werner Jan 20 '22 at 04:33