bloomers
bloomers

Reputation: 285

How can I use MathJax or LaTex in an html file?

I cannot get it to work and I'm not sure what I'm doing wrong.

I've downloaded MathJax.js, created an html file and linked it to the js file appropriately. I even copied and pasted from a previously answered question on here and just changed the link from a vpn (the vpn didn't work either, but the question and response were over three years old) to the js file on my machine.

Here's what I have in my html:

<html>
   <head>
    <title>MathJax</title>
    <script type="text/x-mathjax-config">
    MathJax.Hub.Config({"HTML-CSS": { preferredFont: "TeX", availableFonts: ["STIX","TeX"] },
        tex2jax: { inlineMath: [ ["$", "$"], ["\\\\(","\\\\)"] ], displayMath: [ ["$$","$$"], ["\\[", "\\]"] ], processEscapes: true, ignoreClass: "tex2jax_ignore|dno" },
        TeX: { noUndefined: { attributes: { mathcolor: "red", mathbackground: "#FFEEEE", mathsize: "90%" } } },
        messageStyle: "none"
    });
    </script>    
    <script type="text/javascript" src="MathJax.js"></script>
    <script type="text/javascript" src="latest.js"></script>

  </head>
  <body>
     The definition of the Euler-Mascheroni constant is
     \gamma=\lim_{n\to\infty}\left(\sum_{k=1}^n\frac1k-ln(n)\right) 
  </body>
</html>

I would greatly appreciate any assistance.

Upvotes: 8

Views: 7256

Answers (2)

Liam
Liam

Reputation: 1591

Here is a file I constructed from the documentation examples

<html>
  <head>
    <!-- See http://docs.mathjax.org/en/latest/web/start.html#using-mathjax-from-a-content-delivery-network-cdn -->
    <script type="text/javascript" id="MathJax-script" async
        src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js">
    </script>
  </head>
<body>
<p>
  From the <a href="https://www.w3.org/Math/MJ/Overview.html">overview docs</a>, in MathML: Let's consider <math><mi>a</mi><mo>≠</mo><mn>0</mn></math>.
</p>
<p>
  With <a href="http://docs.mathjax.org/en/latest/basic/mathematics.html">\(\LaTeX\) input</a>:
  When \(a \ne 0\), there are two solutions to \(ax^2 + bx + c = 0\) and they are
  $$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$
</p>
</body>
</html>

Upvotes: 4

Peter Krautzberger
Peter Krautzberger

Reputation: 5305

There are a few problems.

  • If you don't specify a so-called combined configuration file, you need to specify all necessary components yourself. In particular, input, output and in your case the TeX pre-processor to find TeX markup in the page
  • If you use TeX input, you need to wrap input in the delimiters of your choice.

For example

    <script type="text/x-mathjax-config">
    MathJax.Hub.Config({
      jax: ["input/TeX", "output/HTML-CSS"],
      extensions: ["tex2jax.js"],
      "HTML-CSS": { preferredFont: "TeX", availableFonts: ["STIX","TeX"] },
      tex2jax: { inlineMath: [ ["$", "$"], ["\\(","\\)"] ], displayMath: [ ["$$","$$"], ["\\[", "\\]"] ], processEscapes: true, ignoreClass: "tex2jax_ignore|dno" },
      TeX: { noUndefined: { attributes: { mathcolor: "red", mathbackground: "#FFEEEE", mathsize: "90%" } } },
      messageStyle: "none"
    });
    </script>    
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js"></script>

     The definition of the Euler-Mascheroni constant is
     $\gamma=\lim_{n\to\infty}\left(\sum_{k=1}^n\frac1k-ln(n)\right) $

Caveat. I don't know what latest.js should do and you seem to be using a local installation so be sure to check the docs for that, http://docs.mathjax.org/en/latest/installation.html.

Upvotes: 6

Related Questions