[Tex/LaTex] Subscripts after a macro for \left( and \right) parentheses

math-modeparenthesissubscripts

I'm trying to come up with some macro for round parentheses that looks nicely in both inline and display modes. The constraints are:

  • The macro should behave like \left( \right) in display mode
  • It should behave like ordinary ( and ) in all other cases
  • It should play well with subscripts

Here is what I've tried:

\documentclass{scrbook}
\usepackage{amsmath}

% commands for round parentheses
\newcommand{\rParA}[1]{\mathchoice{\left(#1\right)}{(#1)}{(#1)}{(#1)}}
\newcommand{\rParB}[1]{\left(#1\right)}

\begin{document}
  \begin{minipage}[H]{0.5\linewidth}
  Here is some process $\rParA{A^N_{\lfloor t / N \rfloor}}_t$.
  Here is another process $\rParB{B^N_{\lfloor t / N \rfloor}}_t$.
  Here is what they look like in display mode:
  \begin{align*}
    \rParA{A^N_{\lfloor t / N \rfloor}}_t
    \quad
    \rParB{B^N_{\lfloor t / N \rfloor}}_t
  \end{align*}
  \end{minipage}
\end{document}

This code contains two macros. The first one works with \mathchoice, the second one just inserts \left and \right everywhere.
Here is the outcome:

enter image description here

The version A behaves as expected in inline-mode (the parentheses stay as short as possible, this is what I want), however, it breaks in display-mode (the subscript floats somewhere up in the sky, this is bad).

The version B occupies way to much space in inline-mode (the parentheses are too tall and influence line-spacing), but the subscript in display-mode is on it's correct position (this is good).

How can I get a macro that behaves like A in inline-mode but like B in display mode?

Best Answer

I'm not sure you want to do this or, better, I discourage you to do this: automatically applying \left and \right is always wrong.

\documentclass{scrbook}
\usepackage{amsmath}

% commands for round parentheses
\makeatletter
\DeclareRobustCommand{\rPar}[1]{%
  \@ifnextchar_{\rPar@sb{#1}}{\rPar@nosb{#1}}%
}
\newcommand{\rPar@sb}[3]{%
  % #1 is what we already have, #2 is _, #3 is the subscript
  \mathchoice{\left(#1\right)_{#3}}{(#1)_{#3}}{(#1)_{#3}}{(#1)_{#3}}%
}
\newcommand{\rPar@nosb}[1]{%
  \mathchoice{\left(#1\right)}{(#1)}{(#1)}{(#1)}%
}
\makeatother

\begin{document}
  \begin{minipage}{0.5\linewidth}
  Here is some process $\rPar{A^N_{\lfloor t / N \rfloor}}_t$.
  Here is another process $\rPar{B^N_{\lfloor t / N \rfloor}}$.
  Here is what they look like in display mode:
  \begin{equation*}
    \rPar{A^N_{\lfloor t / N \rfloor}}_t
    \quad
    \rPar{B^N_{\lfloor t / N \rfloor}}
  \end{equation*}
  \end{minipage}
\end{document}

enter image description here

Related Question