Repository navigation
Description
Having just implemented a polyfill for elementary math, that got me thinking about some related ideas:
- The most obvious concept related to long division is synthetic division. It is basically the same idea as long division except that you are dividing polynomials. With synthetic division, the columns contain numbers (the coefficients of the polynomial), not just digits. As a refresher, see this page and the example taken from it below):
| Polynomial Division | Synthetic Division |
|---|---|
![]() |
![]() |
- Synthetic division is a shorthand for long division of polynomials (left example above). Long division of polynomials is basically the same idea as long division of numbers except that instead of digits, you have monomials that need to go into their own column. Doing that automatically requires knowing the variable you want to "sort" on so that each monomial goes into the proper column.
- A very similar property is needed when displaying systems of equations -- each monomial wants to be in it's own column (in this case, the top level element would not be
mlongdiv, butmstack).
There are a few complications such as decimal alignment of the coefficients:
8.44x + 55 y = 0
3.1 x - 0.7y = -1.1
Note that alignment requires knowing what characters/operators act as column separators (e.g., +and -, along with = and a few other relational operators). These would be inside of mo elements, so potentially any mo element could be a separator, or maybe an attribute specifies what the separators are (something to think about/discuss).
The above example is taken from the MathML 3 spec formaligngroup and malignmark. I think only MathPlayer ever implemented those elements and I suspect that you can count on your fingers the number of times they have been used. It is a very complicated feature to implement and to use. In contrast, I think the above features are an incremental extension to elementary math layout, so implementation (especially via an extension to the polyfill I wrote), means that supporting these features would be universal (assuming I or someone else extended the polyfill). Just as important, using this extension would be simple as it is a declarative notation that doesn't require modifying the generated layout other than at a high level (wrapping with mstack or mlongdiv). It would be less powerful though.
I suspect that this proposed extension to elementary math handles the large majority of cases where people play games with tables to achieve alignment, both in MathML and in TeX. @davidcarlisle: do you have any estimate of how many uses of table for alignment in TeX would be covered by this proposed extension? What are some of the cases that are missed by it?


Activity
dginev commentedon Oct 9, 2020
Hello. I was looking for an appropriate issue to attach a recent piece of news I spotted, and since this issue discusses
malignmark, it seems appropriate. There is a recent post about bypassing the sanitization of DOMPurify through an abuse of parsing MathML in HTML, details here:https://portswigger.net/daily-swig/dompurify-mutation-xss-bypass-achieved-through-mathml-namespace-confusion
Summarized as:
This might be relevant if you're searching for additional reasons for deprecation.
NSoiffer commentedon Oct 15, 2020
davidcarlisle commentedon Oct 15, 2020
NSoiffer commentedon Oct 17, 2020
davidcarlisle commentedon Aug 11, 2022
the schema has been updated to restrict use of malignmark, and to remove grouplaign attribute except in legacy schema
w3c/mathml-schema@4e897dc
NSoiffer commentedon Aug 15, 2024
The group tentatively agreed that these are no longer needed: they aren't implemented in browsers and are rarely generated. The main use is to get alignment right at the character level (e.g., decimal alignment). @davidcarlisle pointed out that there is a Unicode space character (U+2007) that is meant to be the width of a digit and that this can be used as padding to get decimal alignment to work.
I pointed out that with intent table properties, the accessibility problem of splitting equations across columns goes away.
This section (which is somewhat simplified from MathML 3) still is quite large, so removing this would be a good simplification to the spec and help align it with it.
@MurrayIII currently uses
malignmarkin his UnicodeMath implementation. He will investigate whether this is really needed. If not, then we can remove these from the spec.MurrayIII commentedon Nov 14, 2024
For the equation
Word copies the following MathML
NSoiffer commentedon Nov 14, 2024
Reformatted the above MathML to be more readable:
This makes it easier to see the
maligngroupandmalignmarkelements.davidcarlisle commentedon Nov 14, 2024
If I change that example to 103 rather than 13, so the expressions have different lengths
that renders (in Edge here) as
So there is no alignment at all visually (similarly in firefox)
If I add
to get mathjax rendering it still doesn't align:
28 remaining items
davidcarlisle commentedon Feb 19, 2025
Use of
float:rightmakes the table celldisplay:blockand while, between us, we have managed to hide most the bad effects of that, it's still problematic.It turns out that while
text-align:rightdoesn't work in chrome,text-align:-webkit-rightdoes, and as always in css you can use both and the webkit version will be ignored by systems that should ignore it so I getFirefox

