automatic numbering updates

264 views
Skip to first unread message

Ivan Savov

unread,
Feb 21, 2012, 10:01:00 PM2/21/12
to mathja...@googlegroups.com

Hello,


I am am testing out the automatic equation numbering in AMSmath.js,
in the 2.0 release and I am running into a problem in a use case, which
involves the equations being dynamically updated.

I have a equation environment with a \label{} inside an editable div:
   \begin{equation}
      \sin\theta     \label{myEqn}
   \end{equation}
The first time the page loads fine (1) appears on the right, and
the key:value pair  "myEqn":'1' appears in MathJax.Extensions["Tex/AMSmath"].labels

After editing the source of the div, when I save, I issue this:
  MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
which now errors out saying "myEqn" is mutiply defined,
because MathJax is processing the equation as if were new.

Is there a way to trigger the equation numbering routines for
the whole document?


I am not sure how the "hooks" work here:
https://github.com/mathjax/MathJax/blob/v2.0-candidate/unpacked/extensions/TeX/AMSmath.js#L517



Also, I would recommend that the "mutiply defined" error
be downgraded to a warning -- In latex if you define multiple
labels with the same name, you get warnings, but the
last one will work.


Finally, if you guys need any help with the 2.0 documentation
proofreading, give me a shout about what need to be done.


Thank you,

   Ivan


PS: This is my general config (pretty standard)

   <script type="text/x-mathjax-config">
         MathJax.Hub.Config({
           jax: ["input/TeX","output/HTML-CSS"],
           extensions: ["tex2jax.js"],
           tex2jax: {
             inlineMath: [["$","$"],["\\(","\\)"]],
             displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
             processEscapes: true,
             processEnvironments: true
           },
           TeX: {
               extensions: ["AMSmath.js"],
               equationNumbers: {  autoNumber: "AMS"  }  //automatic eqn numbering !!!
           }
         });
   </script>

Davide P. Cervone

unread,
Feb 23, 2012, 3:23:33 PM2/23/12
to mathja...@googlegroups.com
> I am am testing out the automatic equation numbering in AMSmath.js,
> in the 2.0 release and I am running into a problem in a use case,
> which
> involves the equations being dynamically updated.

Yes, that is going to interact badly with the labels and numbering.

> I have a equation environment with a \label{} inside an editable div:
> \begin{equation}
> \sin\theta \label{myEqn}
> \end{equation}
> The first time the page loads fine (1) appears on the right, and
> the key:value pair "myEqn":'1' appears in MathJax.Extensions["Tex/
> AMSmath"].labels
>
> After editing the source of the div, when I save, I issue this:
> MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
> which now errors out saying "myEqn" is mutiply defined,
> because MathJax is processing the equation as if were new.

Right, because it IS new (as far as MathJax is concerned). There is
no connection between the original equation and the new one because
you have replaced the contents of the div with new contents. It could
have more equations or fewer equations, and some could be labeled that
weren't before, and the numbering could have changed by the use of
\nonumber or \notag, and so on. There is no real way to tell what the
numbering of the new equations should be.

The best that I can think of would be that you would have to reprocess
all the mathematics again from scratch (as you suggest below).

> Is there a way to trigger the equation numbering routines for
> the whole document?

Yes, MathJax.Hub.Reprocess() would go through the page again
reprocessing all the mathematics from scratch; but it doesn't clear
the equation numbers or labels, so that would cause ALL your labels
would cause errors. To do what you want, you need to clear the labels
and equation numbering, and there isn't an API call for that. (I'm
adding one in response to this situation, but it's not in the 2.0-beta
version on the CDN at the moment).

For now, you can use

function resetEquationNumbers() {
var AMS = MathJax.Extension["TeX/AMSmath"];
AMS.startNumber = 0;
AMS.labels = {};
}

to clear the labels and reset the numbering. Then

MathJax.Hub.Queue(
resetEquationNumbers,
["PreProcess",MathJax.Hub],
["Reprocess",MathJax.Hub]
);

should re-typeset the page using fresh equation numbers and labels.
Note that you can't use MathJax.Hub.Typeset(), since that will only
typeset NEW math, not the existing math. The MathJax.Hub.Reprocess()
call will cause existing math to be reprocessed, but it doesn't run
the tex2jax preprocessor to locate NEW math. So you need to call the
preprocessors by hand using MathJax.Hub.PreProcess(), and then
reprocess the math (which will handle both the original math and any
new math found by the preprocessor).

This seems inefficient, but because equation numbers and labels (and
the order and number of equations) can change during the editing, I
don't see any way to get around having to reprocess the math (at least
not without caching a lot more information about the labels and
numbers for each equation). I'll keep thinking about it for v2.1, but
for now, this should work.

BTW, the new routine that I've added to the API is
MathJax.InputJax.TeX.resetEquationNumbers, so for the final 2.0
release, you should be able to use

MathJax.Hub.Queue(
["resetEquationNumbers",MathJax.InputJax.TeX],
["PreProcess",MathJax.Hub],
["Reprocess",MathJax.Hub]
);

> Also, I would recommend that the "mutiply defined" error
> be downgraded to a warning -- In latex if you define multiple
> labels with the same name, you get warnings, but the
> last one will work.

There is no difference between a warning and an error in MathJax.
MathJax either displays the mathematics (in which case there is no
error or warning message), or it shows a message (in which case it
doesn't show the mathematics). While it would be possible for the new
label to override the original one, there is no place to show the
message if it is not treated as an error (there is no separate log
file like in actual TeX). It seems better to let you know about the
problem rather than ignore it and potentially have inconsistent
references (the ones from before the second occurrence of the label
would be one value and the ones after would be another value) with no
indication of that.

> Finally, if you guys need any help with the 2.0 documentation
> proofreading, give me a shout about what need to be done.

That would be great. If you want to review the current versions of
the documentation, you can look at

http://devel.mathjax.org/mathjax/dpvc/2.0-docs/docs/html/

I would be happy to have some other people read through these. Note,
however, that we are planning the official release for Sunday, the
26th, so there is not much time to make corrections. Also note that
there are references to example files, but these link to http://cdn.mathjax.org/mathjax/latest/test
; since that is still v1.1, the new examples are not there. You can
find them at

http://devel.mathjax.org/mathjax/dpvc/2.0-docs/test/

instead.

Davide

Reply all
Reply to author
Forward
0 new messages