Why doesn't \\ display a newline in mathjax?

Issue

I am under the impression that you should use \\ for newlines with mathjax, however I can’t get it to work. What am I doing wrong here?

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8" />
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
</head>
<body>
<p><span class="math display">\[
    1 x x^2 \\
    1 y y^2 \\
    1 z z^2 \\
\]</span></p>
</div>
</body>
</html>

I expect to see 3 lines, but I get this:

unexpected formatting

Other stackoverflow posts claim that \\ should work, eg: https://math.meta.stackexchange.com/questions/11720/new-line-within-mathjax

Solution

You should use HTML to break lines as MathJax only handles math mode and does not process the backslashes:

<p>
    <span class="math display">
        \(1 x x^2 \)</br>
        \(1 y y^2 \)</br>
        \(1 z z ^2 \)</br>
    </span>
</p>

Answered By – Thanos T.

Answer Checked By – Pedro (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.