5

The equation below seems fine to me but when I insert this into a TeX file, it gives me back an error. Is anything wrong? The scope was to compressed the equation.

\begin{align*}
U & = -\frac{S \epsilon ^2 \Big(-108 S \lambda ^2-108 S \lambda ^2 \cos2 \tau \Big)}{432 \lambda ^3} \\
  & -\frac{S \epsilon ^3 \left(72 \text{g2} S^2 \lambda ^{3/2} \cos\tau -72 g_2 S^2 \lambda ^{3/2} \cos3 \tau \right)}\\
  & {432 \lambda ^3}-\frac{1}{432 \lambda ^3}S \epsilon ^4 \Bigl( -280 g_2^4 Z+378 g_2 g_4 Z-135 g_5 Z+128 g_2^2 S \lambda  \\
  & +64 g_2^2 S^3 \lambda +36 g_2^2 Z \lambda+54 S^3 \lambda ^2-9 Z \lambda ^2-280 g_2^4 Z \cos 2 \tau ]+378g_2 g_4 Z \cos 2 \tau  \\
  & -135 g_5 Z \cos2 \tau+4 g_2^2 \left(32 S+28 S^3+9 Z\right) \lambda \cos2 \tau +81 S^3 \lambda ^2 \cos2 \tau \\
  & -9 Z \lambda ^2 \cos2 \tau  -48 g_2^2 S^3 \lambda  \cos4 \tau +27 S^3 \lambda ^2 \cos 4 \tau \Bigr).
\end{align*}
1
  • 2
    Please provide a Minimal Working Example beginning with \documentclass and ending with \end{document} so that we can compile it with all the packages you use and find the error. – marczellm Nov 11 '13 at 11:53
7

The immediate cause for the error message you're getting is that the \frac term on the second equation line is missing the denominator term. What seems to have happened is that the denominator term, {432 \lambda ^3}, somehow ended up at the start of the third line. Moving it to the end of the second line will remove the LaTeX error.

To make it easier on your readers to take in this equation, it may be a good idea to factor out the common term \frac{S}{432 \lambda ^3} and group the remaining terms into those that involve second, third, and fourth powers of \epsilon:

enter image description here

\documentclass{article}
\usepackage{amsmath}
\begin{document}
  \begin{align*}
    U = -\frac{S}{432 \lambda ^3}
        &\Bigl[\phantom{{}+}\epsilon ^2 \bigl(-108 S \lambda ^2-108 S \lambda ^2 \cos2 \tau \bigr) \\
        & +\epsilon ^3 \bigl(72 g_2 S^2 \lambda ^{3/2} \cos\tau -72 g_2 S^2 \lambda ^{3/2} \cos3 \tau \bigr)\\
        & +\epsilon ^4 \Bigl( -280 g_2^4 Z+378 g_2 g_4 Z-135 g_5 Z + 128 g_2^2 S \lambda + 64 g_2^2 S^3 \lambda  \\
        &\qquad +36 g_2^2 Z \lambda+54 S^3 \lambda ^2-9 Z \lambda ^2-280 g_2^4 Z \cos 2 \tau  + 378g_2 g_4 Z \cos 2 \tau \\
        &\qquad - 135 g_5 Z \cos2 \tau+4 g_2^2 \left(32 S+28 S^3+9 Z\right) \lambda \cos2 \tau +81 S^3 \lambda ^2 \cos2 \tau \\
        &\qquad- 9 Z \lambda ^2 \cos2 \tau -48 g_2^2 S^3 \lambda \cos4 \tau +27 S^3 \lambda ^2 \cos 4 \tau \Bigr)\Bigr].
  \end{align*}
\end{document}
0
6

As stated above, you cannot have the second argument of the fraction on a separate line. If I understand the equation correctly, this is the output you would expect from what you've written.

enter image description here

The TeX is here, but notice it's still not mathematically correct (the unpaired bracket on the 4th line.

\documentclass{article}
\usepackage{amsmath}

