2

Command \ifmmode misjudged in math environment of package amsmath. An mwe is like

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{gather}
  \ifmmode123\else456\fi
\end{gather}
\end{document}

In math eqvironment, it should have produced 123 in gather environment. But the outcome is just the opposite. Similar cases appear in align, eqarray and so on. But in equation, it produces the right outcome. Is this a bug? Or how to fix it? Thansks for help!

0
1

You can \protect the invocation of \ifmmode. David's comment provides more info on the "why".

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{gather}
  \protect\ifmmode abc\else def\fi
\end{gather}
\end{document}
2
  • 1
    no not the multi-pass (you will see the same in array, which is one pass) it is the lookahead for \multicolumn or \hline that happens before the cell (and so math mode) starts. – David Carlisle Jan 21 at 14:42
  • Thanks @DavidCarlisle I will edit out that comment. – Steven B. Segletes Jan 21 at 14:43

Not the answer you're looking for? Browse other questions tagged or ask your own question.