1

The following MWE points out that, without fleqn class option, math internal mode is detected ("i" and "o") but, as soon as fleqn class option is enabled, this mode is not detected anymore ("i" and "i").

Do you see what's going on?

\documentclass
%[fleqn]
{article}
%
\newcommand{\test}{%
  \relax%
  \ifinner%
  i%
  \else%
  o%
  \fi%
}
%
\begin{document}    
$\test$
%
\begin{equation}
  \test
\end{equation}
\end{document}
7
  • \ifinner has never been a good test for being in inline or display math.
    – egreg
    Mar 31, 2016 at 13:41
  • With fleqn you have for equation something like $\m@th\displaystyle \hskip\mathindent\bgroup.... Without fleqn you have plain $$.... Mar 31, 2016 at 13:42
  • 2
    @DenisBitouzé Without fleqn you will end up in $$...$$, with fleqn you will end up in $...$. For more look at article.cls and fleqn.clo. Mar 31, 2016 at 13:49
  • 2
    See tex.stackexchange.com/questions/53155/…
    – egreg
    Mar 31, 2016 at 13:50
  • 3
    in other words the inner detection is working, it is just that the answer is not what you expected. It's hard to find any use case where \ifinner is a useful test in math mode. Mar 31, 2016 at 14:06

1 Answer 1

1

\ifinner does not really test anything useful in math mode whether or not fleqn is used.

If you want to distinguish displaystyle then unfortunately you need to use \mathchoice.

The following produces t inline and d in display whether or not the [fleqn] option is used.

\documentclass
[fleqn]
{article}
%
\newcommand{\test}{%
\mathchoice
{\displaystyle d}%
{\textstyle t}%
{\scriptstyle s}%
{\scriptscriptstyle 2}%
}
%
\begin{document}    
$\test$
%
\begin{equation}
  \test
\end{equation}
\end{document}
2
  • If just \displaystyle vs non \displaystyle matters, isn't amsmath's \if@display reliable? Mar 31, 2016 at 15:56
  • 1
    @DenisBitouzé if you only use amsmath constructs and never $$ or eqnarray or any other non-amsmath math construct then yes. Mar 31, 2016 at 15:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .