MathJax Tags, Formatting and PDF Exports


We at the MacEwan University Library been working on a local install of PressBooks to facilitate open scholarship and, primarily, textbook development for faculty and students. It’s still a very young service, but we’re working with a number of authors on Statistics textbooks. The authors wanted to use LaTeX, so we chose to implement MathJax for its superior accessibility. Focusing first on the web display, we’ve been using [latex]…[/latex] tags for inline math and $$…$$ tags for formulae that should appear larger, centered and on its own line. For the web display, this has worked well.

Unfortunately, we didn’t work out the quirks of PDF export first. We’re using PrinceXML and have a working pb-mathjax instance. Now that a couple of the Stats textbooks are nearing completion, we’ve tried exporting them as PDFs only to discover that only the [latex]…[/latex] tagged math is getting displayed properly. $$…$$ just shows up as raw LaTeX code.

This probably isn’t news for this community, but before we get launch a retraining and conversion project to get the in-process Stats textbooks working equally well in both web and PDF, I wanted to ask those with greater experience how you would solve such a problem. Namely:

a) Is there a way to tweak the PDF export from PressBooks so that it converts $$…$$ notation MathJax just like it appears in the web version?

b) Failing that, is there a way to force [latex]…[/latex] tagged formulae to format themselves in block format as opposed to in-line formatting? By default those tags make the text smaller, more compressed and somewhat harder to read when compared to $$…$$ format. This makes sense for in-line formulae, but we’d rather it spread out for ease of reading if it’s by itself on its own line. As an example (focusing on the bottom equation):

… is $$…$$ format and reads a bit better than:

… which is the equivalent in [latex]…[/latex] format.

hi @schoutenm this is a known issue and something in our current product backlog: Add support for additional LaTeX delimiters · Issue #18 · pressbooks/pb-mathjax · GitHub. We’d like to address it at some point – but for now the regex that we use to generate images for EPUB and PDF exports is only capable of recognizing the [latex] shortcodes and not other common math delimiters that folks who use LaTeX elsewhere may be used to. I don’t have an ETA for you on when this will be fixed/resolved, unfortunately. One possible solution might be activating the WP QuickLaTeX plugin just before producing your export files and then turning it off again once exports have been created? Other than that, I’m afraid you’ll just have to wait until we add this feature to our MathJax integration. As this project is open source, PRs are always welcome :wink:

Simple solutions are often the best ones! Thanks! This will tide us over until this issue is addressed or I learn Wordpress development, whichever comes first. :grinning: