Opened 2 months ago
Last modified 2 days ago
#66153 new defect (bug)
wptexturize alters the content of math elements, including the LaTeX annotation
| Reported by: | ellatrix | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | 7.3 |
| Component: | Formatting | Version: | |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: |
Description
See https://github.com/WordPress/wordpress-develop/pull/13647.
The proposed fix is to add math to the exclusion list.
Change History (6)
This ticket was mentioned in PR #13647 on WordPress/wordpress-develop by @ellatrix.
2 months ago
#1
This ticket was mentioned in PR #13757 on WordPress/wordpress-develop by @therssoftware.
8 weeks ago
#2
Description
wptexturize() automatically converts ASCII quotes, dashes, and primes into typographical curly quotes, en/em-dashes, and multiplication symbols.
MathML elements and LaTeX source annotations stored inside <annotation encoding="application/x-tex"> represent notation and source code rather than prose. Converting characters inside <math> elements corrupts formulas and breaks LaTeX rendering.
This PR adds 'math' to the default list of elements skipped by wptexturize() ($default_no_texturize_tags), updates the corresponding @since 7.2.0 docblocks, and adds unit tests covering MathML, LaTeX annotations, and filter propagation.
Trac ticket: https://core.trac.wordpress.org/ticket/66153
#3
@
7 weeks ago
Patch Testing Report
Patch tested: https://github.com/WordPress/wordpress-develop/pull/13647 (head b489039)
Environment
- WordPress: trunk
dc829be(reproduction) and the PR head (patch) - PHP: 8.4.26 (CLI, Windows)
- Database: SQLite (SQLite Database Integration 3.0.2)
- Test method: PHPUnit test calling
wptexturize()on prose followed by a MathML element with a LaTeX annotation.
Steps
Input:
<p>He said "hi" -- 3x4.</p><math><mi>x</mi><mo>--</mo><mn>1</mn><annotation encoding="application/x-tex">x--1 "a" 2'</annotation></math>
Actual results
Trunk (bug reproduced): the MathML operator and the LaTeX source are texturized.
<p>He said “hi” — 3×4.</p><math><mi>x</mi><mo>—</mo><mn>1</mn><annotation encoding="application/x-tex">x–1 “a” 2′</annotation></math>
With the patch: the <math> element is returned unchanged, and the prose before it is still texturized.
<p>He said “hi” — 3×4.</p><math><mi>x</mi><mo>--</mo><mn>1</mn><annotation encoding="application/x-tex">x--1 "a" 2'</annotation></math>
- ✅ Patch fixes the issue.
- ✅
tests/phpunit/tests/formatting/wpTexturize.phpon the PR head: OK (358 tests, 443 assertions).
Additional notes
https://github.com/WordPress/wordpress-develop/pull/13757 makes the same change. It gives the same output for this input, and its wpTexturize.php passes too (359 tests, 446 assertions).
AI assistance: Claude Code (Claude Opus 5.5) helped write the test. The results above come from running it.
wptexturize()rewrites text inside MathML. The Math block and the inline math format save the LaTeX source in an<annotation encoding="application/x-tex">inside the<math>element, and on the front end and in feeds that source comes out changed:-becomes an en dash, straight quotes become curly,...becomes an ellipsis. Anything that reads the annotation (copying the LaTeX, a plugin that re-renders it, assistive technology) gets source the author did not write. When a formula cannot be rendered, the annotation is what the browser displays, so readers see it too.<mtext>and<mo>content is rewritten the same way.This adds
mathto the elementswptexturize()skips, next topre,code,kbd,style,scriptandtt. The content of amathelement is notation, not prose.Before:
<annotation encoding="application/x-tex">f'(x) – 1 \text{“q”}</annotation>After, the annotation is unchanged:
f'(x) - 1 \text{"q"}. Text around the formula is still texturized. Includes a unit test.Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Fable 5.1
Used for: Finding the bug, writing the change and the test; reviewed by me.
---
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.
🤖 Generated with Claude Code