Katex: Could \begin{align} and \begin{split} be added?

Created on 23 May 2018  路  6Comments  路  Source: KaTeX/KaTeX

These are useful for long equations that aren't simple matrices, multiple long equations in sequence, among other things, and are a lot nicer than what I'm currently using (basically \begin{aligned} with set alignment points, which is super brittle and it doesn't look very pretty).

enhancement

Most helpful comment

There are more subtle differences between \begin{align} and \begin{aligned}, though, ones which make \begin{aligned} (and thus KaTeX as a whole) untenable for my workflow. In particular, you're not supposed to be able to use use \tag() in a \begin{aligned} environment. It gives errors in MathJax (and actual LaTeX I believe), where the correct solution is to instead use \begin{align} (unsupported in MathJax). This means I can't keep the same source code compatible with different engines.

For example, the following snippet renders incorrectly using KaTeX - it puts the tag centered in the middle of the whole block, instead of at the bottom line where it belongs. I think it is also incorrect I guess to allow \tag inside of the aligned environment in the first place, as MathJax (and I assume proper LaTeX) doesn't accept it.

\begin{aligned}
\Delta K = K_2 - K_1 = +W_{12} \\
\Delta U = U_2 - U_1 = -W_{12} \\
\Delta K + \Delta U \\
K_2 + U_2 = K_1 + U_1 \\
E = K + U \tag{mechanical energy is conserved}
\end{aligned}

All 6 comments

The {split} environment would certainly be useful. Without {split}, one can usually hack something together with {aligned}, \phantom, and \mathllap, but the same thing is easier and cleaner with {split}. We should definitely have that on our list of things to do.

You titled this issue by requesting {split} and {align}. I'm confused by the {align} part because the only difference between {align} and {aligned} is that {aligned} can be used only when LaTeX is already in math mode. KaTeX starts out already in math mode, so one would nest one {aligned} inside another {aligned}. The outer environment doesn't have to be {align}.

Or maybe you meant something else. {equation} perhaps?

I'm unfamiliar with split, but my reading of amsmath docs so far suggests that it's equivalent to matrix but with arraycolsep set to zero. Is this correct? If so, it should be relatively easy to add.

And agreed, we already effectively support align via aligned, though I'd still like to add it as an alternative to \[ at the top level.

Yes, this is rarely essential on web pages but split is really useful in things like IEEE journals where the columns are narrow - obviously this is not quite the primary use-case of KaTeX as such, but for having the same equations across both.
Apropos @edemaine's idea, the AMS implementation seems to be distinct from matrix but I suspect that recycling matrix to this end would be adequate for most KaTeX use-cases.

This would also be useful on mobile devices where the screen is narrow.

There are more subtle differences between \begin{align} and \begin{aligned}, though, ones which make \begin{aligned} (and thus KaTeX as a whole) untenable for my workflow. In particular, you're not supposed to be able to use use \tag() in a \begin{aligned} environment. It gives errors in MathJax (and actual LaTeX I believe), where the correct solution is to instead use \begin{align} (unsupported in MathJax). This means I can't keep the same source code compatible with different engines.

For example, the following snippet renders incorrectly using KaTeX - it puts the tag centered in the middle of the whole block, instead of at the bottom line where it belongs. I think it is also incorrect I guess to allow \tag inside of the aligned environment in the first place, as MathJax (and I assume proper LaTeX) doesn't accept it.

\begin{aligned}
\Delta K = K_2 - K_1 = +W_{12} \\
\Delta U = U_2 - U_1 = -W_{12} \\
\Delta K + \Delta U \\
K_2 + U_2 = K_1 + U_1 \\
E = K + U \tag{mechanical energy is conserved}
\end{aligned}

Closed via PR#2369.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

oddhack picture oddhack  路  3Comments

OisinMoran picture OisinMoran  路  4Comments

pyramation picture pyramation  路  4Comments

yawnoc picture yawnoc  路  3Comments

fabiospampinato picture fabiospampinato  路  4Comments