MathJax: improved autonumbering Re: Missing symbols

128 views
Skip to first unread message

Victor Ivrii

unread,
Oct 23, 2012, 5:02:39 AM10/23/12
to mathja...@googlegroups.com
On Mon, Oct 22, 2012 at 12:36 PM, Paul Topping <pa...@dessci.com> wrote:
> I agree that it would be nice to “support everything in LaTeX2e math mode”
> or some equivalent simple statement.


I am afraid EVERYTHING is impossible but I would like to improve
autonumbering in two ways

(1) Support \numberwithin{equation}{section} (etc). Definitely
sectioning is not a MJ' business (and thus autonumbering of sections
also is not for MJ) but if section is (re)defined like $\section=3$
then MJ resets equation counter and prints (3.1), (3.2) etc instead
of say (23), (24), etc.

(1)' support even for $\section=3.2$

(2) Support for cross-references. Definitely I can reference from
outside any particular equation like (<a
href="http://www.math.toronto.edu/courses/apm346h1/20129/L15.html#mjx-eqn-eq-12">15.12</a>)
but it is a cumbersome. Meanwhile LaTeX package xr-hyper provides much
more elegant solution.

If we define

\externaldocument[V1-]{volume1}[http://mybook.com/volume1.pdf]
(several could be defined)
then \ref{V1-eq-Cauchy} provides a link to a correct equation
(labelled as {eq-Cauchy} in http://mybook.com/volume1.pdf

Sure there could be several variants of support.

(a) The simplest (no support for external labels)
\externaldocument[L1-]{Lecture1}[http://mybook.com/Lecture1.html]
then( \ref{L1-5}) would print (1.5) and provide a link to equation (5)
in Lecture1.

(b) Slow (support for external labels)
then \ref{L1-eq-Cauchy} would print (1.5) and provide a link to
equation (5) in Lecture1 provided (5) was a number for a
label{eq-Cauchy} in Lecture1.

This would be slow as MJ would need to autonumber Lecture1 as well
(but no rendering)

(c) Complete emulation of xr-hyper. xr-hyper does not require
processing of the external document but the presence of its aux file
containing relations between labels and equation numbers (actually, it
is bit more complicated). So if I have L1.html then running some
external program (some script) I produce a file Lecture1.mj-aux; I
will place it as readable file in the same directory as myfile.html
and myfile.html containing
\externaldocument[L1-]{Lecture1}[http://mybook.com/Lecture1.html}
would read Lecture1.mj-aux instead of processing
http://mybook.com/Lecture1.html}


Victor



--
========================
Victor Ivrii, Professor, Department of Mathematics, University of Toronto
http://www.math.toronto.edu/ivrii

madsen...@gmail.com

unread,
Jan 7, 2016, 5:01:14 PM1/7/16
to MathJax Users
I was looking to number equations exactly as point (1)'. Has something like this been implemented in MathJax, and if not is there a viable workaround to get the same effect?

Davide P. Cervone

unread,
Jan 18, 2016, 5:12:06 PM1/18/16
to mathja...@googlegroups.com
Well, this doesn't do everything Victor suggested, but it does implement (1) and (1)' that you requested.  His suggestions for cross references are good ones, and it would be nice to see an extension that does that.   In fact, this example should be made into an extension as well.  Anyone want to give it a go?

In any case, here is an example that implements \section{n} and makes the equation tags format using the section number (it can actually be anything, not just a number).  Perhaps that is sufficient for your needs.

<!DOCTYPE html>
<html>
<head>
<title>Equation numbers by section</title>
<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>
</head>
<body>

\begin{align}
  a+b &= c
\end{align}

<div style="display:none; position:absolute">
\(\section{E}\)
</div>

\begin{equation}
E=mc^2
\end{equation}

<div style="display:none; position:absolute">
\(\section{1}\)
</div>

\begin{align}
  a+b &= c
\end{align}

\begin{align}
  a+b &= c
\end{align}


<div style="display:none; position:absolute">
\(\section{1.1}\)
</div>

\begin{align}
  a+b &= c
\end{align}

<div style="display:none; position:absolute">
<!-- back to the default numbering sequence -->
\(\section{}\)
</div>

\begin{align}
  a+b &= c
\end{align}

<div style="display:none; position:absolute">
<!-- back to numbers starting with "E." starting where we left off -->
\(\section{E}\)
</div>

\begin{equation}
E=mc^2
\end{equation}

\begin{equation}
E=mc^2
\end{equation}

</body>
</html>

See if that does what you need.

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.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
Message has been deleted
0 new messages