Support for LaTeX commands inside \text

79 views
Skip to first unread message

racoon

unread,
Nov 27, 2015, 6:55:44 AM11/27/15
to MathJax Users
Hi,

MathJax only supports (La)TeX math by default. On the other hand it supports the \text (\textrm and the like) command which is great. Is it somehow possible to define LaTeX macros to be used inside \text, e.g. \text{H\textsubscript{2}O} or even more complex \text{\emph{H\textsubscript{2}O}}?

Best,
Daniel

racoon

unread,
Dec 4, 2015, 6:03:00 AM12/4/15
to MathJax Users
The documentation says:

"Note that the TeX input processor implements only the math-mode macros of TeX and LaTeX, not the text-mode macros. MathJax expects that you will use standard HTML tags to handle formatting the text of your page; it only handles the mathematics." (http://mathjax.readthedocs.org/en/latest/tex.html)

So I guess what is written inside \text is considered to be non-math-mode macros. So I guess I am stuck with parsing macros inside \text manually and transform them using math-mode macros before MathJax renders. Like

\text{H\textsubscript{2}O} -> \text{H$_\text{2}$O}

Peter Krautzberger

unread,
Dec 4, 2015, 6:22:40 AM12/4/15
to mathja...@googlegroups.com

[This wasn't sent out earlier.]

Hi,

Yes, but you'll have to dig a little deeper (basically: write an extension). Start by looking at the TeX input jax itself and the implementation of \text etc.

Text-mode commands are generally outside the scope of MathJax. Some easy macros might be technically possible but TeX's text-mode is a very different beast (both for TeX and when thinking of rendering that to the web). 

From our (MathJax team) perspective, we'd suggest to submit such extensions to the third party extension repo which we mirrored to the CDN.

Best regards,
Peter.

--
You received this message because you are subscribed to the Google Groups "MathJax Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mathjax-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Davide P. Cervone

unread,
Dec 4, 2015, 8:39:01 AM12/4/15
to mathja...@googlegroups.com
So I guess what is written inside \text is considered to be non-math-mode macros. So I guess I am stuck with parsing macros inside \text manually and transform them using math-mode macros before MathJax renders. Like

\text{H\textsubscript{2}O} -> \text{H$_\text{2}$O}

For this particular usage, there is alto the mhchem packge, where you could use \ce{H2O}.  In any case, I would say that \mathrm{H_2O} is a better translation (or \text{H}_2\text{O} if you really want to use \text).

Otherwise, you could follow Peter's suggestion of writing an extension.  See


for an example of handling some backslashes in text mode (though your application would require more than just a text substitution).  The original function is at


and you could have it return an mrow containing the MathML that encodes the output you want.

If you want to use regular-expression-type transformations, it might be easier to replace InternalMath (just above InternalText) instead.  You could do regular expression replacements on the incoming text that inserted dollar signs like the ones you and then call the original InternalMath to have it processed.  That way, you don't have to understand the MathML that you need to produce.

Davide

Am Freitag, 27. November 2015 12:55:44 UTC+1 schrieb racoon:
Hi,

MathJax only supports (La)TeX math by default. On the other hand it supports the \text (\textrm and the like) command which is great. Is it somehow possible to define LaTeX macros to be used inside \text, e.g. \text{H\textsubscript{2}O} or even more complex \text{\emph{H\textsubscript{2}O}}?

Best,
Daniel

racoon

unread,
Dec 4, 2015, 10:05:40 AM12/4/15
to MathJax Users
Thanks Peter and Davide. I'll have a look at that.
Reply all
Reply to author
Forward
0 new messages