Skip to content

TeX Macro with number

Davide P. Cervone edited this page May 28, 2013 · 3 revisions

From https://groups.google.com/d/msg/mathjax-users/_MEIDwawiVU/-YA1JAS8zJsJ


In few of our legacy documents there are few TeX macros defined as \user1 and \user2.

Macros: { 
      userx: ['\\\\pmb{#1}',1],
      user1: ['\\\\pmb{#1}',1],
       nulldelimiterspace: '0pt',
    }

In macros the "user1" doesnt have any effect. It doesnt give any errors either.

One other issue is in our TeX file \kern -\nulldelimiterspace. How to I define them in MathJax. If it is not possible with MathJax then I have to write a pre-process function to convert then before giving them view.

Regards Dominic


Unless you have a very non-standard TeX setup you can not define macros with numbers in their name.

If by "legacy document" you mean existing TeX documents then almost certainly \user1 and \user2 will be the macro \user taking arguments 1 and 2 respectively. (It is possible in TeX to define digits such that they are allowed in macro names, but then they may not be used as digits in numbers or lengths etc.)

David


David beat me to it, as I was going to say essentially the same
thing. I think what you want is

Macros: { 
  user: ['\\\\pmb{#1}',1] 
} 

so that \user1 will get you a bold 1, and \user2 will get you a bold 2. You might be better off using \boldsymbol rather than \pmb as the result will generally look better, although there are some symbols that don't have a bold form in the MathJax fonts, so perhaps that is why you use \pmb.

Also note that the last entry in your Macros block should not have a comma after it, as that will confuse some versions of IE.

As for \nulldelimiterspace, see this discussion

You can add a prefilter to the TeX processing via

<script type="text/x-mathjax-config"> 
MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () { 
  MathJax.InputJax.TeX.prefilterHooks.Add(function (data) { 
    data.math = data.math.replace(/\\\\kern *-\\\\nulldelimiterspace/g,""); 
  }); 
}); 
</script> 

(place this before the script that loads MathJax.js itself). This
will remove all the \kern -\nulldelimiterspace references in your TeX
equations before processing them.

Davide


Thanks lot both David(s),

With the same data.math.replace function I was able to replace the \user2 with \pmb. It works great now.

data.math = data.math.replace(/\\\\user2/g,"\\\\pmb");

Best Regards Dominic

Clone this wiki locally