# How to call external javascript?

**URL:** <https://forum.pinegrow.com/t/how-to-call-external-javascript/7900>\
**Category:** Javascript\
**Created:** [April 5, 2023, 4:27pm UTC](https://forum.pinegrow.com/t/how-to-call-external-javascript/7900 "2023-04-05T16:27:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dculp](https://avatars.discourse-cdn.com/v4/letter/d/e47c2d/32.png) [@dculp](https://forum.pinegrow.com/u/dculp)\
**Post date:** [April 5, 2023, 4:27pm UTC](https://forum.pinegrow.com/t/how-to-call-external-javascript/7900/1 "2023-04-05T16:27:10Z")

</div>

Davide P. Cervone’s html with internal javascript ([https://groups.google.com/g/mathjax-users/c/jUtewUcE2bY/m/0-sg2F2aCAAJ](https://groups.google.com/g/mathjax-users/c/jUtewUcE2bY/m/0-sg2F2aCAAJ)) allows renumbering of mathjax equations. The output gives (with my comments on the left) –

![image](https://canada1.discourse-cdn.com/flex036/uploads/pinegrow/original/2X/4/47d46458c68229a04e0cdaeb736cdd59b186c516.png)

**How can I create a stand-alone javascript that does the same thing?**

As an attempt, I extracted the following from Cervone and saved to number\_equations.js –

```auto
    <script type="text/x-mathjax-config">
    MathJax.Hub.Register.StartupHook("TeX AMSmath Ready",function () {
      var sectionDefault = {name: "", num: 0};
      var sections = {}, section = sectionDefault;
    
      //
      // The MathJax objects we need to modify
      //
      var TEX = MathJax.InputJax.TeX, PARSE = TEX.Parse;
      var AMS = MathJax.Extension["TeX/AMSmath"];
    
      //
      // Add \section{n} and \seteqnumber{n} macros
      //
      TEX.Definitions.Add({
        macros: {
          section: "mySection",
          seteqnumber: "mySetEqNumber"
        }
      });
    
      PARSE.Augment({
        //
        // \section{n}
        // Sets the current section. The n is used in tags and also in
        // the anchor names. The equation numbers are set to 0 when the
        // section is changed. If a section is reused, the numbers restart
        // where we left off.
        //
        mySection: function (name) {
          section.num = AMS.number;
          var n = this.GetArgument(name);
          if (n === "") {
            section = sectionDefault;
          } else {
            if (!sections["_"+n]) sections["_"+n] = {name:n, num:0};
            section = sections["_"+n];
          }
          AMS.number = section.num;
        },
    
        //
        // \seteqnumber{n}
        // sets the next equation number to be n (a positive integer).
        //
        mySetEqNumber: function (name) {
          var n = this.GetArgument(name);
          if (!n || !n.match(/^ *[0-9]+ *$/)) n = ""; else n = parseInt(n)-1;
          if (n === "" || n < 1) TEX.Error("Argument to "+name+" should be a positive integer");
          AMS.number = n;
        }
      });
    
      //
      // Configure the formatting of the tags and IDs. The IDs need to 
      // include the secetion number as well so that the equations in 
      // different sections get different anchors.
      //
      MathJax.Hub.Config({
        TeX: {
          equationNumbers: {
            formatTag: function (n) {return "("+(section.name+"."+n).replace(/^\./,"")+")"},
            formatID: function (n) {
              n = (section.name+'.'+n).replace(/[:"'<>&]/g,"").replace(/^\./,"");
              return 'mjx-eqn-' + n;
            }
          }
        }
      });
    });
    </script>
    
    <script type="text/x-mathjax-config">
    MathJax.Hub.Config({
      TeX: {
        equationNumbers: {
          autoNumber: "AMS"
        }
      }
    });
    </script>

```

This is called by replacing everything in Cervone’s html between `<head> </head>` with –

```auto
<head>
    <title>Equation numbers by section</title>
    <script type = "text/javascript" src="number_equations.js"></script>  

    <script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML-full"></script>
</head>

```

This gives formatted mathjax equations but without any numbering –

![image](https://canada1.discourse-cdn.com/flex036/uploads/pinegrow/original/2X/e/eca7dd6acdbdfd288c05ce3c3274fe1a50b49f02.png)

I suspect I’m missing something in number\_equations.js. (I know little about how to do this so please be explicit with any suggestions.)

Thanks,  
Don C.
