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
  • #1633
Closed
Open
Issue created Oct 05, 2016 by Administrator@rootContributor

HTML-CSS output: if the page already contains an element with id "MathJax-Element-N-Frame", predictably bad things result

Created by: christianp

An author of some text didn't know how to get a π symbol, so he got MathJax to render it, then copied and pasted the output back into the WYSIWYG editor. What he didn't notice (and it can reasonably be argued he shouldn't have to worry about this) was that he had pasted in the entire HTML element produced by MathJax, which had id attribute MathJax-Element-3-Frame. To compound his bad luck, he pasted all this before the third occurence of LaTeX in the page.

When MathJax processes a bit of LaTeX, it inserts an element with an ID of the form MathJax-Element-N-Frame in place, to store the rendered output. Later on, when it comes to filling that element up, it uses document.getElementById to retrieve it. In this case, that returns the pasted element instead of the one MathJax just created.

I've made a minimal example at http://codepen.io/christianp/pen/VKymrd. Here's how it looks on Chrome: image (The person who reported this was running Firefox)

Not only has the third bit of maths gone in the wrong place, the metrics seem to be messed up for every other bit of maths on the page, even stuff that appeared before our pasted element.

The obvious solution is not to have such badly-named elements in your page to start with, but I think MathJax could be more careful here.

I can think of two solutions

  • rather than using document.getElementById(jax.inputID+'-Frame'), keep a reference to the element itself. I assume there's a good reason we don't do this.
  • At the cost of one extra call (actually, maybe a few) to document.getElementById for each bit of maths, in MathJax.ElementJax.GetID, check that the element #MathJax-Element-N-Frame doesn't already exist. There are a few elements for each N though, right? And I suppose we could be really unlucky and have those elements added into the page in-between different stages of the MathJax process.
Assignee
Assign to
Time tracking