\begin{document} 
  \begin{align*} 
    U = & -\frac{S \epsilon ^2 \Big(-108 S \lambda ^2-108 S \lambda ^2 \cos2 \tau \Big)}{432 \lambda ^3} \\
        & - \frac{S \epsilon ^3 \left(72 \text{g2} S^2 \lambda ^{3/2} \cos\tau -72 g_2 S^2 \lambda ^{3/2} \cos3 \tau \right)}{432 \lambda^3} \\
        & - \frac{1}{432 \lambda ^3} S \epsilon ^4 \Bigl( -280 g_2^4 Z+378 g_2 g_4 Z-135 g_5 Z + 128 g_2^2 S \lambda \\
        & + 64 g_2^2 S^3 \lambda +36 g_2^2 Z \lambda+54 S^3 \lambda ^2-9 Z \lambda ^2-280 g_2^4 Z \cos 2 \tau ] + 378g_2 g_4 Z \cos 2 \tau \\
        & - 135 g_5 Z \cos2 \tau+4 g_2^2 \left(32 S+28 S^3+9 Z\right) \lambda \cos2 \tau +81 S^3 \lambda ^2 \cos2 \tau \\ 
        &- 9 Z \lambda ^2 \cos2 \tau -48 g_2^2 S^3 \lambda \cos4 \tau +27 S^3 \lambda ^2 \cos 4 \tau \Bigr). 
  \end{align*}
\end{document}
2
  • 1
    This is a not good code for alignment; the & should be put before the relation symbol (here =). (It works in this particular case but it is not a recommended use.) – Svend Tveskæg Nov 11 '13 at 12:38
  • One should put the & where alignment is needed. But the first line should begin U = {} &, because a relation needs something on both sides of it for best spacing. The align* environment automatically supplies a {} for the right side of the &, but not for the left. I would also indent the last three lines a little further with \quad, to visually indicate they are all grouped between the \Big parentheses. – Dan Nov 11 '13 at 22:58
5

I have tried to clean up the code but I am not sure I have caught it all:

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\begin{align*}
  U
  &= -\frac{S \epsilon^2 \left(-108 S \lambda^2 - 108 S \lambda^2 \cos 2\tau \right)}{432 \lambda^3} \\
  &\hphantom{{}=} - \frac{S \epsilon^3 \left(72 g_2 S^2 \lambda^{3/2} \cos \tau - 72 g_2 S^2 \lambda^{3/2} \cos 3\tau \right)}{432 \lambda^3}\\
  &\hphantom{{}=} - \frac{1}{432 \lambda^3} S \epsilon^4 \bigl(-280 g_2^4 Z + 378 g_2 g_4 Z - 135 g_5 Z + 128 g_2^2 S \lambda\\
  &\hphantom{{}=} + 64 g_2^2 S^3 \lambda + 36 g_2^2 Z \lambda + 54 S^3 \lambda^2 - 9 Z \lambda^2 - 280 g_2^4 Z \cos 2\tau] + 378 g_2 g_4 Z \cos 2\tau\\
  &\hphantom{{}=} - 135 g_5 Z \cos 2\tau + 4 g_2^2 \left(32 S + 28 S^3 + 9 Z\right) \lambda \cos 2\tau + 81 S^3 \lambda^2 \cos 2\tau\\
  &\hphantom{{}=} - 9 Z \lambda^2 \cos 2\tau - 48 g_2^2 S^3 \lambda \cos 4\tau + 27 S^3 \lambda^2 \cos 4\tau \bigr).
\end{align*}

\end{document}

Note the use of \hphantom{{}=} to get the correct alignment.

P.S. In the fourth line of the output, there is a ] but no [.

5

Accidentally you split the line in the middle of a fraction.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
U & = -\frac{S \epsilon ^2 \Big(-108 S \lambda ^2-108 S \lambda ^2 \cos2 \tau \Big)}{432 \lambda ^3} \\
 &-\frac{S \epsilon ^3 \left(72 \text{g2} S^2 \lambda ^{3/2} \cos\tau -72 g_2 S^2 \lambda ^{3/2} \cos3 \tau \right)}{432 \lambda ^3}\\
 & -\frac{1}{432 \lambda ^3}S \epsilon ^4 \Bigl( -280 g_2^4 Z+378 g_2 g_4 Z-135 g_5 Z+128 g_2^2 S \lambda  \\
 &  +64 g_2^2 S^3 \lambda +36 g_2^2 Z \lambda+54 S^3 \lambda ^2-9 Z \lambda ^2-280 g_2^4 Z \cos 2 \tau ]+378g_2 g_4 Z \cos 2 \tau  \\
  & -135 g_5 Z \cos2 \tau+4 g_2^2 \left(32 S+28 S^3+9 Z\right) \lambda \cos2 \tau +81 S^3 \lambda ^2 \cos2 \tau \\
  &-9 Z \lambda ^2 \cos2 \tau  -48 g_2^2 S^3 \lambda  \cos4 \tau +27 S^3 \lambda ^2 \cos 4 \tau \Bigr).
