genfrac with delimiters in sum

19 views
Skip to first unread message

David Farmer

unread,
Apr 2, 2015, 10:21:29 PM4/2/15
to mathja...@googlegroups.com
I am trying to write a sum over the integers where the Legendre symbol has a certain value.
You don't need to know what that means, except for the fact that the Legendre symbol looks
like a fraction in parentheses, and in TeX it is usually written using the \genfrac macro.

When I try to put a \genfrac as the subscript to a \sum or \prod, I get
[Math Processing Error] with no specific statement of what went wrong.

The first 3 of these work fine, and the 6th gives an error.  The 4th and 5th sort-of work,
but if you look carefully you can see that the 3rd and 4th do not look the same,
so I would rather not use that approach if I don't have to (but maybe some \mathstrut's
would help it look better).

begin{equation}
\sum_{\frac{n}{2}>5} n^2
\end{equation}

\begin{equation}
\sum_{\genfrac{}{}{}{}{n}{2}>5} n^2
\end{equation}

\begin{equation}
\genfrac{(}{)}{}{}{n}{2}>5
\end{equation}

\begin{equation}
\sum_{\left(\frac{n}{2}\right)>5} n^2
\end{equation}

\begin{equation}
\sum_{\genfrac{(}{)}{}{}{n}{2}>5} n^2
\end{equation}

Here are those equations on a web page:

http://aimath.org/~farmer/print/mathjax_genfrac.html

Can I use \genfrac or do I have to do it another way?

Regards,

David

ps.  The math is nonsense: I just made an example to illustrate my question.

Davide P. Cervone

unread,
Apr 3, 2015, 8:20:58 AM4/3/15
to mathja...@googlegroups.com
Here's what's going on:  \genfrac uses \mathchoice to set up the delimiters (more on this below), and \sum uses the MathML tag <munderover> to put the subscript under the sigma.  The \mathchoice macro needs to know the MathML displaystyle and scriptlevel before it can choose which of the four alternatives it should use, and these are determined by the parent element of the \mathchoice, which is the <munderover>.  But <munderover> needs to know its children's core <mo> element (if any) in order to determine its child's scriptlevel (if is different if the <mo> has the attribute accent="true" rather than accent="false").  But \mathchoice can't give <munderover> its core <mo> until it knows the scriptlevel.  That leads to an infinite loop when \mathchoice is used in the under of over position of munderover.  That infinite loop is what is causing the Math Processing Error (the browser eventually throws an error when the call-stack size is exceeded).

I've started an issue tracker for this at


I have a patch that will break the loop.  For now, you can use the following patch on your page:

<script type="text/x-mathjax-config">
  MathJax.Hub.Register.StartupHook("TeX mathchoice Ready",function () {
    MathJax.ElementJax.mml.TeXmathchoice.Augment({
      choice: function () {
        if (this.selection != null) return this.selection;
        if (this.choosing) return 2; // prevent infinite loops:  see issue #1151
        this.choosing = true;
        var selection = 0, values = this.getValues("displaystyle","scriptlevel");
        if (values.scriptlevel > 0) {selection = Math.min(3,values.scriptlevel+1)}
          else {selection = (values.displaystyle ? 0 : 1)}
        // only cache the result if we are actually in place in a <math> tag.
        var node = this.inherit; while (node && node.type !== "math") node = node.inherit;
        if (node) this.selection = selection;
        this.choosing = false;
        return selection;
      }
    });
  });
</script>

Thanks for reporting the error.

Note that the 3rd and 4th equations in your test file are SUPPOSED to look different, as they look different in actual LaTeX.  Here is a screen shot of the test code from actual LaTeX:


Hope that helps.

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.

David Farmer

unread,
Apr 3, 2015, 9:27:45 AM4/3/15
to mathja...@googlegroups.com

Even with the explanation I probably couldn't have figured out how
to fix it, but the patch you made is working perfectly.

Thank you, and thank you for responding so quickly!

William F Hammond

unread,
Apr 3, 2015, 1:56:02 PM4/3/15
to mathja...@googlegroups.com

Davide --

The \mathchoice macro needs to know the MathML displaystyle and scriptlevel before it can choose which of the four alternatives it should use, ...

For the original 5th equation it seems that, without using config code for MathJax, setting the 4th argument of \genfrac to 2 (thereby explicitly specifying scriptstyle) will provide a fix.

           -- Bill
Reply all
Reply to author
Forward
0 new messages