Page MenuHomePhabricator

CSS styles for native MathML and client side MathJax mode
Open, HighPublic

Assigned To
None
Authored By
SalixAlba
Aug 10 2026, 9:26 AM
Referenced Files
F103285903: image.png
Wed, Sep 16, 4:23 PM
F103285873: image.png
Wed, Sep 16, 4:23 PM
F103285817: image.png
Wed, Sep 16, 4:23 PM
F103285773: image.png
Wed, Sep 16, 4:23 PM
F103285711: image.png
Wed, Sep 16, 4:23 PM
F103285639: image.png
Wed, Sep 16, 4:23 PM
F103285607: image.png
Wed, Sep 16, 4:23 PM
F103285560: image.png
Wed, Sep 16, 4:23 PM

Description

In https://en.wikipedia.org/wiki/Wikipedia_talk:WikiProject_Mathematics#Bugs_and_Glitches there is a discussion on CSS issues with formatting <math display=block> elements. There is a local preference there to have these left-aligned with margin-left: 1.6em. This brings up a number of issues that might apply to CSS for all sites.

Ideally CSS should be configured so that there is no difference between the different rendering modes. I've created a test-case at https://en.wikipedia.org/wiki/User:Salix_alba/sandbox#Indentation_of_%3Cmath_display%3Dblock%3E_elements showing the different options.

  1. Font size of MathML formats. The SVG options uses a slightly bigger font size. This can be matched by adding stype rules for the MathML <math> tag with
math.mwe-math-element-block {  
	font-size: 118%;
}
math.mwe-math-element-inline {
	font-size: 118%;
}
  1. Spacing around blocks. The https://en.wikipedia.org/wiki/MediaWiki:Common.css has style rules
/* larger inline math */
span.mwe-math-mathml-inline {
	font-size: 118%;
}

/* Make <math display="block"> be left aligned with one space indent for 
 * compatibility with style conventions
 */
.mwe-math-fallback-image-display,
.mwe-math-mathml-display {
	margin-left: 1.6em !important;
	margin-top: 0.6em;
	margin-bottom: 0.6em;
}

.mwe-math-mathml-display math {
	display: inline;
}

The MathML mode produces a

<math xmlns="http://www.w3.org/1998/Math/MathML" class="mwe-math-element mwe-math-element-block mathjax_ignore" display="block" ...>

element, and the client-side SVG produces

<mjx-container class="MathJax" jax="SVG" overflow="overflow" display="true"><svg ...

These need corresponding CSS styles

mjx-container[display] {  
	text-align: left !important; 
	margin-left: 1.6em !important;
}
math.mwe-math-element-block {  
	display: flex;
  	justify-content: left;
	margin-left: 1.6em;
	margin-top: 0.6em;
	margin-bottom: 0.6em;
}
  1. It would be nice to have the same CSS options for the latex source mode. So if someone wanted to use the MathJax CDN via their common.js would have the same styles.
span.mwe-math-fallback-source-display {  
	margin-left: 1.6em;
	margin-top: 0.6em;
	margin-bottom: 0.6em;
}
  1. At https://en.wikipedia.org/wiki/MediaWiki_talk:Common.css#Allignment_of_%3Cmath_display=block%3E @Izno has commented on the !important tags. Ideally we should be able to remove these. These seem to be needed as style sheet is included in the head of the page with
<style id="MJX-SVG-styles">

That overrides preferences from load.php and common.css.

  1. I've used display: flex; for the MathML <math> element, wondering if the rule
.mwe-math-mathml-display math {
	display: inline;
}

is needed or should be flex as well.

Event Timeline

I've created a test case at https://www.mediawiki.org/wiki/Extension:Math/T434419 using the default styles here, and https://www.mediawiki.org/wiki/Extension:Math/T434419/left-align using a style sheet with left-alignment, and modified font-sizes and vertical margins.

