Splitting lines for long equations

If you need something you can simply throw the sympy-produced equations into, then you can try breqn package. It handles all \lefts and \rights automatically, but, as expected, it will not do wonders and the output will never be as good as a manually tuned one. It also has some clashes which you have to take care of.

\documentclass{article}
\usepackage{amsmath}
\usepackage{breqn}
\begin{document}

\begin{dmath*}
X''(x) = \left(- 2 C_{1} \sqrt{\lambda} \sin{\left (\sqrt{\lambda} x \right )} -
 C_{1} \lambda \cos{\left (\sqrt{\lambda} x \right )} + 
 C_{1} \cos{\left (\sqrt{\lambda} x \right )} +  
 2 C_{2} \sqrt{\lambda} \cos{\left (\sqrt{\lambda} x \right )} -
 C_{2} \lambda \sin{\left (\sqrt{\lambda} x \right )} + 
 C_{2} \sin{\left (\sqrt{\lambda} x \right )}\right) e^{x}
\end{dmath*}

\end{document}

enter image description here


Some comments:

  • The macros \sin and \cos don't take arguments. Writing \sin{...} doesn't generate an error, but it doesn't generate anything good either (and it does create code clutter).

  • Get rid of all \left and \right sizing instructions. They're not needed, and the outermost pair is going to create a syntax error once you introduce a line break.

  • Load the amsmath package and use an align* environment to typeset the equation over two lines.

  • I'd give more prominence to the e^{x} term, by placing it first rather than dead-last.

enter image description here

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
X''(x) &= e^{x} \bigl[ - 2 C_{1} \sqrt{\lambda} \sin (\sqrt{\lambda} x) 
          - C_{1} \lambda \cos (\sqrt{\lambda} x) 
          + C_{1} \cos (\sqrt{\lambda} x) \\
  &\qquad +  2 C_{2} \sqrt{\lambda} \cos(\sqrt{\lambda} x) 
          - C_{2} \lambda \sin(\sqrt{\lambda} x) 
          + C_{2} \sin(\sqrt{\lambda} x)\bigr]
\end{align*}
\end{document} 

Just remove all \left and \right commands. They are not only the cause for the error (you cannot have \left in one row and the matching \right in another), but they make for too big parentheses.

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{equation*}
\begin{split}
X''(x) = (- 2 C_{1} \sqrt{\lambda} \sin{ (\sqrt{\lambda} x  )} -
 C_{1} \lambda \cos{ (\sqrt{\lambda} x  )} \\
+ C_{1} \cos{ (\sqrt{\lambda} x  )} +  2 C_{2} \sqrt{\lambda} \cos{ (\sqrt{\lambda} x  )} - \\
C_{2} \lambda \sin{ (\sqrt{\lambda} x  )} + C_{2} \sin{ (\sqrt{\lambda} x  )}) e^{x}\
\end{split}
\end{equation*}

\end{document}

enter image description here

Now, let's improve this display.

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{equation*}
\begin{split}
X''(x) &= e^x\bigl(
          - 2C_{1}\sqrt{\lambda}\sin(\sqrt{\lambda}\,x) - C_{1}\lambda\cos(\sqrt{\lambda}\,x) \\
  &\qquad + C_{1}\cos(\sqrt{\lambda}\,x) + 2C_{2}\sqrt{\lambda}\cos(\sqrt{\lambda}\,x) \\
  &\qquad - C_{2}\lambda\sin(\sqrt{\lambda}\,x) + C_{2}\sin(\sqrt{\lambda}x)
\bigr)
\end{split}
\end{equation*}

\end{document}

enter image description here