[Tex/LaTex] How to typeset LaTeX math proofs with long lines

alignmath-mode

I usually typeset math proofs in LaTeX by using the align environment. For instance,

\documentclass{article}
\usepackage{amsmath,mathtools}
\begin{document}
\begin{align}
& x^2 \\
&= x*x \\
&= x+x
\end{align}
\end{document}

This works great, until the lines become too long to fit on the page. Ideally, I'd like to use something like the multline environment on one line to accomplish this. For instance, I'd like overly long lines to wrap, while still aligning, like this:

= x+x+x+x+x+x+x+x+x+x+x+x+x+  
                x+x+x+x+x+x+x+x  
= y+y+y+y+y+y+y+y+y+y+y+y+y+y+y

Using multlined from the mathtools package inside of align results almost works:

\begin{align}
& \begin{multlined}x+x+x+x+x+x+x+x+x+x+x+x\\x+x+x+x+x+x+x+x\end{multlined}\\
&= y+y+y+y+y+y+y+y+y+y+y+y+y+y+y
\end{align}

Unfortunately, the second multiline equation aligns to the rightmost part of the first multiline equation, rather than aligning to the right of the align block, which looks very awkward:

First attempt

Manually specifying a width to multlined so that it fills the align block results in something that looks half-decent, but feels hacky:

\begin{align}
& \begin{multlined}[c][3.63in]x+x+x+x+x+x+x+x+x+x+x+x\\x+x+x+x+x+x+x+x\end{multlined}\\
&= y+y+y+y+y+y+y+y+y+y+y+y+y+y+y
\end{align}

Good alignment

Is there a better way of handling long lines in proofs?

Best Answer

You have known Morten Høgholm's mathtools, then you can try his breqn package:

\documentclass{article}
\usepackage{breqn}

\begin{document}
\hsize=12cm
\begin{dmath}
f(x) = x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x = x*c
\end{dmath}

\hsize=6cm
\begin{dmath}
f(x) = x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x = x*c
\end{dmath}

\hsize=3cm
\begin{dmath}
f(x) = x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x = x*c
\end{dmath}
\end{document}

enter image description here