Synchronizing ‘setRenderer’ with ‘Typeset’

23 views
Skip to first unread message

Daniel

unread,
Jan 18, 2017, 12:33:49 PM1/18/17
to MathJax Users
I am typsetting elements1 with the SVG renderer "manually":

MathJax.Hub.Queue(['Typeset', MathJax.Hub, elements1, {}]);

I also switch the renderer sometimes in order to typset some elements2 manually in CHTML:

MathJax.Hub.Queue(
  ['setRenderer', MathJax.Hub, 'CommonHTML'],
  ['Typeset', MathJax.Hub, elements2],
  ['setRenderer', MathJax.Hub, 'SVG'],
);

Strangely, it sometimes happens that the elements1 are typeset using the CHTML renderer which in turn leads to an error on my page. I thought pushing to the queue as I did would make this impossible. So I am wondering whether I misunderstood something.

Best,
Daniel

Daniel

unread,
Jan 18, 2017, 2:23:13 PM1/18/17
to MathJax Users
Here is another hypothesis on what is happening, but it is hard for me to test the theory. I hope those of you who know MathJax better can.

The elements2 are a HTMLCollection which I get via

document.getElementsByClassName

It could be that the error is happening only if the collection is empty (length = 0). Is MathJax somehow typesetting other elements if the collection is empty? Cannot really believe this. But might be still a helpful observation...

Davide Cervone

unread,
Jan 18, 2017, 3:43:48 PM1/18/17
to mathja...@googlegroups.com
Alas, you are correct, the issue is when elements2 is empty.  See


for details of why this causes the problem.  For now, add {} to the call for Typeset for elements2:

MathJax.Hub.Queue(
  ['setRenderer', MathJax.Hub, 'CommonHTML'],
  ['Typeset', MathJax.Hub, elements2, {}],
  ['setRenderer', MathJax.Hub, 'SVG'],
);

That should do it.  Butt better might be to check if elements2 is empty before queuing any calls:

if (elements2.length) {
  MathJax.Hub.Queue(
    ['setRenderer', MathJax.Hub, 'CommonHTML'],
    ['Typeset', MathJax.Hub, elements2, {}],
    ['setRenderer', MathJax.Hub, 'SVG'],
  );
}

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.

Daniel

unread,
Jan 19, 2017, 3:07:13 AM1/19/17
to MathJax Users
Perfect. Thanks.

I was already wondering why I had the {} in the typeset call of elements1. But could not remember why. Must have been a longer time ago I added that. Now I will make a note there to not forget it again.

I have used the element2.length check (and might do so with the elements1 - but it worked fine so far so maybe I better don't touch it and just make a comment).
Reply all
Reply to author
Forward
0 new messages