Renewcommand with let not working

21 views
Skip to first unread message

Andrew Murdza

unread,
Sep 1, 2023, 2:20:41 PM9/1/23
to MathJax Users
I would like to do the equivalent this code in Mathjax

\let\oldsqrt\sqrt \renewcommand{\sqrt}[1]{\p{\oldsqrt{#1}}}

where \p is the command
p: ['\\class{invisible}{#1}',1],

I am wondering how to do this in window.Mathjax's macro notation:

I tried this but it didn't work because I get a "math input error". I'm pretty sure this because of the lack of \let.

sqrt: ['\\p{\\sqrt{#1}}', 1],

I added an import for let which requires newcommand

window.MathJax = Object.assign({
loader: { load: ['[tex]/color','[tex]/textcomp','[tex]/newcommand'] },
tex: {
inlineMath: [['$', '$'], ['\\(', '\\)']],
packages: { '[+]': ['bold-chars', 'color','textcomp','newcommand'] },
macros: Object.assign({


I then tried 

sqrt: ['\\let\\oldsqrt\\sqrt\\p{\\oldsqrt{#1}}', 1],

But I still get the "math input error".

Davide Cervone

unread,
Sep 12, 2023, 10:16:02 AM9/12/23
to mathja...@googlegroups.com
When you do

sqrt: ['\\p{\\sqrt{#1}}'1],

you are doing the equivalent of 

\renewcommand{\sqrt}[1]{\p{\sqrt{#1}}}

which creates an infinite loop.  This causes the "math input error" with an error about the maximum number of macro substitutions being exceeded.  You are right that your \let command is crucial to the operation of your proposed code.  Unfortunately, the tex.macros configuration option doesn't have a means of performing a \let command.  But you could use something like

MathJax = {
  startup: {
    ready() {
      MathJax.startup.defaultReady();
      MathJax.tex2mml(String.raw`\let\oldsqrt\sqrt \renewcommand{\sqrt}[1]{\p{\oldsqrt{#1}}}`);
    }
  }
};

to perform the definitions that you need.  (You could do all the macro definitions that way, if you wanted.)

Davide


--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/mathjax-users/e3d05ab9-2762-4cc7-ab5b-648ec70b86c1n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages