I am asking a question that has appeared many times on TeX StackExchange but none of the answers seem to work for my use case.

I am trying to introduce line breaks, programmatically, into really long equations that will typically happen between either \left \right pairs or in \sqrt. And I am using Mathjax to render (using Jupyter Notebook), meaning I only have a subset of Latex implemented and am not able to use packages such as breqn.

Here is my example code:

\sqrt{a + b + c + d + e + f + g} &= 
    \sqrt{243324234.00000 + 234324.00000000000 +\\
    2342348987987897987.00000000000 + 32234234.00000000000000 +\\
    20909.0000000000000000 + 12321.000000} &= 42

(I am not actually using numbers with that many decimal places, I just needed to fill space up for my example; I am using many long numbers similar to this, though).

Now, the weird part is that it renders on-screen, just fine. But when I go to compile it into PDF using xelatex (via nbconvert), I get the following errors:

nbconvert failed: PDF creating failed, captured latex output:
Failed to run "xelatex .\notebook.tex -quiet" command:
notebook.tex:421: Missing $ inserted
notebook.tex:422: Missing } inserted
notebook.tex:424: Missing { inserted
notebook.tex:425: Missing 

Here is what else I have tried:
\sqrt too long for one line - However, I do not have access to the \multlined environment within Mathjax.

Long \sqrt in two lines - \split{} creates an unbreakable box which flows off of the page, both on-screen and when compiled.

This is programmatically created Latex output. I have tried putting each equation into either its own \align environment (if it was a "small" equation) or \multline environment (if it is a "large" equation), which kind of works but this is not good Latex practice and it prevents any kind of actual alignment and spacing adjustment between equations. My preference is not to do this.

So, given these parameters, is it possible to programmatically introduce semi-arbitrary line breaks into equations in an AMS math environment that will compile?

Thank you so much for any advice or help.


This might be a bit off-topic since MathJax is not LaTeX, but a web equation extension which accepts a markup language inherited from LaTeX, as one of its input style.

In MathJax, you can directly use multline environment inside other multi-line math environments. Note the {} added to keep proper spacing around +.

\sqrt{a + b + c + d + e + f + g} &= 
    \sqrt{\begin{multline}243324234.00000 + 234324.00000000000 + {}\\
    2342348987987897987.00000000000 + 32234234.00000000000000 + {} \\
    20909.0000000000000000 + 12321.000000\end{multline}} &= 42

multi-line sqrt in mathjax

  • This didn't work for me: I copied it in but the multline appears to cause some numbers to overlay on each other. Additionally, it won't compile, either :( – Connor Ferster Mar 31 '20 at 1:00
  • @ConnorFerster Which version of MathJax are you using? Since my answer works well on mathjax.org/#demo – muzimuzhi Z Mar 31 '20 at 1:02

Ok, following muzumuzhi Z's lead, I tried their suggestion but substituting gathered for multline and it seems to work.

The other important thing is that I needed to ensure I also used \[ ... \] around my aligned environment.

Here is my revised code:

\sqrt{a + b + c + d + e + f + g} = 
\sqrt{\begin{gathered} 233324234.00000 + 234324.00000000000  +{}\\
    2342348987987897987.00000000000 + 32234234.00000000000000 +{}\\
     20909.0000000000000000 + 12321.000000 \end{gathered}} &= 42

Interestingly, this also seems to work for \left( ... \right) line breaks, also!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.