Skip to content

Math Block: Fix matrix/array cell alignment in Chromium - #81019

Closed
Mustafabharmal wants to merge 7 commits into
WordPress:trunkfrom
Mustafabharmal:fix/math-block-matrix-alignment
Closed

Mustafabharmal wants to merge 7 commits into
WordPress:trunkfrom
Mustafabharmal:fix/math-block-matrix-alignment

Conversation

@Mustafabharmal

Copy link
Copy Markdown
Contributor

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-right and .tml-left classes 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 aligned environments 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.

  • Adds alignment rules for the .tml-right and .tml-left classes emitted by Temml.
  • Uses the same Chromium-specific @supports rule as Temml to apply the required -webkit- alignment values only where needed.
  • Marks the alignment declarations with /*rtl:ignore*/ since mathematical alignment should remain left-to-right regardless of the page's text direction.

Testing Instructions

  1. Create a new post or page.
  2. Insert a Math block.
  3. Paste the LaTeX example from the issue (or any expression containing matrices inside an aligned environment).
  4. View the rendered output in Chrome or another Chromium-based browser.
  5. Verify the matrix labels and = signs are aligned correctly.
  6. Repeat the test in Safari and Firefox.
  7. Verify the expression renders correctly in all supported browsers.
  8. Publish or preview the post and verify the front-end rendering matches the editor.

Screenshots or screencast

Before

Matrices and aligned expressions render with misaligned columns in Chromium-based browsers because the Temml alignment classes are not styled.

image

After

Matrices and aligned expressions render with consistent column alignment across supported browsers, matching Temml's intended output.

image

@github-actions github-actions Bot added the [Package] Block library /packages/block-library label Jul 31, 2026
@Mustafabharmal Mustafabharmal mentioned this pull request Jul 31, 2026
3 of 6 tasks
@github-actions

github-actions Bot commented Jul 31, 2026 •

Copy link
Copy Markdown

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: Mustafabharmal <mustafabharmal@git.wordpress.org>
Co-authored-by: ellatrix <ellatrix@git.wordpress.org>
Co-authored-by: im3dabasia <im3dabasia1@git.wordpress.org>
Co-authored-by: vedant-ere <vedantere@git.wordpress.org>
Co-authored-by: BlackStar1991 <blackstar1991@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@im3dabasia im3dabasia added [Type] Bug An existing feature does not function as intended [Block] Math labels Jul 31, 2026
@im3dabasia

Copy link
Copy Markdown
Contributor

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 {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need these for the format too

ellatrix and others added 3 commits September 16, 2026 10:29
`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>
ellatrix
ellatrix previously approved these changes Sep 16, 2026
@ellatrix

Copy link
Copy Markdown
Member

@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 im3dabasia left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ( {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do the @WebKit / @Firefox projects run in CI, or does only Chromium check this?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default is Chromium, @WebKit @Firefox means those are included too now.

// within a pixel.
async function getMisalignedCells( container ) {
const cells = container.locator(
'.wp-block-math mtd.tml-right, .wp-block-math mtd.tml-left'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline styles don't have a stylesheet loader like blocks do. Common css is meant exactly for these common content tags imo.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we link to the matching lines in Temml's stylesheet here, to make future updates easier?

ellatrix and others added 2 commits September 17, 2026 08:49
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@ellatrix

Copy link
Copy Markdown
Member

I've fixed this in #83164 and prop'ed you all. Feel free to report issues if any, thank you!

@ellatrix ellatrix closed this Sep 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Math [Package] Block library /packages/block-library [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Math component Problem with matrix

3 participants