\end{align*}
\end{document}
1
  • 4
    I would recommend replacing all but the first & with &\quad to get the subobordinated lines indented a bit. – Mico Nov 11 '13 at 12:04
4

There was a line break in the middle of a \frac command. Also, for writing multilined equations, the amsmath package included multiline and split. Split can be used to align equations relative to the first line, a shown here:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
\begin{split}
U 
&= -\frac{S \epsilon ^2 \Big(-108 S \lambda ^2-108 S \lambda ^2 \cos2 \tau \Big)}{432 \lambda ^3} \\
&\hphantom{{}=}-\frac{S \epsilon ^3 \left(72 \text{g2} S^2 \lambda ^{3/2} \cos\tau -72 g_2 S^2 \lambda ^{3/2} \cos3 \tau \right)}{432 \lambda ^3}\\
&\hphantom{{}=}-\frac{1}{432 \lambda ^3}S \epsilon ^4 \Bigl[ -280 g_2^4 Z+378 g_2 g_4 Z-135 g_5 Z+128 g_2^2 S \lambda  \\
&\hphantom{{}=}+64 g_2^2 S^3 \lambda +36 g_2^2 Z \lambda+54 S^3 \lambda ^2-9 Z \lambda ^2-280 g_2^4 Z \cos 2 \tau ]+378g_2 g_4 Z \cos 2 \tau  \\
&\hphantom{{}=}-135 g_5 Z \cos2 \tau+4 g_2^2 \left(32 S+28 S^3+9 Z\right) \lambda \cos2 \tau +81 S^3 \lambda ^2 \cos2 \tau \\
&\hphantom{{}=}-9 Z \lambda ^2 \cos2 \tau  -48 g_2^2 S^3 \lambda  \cos4 \tau +27 S^3 \lambda ^2 \cos 4 \tau \Bigr).
\end{split}
\end{align*}
\end{document}

I have also updated my answer to include the \hphantom{{}=} as suggested by @Svend_Tveskæg

3
  • 1
    Since the align* environment already provides an alignment mechanism across split equations, there's no gain from inserting an additional split environment. (Try it: Remove the \begin{split} and \end{split} statements from your example and recompile.) If you want to use the split environment, it should probably be encased in an equation* environment. – Mico Nov 11 '13 at 13:42
  • Hmm, so you're correct. Is there any gain from multiline? – NictraSavios Nov 11 '13 at 13:46
  • Since the multline environment doesn't provide a means for aligning the individual lines, I don't think it's a good candidate for typesetting the equation at hand. – Mico Nov 11 '13 at 14:00
2

Building on Mico's answer, the structure of the equation can be made even clearer by pulling out common factors of (\cos \tau + 1) and similar. This reveals the parallel structure involving powers of S, g2, and λ, and the odd-man-out term with Z and the other g's.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
{\def\phefour#1{\phantom{\mathbin{-}\epsilon^4 \, \smash{\Bigl(}}\mathbin{#1}}
  \begin{align*}
    U = \frac{S}{432 \lambda ^3} \Bigl[
        & \mathbin{\phantom{+}}\epsilon ^2 \, 108 S \lambda^2 \bigl(\cos 2\tau + 1\bigr) \\
        & +\epsilon ^3 \, 72g_2 S^2 \lambda^{3/2} \bigl(\cos 3\tau - \cos \tau \bigr) \\
        & -\epsilon ^4 \, \Bigl(
 \mathbin{\phantom{+}}   128 g_2^2 S   \lambda   \bigl(\cos 2\tau + 1\bigr) \\
&\phefour              -  16 g_2^2 S^3 \lambda   \bigl(3\cos 4\tau - 7\cos 2\tau -4\bigr) \\
&\phefour              +  27       S^3 \lambda^2 \bigl(\cos 4\tau + 3\cos 2\tau + 2\bigr) \\
&\phefour - Z \bigl( 9\lambda^2 + 135 g_5 - 378 g_2 g_4 - 36 g_2^2 + 280 g_2^4 \bigr) 
              \bigl(\cos 2\tau + 1\bigr)
  \Bigr) \Bigr]
  \end{align*}}
\end{document}

rendered equation from TeX math above

If this were critical to a paper I were writing, I might spend even more time aligning all the sub-factors neatly, but that's me and my obsessions.

(Refactorization thanks to Maxima, any errors are mine.)

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.