Make MathML selectable for great interop with apps that consume MathML in HTML such as Word and PowerPoint
- In the web browser load the following webpage that uses MathJax 4.1 with assistiveMml on: https://petewu100.blob.core.windows.net/newcontainer/MathJax.4.1.Test.htm
- Drag across the web page to select some content including some math.
- Ctrl+C to Copy.
- Boot Word for Windows Version 2508 or later.
- Blank Document.
- Ctrl+V to Paste.
=> Note: the pasted content only contains the heading text and not the math.
Expected: the math to be included as well.
- In the web browser, go to https://petewu100.blob.core.windows.net/newcontainer/SelectableMathMLBookmarklet.htm.
- Click on the "Selectable MathML" link and drag it to the browser Favorites or Bookmarks bar.
- Go back to https://petewu100.blob.core.windows.net/newcontainer/MathJax.4.1.Test.htm.
- Click the "Selectable MathML" button on the browser Favorites or Bookmarks bar.
- Drag across the web page to select some content including some math.
- Ctrl+C to Copy.
- Switch back to Word.
- Ctrl+V to Paste.
=> Note: now the math is included.
Expected: the math to be included after step 6 without having to use the "Selectable MathML" bookmarklet.
MathJax adds the following CSS rule in the webpage which makes the MathML unselectable:
mjx-assistive-mml { -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; }
Why?
I haven't noticed any interaction problems when the MathML is selectable. Other math packages on the web keep the MathML selectable and it doesn't seem to cause any problems.
Making the MathML selectable has a huge benefit. It allows the math to be copy/paste to apps that consume MathML in HTML such as Word, PowerPoint. Excel (within shapes in SmartArts), and soon OneNote. Furthermore, the semantics of the math are preserved so that it is editable and accessible in the documents.
https://github.com/user-attachments/assets/1513164f-9615-41ec-8d78-f9dfe6843f98
Thanks for your feature request.
The assistiveMML extension originally was included as a temporary means of providing screen-reader support while the speech rule engine (SRE) that underlies MathJax's speech generation was improved in order to make it the default screen-reader support. It is likely to be deprecated in a future version.
The mml-svg.js component that you are loading has the SRE-geenrated speech on by default. You should not include assistiveMML in that case, as the two are different alternatives for the same thing. As it stands, the assistiveMML does nothing, as the SRE speech component will mark it aria-hidden="true" in order to avoid both the SRE speech and the assistive MathML from being voiced by screen readers. Unless you are accessing this MathML programmatically by other code on the page, the assistiveMML extension is just a waste of time.
There are a number of issues involved with allowing the MathML to be selected.
-
While the SVG output is not selectable (as it uses SVG paths, not text), the CHTML output is selectable, and since assistiveMML can be used with either one, allowing it to be selected would mean that you would get duplicate content when CHTML is used.
-
Because the assistive MathML is inserted at the end of the DOM nodes for the math, selecting it can be problematic if you are stopping your selection within or at the end of an equation (rather than selecting additional text past the end of the expression). This makes it less reliable and a source of confusion and frustration.
-
While your example works in Windows, it does not work in some other environments. For example, in MacOS with Word, that MathML doesn't produce formatted math, but only the text of the MathML is inserted. For example:
We don't generally include features that don't work across browsers and OSes (and screen-readers, when appropriate).
For these reasons, it is unlikely that that MathML will be made selectable.
Oh, I forgot to mention, there are several issues with the MathJax configuration in your test file.
First, because you are loading the mml-svg.js component, which includes input/mml and output/svg, there is no need to specify those in the loader.load array, as they are already loaded. So the loader section can be removed entirely (but see below).
Second, the parseAs value of mml is not valid. There are two valid options, html and xml. You probably want xml.
Third, since you are disabling the contextual menu, it is a little counter-intuitive to use menuOptions just to load the assistiveMML component. It would be more direct to include a11y/assistive-mml in the loader.load array and use options to set enableMenu: false and enableAssistiveMml: true.
Fourth, you have window.MathJax = window.MathJax = { ... }, which is redundant.
So a better configuration would be:
window.MathJax = {
loader: {
load: ["a11y/assisitve-mml"],
},
mml: {
parseAs: "xml" // Ensures MathML parsing as xml
},
options: {
enableMenu: false,
enableAssistiveMML: true,
}
};
Thank you for taking a look at this, Davide.
Apologies for the messy MathJax config in the hastily composed test file. I have published a new test file that uses loader: { load: [ "a11y/assistive-mml"], }, as you have suggested (with typo fixed) and removed the enableAssistiveMML option as that doesn't seem to be needed anymore and causes an error. The new test file is here:
https://petewu100.blob.core.windows.net/newcontainer/MathJax.4.1.Test.d.htm
Regarding your feedback:
- It might make sense to make the CHTML output unselectable. Copy/pasting that gives you unreadable gibberish (since the complex CSS applied to it is often not preserved in the process). But even with the CHTML selectable, users can simply delete the undesired content after copy/paste if they want. In the Microsoft 365 apps, the HTML importers recognize the container elements for this HTML content for some popular math packages (including certain versions of MathJax) and filter it out.
- It seems like the drag handling in an equation processed by MathJax, doesn't allow selecting a range within an equation. While that is not ideal, including whole equations in a selection works great and I think that is the most common scenario that users do and would want to work properly.
- There is absolutely nothing platform-specific about MathML in HTML being great for interoperability. I just used Word for Windows as example. It also works in Word for Mac version 16.100 or later as well as PowerPoint and Excel (within shapes and SmartArts) for Windows version 2508, Mac version 16.100, iOS version 2.100, and Android version 16.0.19220.20000, PowerPoint for the web, and OneNote for Windows version 2601, Mac version 16.105, iOS version 2.105, and Android version 16.0.19628.20000 or later. And it will expand to more apps in the future. And it works with all major browsers. That is incredible reach to hundreds of millions of customers, and we are already seeing high usage on sites with selectable MathML such as Wikipedia, ChatGPT, and others.
Also, while the SRE-generated speech in MathJax has broad reach, the screen reader experience is richer with MathML when using a MathML-capable screen reader since it allows you to navigate hierarchically through the elements, so you have time to understand the content and structure rather than having to listen to the whole equation in one go. And the list of MathML-capable screen readers will be growing soon ;).
We are working closely with the DAISY consortium to improve interoperability of math across the ecosystem, and they are especially excited about copy/pasting selections containing MathML into Microsoft 365 apps. They are supportive of the approach of making MathML selectable and Neil Soiffer referred me to this github to file a request with MathJax.
Please consider whether this change can be made. I can set up time to chat as well if you'd like.
Thank you.
FYI, this blog post from August 2025 covers many of the improvements to math in Microsoft 365:
https://techcommunity.microsoft.com/blog/microsoft365insiderblog/writing-and-presenting-about-math-is-easy-and-inclusive-with-microsoft-365/4439216
I'll be posting another blog post with more improvements soon.
It might make sense to make the CHTML output unselectable.
That was the case when MathJax v3.0 was released, and there was considerable blowback from that.
It seems like the drag handling in an equation processed by MathJax, doesn't allow selecting a range within an equation.
The SVG output that you are using is not selectable because the characters are rendered as paths, not text. But in CHTML output drag selection within an expression is possible.
including whole equations in a selection works great
My original post was not very clear on the problem that I was trying to point out, and including partial selection in my description was probably a bad idea. The issue I was trying to point out is that if you make a selection that ends with an expression and doesn't include any text beyond that, you are likely not to get the MathML for that final equation even though it is selected. At least that's how things worked when we experimented with this approach a few years ago. That fragility in the selection process was enough to have us shelve it at the time.
It also works in Word for Mac version 16.100
Ah, I was using Word 16.96 from last July, so I guess that wasn't new enough to get this feature. I don't have access to most of the other products you mention, but I did try it with PowerPoint on the Web, which I do have access to. It still didn't work for me:
Also, while the SRE-generated speech in MathJax has broad reach, the screen reader experience is richer with MathML when using a MathML-capable screen reader since it allows you to navigate hierarchically through the elements,
MathJax's expression explorer also does this (and has done it since v2.7). In v4, if you tab to an expression it should enter the explorer automatically (in earlier versions you needed to turn on the explorer). Use the down arrow key to move into the lower levels of the expression and the left and right keys to move among the terms at a given level. Use the up arrow to move to higher levels again. The "h" key should open a help dialog that explains additional features.
I have marked your issue as a feature request, so it will remain in the queue of features to consider.
Thank you, @dpvc.
If you are a Microsoft 365 subscriber, you can update your Word for Mac build by going to the Help menu and then Check for Updates.
Regarding selecting near the boundary of the MathML: there was a bug in Chromium in this scenario, but it was fixed recently. For example, in the following webpage, https://petewu100.blob.core.windows.net/newcontainer/MathMLInHTML.JustMath.htm, press Ctrl+A to Select All, then press Ctrl+C to Copy and the full MathML will be included in the HTML posted to the clipboard. When you Paste it into recent versions of Word or PowerPoint for Windows or Mac, native math is inserted. It works with Edge 144.0.3719.104 and Chrome 144.0.7559.110. It also works with Firefox 147.0.2. Unfortunately, it doesn't currently work with Safari, but we can follow up with that team on fixing the problem.
Regarding PowerPoint for the web: unfortunately the app has very limited support for math in general, so it would be better to test in the desktop apps for now. You can Paste MathML in HTML into it, but only when no object is selected and it is creating a new object. When you click into an existing text box or shape and Paste, it doesn't insert native math, because it doesn't even have the ability to go into text edit mode for objects that contain native math. Anyway, the desktop apps have more robust support for native math.
Selectable MathML works awesome on webpages such as ChatGPT and Copilot (which both use KaTeX) and Wikipedia. Would love for it to work on webpages that use MathJax as well.
FYI, I just published another blog post on math improvements in Microsoft 365: Make math inclusive for everyone with Microsoft 365
Thank you.
Regarding PowerPoint for the web: unfortunately the app has very limited support for math in general, so it would be better to test in the desktop apps for now.
I only used this since it was one of the things you listed as supporting the copy and paste feature.
in the following webpage, ..., press Ctrl+A to Select All, then press Ctrl+C to Copy and the full MathML will be included in the HTML posted to the clipboard.
I'm sorry, again I have not been clear on the issue, as your example page has nothing to do with the problem I was trying to illustrate. Certainly you can select MathML and certainly "select all" will select everything on the page. The issue I was trying to address is not selection near the boundary of MathML, but selection when the MathML is visually hidden near the boundary of the visual rendering from MathJax.
For example, consider the following HTML (that doesn't use MathJax, but has a simpler simulation of the situation I described):
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>MathML selection test</title>
<style>
mjx-math {
color: green;
}
mjx-container {
position: relative;
display: inline-block;
}
mjx-assistive-mml {
z-index: -1;
display: block;
position: absolute;
right: 0;
top: 0;
left: 0;
bottom: 0;
}
mjx-mml {
display: block;
height: 1px;
width: 1px;
padding: 1px 0 0 1px;
overflow: hidden;
}
#output {
border: 1px solid black;
width: auto;
display: inline-block;
}
</style>
</head>
<body>
<p>
This is text
<mjx-container><mjx-math>pretend math</mjx-math><mjx-assistive-mml><mjx-mml>MATHML</mjx-mml></mjx-assistive-mml></mjx-container>
and more text.
</p>
<div id="output"></div>
<script>
const output = document.querySelector('#output');
document.addEventListener('selectionchange', () => {
const selection = window.getSelection();
output.innerHTML = selection ? selection.toString() : '';
});
</script>
</body>
</html>
Here, we have some text ("pretend math" shown in green) that represents the math layout from MathJax, and some visually hidden text ("MATHML") that represents the assistive MathML. Below that is a div that shows the text that is currently selected (so you can see if "MATHML" is included or not, since it is visually hidden in the main sentence).
If you drag select from the start of the sentence to the end of the pretend math, you often fail to get the "MATHML" that represents the equation. Here is a screen shot:
This means you will not get the MathML to paste into your document, and if the visual math were not included in the copy, as you suggested above, then you would get no math when you pasted, even though the math was selected when you copied it.
If you use SHIFT-Right-arrow to extend the selection a character at a time, expecting to get the space and text that follows the pretend math, instead the selection doesn't seem to change, as you get the characters within the visually hidden MATHML, with no way of knowing that that is happening:
(This is true even if the MATHML is actual MathML nodes rather than the plain text used here.)
Conversely, if you drag select from the end of the sentence to just before the "pretend math", you can accidentally include the "MATHML" without knowing that:
Pasting that will insert math that you didn't think you had selected.
This is why I say that this approach leads to unexpected and mysterious results (and frustration) in some instances. Yes, it works if you always select text on both sides of the math, but when selecting to the edge of the math or extending the selection by arrow keys, the results are not reliable.
MathJax allows you to copy the MathML from a single expression using its contextual menu, and it may be that MathJax could provide a means of including the MathML (or the original LaTeX) in larger selections, but this probably isn't the way to do it.
As I said, I'm leaving this marked as a feature request in order to keep it in the queue for possible future development. At this point, I have said what I intend to for this issue, so probably will not be making further posts here.
@dpvc
Regarding PowerPoint for the web: Sorry about that. I should have just left that off the list of apps that support Pasting MathML in HTML. Please try one of the many other apps I listed to see how it works. It is a very compelling experience, and we are seeing much higher usage than expected. There is a lot of selectable MathML in webpages!
Regarding the hidden MathML unexpectedly being included or excluded from the selection : That problem does not seem specific to hidden MathML and could happen with all sorts of other stuff on a webpage. And I also don't think it is something that would cause major user dissatisfaction. If the math was included and they didn't want it, they can simply delete it. If the math wasn't included, and they wanted it, they could simply try again with an expanded selection. Having to make adjustments like these when copy/pasting content is extremely common and not something users don't know how to cope with.
If your main reservation about making the MathML selectable is this issue, then I think this downside is extremely small in comparison to the upside that it brings.
Thank you for considering it.