Skip to content

feat: \substack and the subarray environment - #3118

Open
shupphar wants to merge 1 commit into
arnog:masterfrom
shupphar:feat-substack
Open

shupphar wants to merge 1 commit into
arnog:masterfrom
shupphar:feat-substack

Conversation

@shupphar

Copy link
Copy Markdown

\substack{i<n \\ j<m} (amsmath), the usual way to stack the conditions under a \sum, is an unknown command, and the \\ inside it is a second error. KaTeX, Temml and MathJax all support it.

What this adds

  • subarray is a tabular environment with one column, l or c, as in amsmath.
  • \substack{…} is \begin{subarray}{c}…\end{subarray}. It's a function whose argument is rows, as \displaylines already is, and it serializes back as \substack{…}. A & inside it is ignored, since it has one column.
  • Layout. Both are set as amsmath and KaTeX set them: script style, \arraystretch 0.5, no space before or after the column, and no \jot between rows.
  • Editing. Adding a row (ctrl/cmd+Enter, addRowAfter) in a subscript or superscript that isn't already in an array, such as the lower limit of a \sum, splits it at the caret into a two-line \substack. Inside a \substack, it adds a line. Before this, addRowAfter there did nothing.

Tests

  • Unit: a SUBSTACK AND SUBARRAY block in test/latex.test.ts covers round trips with no verbatim LaTeX kept, no parse errors, and that \substack draws exactly as {subarray}{c}.
  • Playwright: test/playwright-tests/substack.spec.ts checks that ctrl+Enter in a sum's limit makes \sum_{\substack{i<n\\ j<m}}, and that ctrl+Enter in a \substack adds a line.
  • Existing suites: the jest suites pass, and the Playwright suite passes in Chrome.

Suggested changelog line: \substack and the subarray environment are supported; adding a row in the limit of a \sum stacks it in a \substack.

🤖 Generated with Claude Code

`\substack{i<n \\ j<m}` (amsmath) stacks lines in a subscript or a
superscript, most often the conditions of the limits of a `\sum`. It was an
unknown command, and the `\\` inside it another error.

`\substack` is `\begin{subarray}{c}...\end{subarray}`. Both are now arrays:
`subarray` is a tabular environment with one column, `l` or `c`; `\substack`
is a function whose argument is rows, as `\displaylines` is, and serializes as
`\substack{...}`. As amsmath and KaTeX set them, they are in script style,
with an `\arraystretch` of 0.5, no space before or after the column, and no
`\jot` between rows.

In the editor, adding a row (ctrl/cmd+Enter) in a subscript or superscript
that is not in an array, such as the lower limit of a `\sum`, splits it at
the caret into a two-line `\substack`; in a `\substack`, it adds a line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant