Convertion from MathJax 2 to MathJax 3

192 views
Skip to first unread message

Alexey

unread,
Nov 17, 2019, 4:40:01 PM11/17/19
to MathJax Users
Greetings all! I need some help with converting two functions from Mathjax v.2.7.5 to MathJax v.3.0.0. I converted MathJax.Hub.Config by using online converter, but I have not enough knowledges for transforming MathJax.Hub.Register.StartupHook. I have two functions. First of them is used for adding 'displaystyle' to all formulas:

<script type="text/x-mathjax-config">
       
MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
         
MathJax.InputJax.TeX.prefilterHooks.Add(function (data) {
           
if (!data.display) {data.math = "\\displaystyle{"+data.math+"}"}
         
});
       
});
 
</script>



The second function is used for making some elements larger:

<script type="text/x-mathjax-config">
       
MathJax.Hub.Register.StartupHook("mml Jax Ready", function () {
         
MathJax.ElementJax.mml.math.prototype.defaults.scriptsizemultiplier  
           
= .8;
         
MathJax.ElementJax.mml.math.prototype.defaults.scriptminsize =  
           
"12px";
       
});
</script>



I am not a programmist, so it's difficult for me to 'translate' these functions from one version MathJax to another. May be somebody can help me please?
Another problem with MathJax 3.0.0 is line breaking. I used symbols '\\' for displaying formula in new line, but in MathJax 3.0.0 these symbols are ignored. May be I should add some additional component?


And one small additional question from newbie in programming :) Is it possible make local installation of new version of MathJax by simple copying files to the shared hosting without such terrible words as 'npm' and others? :)

Davide Cervone

unread,
Nov 18, 2019, 6:42:35 PM11/18/19
to mathja...@googlegroups.com
I have not enough knowledges for transforming MathJax.Hub.Register.StartupHook. I have two functions. First of them is used for adding 'displaystyle' to all formulas:
The second function is used for making some elements larger:

These can be accomplished using

<script>
MathJax = {
  startup: {
    ready() {
      //
      //  Adjust the default script scaling parameters
      //
      const math = MathJax._.core.MmlTree.MmlNodes.math.MmlMath;
      math.defaults.scriptminsize = '12px';
      math.defaults.scriptsizemultiplier = .8;
      //
      //  Create the usual MathJax objects
      //
      MathJax.startup.defaultReady();
      //
      //  Add a TeX jax pre-filter to add \displaystyle{...} around in-line material
      //
      MathJax.startup.document.inputJax[0].preFilters.add((data) => {
        if (!data.math.display) {
          data.math.math = '\\displaystyle{' + data.math.math + '}';
        }
      });
    }
  }
};
</script>

You will need to incorporate whatever other configuration you need (the ones generated by the converter) into this MathJax object.

Another problem with MathJax 3.0.0 is line breaking. I used symbols '\\' for displaying formula in new line, but in MathJax 3.0.0 these symbols are ignored. May be I should add some additional component?

The line-breaking has not been ported to version 3 yet, so \\ outside of multiline environments like arrays and alignments will not be processed.

On the other hand, if you use

\displaylines{
  line1 \\
  line2
}

you will get the two lines one above the other.  Perhaps that will do as a work-0around for now.

Is it possible make local installation of new version of MathJax by simple copying files to the shared hosting without such terrible words as 'npm' and others? :)

You can got to


and there is a green "Clone or download" button. Click it and use the "Download ZIP" link to download an archive containing the files that are stored on the CDN.  You can put them on your web server and use them from there.  You probably aren't using ALL the files in the archive, but if you delete them, you need to be careful not to delete something you need, like the font .woff files, or the speech-rule-engine (sre) files, or problems could occur if one of your users calls for one of them.

Hope that helps.

Davide

Alexey

unread,
Nov 19, 2019, 1:59:03 AM11/19/19
to MathJax Users
Thanks a lot for your answer :)
I tried to use this script, but I think that I used it incorrectly. Full script is here:

<script>
MathJax = {
  startup
: {
    ready
() {
     
//
     
//  Adjust the default script scaling parameters
     
//
     
const math = MathJax._.core.MmlTree.MmlNodes.math.MmlMath;
      math
.defaults.scriptminsize = '12px';
      math
.defaults.scriptsizemultiplier = .8;
     
//
     
//  Create the usual MathJax objects
     
//
     
MathJax.startup.defaultReady();
     
//
     
//  Add a TeX jax pre-filter to add \displaystyle{...} around in-line material
     
//
     
MathJax.startup.document.inputJax[0].preFilters.add((data) => {
       
if (!data.math.display) {
          data
.math.math = '\\displaystyle{' + data.math.math + '}';
       
}
     
});
   
}
 
}
};
</script>

<script>
window
.MathJax = {
  tex
: {
    inlineMath
: [["$","$"],["\\(","\\)"]],
    tags
: "ams",
    macros
: {
      arctg
: '\\operatorname{arctg}',
      arcctg
: '\\operatorname{arcctg}',
      tg
: '\\operatorname{tg}',
      ctg
: '\\operatorname{ctg}',
      rang
: '\\operatorname{rang}',
     
Tr: '\\operatorname{Tr}',
     
Sp: '\\operatorname{Sp}',
      lg
: '\\operatorname{lg}',
      sh
: '\\operatorname{sh}',
      ch
: '\\operatorname{ch}',
      th
: '\\operatorname{th}',
      cth
: '\\operatorname{cth}',
     
Arsh: '\\operatorname{Arsh}',
     
Arch: '\\operatorname{Arch}',
     
Arth: '\\operatorname{Arth}',
     
Arcth: '\\operatorname{Arcth}',
      sgn
: '\\operatorname{sgn}',
      boldred
: ['\\color{red}{\\boldsymbol{#1}}', 1],
      boldblue
: ['\\color{blue}{\\boldsymbol{#1}}', 1],
      boldgreen
: ['\\color{green}{\\boldsymbol{#1}}', 1],
      boldpurple
: ['\\color{purple}{\\boldsymbol{#1}}', 1],
      normred
: ['\\color{red}{#1}', 1],
      normblue
: ['\\color{blue}{#1}', 1],
      normgreen
: ['\\color{green}{#1}', 1],
      normpurple
: ['\\color{purple}{#1}', 1]    
   
}
 
},
  options
: {
    ignoreHtmlClass
: 'tex2jax_ignore',
    processHtmlClass
: 'tex2jax_process'
 
}
};
</script>

<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js" id="MathJax-script"></script>


But parameter 'displaystyle' did not appear:

Отправка.png



May be I inserted script in the wrong place?

Davide Cervone

unread,
Nov 19, 2019, 6:23:44 AM11/19/19
to mathja...@googlegroups.com
You have to combine the two scripts into a single one that assigns a single object to the MathJax variable.  The way you have it now, the second script overwrites the first, and you lose the changes that it specifies.

So you want to use

<script>
MathJax = {
  startup: {
    ready() {
      //
      //  Adjust the default script scaling parameters
      //
      const math = MathJax._.core.MmlTree.MmlNodes.math.MmlMath;
      math.defaults.scriptminsize = '12px';
      math.defaults.scriptsizemultiplier = .8;
      //
      //  Create the usual MathJax objects
      //
      MathJax.startup.defaultReady();
      //
      //  Add a TeX jax pre-filter to add \displaystyle{...} around in-line material
      //
      MathJax.startup.document.inputJax[0].preFilters.add((data) => {
        if (!data.math.display) {
          data.math.math = '\\displaystyle{' + data.math.math + '}';
        }
      });
    }
  },

instead.  My statement

"You will need to incorporate whatever other configuration you need (the ones generated by the converter) into this MathJax object."

was meant to indicate this.

Davide


<Отправка.png>



May be I inserted script in the wrong place?

--
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/fd3dbd91-2145-4f96-af0c-be4d84f7968b%40googlegroups.com.
<Отправка.png>

Alexey

unread,
Nov 21, 2019, 11:25:55 AM11/21/19
to MathJax Users
Thanks a lot :) I tried to insert all code in one function, but I used semicolon instead comma - that's why my code didn't work :) Thanks again for your help - all your advices are very useful for me. I added MathJax 3 to some pages of the my site - it works fast.

roger leveriza

unread,
Nov 27, 2019, 12:18:47 PM11/27/19
to MathJax Users
Reply all
Reply to author
Forward
0 new messages