Fifi
Fifi

Reputation: 3605

Automatic Equation Numbering with MathJax v3.0

I would like to add equation numbers with MathJax v3.0. I don't understand where the following code must be added :

window.MathJax = {
  tex: {
    tags: 'ams'
  }
};

I made a non working JSFiddle here with some of my trials.

Edit : I need to number automatically all the equations.

Upvotes: 1

Views: 728

Answers (4)

user29819687
user29819687

Reputation: 11

The code you referenced should be added in as a script in the header of your html document. Then, as previously answered, you can typeset latex math in your html using the equation environment \begin{equation} ... \end{equation}. Here is a basic html sample. You can see its output at https://imgur.com/a/eNZ96QC

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>MathJax Equation Numbering</title>

    <!-- Load MathJax into document -->
    <script type="text/javascript" id="MathJax-script" async
    src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js">
    </script>
    <!-- Configure MathJax to allow equation numbering -->
    <script>
    window.MathJax = {
        tex: {
            tags: 'ams'
        }
    };
    </script>

</head>
<body>
    <h2>Equations Without Numbers</h1>
        <p>
            We can see that the equation for Newton's law of gravity is unnumbered:
            
            \begin{equation*}
            F = G \frac{m_{1}m{2}}{r^{2}}
            \end{equation*}  
        </p>
        
    <h2>Equations With Numbers</h1>
        <p>
            We can see that the equation for Euler's identity, shown in Equation \eqref{eq:Euler}, is numbered:
                
            \begin{equation}
            e^{i\pi} + 1 = 0
            \label{eq:Euler}
            \end{equation}
        </p>
            
</body>
</html>

Upvotes: 1

Louis Lin
Louis Lin

Reputation: 11

I would recommend viewing Equation numbering in Jupyter notebooks

One of the solutions that I used from there is:

%%javascript
MathJax.Hub.Config({
    TeX: { equationNumbers: { autoNumber: "AMS" } }
});

Run this in another cell and the automatic numbering should be turned on.

Upvotes: 1

The_ehT
The_ehT

Reputation: 1230

With the configuration tag:'ams' you need to wrap the equation with \begin{equation} and \end{equation} . So write your equation as -

\begin{equation}
x_1 = \sqrt(y) 
\end{equation}

Upvotes: 3

Fifi
Fifi

Reputation: 3605

Changing ams to all resolves the problem :

<script>window.MathJax = { tex: { tags: 'all' } }; </script>

https://jsfiddle.net/Lordfc0v/2/

Upvotes: 1

Related Questions