Skip to content

Fix CSS for zero-width combining characters so it doesn't impact other variants.#1445

Open
dpvc wants to merge 1 commit intodevelopfrom
fix/combining-chars
Open

Fix CSS for zero-width combining characters so it doesn't impact other variants.#1445
dpvc wants to merge 1 commit intodevelopfrom
fix/combining-chars

Conversation

@dpvc
Copy link
Member

@dpvc dpvc commented Mar 19, 2026

In some fonts, the combining characters are zero-width (so that they overlap the character on the left). Others are normal width, and the browser positions the character automatically, at least win some browsers (not Safari). MathJax has to accommodate both types of characters, and browsers that do and do not handle the normal width characters themselves. It does this by setting width CSS for the zero-width characters so that they have the actual width of the ink of the character and margin-left to position it so it extends to the left. This gives the character an actual width, but still places it as usual when not used as an accent. But if there are other sizes of the character that are not zero-width, they will inherit the margin-left from the normal size, and so get placed incorrectly.

This happens with U+0332 (combining underline) in the mathjax-newcm font. For example, the expression

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
  <munder>
    <mi>&#x2202;</mi>
    <mo>&#x332;</mo>
  </munder>
  <munder>
    <mi>t</mi>
    <mo>&#x332;</mo>
  </munder>
</math>

currently produces output where the first underline is shifted to the left:

underline misplaced

This is because the CSS for the normal size (used under the "t") has margin-left, while the first one (in a larger size) does not, but inherits the margin-left from the normal size when it shouldn't.

The solution used here is to isolate the normal size's CSS to not apply to other variants when it has margin-left set. That is done by adding a :not() portion to the selector that rules out versions taken from other variants.

@dpvc dpvc requested a review from zorkow March 19, 2026 11:32
@dpvc dpvc added this to the v4.2 milestone Mar 19, 2026
@codecov
Copy link

codecov bot commented Mar 19, 2026

Codecov Report

❌ Patch coverage is 0% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.49%. Comparing base (5caee44) to head (2e0c4e5).

Files with missing lines Patch % Lines
ts/output/chtml/FontData.ts 0.00% 8 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1445      +/-   ##
===========================================
- Coverage    86.49%   86.49%   -0.01%     
===========================================
  Files          340      340              
  Lines        86044    86050       +6     
  Branches      4833     3190    -1643     
===========================================
  Hits         74425    74425              
- Misses       11595    11625      +30     
+ Partials        24        0      -24     

☔ View full report in Codecov by Sentry.
📢 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.

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.

1 participant