latex3 / latex2e

The LaTeX2e kernel
https://www.latex-project.org/
LaTeX Project Public License v1.3c
1.94k stars 267 forks source link

amsmath: request to add \subalign #461

Open RuixiZhang42 opened 3 years ago

RuixiZhang42 commented 3 years ago

Brief outline of the enhancement

Sometimes it is desirable to have alignment points in a subscript index.

I should give credit to egreg, since this idea originated at https://tex.stackexchange.com/a/198806 but I had added a few more enhancements.

Minimal example showing the desired new behaviour

\RequirePackage{latexbug}
\documentclass{article}
\usepackage{amsmath}

\makeatletter
% An optional argument for vertical alignment choices.
\newcommand*\subalign[2][c]{%
% Maybe use the new \cs{ams@pos@<t|b|c|<empty>>} method for improvement?
  \if#1t\vtop\else\if#1b\vbox\else\vcenter\fi\fi{%
% My contribution is \cs{centry} for centered entry, see below.
    \let\centry\@centry
% Basic setup, identical to \env{subarray}.
    \Let@ \restore@math@cr \default@tag
% Emulate \cs{atop} in \cs{scriptstyle}. For luatex, use \cs{Umath...}.
    \baselineskip\fontdimen10 \scriptfont\tw@
    \advance\baselineskip\fontdimen12 \scriptfont\tw@
    \lineskip\thr@@\fontdimen8 \scriptfont\thr@@
    \lineskiplimit\lineskip
% Start the alignment.
    \ialign{%
% My contribution is adding a |&| in front of the first entry
% in the preamble, so we get ``infinite'' columns.
      &\hfil$\m@th\scriptstyle##$%
      &$\m@th\scriptstyle{}##$\hfil\crcr
      #2\crcr
    }%
  }%
}
% When \cs{centry} is used outside of \cs{subalign}, it does nothing.
% (Maybe we can write |\newcommand*\centry[1]{#1}|, but this will ``fix''
% the catcode of |#1|, so currently I prefer the empty definition here.)
\newcommand*\centry{}
% Inside \cs{subalign}, we let \cs{centry} to \cs{@centry}, which does the
% actual work. It omits the template, sets its argument in \cs{scriptstyle},
% and centers the argument by adding `\hfil` glues on both sides.
\newcommand*\@centry[1]{%
  \omit
  \hfil$\m@th\scriptstyle#1$\hfil
}
\makeatother

\begin{document}
\verb|\substack| versus \verb|\subalign|:
\[
\sum_{\substack{i\le m\\j\le n}}
\quad\text{versus}\quad
\sum_{\subalign{i&\le m\\j&\le n}}
\]

\verb|\subalign| can also have more than two columns:
\[
\sum_{\subalign{m_1&\le i&&\le m_2\\n_1&\le k&&\le n_2}}\quad
\sum_{\subalign{m_1&\le&i&\le m_2\\n_1&\le&k&\le n_2}}\quad
\sum_{\subalign{m_1&\le&\centry{i}&\le m_2\\n_1&\le&\centry{k}&\le n_2}}
\]
In the first sum we put $i$ and~$k$ in the 2nd column;
in the second sum we put $i$ and~$k$ in the 3rd column.
Both are unsatifactory (unbalanced white space around~$i$).
In the third sum, we put $i$ and~$k$ in the 3rd column,
\emph{but also use} \verb|\centry| \emph{to center these entries}.

When we have just one column, using \verb|\subalign|+\verb|\centry|
duplicates the effect of\/ \verb|\substack|:
\[
\prod_{\substack{i\le m\\j\le n}}\quad
\prod_{\subalign{\centry{i\le m}\\\centry{j\le n}}}
\]

Finally, bonus for vertical alignment choices (optional argument 
\verb|t|, \verb|c|, or~\verb|b|):
\[
f\Bigl(\frac{mx}{m^2+n^3}\Bigr)\bigg|_{\subalign[t]{m&=-1\\n&=1}}\quad
f\Bigl(\frac{mx}{m^2+n^3}\Bigr)\bigg|_{\subalign[c]{m&=-1\\n&=1}}\quad
f\Bigl(\frac{mx}{m^2+n^3}\Bigr)\bigg|_{\subalign[b]{m&=-1\\n&=1}}
\]
\end{document}

subalign

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity.