# Variant of \left, \right, …that gets ignored in inlinemath

I am trying to construct a variant of \left, \right, and \middle that are ignored in inlinemath.

Intended behavior:

$\lft( 2^{2^2} \rgt)$ -> behaves as $\left( 2^{2^2} \right)$

$$\lft( 2^{2^2} \rgt)$$ -> behaves as $$( 2^{2^2} )$$

Help would be much appreciated.

Disclaimer:

• Attempts to get this behavior using mathchoice was not successful. The problem seems to be that stuff like \mathchoice{\left}{}{}{} is invalid because TeX expects the delimiter (and the corresponding \right) within the same group.
• Attempts to get the desired behavior by influencing the order of expansion (e.g. with noexpand) were unsuccessful, but I'm not a pro regarding this stuff.
• I know that some people think that one should not automate the usage of \left and \right. I would like to have this anyhow (-:
• I know that I could simply defining something like \newcommand{\paren}[1]{\mathchoice{\left(#1\right)}{(#1)}{(#1)}{(#1)}}. However, my problem still occurs if the argument contains \middle.

Not sure how useful this can be.

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\newcommand{\lft}{\if@display\expandafter\left\fi}
\newcommand{\mdl}{\if@display\expandafter\middle\fi}
\newcommand{\rgt}{\if@display\expandafter\right\fi}
\makeatother

\begin{document}

\begin{center}% just to make a smaller picture
$$\lft( 2^{2^2} \rgt)$$
\end{center}
$\lft( 2^{2^2} \rgt)$

\end{document}


Explanation: amsmath does \everydisplay{\@displaytrue}.

• Why are the \expandafters needed here? – user125730 Dec 6 '18 at 0:29
• @user125730 They are not strictly needed, because \left, \middle and \right will expand the \fi anyway, but getting rid of the \fi before delivering the “true” or “false” texts is generally better. – egreg Dec 6 '18 at 9:03