We will render math Formula in browser by Js engine MathJax.
Download the mathjax package to host it from our own server.

git clone https://github.com/mathjax/MathJax.git mj-tmp
mv mj-tmp/es5 <path-to-server-location>/mathjax
rm -rf mj-tmp

Write a JS file which import mathjax to analyze string which contains latex math code.

check-for-tex.js:

(function () {
  var body = document.body.textContent;
  if (body.match(/(?:\$|\\\(|\\\[|\\begin\{.*?})/)) {
    if (!window.MathJax) {
      window.MathJax = {
        tex: {
          inlineMath: {'[+]': [['$', '$']]}
        }
      };
    }
    var script = document.createElement('script');
    script.src = 'mathjax/tex-chtml.js';
    document.head.appendChild(script);
  }
})();

Test it in the html page:

<html>
   <head>
      <script src="check-for-tex.js" defer></script>
   </head>
   <body>
      <div>
         Math Formula: <span id="answer"/>
      </div>
      <script>
         document.getElementById("answer").innerHTML = "$ 2^{24} \\times 10 + \\frac{1}{2}$";
      </script>
   </body>
</html>

We can get the result:

Categories: Web

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments

Content Summary
: Input your strings, the tool can get a brief summary of the content for you.

X
0
Would love your thoughts, please comment.x
()
x