How to call external javascript?

Davide P. Cervone’s html with internal javascript (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

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 –

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

<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

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.