Skip to content

Ignore braces in array preamble. (mathjax/MathJax#3565)#1508

Open
dpvc wants to merge 4 commits into
developfrom
issue3565
Open

Ignore braces in array preamble. (mathjax/MathJax#3565)#1508
dpvc wants to merge 4 commits into
developfrom
issue3565

Conversation

@dpvc

@dpvc dpvc commented Jun 15, 2026

Copy link
Copy Markdown
Member

This PR adds rules to the array preamble column parser to ignore braces within the preamble (when they aren't used to enclose an argument to one of the column specifications). This isn't exactly in line with LaTeX, which does seem to process the braces in some way, but I can't figure out what it is, and don't see any documentation for it. It looks like it might be to allow multi-character column specifiers, but then it also seem to allow multiple copies of a single column specifier, but not mixed ones. So I'm not sure what it actually does. In any case, ignoring them seems to handle the situation given in the original issue tracker.

I also added test for this situation.

Resolves issue mathjax/MathJax#3565.

@dpvc dpvc requested a review from zorkow June 15, 2026 10:41
@dpvc dpvc added this to the v4.1.3 milestone Jun 15, 2026
@codecov

codecov Bot commented Jun 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.48%. Comparing base (a65456c) to head (ad4abdd).
⚠️ Report is 17 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #1508   +/-   ##
========================================
  Coverage    86.47%   86.48%           
========================================
  Files          340      340           
  Lines        86125    86162   +37     
  Branches      3206     3210    +4     
========================================
+ Hits         74476    74513   +37     
  Misses       11649    11649           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@zorkow

zorkow commented Jun 18, 2026

Copy link
Copy Markdown
Member

The current fix does indeed solve the issue, but it seems to be very generous, as it allows any combination of well-braced expressions in the preamble, including empty ones, arbitrarily nested ones etc.

After some experimentation, here are the rules I believe LaTeX follows:

  1. If there is a braced entry with multiple characters that is the only entry allowed. E.g., {{clc}} is allowed, but {{cl}{c}} or {{cl}c} are not.
  2. The entry can consist of a mix of braced and unbraced single characters, e.g., {{c}{l}{c}{r}} or {{c}l{c}r}
  3. Multiple nesting of braces, like {{{c}}} is not allowed, with the exception
  4. The only time nested braces are allowed is in the case of p entries.

Having said that, I am not sure if it makes sense to expend time on implementing these rules, since we do not know

  1. if these are really the exact rules
  2. what the intention of this syntax is or its use cases
  3. if not throwing an error on multiple nested {{{c}}} or empty {} entries is, could be a problem

@dpvc

dpvc commented Jun 18, 2026

Copy link
Copy Markdown
Member Author

OK, I looked into the details of the code for the actual LaTeX array package, and it looks like the preamble is tokenized into either single characters or braced groups, and then those are processed as column specifiers (where some can take the following token as a parameter, as in p{10em}). Using braces around single characters works, as you point out, but around other things can lead to some weird error messages (like "missing number", or even parsing on to the \end{array} for the next \begin{array}; very strange).

I have pushed a commit that better matches this behavior, though not the strange messages (it will always be "Illegal param-token"). I also remove one set of braces from the entire expression, if there is such a pair.

I think this matches LaTeX pretty well, and if there are other edge cases, we can deal with them later.

@dpvc

dpvc commented Jun 19, 2026

Copy link
Copy Markdown
Member Author

While looking through the documentation for array.sty, I found that the order for multiple > or < entries are done in the reverse order. This was not being done in MathJax, so I've pushed another commit to reverse the order to match LaTeX. I also added a test for it.

I also forgot to mention that in the previous commit I added support for newlines in the preamble, and I added a test for that.

@zorkow

zorkow commented Jun 19, 2026

Copy link
Copy Markdown
Member

Here's one example I found that works in LaTeX, but not in MathJax:

\left(\begin{array}{{r}c{l}}a&bb& ccc\\ ddd& e & ff\end{array}\right)

@dpvc

dpvc commented Jun 19, 2026

Copy link
Copy Markdown
Member Author

Right, thanks. The removal of outer braces was too simplistic. I had convinced myself that that would work, but of course I should have known better.

I've made a new commit to fix the issue, and add a new test for your example.

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.

2 participants