-
Notifications
You must be signed in to change notification settings - Fork 826
LaTeX Block: Switch to MathML and add styling support #44928
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Conversation
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
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:
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:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Code Coverage Summary7 files are newly checked for coverage. Only the first 5 are listed here.
Full summary · PHP report · JS report If appropriate, add one of these labels to override the failing coverage check:
Covered by non-unit tests
|
Are the |
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> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<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' ) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aria-label={ __( 'Edit Math', 'jetpack' ) } | |
aria-label={ __( 'Edit math', 'jetpack' ) } |
<Text upperCase>{ __( 'Preview', 'jetpack' ) }</Text> | ||
{ source.trim() && ( | ||
<div | ||
className="jetpack-math-rendered" | ||
style={ style } | ||
ref={ r => r !== renderAreaRef && setRenderAreaRef( r ) } | ||
/> | ||
) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<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:


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:
Jetpack product discussion
Does this pull request change what data or activity we track or use?
No.
Testing instructions:
Tex format
\int_{x=a}^{y} \frac{df(x)}{dx} \, dx = f(y) - f(a)
LaTeX.MathML
<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>