complicated LaTeX macro possible?

315 views
Skip to first unread message

Tim Arnold

unread,
May 14, 2015, 3:21:34 PM5/14/15
to mathja...@googlegroups.com
I have a macro in LaTeX and I'm doubtful it can be rendered correctly so I thought I'd ask here.
The definition in LaTeX is this:

    \newcommand{\Argument}[1]{%
       \text{\textmd{\textit{\textsf{#1}}}}%
    }

Presuming it is given in math mode, it renders its argument in medium sans-serif italic *as if in text-mode.*
At first, I thought the trickiest part was combing the two font families.
Currently I have it defined in the MathJax: {TeX: {Macros:}} section as:

    Argument: ['\\mmlToken{mtext}[mathvariant="sans-serif-italic"]{#1}',1]

I thought that would do the trick until I saw a user type:

    \Argument{num\_hours}

Of course, the backslash is rendered with my above definition for MathJaX.

As I say, I think the desired rendering may not be possible: 'num_hours' as text in san-serif italic.

Any suggestions?

thanks,
--Tim

Peter Krautzberger

unread,
May 14, 2015, 3:40:32 PM5/14/15
to mathja...@googlegroups.com

Hi Arnold,

You have to go a little deeper in terms of macro definitions, i.e., hook into the TeX input jax. Here's an example for bolditalic that I hope is easy to modify.

Peter.

http://codepen.io/pkra/pen/HpFKr

--
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 Krautzberger

unread,
May 14, 2015, 3:40:59 PM5/14/15
to mathja...@googlegroups.com

Uhm.. I meant Hi Tim :-)

Davide P. Cervone

unread,
May 14, 2015, 3:41:25 PM5/14/15
to mathja...@googlegroups.com
Take out the backslash and you should be in business.  MathJax does not process any macros in text mode, including \_, so you need to use the characters you want literally, not as macros.  

Davide


Peter Krautzberger

unread,
May 14, 2015, 3:44:28 PM5/14/15
to mathja...@googlegroups.com

Ah, I misread Tim's question. Thanks for correcting me Davide!

Davide P. Cervone

unread,
May 14, 2015, 3:44:35 PM5/14/15
to mathja...@googlegroups.com
@Peter, his use of \mmlToken with an mtext element and mat variant of sans-serif-italic is all that is needed to get the font set correctly.

I should have said that MathJax doesn't process macros in the arguments to \mmlToken, not in text-mode (even though that is also true).  The argument to \mmlToken is put into the mtext tag verbatim, so no macros are processed there.

Davide

Peter Krautzberger

unread,
May 14, 2015, 3:47:16 PM5/14/15
to mathja...@googlegroups.com

Right, I was thinking he wanted a macro that would accept other TeX inside of it.

Davide P. Cervone

unread,
May 14, 2015, 3:49:08 PM5/14/15
to mathja...@googlegroups.com

Right, I was thinking he wanted a macro that would accept other TeX inside of it.


yes, your approach would allow that, but not if he wants the contents to be treated like text (e.g., spaces are retained).

Davide

Peter Krautzberger

unread,
May 14, 2015, 3:51:20 PM5/14/15
to mathja...@googlegroups.com

Yup.

Tim Arnold

unread,
May 14, 2015, 3:57:28 PM5/14/15
to mathja...@googlegroups.com, dp...@union.edu
Thanks for the quick help! I understand the mmltoken treats the text verbatim--but if I take out the underscore it won't compile in LaTeX.

  \newcommand{\Argument}[1]{%

    \text{\textmd{\textit{\textsf{#1}}}}%

   }


    $y\Argument{num_hours}x$


00000000000000000

! Missing $ inserted.

<inserted text>

$

l.9 $y\Argument{num_hours}

x$

Tim Arnold

unread,
May 14, 2015, 4:28:45 PM5/14/15
to mathja...@googlegroups.com, dp...@union.edu
I was probably unclear with my question, but Peter's solution helped me out a lot. This bit:

MathJax.Hub.Register.StartupHook("TeX Jax Ready", function () {
var MML = MathJax.ElementJax.mml;
  MathJax.InputJax.TeX.Definitions.Add({
    macros: {
        bfit: ['SetFont',MML.VARIANT.SANSSERIFITALIC],
        mathbfit: ['Macro','{\\bfit #1}',1],
        oversegment: ['UnderOver','00AF']
    }
  });
});

seems to work with this math:
 $ \bfit num\_spec \, \mathbfit{another\_numx}$

I wouldn't have thought of that by myself!

thanks,
--Tim

Tim Arnold

unread,
May 15, 2015, 4:21:42 PM5/15/15
to mathja...@googlegroups.com
hi Peter,
Your code really helped. I'm trying now to add it to the MathJax-Node library (locally only) in the mj-single.js lib.

Do you have any suggestion for where that StartupHook/Definitions.Add code should go? 

thanks again,
--Tim

Davide P. Cervone

unread,
May 19, 2015, 12:04:04 PM5/19/15
to mathja...@googlegroups.com
Tim:

You should be able to pass the definition to mj-single via the config() call in the script that uses mj-single.js.  For example

var mjx = require("./lib/mj-single.js");
mjx.config({
  MathJax: {
    TeX: {Augment: {
      Definitions: {
        macros: {bfit: ['SetFont','bold-italic']}
      }
    }}
  }
});
mjx.start();

(It is not actually necessary to use the StartupHook to do this, as the Augment property of the TeX configuration block can be used to create the definition.  Note, however, that you must replace MML.VARIANT.BOLDITALIC by the string 'bold-italic', since the MML variable is not available to you here.)

It turns out, however, that the code that there is a problem using arrays within your configuration like this (the arrays are passed MathJax running inside a jsdom window, and the Array object there is not the same one as the Array object outside the jsdom window, and so MathJax doesn't recognize this as an array).

I have a patch to work around that, but it is not in the production copy of MathJax-node, so you would have to check out the issue96 branch of MathJax-node in order to obtain the fix (or just replace the two files in MathJax-node/lib with the ones from that branch).

Hope that gets you started down the right path.

Davide

Tim Arnold

unread,
May 19, 2015, 2:14:35 PM5/19/15
to mathja...@googlegroups.com, dp...@union.edu
thank you, that is good information--I'll continue to work on this.
thanks,
--Tim
Reply all
Reply to author
Forward
0 new messages