# MathML and inline equations

I’ve been playing with the mathml in pressbooks that came in the last update. I’ve been unable so far to make mathml appear inline in a paragraph, so far, the Wordpress editor has been forcing line breaks before and after every math equation.

I know that to force mathml to work you had to force it into one line in the HTML editor, is this a related problem.

I’ve been generating my mathml in math type and copying and pasting the code into Wordpress.

1 Like

I have been having the same issue, and have compromised by using LaTeX for inline equations and MathML for large equations that are set aside from the text. This works for me, but I’d love to see a fix for this issue so I can be more consistent with my coding!

Thanks for confirming it isn’t just me. I’ll open an issue on GitHub.

Two theories:

One

We do not strip out the display attribute and you need to set it. MathML is displaying as a block element. You need to change it to inline, as needed.

For mathematics written in MathML notation, you mark your mathematics using standard [itex] tags, where <math display="block"> represents displayed mathematics and <math display="inline"> or just [itex] represents in-line mathematics.

Basically, CSS.

Sources:

Caveat: MathJax is doing the rendering, not the web browser. It uses a hybrid JavaScript/CSS config. It may require more jiggling in the Custom Styles editor:

http://docs.mathjax.org/en/latest/reference/CSS-styles.html

Two

When you view source, is the [itex] wrapped in <p> tags? Then WordPress is wrapping MathML using wpautop or similar. I can look into that if you show me an example, but I don’t think that’s the case?

@beckej

I looked at the example in your GitHub ticket. This is the source:

<p class="para block" id="fwk-shafer-ch02_s01_s03_p01">In our example of the exam scores in a statistics class, five students scored in the 80s. The number 5 is the <em class="emphasis">frequency</em> of the group labeled “80s.” Since there are 30 students in the entire statistics class, the proportion who scored in the 80s is 5/30. The number 5/30, which could also be expressed as <span class="inlineequation" id="shafer-20121106-125753-084206"></p>
<math xml:id="fwk-shafer-ch02-m0003" ... snip ...


Specifically:

</p><math


So, yes, it will break.

What does it look like in the admin editor? What’s that <span class="inlineequation" id="shafer-20121106-125753-084206"> tag about?

Looked at the GitHub ticket again, you linked to a test book @SteelWagstaff made? I have access to the source. I have updated the GitHub ticket with the relevant info. I’ll look into it sooner than later.

The source for this book was this open textbook from Saylor: https://saylordotorg.github.io/text_introductory-statistics/s06-01-three-popular-data-displays.html. Steve Covello at Granite State was trying to import it to use in Pressbooks. The HTML import routine stripped out the HTML – but I was able to get the math to display by copy/pasting the source (though relative links to images broke). That’s why there’s extra cruft in the HTML – it was a quick & dirty copy/paste job to see if the MathML would display using that method of import.

It’s a WordPress bug:

https://core.trac.wordpress.org/ticket/13340

If I apply this patch it fixes the issue:

https://core.trac.wordpress.org/attachment/ticket/13340/13340.diff

For obvious reasons, I can’t simply patch wp-includes/formatting.php, WordPress must do it…

Thanks for spending some time on this @dac.chartrand. We don’t have users that are using MathML yet, but SUNY has said for accessibility purposes they want things written in MathML whether that be for online, print, or otherwise.

In their draft document, they specifically ask us to look into MathType or equivalent for the generation of MathML. So I’ve been doing this two ways- Using the MathType Desktop app, you can write an equation, and then you can set the cut and paste preferences to output whatever format you want. LaTeX optimized for WordPress, LaTeX optimized for MathJax, and a few MathML options. I have 6 export options for MathML:

• MathML 2.0 (m namespace)
• MathML 2.0 (namespace attr)
• MathML 2.0 (no namespace)
• MathML 3.0 (m namespace)
• MathML 3.0 (namespace attr)
• MathML 3.0 (no namespace)

Edit: Actually, where it says configure for application or website one of the options is MathJax:MathML. I think that’s definitely what I should use.

MathType also has an integration for WordPress, and I started messing around with it a little. I installed it by using this plugin.

What’s interesting about this is that when the plugin is installed it renders nicely in WP Editor. I don’t know what kind of magic they baked in it to make that work, but letting faculty see what they are working on in the moment would be huge for us, plus it has a pretty simple editor that pops up, and when you close it, it has just placed MathML into your book. I only wish it was open source.

Image 1: Tiny MCE button

Image 2: Easy to use Editor

Image 3: Renders as an image in the editor screen, (including automatically generated alt text for accessible downloads across all formats

Image 4: But on the backend, it’s still just MathML. I think that’s good because…

Image 5: when I go to the web version of the book, it is still rendering in MathJax which I think has tools where you can go through an equation at your speed. (I think?)

My point in all this, is I think MathML is the way to go in the future if we can figure out these issues and convince WordPress to make changes upstream.

2 Likes

Hi Ed–thanks for sharing the link to the Equation Editor plugin, which looks very interesting. We haven’t done any kind of plugin review to investigate its compatibility with Pressbooks, but it does look quite slick. The free version appears to be open source, and the ‘pro’ license apparently costs \$10USD, but I have no idea about how the two versions differ. I don’t think we’ll be able to get to reviewing it in the immediate future, but if users were interested in using it on one of our hosted networks, they can use our third party plugin request/review process to get it on our radar.

While MathML is certainly exciting as a standard, it unfortunately still lacks broad browser support (see https://caniuse.com/#search=mathml), which means that for the foreseeable future, we’ll likely need to rely on intermediaries like MathJax to allow most web users to see the expected output. Separately, we are also hopeful that WordPress will make the upstream changes that allow us to safely fix the inline display issue. Fingers crossed …

1 Like

Hi Steel,

Everything you say makes sense. The browser plugin is open-source, but it is just a shell linking to MathType, which is a product created by Wiris. MathType is a funny company, because right now there is free integration into GoogleDocs, Word, and you might be familiar with it in Canvas and Blackboard. You could also choose from the plugin settings an open source Latex generator for example.

You might notice in my screenshot that shows that WIRIS math editor that it says “Free Trial, you are using the demo version…”

I checked out this caniuse.com link that Steel shared. That’s kind of the rationale that the Wordpress integrators used when deciding not to allow this change throughout the years was that MathML isn’t widely enough adopted/supported.

However, it being one of the languages of MathJax, which does have widescale support across web browsers, is there a way to make that argument more clearly in a way that a WordPress developer without extensive math/accessibility experience would understand?

Great question, Ed. I think you might be referring to this comment? https://core.trac.wordpress.org/ticket/13340#comment:11 I don’t know if I have much to add by way of advice, but if you’re looking for phrasing I think the way that I’d put it is this:

While it’s true that browser support for MathML is incomplete, MathML has been a W3C recommendation for more than 15 years, the 3rd version (released in 2014) is an ISO standard, and it has been a standard element in the HTML5 specification since 2014. Furthermore, there’s a widely-used, openly-licensed, cross-platform JavaScript display engine for mathematics called MathJax that works in all browsers that can accept MathML as one of its input syntaxes. There are clear reasons, based both in our desire to use web standards and to make more accessible websites, that many of us would like to use MathML in our WordPress-based sites. Would you be willing to reconsider your decision not to treat [itex] as a "first-class citizen of wpautop()"?

I could post this directly myself, of course, but Dac’s already weighed in on the ticket and asked for a solution that would work for us at Pressbooks if implemented.