New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Array of elements passed to Typeset is ignored if no callback is given #1680
Comments
The issue here is a little more complicated than it might appear, and has to do with the fact that a callback (in MathJax) need not be a function, but can be specified in a variety of other ways (see the callback documentation). When a single argument is passed to if (callback == null && (MathJax.Object.isArray(element) || typeof element === 'function'))
{try {MathJax.Callback(element); callback = element; element = null} catch(e) {}} Here, if there is no callback (i.e., only one argument was passed), and if that argument looks like it could be a callback specification (a callback can be a function or an array with the right kind of elements), then It turns out that the situation that causes problems is when the single argument to The problem actually is in So line 301 is the culprit. It should only unpack the array if it is an array whose one element is a function object, not just any object. Until that is fixed, it is best to use
to force there to be an empty callback if the query select could return an array with only one element. |
…s (by only unpacking singleton callback arrays when the one element is a function). Resolves issue mathjax#1680.
The |
Properly handle arrays of elements in Typeset() call without callbacks. #1680
==> Merged |
==> In testsuite API/Callback/issue1680.html |
The documentation for
Hub.Typeset
suggests that you can pass an array of elements or a callback or both:However, the argument handling in the
elementCallback
helper method has some (IMHO) odd behaviour whenelement
is an array andcallback
is not specified. The code in question is:The result is that
callback
ends up being set to the first element in the array, andelement
is set tonull
. Theelement
then defaults to the document'sbody
later on, which in most cases masks the bug (unless the intended elements aren't yet in thebody
, in which case much confusion ensues). However, if you usesignal.Interest
to track the events, you can see that the element is not actually tracked.It's also worth noting that this affects other hub functions, such as
Update
.Example
Run this in the dev console on the home page:
Output:
When the callback is not specified, the signal messages indicate that MathJax is searching the
body
. When the callback is specified, the signal messages indicate that MathJax is searching thediv.hero-math
element, which is what was intended.The text was updated successfully, but these errors were encountered: