Skip to content

Conversation

alshakero
Copy link
Member

@alshakero alshakero commented Aug 24, 2025

Proposed changes:

This switches the LaTeX block to render MathML instead of HTML and renames it to Math. This has many benefits:

1. Works natively in the Jetpack app!
2. No need to render on the client side thus load a 3rd party library. Faster. Safer.
3. No need for client side CSS since <math> comes styled natively.
4. Supported by all browsers.

It also extends the block to support font size, colors, and spacing.

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

Does this pull request change what data or activity we track or use?

No.

Testing instructions:

Tex format

  1. Apply this.
  2. Sandbox a site and go to /wp-admin/post-new.php
  3. Add a Math block.
  4. Use \int_{x=a}^{y} \frac{df(x)}{dx} \, dx = f(y) - f(a) LaTeX.
  5. Save the page.
  6. It should render the follwing forumla.
image

MathML

  1. Add a Math block.
  2. Enter <math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>f</mi><mo>=</mo><msup><mi>x</mi><mn>2</mn></msup></mrow><annotation encoding="application/x-tex">f=x^2</annotation></semantics></math>
  3. Save the page.
  4. It should render the follwing forumla.
image

@github-actions github-actions bot added [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Status] In Progress labels Aug 24, 2025
Copy link
Contributor

github-actions bot commented Aug 24, 2025

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!


Jetpack plugin:

The Jetpack plugin has different release cadences depending on the platform:

  • WordPress.com Simple releases happen as soon as you deploy your changes after merging this PR (PCYsg-Jjm-p2).
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly:
    • Scheduled release: September 2, 2025
    • Code freeze: September 1, 2025

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

@github-actions github-actions bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Aug 24, 2025
Copy link
Contributor

github-actions bot commented Aug 24, 2025

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack), and enable the fix/latex-block-v2 branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack fix/latex-block-v2

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

Copy link

jp-launch-control bot commented Aug 24, 2025

Code Coverage Summary

7 files are newly checked for coverage. Only the first 5 are listed here.

File Coverage
projects/plugins/jetpack/extensions/blocks/math/edit.js 0/19 (0.00%) 💔
projects/plugins/jetpack/extensions/blocks/math/editor.js 0/1 (0.00%) 💔
projects/plugins/jetpack/extensions/blocks/math/icon.js 0/2 (0.00%) 💔
projects/plugins/jetpack/extensions/blocks/math/math.php 0/7 (0.00%) 💔
projects/plugins/jetpack/extensions/blocks/math/save.js 0/5 (0.00%) 💔

Full summary · PHP report · JS report

If appropriate, add one of these labels to override the failing coverage check: Covered by non-unit tests Use to ignore the Code coverage requirement check when E2Es or other non-unit tests cover the code Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage.

@alshakero alshakero added the [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it label Aug 25, 2025
@alshakero alshakero marked this pull request as ready for review August 27, 2025 18:51
@alshakero alshakero marked this pull request as draft August 27, 2025 19:37
@alshakero alshakero changed the title LaTeX Block: Switch to MathML LaTeX Block: Switch to MathML and add styling support Aug 28, 2025
@alshakero alshakero marked this pull request as ready for review August 28, 2025 09:34
@alshakero alshakero requested review from simison and jeherve August 28, 2025 11:27
@simison
Copy link
Member

simison commented Aug 28, 2025

Are the <math> tags rendered by default with math-style: compact? I would've expected normal instead (https://developer.mozilla.org/en-US/docs/Web/CSS/math-style). In future that could be a setting.

@simison
Copy link
Member

simison commented Aug 28, 2025

There is some issue with background not applied to the grey box but something inside it:

Block selected
Screenshot 2025-08-28 at 15 22 33

Block unselected:
Screenshot 2025-08-28 at 15 22 37

What do you think adding border controls as well? They fit well the use case:

Screenshot 2025-08-28 at 15 21 02
		"__experimentalBorder": {
			"color": true,
			"radius": true,
			"style": true,
			"width": true,
			"__experimentalDefaultControls": {
				"color": true,
				"radius": true,
				"style": true,
				"width": true
			}
		},

@simison
Copy link
Member

simison commented Aug 28, 2025

Likely best to remove the grey box entirely since we don't render it on frontend either? I think it's better as plain transparent formula, and folks can add background if they need.

Screenshot 2025-08-28 at 15 26 36 Screenshot 2025-08-28 at 15 26 31

@simison
Copy link
Member

simison commented Aug 28, 2025

Worked beautifully on emails as well!

Screenshot 2025-08-28 at 15 30 11

@alshakero
Copy link
Member Author

alshakero commented Aug 28, 2025

Are the tags rendered by default with math-style: compact? I would've expected normal instead (developer.mozilla.org/en-US/docs/Web/CSS/math-style). In future that could be a setting.

It seems to come from the user agent. So I guess MDN is incorrect or something.

Addressed all the rest. Looks great now.


const LatexPlaceholder = () => {
return (
<span className="jetpack-math-rendered-placeholder">{ __( 'Write Math…', 'jetpack' ) }</span>
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<span className="jetpack-math-rendered-placeholder">{ __( 'Write Math…', 'jetpack' ) }</span>
<span className="jetpack-math-rendered-placeholder">{ __( 'Write math…', 'jetpack' ) }</span>

We try to use sentence case over title case everywhere nowadays.

{ ...blockProps }
tabIndex={ 0 }
role="button"
aria-label={ __( 'Edit Math', 'jetpack' ) }
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
aria-label={ __( 'Edit Math', 'jetpack' ) }
aria-label={ __( 'Edit math', 'jetpack' ) }

Comment on lines +59 to +66
<Text upperCase>{ __( 'Preview', 'jetpack' ) }</Text>
{ source.trim() && (
<div
className="jetpack-math-rendered"
style={ style }
ref={ r => r !== renderAreaRef && setRenderAreaRef( r ) }
/>
) }
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<Text upperCase>{ __( 'Preview', 'jetpack' ) }</Text>
{ source.trim() && (
<div
className="jetpack-math-rendered"
style={ style }
ref={ r => r !== renderAreaRef && setRenderAreaRef( r ) }
/>
) }
{ source.trim() && (
<>
<Text upperCase>{ __( 'Preview', 'jetpack' ) }</Text>
<div
className="jetpack-math-rendered"
style={ style }
ref={ r => r !== renderAreaRef && setRenderAreaRef( r ) }
/>
</>
) }

I think it looks better hiding the "Preview" until there's some content:

Screenshot 2025-08-29 at 10 23 07 Screenshot 2025-08-29 at 10 23 26

@simison
Copy link
Member

simison commented Aug 29, 2025

Otherwise works great, just border getting applied to Placeholder component:

Screenshot 2025-08-29 at 10 07 34

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Latex [Block] Math [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Status] In Progress [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants