0

I've just learned about math MathJax. I've read some documentation, and it looks nice but If I understood it right it scans html page for equations and automatically replace them with HTML/SVG or whatever.

My concern is that I'm generating my page from raw text (simply strings) in JS and I would like to just simply pass certain parts of it to MathJax and get html string in return. I looked at the API but unless I'm missing something, there is no such option and I can only do things like MathJax.Hub.Process().

So it would look like

  • I'm creating and adding HTML elements to document based on my text.
  • I'm telling MathJax to search for the content I've just created.
  • MathJax is searching for text to parse and removing the content I've just added, striping out text, parsing....
  • MathJax is creating it's own elements add it to document.

Is there a way (without modifying the source code) to do something like this:

  • I'm passing text to MathJax, telling it what is the format.
  • MathJax is returning HTML text string.
  • I'm creating HTML element besed on that text and inserting it at desired place.

I hope I overlooked something.

  • 1
    http://docs.mathjax.org/en/latest/api/html.html – spex Apr 02 '17 at 17:24
  • Well, that could remove the need of adding and removing my elements fist, but I still need to convert the returned element to string or complicate my setup to insert it in proper place... – Paweł Audionysos Apr 02 '17 at 18:01
  • Then maybe take a look at: https://docs.mathjax.org/en/v2.5-latest/typeset.html – spex Apr 02 '17 at 18:30
  • Thanks, but the tick is that I actually don't track individual elements and I'm generating new completely new html each time the change is made. The method you linked is good if you update content you are actually aware of. I guess the answer to my question is sadly "no". – Paweł Audionysos Apr 02 '17 at 18:52
  • There is no API in MathJax to do this. The reasons is that depending on various factors, MathJax requires the DOM context for its layout (this is less often the case for the new outputs). You could write a wrapper that puts your content into a detached node, let MathJax render that and grab the results. On the one hand, that will be poor in performance (serializing only to inject again later), on the other hand, some layout issue might occur since the DOM (and CSS) context where the result ends up might be very different. FWIW, v3 will get such a method but there's no ETA yet. – Peter Krautzberger Apr 04 '17 at 14:21
  • We will see. To be honest this is not a feature I would use extensively. Probably in most cases it would be limited to divisions/fractions format sometimes so that's not really big concern. I was just curious. – Paweł Audionysos Apr 04 '17 at 17:36
  • How can I trigger equation editor style tag which styles the equation to load when i am using mathjax api to insert equation html to the ckeditor? – orangespark Feb 13 '18 at 07:19

0 Answers0