Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • M MathJax
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 304
    • Issues 304
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 15
    • Merge requests 15
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • MathJax
  • MathJax
  • Issues
  • #1680
Closed
Open
Issue created Dec 23, 2016 by Administrator@rootContributor

Array of elements passed to Typeset is ignored if no callback is given

Created by: jdleesmiller

The documentation for Hub.Typeset suggests that you can pass an array of elements or a callback or both: image

However, the argument handling in the elementCallback helper method has some (IMHO) odd behaviour when element is an array and callback is not specified. The code in question is:

if (callback == null && (MathJax.Object.isArray(element) || typeof element === 'function'))
  {try {MathJax.Callback(element); callback = element; element = null} catch(e) {}}

The result is that callback ends up being set to the first element in the array, and element is set to null. The element then defaults to the document's body 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 use signal.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:

MathJax.Hub.signal.Interest(function (message) {console.log(message)});
MathJax.Hub.Queue(['Typeset', MathJax.Hub, $('.hero-math').toArray()]);
MathJax.Hub.Queue(['Typeset', MathJax.Hub, $('.hero-math').toArray(), function callbackHere() {}])

Output: image

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 the div.hero-math element, which is what was intended.

Assignee
Assign to
Time tracking