Make WordPress Core

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

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 math to the elements wptexturize() skips, next to pre, code, kbd, style, script and tt. The content of a math element is notation, not prose.

Before:

<annotation encoding="application/x-tex">f'(x) &#8211; 1 \text{&#8220;q&#8221;}</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

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 @muneebashraf
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 &#8220;hi&#8221; &#8212; 3&#215;4.</p><math><mi>x</mi><mo>&#8212;</mo><mn>1</mn><annotation encoding="application/x-tex">x&#8211;1 &#8220;a&#8221; 2&#8242;</annotation></math>

With the patch: the <math> element is returned unchanged, and the prose before it is still texturized.

<p>He said &#8220;hi&#8221; &#8212; 3&#215;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.php on 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.

This ticket was mentioned in ​Slack in #core by im3dabasia1. ​View the logs.


6 days ago

#5 @im3dabasia1
6 days ago

As per the pre-RC1 7.2 bug scrub:

there are two PRs (​13647 and ​13757), both with merge conflicts. @ellatrix, which one should we go with? We can resolve the conflicts on that one and move it to review.

#6 @audrasjb
2 days ago

  • Milestone 7.2 → 7.3

I'm moving this ticket to 7.3 as WP 7.2 RC1 is going to be released in less than 24h.

Note: See TracTickets for help on using tickets.