MathML and multi character variables (<mi>)

71 views
Skip to first unread message

gobal...@gmail.com

unread,
Jul 20, 2015, 2:44:04 PM7/20/15
to mathja...@googlegroups.com
Hello, I've got MathJax running now and it works very well. The documentation can be steep at first, but you get it eventually (my JavaScript is rudimentary right now). Anyway, I am building a helper site to generate xml including mathml from a set of options and output from MathJax. It's easier to have people input equations that then are show in real time so we get the right equation the first time. And the mathml output is just icing on the cake. However, I'm running into a problem with the mathml output and multi character variables. How do I get mathml to render multi character variables as <mi> entries? I have done a bit of reading on that side, but it seems based on the mathml documentation it should be possible (http://www.w3.org/TR/2003/REC-MathML2-20031021/chapter3.html#presm.mi). Something about the difference between semantic and presentation.

Here is my setup, but I don't do much else as I can't find any configuration options in the docs that would change the behavior. I've been searching and testing different ideas here and there. I am probably missing something, and am hoping someone can point it out quickly. To test output, right now I'm simply right clicking on the output and viewing the mathml. Once I workout variable names, I'll move on to dumping the resulting xml file. I'll work out an example I can share if needed, but the current page isn't available globally. And, sorry again, I'm learning JavaScript as I go.

<script type="text/javascript" src="/.sysassets/mathjax/MathJax.js?config=TeX-MML-AM_HTMLorMML"></script>

(function () {
    var QUEUE = MathJax.Hub.queue;  // shorthand for the queue
    var math1 = null;                // the element jax for the math output.
    var math2 = null;                // the element jax for the math output.

    //
    //  Get the element jax when MathJax has produced it.
    //
    QUEUE.Push(function () {
      math1 = MathJax.Hub.getAllJax("IWMathOutput")[0];
      math2 = MathJax.Hub.getAllJax("WRMathOutput")[0];
    });

    //
    //  The onchange event handler that typesets the
    //  math entered by the user
    //
    window.UpdateIWMath = function (TeX) {
      QUEUE.Push(["Text",math1,TeX]);
    }
    window.UpdateWRMath = function (TeX) {
        QUEUE.Push(["Text",math2,TeX]);
      }
})();

Peter Krautzberger

unread,
Jul 25, 2015, 6:02:03 AM7/25/15
to mathja...@googlegroups.com
Hi,

I'm not sure I really understand what you're after. Perhaps it would help to read through our user group guidelines and to provide a live sample.

If you are asking for a TeX macro that generates a single mi out of a string, then MathJax has a non-standard macro for that -- \mmlToken{mi}{yourstring} would do it.

If you are looking for a way to change MathJax's TeX input to generate single <mi>'s out of longer strings (i.e., without using any macros), then that would be pretty hard because that's pretty incompatible with how TeX (and our input) works.

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.

Peter Buelow

unread,
Jul 29, 2015, 10:21:10 AM7/29/15
to mathja...@googlegroups.com
Thank you for responding. 

I will try to do a live sample if I get a chance but the problem isn't in using MathJax to display something. Effectively, you identify the problem in your 3rd sentence. We want to use predefined variables from a different somewhat manual process to avoid having to figure out how to translate what everyone is familiar with from one process to another. If the user enters X + watt, the resulting MathML doesn't break out the watt variable into a bunch of <mi> entries. So, if I want to use watt as a variable name, I can't do that such that the output MathML <mi>watt</mi> when using MathJax it seems. I don't mind using macros, but the one you list above has it's own compromises I think. If I understand it correctly, I'll have to create one mmlToken entry for each variable I want to use. How do I apply this to my output function? I can't find a good example of something like this in the documentation (or I'm not reading it correctly).

Thanks again.

You received this message because you are subscribed to a topic in the Google Groups "MathJax Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mathjax-users/F2UybgN-Zpo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mathjax-user...@googlegroups.com.

Davide P. Cervone

unread,
Jul 29, 2015, 10:58:48 AM7/29/15
to mathja...@googlegroups.com
You could do the equivalent of 

\def\var#1{\mmlToken{mi}{#1}}

and then use   X+\var{watt}   to get the result you want.  To get this macro, use

