mathjax / MathJax

Beautiful and accessible math in all browsers
http://www.mathjax.org/
Apache License 2.0
10.12k stars 1.16k forks source link

Add the ability to use `\class` across multiple `align` or `array` cells/rows #3168

Open RaphaelSantiago53 opened 8 months ago

RaphaelSantiago53 commented 8 months ago

Is your feature request related to a problem? Please describe. Currently, if the code encapsulated by \class{cls}{ ... } would not have a common and exclusive parent element when rendered that can be used as a target for the class, it doesn't render. This doesn't work for example:

\begin{align}
  (5 - 11i) + (7 + 4i) &= \class{answer}{ (5 + 7) + (-11 + 4)i \\
                       &= 12 - 7i }
\end{align}

Describe the solution you'd like It would be ideal if, instead of being considered an error, the class was applied to multiple elements in the rendered output so that it's more or less equivalent to this:

\begin{align}
  (5 - 11i) + (7 + 4i) &= \class{answer}{ (5 + 7) + (-11 + 4)i } \\
                       &\class{answer}{= 12 - 7i }
\end{align}

Describe alternatives you've considered Using multiple \class{cls} manually is fine in most cases but impractical, especially if the class is added automatically to user-supplied latex in a preprocessing step (I would have to parse the code to make sure to encapsulate the right parts with \class{cls}{ ... }). It also breaks the alignment (e.g. &\class{answer}{= 12 - 7i } in my example above does not align with the above = when rendered).

dpvc commented 8 months ago

While I understand the desire for your feature, this is not in line with how LaTeX works, in general. I know of only one very specialized macro whose argument can extend over multiple cells, and otherwise, bracing for macro arguments must end within the same table cell. It's not impossible, of course, but it is not how bracing usually works, and would be an unusual and non-standard behavior for this macro to have. It is unlikely that we will implement that approach.

It also breaks the alignment (e.g. &\class{answer}{= 12 - 7i } in my example above does not align with the above = when rendered).

Yes, that is correct. Even in actual LaTeX, the alignment will be correct only if the equal sign is the first thing in the cell. For example

\begin{align}
  (5 - 11i) + (7 + 4i) &= (5 + 7) + (-11 + 4)i \\
                       &{= 12 - 7i}
\end{align}

will not have the alignment correct, nor would the x's in the last two lines of

\begin{align}
  (5 - 11i) + (7 + 4i) &= (5 + 7) + (-11 + 4)i \\
                       &                 = 12 - 7i x \\
                       &\phantom{= 12 - 7i} x
\end{align}

be aligned. So this is entirely in keeping with how LaTeX works. You would want to do

\begin{align}
  (5 - 11i) + (7 + 4i) &= \class{answer}{ (5 + 7) + (-11 + 4)i } \\
                       &\class{answer}{{} = 12 - 7i }
\end{align}

to get the alignment correct.