Also, it would be nice for Math to provide a config option to support alignment of block math better rather than having to do it all in Common.css. Probably it only needs to support this left kind of block and the current central block (but I guess if you really wanted you could add support for right blocks as well) (I'm assuming CSS Janus does its thing and takes care of it for rtl wikis). cc @Jdlrobson-WMF

Krinkle renamed this task from CSS styles for clientside SVG and client side MathML options to CSS styles for native MathML and Client side MathJax mode.Aug 19 2026, 7:15 PM
Krinkle renamed this task from CSS styles for native MathML and Client side MathJax mode to CSS styles for native MathML and client side MathJax mode.

For native MathML I adopted this on mediawiki.org as well:

https://www.mediawiki.org/wiki/Extension:Math/Native_MathML/Reported_Cases
https://www.mediawiki.org/wiki/Template:Math_table_row/styles.css

.tpl-math-examples > math,
.tpl-math-examples .mwe-math-mathml-inline {
  font-size: 118%; /* Based on https://en.wikipedia.org/wiki/MediaWiki:Common.css */
}

I'd happy to review any additions to the Math extension so that all wikis get them automatically, and we can reduce manual overrides on each wiki.

Krinkle triaged this task as High priority.Aug 19 2026, 7:33 PM

I looked around various wiki's version of https://en.wikipedia.org/wiki/Frenet%E2%80%93Serret_formulas and most languages have left aligned and indented display equations. Right to left languages like Arabic and Hebrew have right aligned, indented for Hebrew but not Arabic.

This suggested a global option, at least for Wikipedia wikis.

For vertical spacing the extensions seems to provide the rule

mjx-container[display] {
    display: block;
    text-align: center;
    justify-content: center;
    margin: .7em 0;
    padding: .3em 2px;
}

Although I can't see quite where this is generated.

For compatibility between mode, we should have the same spacing for native-MathML with a rule like

math.mwe-math-element-block {
    margin: .7em 0;
}
```.

Font size issues.

I've added a line a<math forcemathmode=native>aB</math>B at the top of https://en.wikipedia.org/wiki/User:Salix_alba/sandbox. On a chromium browser on windows these render as

image.png (90×66 px, 2 KB)

Not great as we would ideally like inline plaintext and math to be the same font size. I get the same with Edge and Firefox on windows, when not logged in.

I thought there might be an OS/browser issue. But I've checked the Safari on Mac's and the issue is the same there.

Q1, should we have the same font size for inline MathML and the surrounding text?

Q2, should inline text and display text have the same font sizes.

Font size issues, this might be font related. I've used Ecosia, a chromium base browser, and updated font size in browser setting to 22pt. Looking at the rendering of

a<math forcemathmode=native>aB</math>B

with various fonts.

Asana Math

image.png (136×60 px, 2 KB)

Cambria Math

image.png (120×62 px, 2 KB)

DejaVu Math TeX Gyre

image.png (140×70 px, 2 KB)

Garamond Math

image.png (132×68 px, 2 KB)

Latin Modern Math

image.png (156×70 px, 2 KB)

STIX Two Math

image.png (134×72 px, 2 KB)

TeX Gyre Bonum Math

image.png (136×76 px, 2 KB)

XITS Math

image.png (134×68 px, 2 KB)

Fira Math

image.png (132×52 px, 2 KB)

GFS Neohellenic Math

image.png (124×68 px, 2 KB)

Its only DejaVu Math TeX Gyre that matches heights for both the a and B. Asana Math, has the same height for B, but slightly less for a. Other are slightly smaller for both. XITS Math and GFS Neohellenic Math are significantly smaller for a.

Could you clarify whether the intent of this task is to establish a shared CSS baseline between native MathML and the client-side MathJax rendering mode, particularly around font metrics, spacing, sizing, and alignment? I’d also like to understand whether there are existing MathJax/native MathML styles or browser-specific differences that should be preserved, and whether the preferred approach is to extend the existing math stylesheet or introduce a separate set of rules for the client-side mode.