<script type="text/x-mathjax-config">
MathJax.Hub.Config({
  TeX: {Macros: {
    var: ["\\mmlToken{mi}{#1}",1]
  }}
});
</script>

just BEFORE the script that loads MathJax.js itself.

Davide

William F Hammond

unread,
Jul 29, 2015, 2:46:07 PM7/29/15
to mathja...@googlegroups.com
I think the fact that Davide suggests this route is an indication that, although there are various fudges, there is no fully satisfactory command for handling multi-character math indicator names on the fly in regular LaTeX with amsmath.  However, for multi-character names the command \operatorname{} seems to work well in regular LaTeX with amsmath, also with tex4ht and latexml.  With MathJax TeX input \operatorname seems to wrap a multi-character symbol name in a single <mo>, which matches the MathML generated using tex4ht and latexml.  I think it would make sense to make \var{} native in MathJax TeX input.


William F Hammond

unread,
Jul 29, 2015, 4:35:52 PM7/29/15
to mathja...@googlegroups.com

On Wed, Jul 29, 2015 at 11:46 AM, William F Hammond <gel...@gmail.com> wrote:
I think it would make sense to make \var{} native in MathJax TeX input.

But if it's made native, its name should be \varname rather than \var so that it has name parallelism with \operatorname.

BTW, looking in the basic amsmath doc (that comes up with texdoc), in section 11 on converting from plain LaTeX to LaTeX with amsmath, it's clear that the author believes \mbox{} to have been the old plain LaTeX way of providing operator (or variable) names.

The introduction of amsmath essentially bifurcates the old use of mbox (in math mode) into \operatorname{} and \text{}.  For generating presentation MathML I think that \mbox{} should go to <mi> when its argument has no white space and <mtext> otherwise.

In fact, does it make sense for \operatorname to go to <mo> while things like \log and \sin go to <mi>?  (I note, however that \max (corresponding to \operatorname*) goes to <mo>.)  I think that <mi> is better than <mo> in most of these cases, and it's a bit unfortunate that amsmath called it \operatorname instead of \varname.

Davide P. Cervone

unread,
Jul 29, 2015, 6:50:20 PM7/29/15
to mathja...@googlegroups.com
However, for multi-character names the command \operatorname{} seems to work well in regular LaTeX with amsmath, also with tex4ht and latexml.  With MathJax TeX input \operatorname seems to wrap a multi-character symbol name in a single <mo>, which matches the MathML generated using tex4ht and latexml.

I would not recommend using \operatorname{} for this, as the semantics are not right for an identifier that is acting as a variable name, as in the example of "X + watt".  The result of \operatorname{name} is essentially \mathop{\rm name}\nolimits (though there is a little more to it), which gives the result TeX class OP rather than TeX class ORD as it should.  That will make a difference in spacing, for one thing, and it will also mean that MathJax may insert invisible function apply in some circumstances.  For example, $\operatorname{watt}x$ would generate

<math xmlns="http://www.w3.org/1998/Math/MathML">
  <mi>watt</mi>
  <mo>&#x2061;<!-- invisible apply --></mo>
  <mi>x</mi>
</math>

It would also allow \limits to be used with the variable name, which is not correct.  It is actually the \mathop{\rm ... } that generates the <mi> element, and that is handled as a special case to get things like \sin and \det as single elements.  Of course, \operatorname{} can include more complicated things than just a name, e.g., \operatorname{log_{10}}, in which case, MathJax will not use an <mi>, must a more complicated <mrow>.  And with \operatorname*{}, you may get an <mo> since it may require movablelimits.

If I were using plain TeX, I would use \hbox{...} for this; in LaTeX, I would use \text{...}, though \mbox{...} would also work.  All of these produce <mtext> elements in MathJax.  I suppose \mathord{\rm ...} could be special-cased like \mathop{\rm ...}, but that is not currently done.  It seems to me that \mmlToken{mi}{...} would be just as easy to use.

Davide


Davide P. Cervone

unread,
Jul 29, 2015, 6:56:44 PM7/29/15
to mathja...@googlegroups.com
> In fact, does it make sense for \operatorname to go to <mo> while things like \log and \sin go to <mi>?

