Repository navigation
Math Block: Fix matrix/array cell alignment in Chromium - #81019
Mustafabharmal wants to merge 7 commits into
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Thanks for picking up the issue, @Mustafabharmal. Usually, we go with the first PR opened for an issue. I believe both PRs only make CSS changes. The other PR is longer because it also includes integration tests. |
| // Temml uses these classes to justify cells in matrices and other | ||
| // arrays. LaTeX alignment is always left-to-right, regardless of the | ||
| // page's text direction, so these are excluded from RTL flipping. | ||
| .tml-right { |
There was a problem hiding this comment.
We'll need these for the format too
`common.css` is loaded on every page and in the editor canvas regardless of which blocks are present, so the rules also cover the inline math format, which produces the same classes and has no stylesheet of its own. The e2e test publishes an `aligned` formula and measures on the front end that every aligned cell's content touches the edge its class names. It fails in Chromium and WebKit without the rules and passes in Firefox, which aligns the cells natively. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The same helper now checks the aligned cells in the editor canvas before publishing and on the front end after, and asserts the cells exist first so the measurement cannot pass on an empty match. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
@Mustafabharmal @im3dabasia Please double check my changes. Yes there's two PRs open. We'll make sure to prop everyone when this merges, so it doesn't really matter which PR is merged. |
im3dabasia
left a comment
There was a problem hiding this comment.
Overall this looks like it's heading in the right direction. I think the title and description could use a refresh to match the latest changes.
|
|
||
| ### Bug Fixes | ||
|
|
||
| - Math: Align the cells of `aligned`, `cases` and tagged equations in Chromium and Safari, in the Math block and in inline math ([#81019](https://github.com/WordPress/gutenberg/pull/81019)). |
There was a problem hiding this comment.
This mentions cases, tagged equations and inline math, but the test only covers aligned. Should we test those too, or trim the entry?
| ] ); | ||
| } ); | ||
|
|
||
| test( 'should align the columns of an aligned environment @webkit @firefox', async ( { |
| // within a pixel. | ||
| async function getMisalignedCells( container ) { | ||
| const cells = container.locator( | ||
| '.wp-block-math mtd.tml-right, .wp-block-math mtd.tml-left' |
There was a problem hiding this comment.
This only checks inside .wp-block-math.
Would it be worth adding an inline math case?
| // LaTeX of the Math block and the inline math format, marks cells of `aligned`, | ||
| // `cases` and tagged equations with these classes and relies on CSS. The | ||
| // alignment is a property of the notation, so it is not flipped for RTL. | ||
| math .tml-right { |
There was a problem hiding this comment.
I'm curious why this went in common.scss, which loads everywhere. Would the Math block's styles plus the inline format's styles work too?
There was a problem hiding this comment.
Inline styles don't have a stylesheet loader like blocks do. Common css is meant exactly for these common content tags imo.
There was a problem hiding this comment.
As long as this doesn't get unwieldy it's fine I think.
| // Chromium only: `text-align: right` does not move the cell's block content, | ||
| // the `-webkit-` value does. Safari parses that value but renders it wrong, so | ||
| // the feature query, taken from temml's own stylesheet, excludes it. | ||
| @supports (not (-webkit-backdrop-filter: blur(1px))) and (not (-moz-appearance: none)) { |
There was a problem hiding this comment.
Could we link to the matching lines in Temml's stylesheet here, to make future updates easier?
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
I no longer think this is the right solution. We shouldn't rely on the classes imo, see #83164
|
I've fixed this in #83164 and prop'ed you all. Feel free to report issues if any, thank you! |
What?
Closes #80732.
Fixes the alignment of matrices and other array-based mathematical expressions rendered by the Math block in Chromium-based browsers.
Why?
The Math block uses Temml to render LaTeX as MathML. Temml emits
.tml-rightand.tml-leftclasses for cells that require explicit horizontal alignment in matrices and other array environments.Although Temml ships companion CSS that applies these alignment rules, Gutenberg currently doesn't include those styles. As a result, Chromium-based browsers don't correctly align these cells, causing expressions such as matrices inside
alignedenvironments to render with misaligned columns.This PR adds the missing alignment rules used by Temml so the rendered output matches Temml's intended presentation across supported browsers.
How?
This change mirrors Temml's upstream alignment styles while keeping them scoped to the Math block.
.tml-rightand.tml-leftclasses emitted by Temml.@supportsrule as Temml to apply the required-webkit-alignment values only where needed./*rtl:ignore*/since mathematical alignment should remain left-to-right regardless of the page's text direction.Testing Instructions
alignedenvironment).=signs are aligned correctly.Screenshots or screencast
Before
Matrices and aligned expressions render with misaligned columns in Chromium-based browsers because the Temml alignment classes are not styled.
After
Matrices and aligned expressions render with consistent column alignment across supported browsers, matching Temml's intended output.