mathjax / MathJax

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

TeX input: array support for @{...} with spacing #2771

Open pkra opened 2 years ago

pkra commented 2 years ago

It would be great to have some level of support for @{...} in the array environment to control column spacing.

pkra commented 2 years ago

In our case, just supporting @{} would already go a long way.

dpvc commented 2 years ago

It is on my list of things to do. I worked a bit on the rowspan and colspan options for tables, and was planning to consider this as part of a larger table update next year.

pkra commented 2 years ago

Thanks. It's not a huge priority for the AMS (it's actually slipped past checks until now despite a few dozen publications having arrays with custom spacing).

pkra commented 2 years ago

Just a quick ping that this has resurfaced with more use cases on our end.

dpvc commented 2 years ago

I'm currently working on line breaking, and have added support for breaking columns that have a fixed width, so have been thinking about implementing some more of the column specifiers (like p{...}), etc. Not sure if I can get everything done before the end of the summer, but I haven't forgotten about this.

pkra commented 2 years ago

Thanks for the update, Davide.

dpvc commented 2 years ago

If you can give me a list of the column specifiers that you need supported, that would help. I'm not all that familiar with them, and not even sure of what the complete list is (if there is one).

pkra commented 2 years ago

Thanks, we'll do that.

pkra commented 1 year ago

Just to follow up, we're still gathering data. The example @{..} is high on our list thought because it can contain fairly arbitrary stuff (in TeX at least), though we mostly have spacing and the odd plain text (e.g. @{=}). It seems like this could just be done as an extra column.

dpvc commented 1 year ago

I don't really know the use-cases for @{...}. Can you give me a curls of complete examples that illustrate what is needed?

I have implemented (in the linebreak branch) everything else from the array.sty package except @{...} and !{...}, as I don't really have a good handle on how they are used. Any help on that would be great.

pkra commented 1 year ago

Here are a couple of examples from real world articles and books.

Most frequently, I see spacing commands in there but in some cases there is actual text content (e.g., the last one below).

\begin{equation}
 \begin{array}{c@{}l} W_{max} \\\downarrow \\W &{}= W_{max}/B, \ G(W/Y) = H_1/B. \\\downarrow \\Y &{}= W_{max} / H_1 \end{array} \tag{14}\cssId{texmlid7}{}
\end{equation}

\begin{array}{lcl@{\quad }lcl@{\quad }lcl} S(H_1, x) &=& \{ 12 \} & S(H_2,x) &=& \{ 12 \} & S(H_3, x) &=& \{ 4, 12 \} \\S(H_5, x) &=& \{ 4,8 \} & S(H_6, x) &=& \{ 8 \} & S(H_7, x) &=& \{ 8 \} \\S(H_9, x) &=& \{ 8 \} & S(H_{10}, x) &=& \{ 8 \} & S(H_{11}, x) &=& \{ 12 \} \\\end{array} 
\end{equation*}

\begin{equation*}
 \begin{array}{rc@{\hskip 1em}c@{\hskip 1em}c} w'_n(0) & = \dfrac{1}{k+1} {\scriptstyle \left(\scriptstyle 2k\atop \scriptstyle k\right)} {\scriptstyle \left(\scriptstyle 2k+1\atop \scriptstyle k\right)} & \text{or} & \dfrac{1}{k+2} {\scriptstyle \left(\scriptstyle 2k+2\atop \scriptstyle k+1\right)} {\scriptstyle \left(\scriptstyle 2k+1\atop \scriptstyle k\right)}, \\[16.0pt]  \text{i.e.,} & {\scriptstyle \left(\scriptstyle 2k+1\atop \scriptstyle k\right)} C_k &\text{or} &{\scriptstyle \left(\scriptstyle 2k+1\atop \scriptstyle k\right)} C_{k+1}, \end{array} 
\end{equation*}

\begin{equation*}
 \begin{array}{c@{\,}c@{\,}l} \tilde{w}^{-1} \Phi ^-(L^Q)\cap \Phi ^+(L^P)&=&w^{-1}\bar{w}\Phi ^-(L^Q)\cap \Phi ^+(L^P)\\&\subset &w^{-1}\Phi ^-\cap \Phi ^+(L^P), \end{array} 
\end{equation*}