\operatorname goes to <mi> not <mo>. \operatorname* goes to <mi> when possible and <mo> when necessary for the use of movablelimits when the operator has super- or subscripts.

> (I note, however that \max (corresponding to \operatorname*) goes to <mo>.)

Again, the operators that allow \limits (like \max and \lim) go to <mo> so that they can have movablelimits set. Function names (like \log and \sin) go to <mi> since they don't need movablelimits.

> I think that <mi> is better than <mo> in most of these cases, and it's a bit unfortunate that amsmath called it \operatorname instead of \varname.

It is properly named because it produces an OP not an ORD element. A \varname macro would need to produce an ORD to get the proper spacing.

Davide

William F Hammond

unread,
Jul 29, 2015, 9:53:10 PM7/29/15
to mathja...@googlegroups.com

On Wed, Jul 29, 2015 at 3:50 PM, Davide P. Cervone <dp...@union.edu> wrote:
I would not recommend using \operatorname{} for this, as the semantics are not right for an identifier that is acting as a variable name, as in the example of "X + watt".  The result of \operatorname{name} is essentially \mathop{\rm name}\nolimits (though there is a little more to it), which gives the result TeX class OP rather than TeX class ORD as it should.  That will make a difference in spacing, for one thing, and it will also mean that MathJax may insert invisible function apply in some circumstances.  For example, $\operatorname{watt}x$ would generate

<math xmlns="http://www.w3.org/1998/Math/MathML">
  <mi>watt</mi>
  <mo>&#x2061;<!-- invisible apply --></mo>
  <mi>x</mi>
</math>

It would also allow \limits to be used with the variable name, which is not correct.

In actual LaTeX with amsmath limits are supposed to become available with \operatorname*.  So I guess the confusion here is that I'm trying to talk about what should happen with actual LaTeX, and you are speaking about the MathJax TeX input language.  In my ideal world a bit of LaTeX math should show up the same via MathJax, tex4ht, and latexml.

But do I deduce correctly from what you've said that MathJax tries to honors all eight of the TeX math character classes?

               -- Bill


William F Hammond

unread,
Jul 29, 2015, 9:57:22 PM7/29/15
to mathja...@googlegroups.com

On Wed, Jul 29, 2015 at 3:56 PM, Davide P. Cervone <dp...@union.edu> wrote:
\operatorname goes to <mi> not <mo>.  \operatorname* goes to <mi> when possible and <mo> when necessary for the use of movablelimits when the operator has super- or subscripts.

Yes. of course, you're right.  Sorry that I misreported on this.

         -- Bill


Davide P. Cervone

unread,
Jul 30, 2015, 5:29:45 AM7/30/15
to mathja...@googlegroups.com
> In actual LaTeX with amsmath limits are supposed to become available with \operatorname*.

I think there is a misunderstanding. What I meant is that you can say \operatorname{...}\limits without an error, while \text{...}\limits produces one. You are right that the \limits is ignored with \operatorname in LaTeX *but it turns out not in MathJax).

> So I guess the confusion here is that I'm trying to talk about what should happen with actual LaTeX, and you are speaking about the MathJax TeX input language.

No I was talking about both, but there are differences, of course.

> But do I deduce correctly from what you've said that MathJax tries to honors all eight of the TeX math character classes?

In HTML-CSS and SVG output yes, but not in NativeMML output (of course). It also implements all the \mathop, \mathbin, \mathrel, etc. commands for specifying the classes.

Davide

Davide P. Cervone

unread,
Jul 30, 2015, 6:13:23 AM7/30/15
to mathja...@googlegroups.com
> In actual LaTeX with amsmath limits are supposed to become available with \operatorname*.

PS, note that \operatorname{...} only prevents \limits if it follows it immediately. If you did

\operatorname{...}\nolimits\limits^2

or

\operatorname{...}\limits\limits^2

or

\operatorname{...}^2\limits

then the 2 would appear above the operator just as it would with \operatorname*{...}. That is because the result really is of class OP (not ORD), and \operatorname eats a (single) \limits token that follows it; it doesn't really prevent \limits from working with it.

Davide
Reply all
Reply to author
Forward
0 new messages