Copying and pasting MathJax from OpenStax

Hello,

We are about to start creating math books and would like to use MathJax for its accessibility-benefits over the WP QuickLaTeX plugin. The workflow many of our faculty will be using to adapt pre-existing texts, predominantly from OpenStax, is to copy and paste from the OpenStax book into the Pressbooks Visual editor. I was glad to see that doing this resulted in the math formulas formatting correctly as MathJax, but they are all showing up twice within Pressbooks, once as plain text and once as MathJax:

https://louis.pressbooks.pub/sandbox1/chapter/mathjax-test/

It looks like the plain text version of the formula always has so I can hide that with CSS, but Iā€™m wondering if that will affect the accessibility of the book.

Has anyone else run into this issue?

Thanks,
EJK

Hi @elizabeth.kelly!

I completely understand that adapting pre-existing texts by bringing them into Pressbooks is the workflow that youā€™re following, however, I do see that sometimes, the math shows up twice or is not rendering exactly the same way as it does on OpenStax (or other websites). This is because when these elements are copied and pasted into the Pressbooks visual editor, extra code, such as formatting, is brought into the editor, as well. Doing this can also make the PDF export of MathJax not render correctly.

There is a workaround, however, without using CSS. If you find a MathJax element on another website that you would like to use, highlight the element, mouse over ā€˜Show Math Asā€™, and select ā€˜MathML Codeā€™ and copy the code. Now that the MathML Code has been copied to your clipboard, you can now paste it into the text editor. Unfortunately, this will result in the math appearing slightly altered in the visual editor, but it will appear as desired on the Web Book and the PDF export of the book.

I hope this helps!

2 Likes

Thanks! I think our cohorts will be adapting whole textbooks, so copying individual formulas is probably not feasible large-scale. Importing from OpenStax using the URL seems to work for the formulas. In previous projects weā€™ve discouraged this approach because it doesnā€™t bring in the images and introduces some formatting issues, but in this case I think this will be easier to deal with than formula issues.

1 Like

I think that understanding a little bit about how mathjax works will help you decide how to do this.

Mathjax using JavaScript to replace math equations with accessible math. Math equations can be written in LaTeX, ASCII math, or written in mathml and mathjax will convert it into accessible math, usually rendering an equation with html and css, plus adding additional mathml as the invisible alternative format for screen readers.

When you are seeing double equations, what is most likely happening is when you selected the text, it pulled the html+css visual version and the assistive mathml and are displaying both.

I would be careful copying from the openstax source, and hereā€™s why. Openstax stores their math in MathML, and Pressbooks keeps math as LaTeX. There is an unpatched bug in Wordpress that adds extra line breaks before and after equations if we use plain MathML.

If you think that the math is coming over ok, what I would double check is math that is supposed to appear in a sentence. If that looks correct, then maybe you are home free! If you are notice extra linebreaks then you are seeing symptoms of the wpautop bug.

What I would look for first before copying fresh new openstax books is to see if anyone else has already done the work and imported the book into pressbooks. I did a lot of this work for suny and we would have to do a lot of cleanup, so finding a book that has already done the cleanup can save months off a project.

Which books were you looking to import?

2 Likes

Thank you! Yes, I am seeing the line breaks before and after equations in imported OpenStax chapters. We will be using the Pressbooks version of a text when possible, but with our previous grant (which did not include any math textbooks), some faculty opted to adapt the version in OpenStax because it had been updated more recently than the Pressbooks version. We are at the very beginning stages of this grant so I do not know yet which books exactly might be adapted, but just trying to figure out what methods to recommend to our faculty before they get too far along. It might be best in this situation to adapt the Pressbooks versions and then manually make any updates that appear in the OpenStax versions.

Thanks for your help!

Pressbooks uses the ā€œforced p-tagā€ in the core code which causes the line break whether you like it or not. I had this same problem transferring Intro Statistics from Saylor HTML into PB with MathJax. Here is the original post:

https://pressbooks.community/t/saylors-introductory-statistics-conversion-is-completed/1251

2 Likes

Hereā€™s the ticket we filed upstream with WordPress regarding the annoying ā€œautopā€ issue with MathML: #13340 (wpautop breaks inline MathML) ā€“ WordPress Trac. I pinged the WordPress core team, but am not expecting anything soon, unfortunately. The original ticket has been open for 13 years(!)

1 Like