\begin{equation*}
 \begin{array}{cc@{\,=\,}c@{\,=\,}l} \mathrm{B}: & 100-4 & 96 & 8\times 12 \\\mathrm{A}: & 96-12 & 84 & 6\times 14 \\\mathrm{B}: & 84-14 & 70 & 2\times 35 \\\mathrm{A}: & 70-2 & 68 & 4\times 17 \end{array} 
\end{equation*}
dpvc commented 1 year ago

OK, thanks, that helps. I'll look into adding @{} support based on this information. I think I see how it can be done.

dpvc commented 1 year ago

Also, if you have anything that uses other column specifiers, like p{...}, m{...} or b{...}, could you try them out and see if they work as expected? Again, I've never used these myself in actual LaTeX, so may not have a complete understanding of what they should do. Thanks!

dpvc commented 1 year ago

OK, I've added @{} support to the linebreaks branch. Give it a try, and let me know how it works for you. It does seem to handle the examples that you provided.

Just as an aside, the @{\,=\,} should probably be @{{}={}} to get the spacing right, and I think the second one is better handled by an align or aligned environment. The spacing can be improved in several of the others as well, but I don't know if you are adjusting things at that level.

pkra commented 1 year ago

OK, I've added @{} support to the linebreaks branch. Give it a try, and let me know how it works for you. It does seem to handle the examples that you provided.

Thanks! I'll check it out.

Just as an aside, the @{\,=\,} should probably be @{{}={}} to get the spacing right, and I think the second one is better handled by an align or aligned environment. The spacing can be improved in several of the others as well, but I don't know if you are adjusting things at that level.

Yeah no argument from me. However, some authors intentionally write macros to hack spacing like that (and complain when those are changed during cleanup). Besides, fixes on that level of detail would be rather expensive.

pkra commented 1 year ago

I gave it a quick test with the "hardest" (the example above starting with \begin{array}{cc@{\,=\,}c@{\,=\,}l}...).

Here's what I'm getting with MathJax:

image

vs LaTeX:

image

where the = appear between the columns in LaTeX.

dpvc commented 1 year ago

Hmm. I tested with that example myself, and it worked for me. Just tested again (on the linebreaks branch) and it works. Are you sure you have the latest copy, and have compiled it? Here's my MathJax output:

mj-at

Your is what would have happened before I made the recent changes to support @{...}.

pkra commented 1 year ago

D'oh! So sorry - I had updated my package file but not installed :disappointed:

Looking good now!

dpvc commented 1 year ago

Ok, thanks for the update. Glad it was an easy fix.

pkra commented 1 year ago

From my latest round of randomized testing:

\begin{equation*}
 \begin{array}{lll@{\hskip 3em}l@{\hskip 3em}l} t & I & \bar{d} & f & C/\mathbb{Q}_2 \\\hline 1 & C_3 & 3 & 1 & y^2 = x^6+4x^4+2x^3+4x^2+1\vphantom {C^{f^f}} \\1 & C_3 & 3 & 3 & y^2 = 4x^6-20x^4-8x^3+21x^2+22x+13 \\\hline 2 & C_3 & 2 & 2 & y^2 = x^6+6x^4-7x^2+16\vphantom {C^{f^f}} \\2 & C_3 & 2 & 4 & y^2 = 5x^6+4x^3-12 \\\hline 1 & C_2 & 2 & 2 & y^2 = -x^6+6x^4-x^2-8\vphantom {C^{f^f}} \\1 & C_2 & 2 & 3 & y^2 = x^6-6x^4+x^2+8 \\\hline 1 & C_6 & 1 & 3 & y^2 = x^6-6x^4+5x^2+8\vphantom {C^{f^f}} \\1 & C_6 & 1 & 4 & y^2 = x^6-31x^4-25x^2-32 \\\end{array} 
\end{equation*}

the last hskip seems to be missing. (Or maybe is a side effect of our mathjax setup not matching the corresponding LaTeX setup in all details)

MathJax rendering:

image

LaTeX rendering:

image

dpvc commented 1 year ago

Thanks, this appears to be a bug with the brace-counting code that seems to be getting confused about the \vphantom at the ends of the lines that are incorrectly spaced. I'll check into it further.

dpvc commented 1 year ago

I was right, there was a problem with the determination of the cell contents that was caused by the braces (though it wasn't a counting issue). I've pushed an update to the linebreaks branch that fixes the problem.

pkra commented 1 year ago

Thanks, Davide. I can confirm the fix.