Chrome
with the correct column alignment, and the equation numbers at the page page margin in chrome (not yet in firefox)
Using this simpler css
MurrayIII commentedon Feb 20, 2025
Unfortunately, these choices for replacing malignmark and maligngroup don't work well for Safari, but we could have different choices for different browsers. Another problem is that any mtd emulation of malignmark and maligngroup messes up the vertical alignment of an equation more than 1`em in height. High quality mathematical typography needs malignmark and maligngroup since they allow vertical alignment within a single mtd. Ditto for equation number work arounds for not having mlabeledtr when the equation has a height of more than 1em. Still another problem is that MathJax doesn't work with the mlabeledtr work arounds, although it does work with the malignmark and maligngroup emulations.
davidcarlisle commentedon Feb 20, 2025
@MurrayIII I agree that the alignment still needs tweaking some more (probably we'll need to offer a version using javascript not just css) which is a shame in a way but it is what it is. javascript would anyway be needed to polyfill from the
<malignmark/>markup as you need to generate extra table columns on which the css can act.If you are generating
<malignmark/>for a current browsers you will need some javascript support to make it work. That could be mathjax or it could be a more specific polyfil we provide here, I don't think it's necessary that it works well if both are used in combination.We could decide not to remove mlabeledtr from the spec, but that doesn't really help as it's not implemented in browsers whatever the spec might say about it. So I think practically speaking we don't have any choice but to remove it from mathml4 to match mathml-core, and then work out the best way of getting the alignments without it.
I think in the end three things will be needed
<maligngroup/>; a javascript polyfiland basically the same again for equation numbers with or without
<mlabeledtr>davidcarlisle commentedon Feb 24, 2025
@MurrayIII
which was a polite way of saying they don't work at all in safari:-)
I got access to a Mac and saw what you meant....
Attached is a file that uses the
float:rightmechanism just for safari and I think looks reasonable.The whole file tests various kinds of latex alignment structures with and without equation numbers,
the mathml including intents for the alignment structures is written by latex during its typesetting
and the generation to html uses ngpdf's implementation of the derivation to html algorithm for tagged pdf, not any tex-specific convertor.
I attach the html here but you can run the entire pipeline starting from latex source using the texlive.net server
at
https://tinyurl.com/mrc5krb6
after latex has finished running it should offer a link to "open in the ngpdf editor" which will show a side by side view of the latex typeset pdf and html/mathml rendering.
html version (as a .txt file due to file restrictions on this site)
align-html.txt
davidcarlisle commentedon Feb 27, 2025
I just used mathpix to generate mathml from an example on screen (actually from @dginev 's codepen in another issue) and selected the output it describes as "Copy Word" but actually it means put MathML rather than LaTeX on the clipboard.
I get
Which doesn't really fit the proposed "cut down" description of only allowing
maligngroupat the top level and only in conjunction withmalignmark(which isn't used at all here).pasting that in to Word gives the expected result
This makes me a bit nervous of mandating any specific minimal use of
maligngroupWe could keep things as they are now in the spec with just the big "not in core" warning. Or I think we could make any use valid but not defined which would make this conforming but essentially mathml3 use.
am not sure we can specify any "simple" version of maligngroup that specifies the above behaviour
@MurrayIII interestingly if I copy the formula out of Word (without editing it) then, after adjusting the namespace prefixes, and indenting for clarity you get this with alternating
<malignmark/>and<maligngroup/>as you have shown previously (but still within one level of<mrow>I think this re-inforces the thought I had above that we can't specify a "simplified"
<malign...that validates and explains both these forms, we need to either keep more or less what we have now in the spec, or declare any use valid, but with undefined behaviour so this behaviour would be valid mathml4, but explained in mathml3.I suspect keeping what we have now in the spec is most reasonable.
davidcarlisle commentedon Feb 28, 2025
It may (should?) be possible to drastically simply the alignment algorithm at
https://w3c.github.io/mathml/#presm_alignment_algo
now alignmark is not allowed in "weird" places, instead of defining it as measuring and aligning in the rendered view we should be able to specify in generic terms how it can be transformed to multiple mtd columns (then the alignment is automatic) and we can say that a polyfill is (or will be) available for such a transform.
davidcarlisle commentedon Mar 12, 2025
A possible algorithm to rewrite
<aligngroup/>to right-left aligned pairs ofmtd.Rewriting
<malignmark/>and<maligngroup/>Remove all
columnalignattributes from<mtable>and<mrow>by adding the implied
columnalignto each cell.If any cell with
columnspanattribute greater than 1 has<maligngroup/>or
<malignmark/>, remove them (such use is effectively not supported.Modify the table one column at a time:
For each column of the table than contains a
<maligngroup/>letn be the maximum number of
<maligngroup/>in a cell in that column.(contains here means a descendent of any depth, but not contained within a tested
mtable)For each cell in the column (examples assume n = 2):
If the cell has no
<maligngroup/>addcolumnspan=2n of if the cell alreadyhas a
columnspanand spans this column, increase thecolumnspanattribute by 2n.<mtd><mi>a</mi></mtd>⟹<mtd columnspan="4"><mi>a</mi></mtd>If the cell has a
<maligngroup/>but fewer than_n_ add additional`to the right (left in rtl direction) of the cell content, so the cell contains n groups.
Cells that have
<maligngroup/>descendents (not counting nestedmtable) are transformed in to 2nmtdtable cellsfirst make n cells, each cell corresponding to one alignment group.
Traverse in markup order, when reaching
<maligngroup/>close all open elements until the<mtd>is closed,then open a new
mtdcell and re-open all the elements, repeating their attributes, with the exception ofidandarg.⟹
Now split each alignment group cell in to two, the first being right aligned and the second left.
If the
mtdhas no<alignmark/>then the alignment point is implicitly at the startadd
<mtd columnalign="right"/>before the cell and addcolumnalign="left"to this element.If the cell does contain (at any depth not counting nested
mtable) an<malignmark/>split thecell as for
<maligngroup/>and addcolumnalign="right"to the firstmtdandcolumnalign="left"to the second.
⟹
davidcarlisle commentedon Mar 13, 2025
@NSoiffer the algorithm in the above comment will need review but some algorithm along those lines would work but... unless someone can think of a better phrasing, it wouldn't shorten the spec much if added inline.
It occurred to me that if we implemented this and added to https://github.com/w3c/mathml-polyfills/ we could document it there
and in the spec just say
davidcarlisle commentedon Oct 6, 2025
Note there is now a standard css property that should be able to replace
-webkit-rightand-moz-right(and already works in Chrome w3c/mathml-core#156 (comment)NSoiffer commentedon Aug 21, 2026
Word now generates columnalignments instead of maligngroup/malignmark. The WG agreed today to deprecate this feature, so the spec needs updating again.
I have created a polyfill that supports the MathML 3 (full) version of maligngroup/malignmark.
davidcarlisle commentedon Oct 8, 2026
PR #585 removed malignmark from MathML 4