Display MathJax dynamically only when there are delimiters

I set up the code below. The documentation for MathJax is not very complete. Can anyone find out more about how I can modify the code below so that Tex only parses when I specify delimiters like $ \ alpha $. I would like to make it work like on math.stackexchange.

<html> <head> <title>MathJax Dynamic Math Test Page</title> <script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"],["\\(","\\)"]] } }); </script> <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML-full"> </script> </head> <body> <script> // // Use a closure to hide the local variables from the // global namespace // (function () { var QUEUE = MathJax.Hub.queue; // shorthand for the queue var math = null; // the element jax for the math output. // // Get the element jax when MathJax has produced it. // QUEUE.Push(function () { math = MathJax.Hub.getAllJax("MathOutput")[0]; }); // // The onchange event handler that typesets the // math entered by the user // window.UpdateMath = function (TeX) { QUEUE.Push(["Text",math,"\\displaystyle{"+TeX+"}"]); } })(); </script> <textarea id="MathInput" size="50" onkeyup="UpdateMath(this.value)"></textarea> <div id="MathOutput"> You typed: ${}$ </div> </body> </html> 
+7
source share
1 answer

The sample code you submitted takes the contents of MathInput and replaces the first MathJax element with the new β€œmath” from MathInput. You want to set MathInput in Setet and create new MathJax elements for delimited text. Here I set the jsFiddle example: http://jsfiddle.net/Zky72/2/

The main change in the UpdateMath function:

  window.UpdateMath = function (TeX) { //set the MathOutput HTML document.getElementById("MathOutput").innerHTML = TeX; //reprocess the MathOutput Element MathJax.Hub.Queue(["Typeset",MathJax.Hub,"MathOutput"]); } 
+19
source

All Articles