Composable arrays / tables / multi-line equations

23 views
Skip to first unread message

Jefferson Carpenter

unread,
Apr 23, 2025, 1:54:02 AM4/23/25
to MathJax Users
Hello!

For context, I'm working on a computer algebra system, and I'm currently using MathJax to display equations in the browser.  Since I need to display arbitrary expressions, I'm finding and using a composable subset of LaTeX.  (Note that most amsmath environments are top-level-only and so cannot be nested to display arbitrary expressions).

A promising environment is just the "array" environment, since I can generate whatever kind of array I need for a given expression, and importantly this environment is composable - arrays can be inside arrays.  However, I am running into at least two issues with this.


1. There may be a display issue in mathjax version 3.

Steps to reproduce: Using the mathjax@3 release version, typeset the equation:

$$\left \lbrace \begin{array}[t]{ll} & 3 \\+ & 4\end{array}\right \rbrace $$

To be very specific, here is some code in my application is the following that prints the above latex, and then typesets it:

console.log(str);
el.innerHTML = str;
MathJax.typeset([el]);

Expected behavior: See a brace-enclosed two-row array.

Actual behavior: The braces enclose additional empty space above the array:
array.png
Note: the [t] setting in the array latex is important to give each nested sub-expression the correct vertical alignment; otherwise they will be vertically centered, which is not the layout I would like.

I would like to know if this is a known issue, or if there are any workarounds.


2: Since I'm attempting to use the "array" environment for all kinds of equations and expressions (as amsmath environments such as "split" cannot be nested), I need to adjust the inner row and column spacing.  I'm just wondering if the discussion here is still the best option, or if there's currently a simpler way https://groups.google.com/g/mathjax-users/c/daApZrHGZik?pli=1


Thank you very much!

I would like to get MathJax to work, but if I cannot, my backup plan is to run Latex on the server, and send the rendered images to the clients.

Davide Cervone

unread,
Apr 23, 2025, 3:47:03 PM4/23/25
to mathja...@googlegroups.com
(Note that most amsmath environments are top-level-only and so cannot be nested to display arbitrary expressions).

There is the "aligned", "alignedat", and "gathered" environments that might be useful and can be nested.  The "mathtools" package includes "lgathered" and "rgathered", plus a "spreadlines" environment that can be used to changes the separation of lines in arrays.  Finally, "split" can be nested.

1. There may be a display issue in mathjax version 3.

Steps to reproduce: Using the mathjax@3 release version, typeset the equation:

$$\left \lbrace \begin{array}[t]{ll} & 3 \\+ & 4\end{array}\right \rbrace $$

...

Expected behavior: See a brace-enclosed two-row array.

Actual behavior: The braces enclose additional empty space above the array:

This is actually the expected behavior, and the output  from actual LaTeX as well.  The reason is that stretchy delimiters like braces are centered on the "math axis" (which is about the position of a minus sign), and the "[t]" specifier means that the array is aligned on the top line, so the math axis for the array is the math axis of the top line.  The stretchy delimiters stretch to the maximum of the height and depth from the math axis, and since the delimiters must be symmetric, they will extend that far both above and below the math axis.  Your array has a lot of depth but not might height, so the delimiters stretch quite a way above the top row (one row's worth, since there is one row of depth below the top line, and if you had two rows below, they would extend two rows above).  That is the way LaTeX is designed, and is the correct output for the expression you gave.

Note: the [t] setting in the array latex is important to give each nested sub-expression the correct vertical alignment; otherwise they will be vertically centered, which is not the layout I would like.

That is why you are getting the delimiters in the way that you are.

I would like to know if this is a known issue, or if there are any workarounds.

It is the correct behavior, so it certainly "known", but not an issue.

As for work-arounds, one would be to not use "[t]" in this situation, or alternatively, when you insert "\left\{" and "\right\}", you might instead use "\left\{\vcenter{" and "}\right\}" instead to override the "[t]" in the inner expression.

2: Since I'm attempting to use the "array" environment for all kinds of equations and expressions (as amsmath environments such as "split" cannot be nested),

("split" can be nested")

I need to adjust the inner row and column spacing.  I'm just wondering if the discussion here is still the best option, or if there's currently a simpler way https://groups.google.com/g/mathjax-users/c/daApZrHGZik?pli=1

The code snippets there should still work, and do provide the means to do what you are asking.  Other approaches are to use `\\[dimen]` to adjust the row space on a line-by-line basis, or use the mathtools package's "spreadlines" environment to adjust the spacing all at once.  Note that you won't be able to reduce the space past a certain point, as the underlying MathML that is used internally won't allow that.

An alternative would be to move to v4 (now out in beta release), which implements more array environment preamble values, including ones that allow you to alter the column spacing.  See


for more details.

Hope that helps.

Davide


Message has been deleted

Jefferson Carpenter

unread,
Apr 24, 2025, 3:18:53 AM4/24/25
to MathJax Users
Oh, fascinating, thank you very much for your insight!  For now I'm moving ahead without the [t] and using some of the code from that other discussion, but I'll refer to this if I have any more layout issues in the future.  Lots of things to try.
Reply all
Reply to author
Forward
0 new messages