1

I'm trying to typeset some large equations generated by Maxima. "align" requires manually managing \right. and \left. around each line break.
I find this time-consuming and error-prone (and I have a lot of these equations to typeset.)

The "breqn" package automates both line breaks and paren matching, but allows the equations to overlap the equation numbers and to extend beyond the right margin. Here's an MWE:

\documentclass{article}
\usepackage{breqn}

\begin{document}
\begin{dgroup}\label{eq:common}
\begin{dmath}
A_{21u} = 
\left(\left(-
 \sin {\it L_1}\,\sin {\it L_2}-\cos {\it L_1}\,\cos {\it L_2}\right)
 \,\sin {\it a_{13}}\,\sin {\it a_{23}}\,\cos {\it l_1}\,\sin 
 {\it l_2}+\sin {\it a_{13}}\,\sin {\it a_{23}}\,\sin {\it l_1}\,
 \cos {\it l_2}+\left(\cos {\it L_1}\,\sin {\it L_2}-\sin {\it L_1}\,
 \cos {\it L_2}\right)\,\sin {\it a_{13}}\,\cos {\it a_{23}}\,\cos 
 {\it l_1}\right)\,\sin {\it r_{13}}+\left(\left(\cos {\it L_1}\,
 \sin {\it L_2}-\sin {\it L_1}\,\cos {\it L_2}\right)\,\sin 
 {\it a_{23}}\,\sin {\it l_2}+\left(\sin {\it L_1}\,\sin {\it L_2}+
 \cos {\it L_1}\,\cos {\it L_2}\right)\,\cos {\it a_{23}}\right)\,
 \cos {\it r_{13}}
\end{dmath}
\begin{dmath}
A_{32n} = 
\left(\left(\left(\left(\sin {\it L_1}\,
 \sin {\it L_2}+\cos {\it L_1}\,\cos {\it L_2}\right)\,\cos 
 {\it a_{13}}\,\sin {\it l_1}+\left(\sin {\it L_1}\,\cos {\it L_2}-
 \cos {\it L_1}\,\sin {\it L_2}\right)\,\sin {\it a_{13}}\right)\,
 \sin {\it l_2}+\cos {\it a_{13}}\,\cos {\it l_1}\,\cos {\it l_2}
 \right)\,\sin {\it r_{13}}+\left(\left(-\sin {\it L_1}\,\sin 
 {\it L_2}-\cos {\it L_1}\,\cos {\it L_2}\right)\,\cos {\it l_1}\,
 \sin {\it l_2}+\sin {\it l_1}\,\cos {\it l_2}\right)\,\cos 
 {\it r_{13}}\right)\,\sin {\it r_{23}}+\left(\left(\cos {\it a_{13}}
 \,\cos {\it a_{23}}\,\cos {\it l_1}\,\sin {\it l_2}+\left(\left(-
 \sin {\it L_1}\,\sin {\it L_2}-\cos {\it L_1}\,\cos {\it L_2}\right)
 \,\cos {\it a_{13}}\,\cos {\it a_{23}}\,\sin {\it l_1}+\left(\cos 
 {\it L_1}\,\sin {\it L_2}-\sin {\it L_1}\,\cos {\it L_2}\right)\,
 \sin {\it a_{13}}\,\cos {\it a_{23}}\right)\,\cos {\it l_2}\right)\,
 \sin {\it r_{13}}+\left(\cos {\it a_{23}}\,\sin {\it l_1}\,\sin 
 {\it l_2}+\left(\sin {\it L_1}\,\sin {\it L_2}+\cos {\it L_1}\,\cos 
 {\it L_2}\right)\,\cos {\it a_{23}}\,\cos {\it l_1}\,\cos {\it l_2}
 \right)\,\cos {\it r_{13}}\right)\,\cos {\it r_{23}}
\end{dmath}
\end{dgroup}
\end{document}

overlaps and violated margins

(Sorry about the size, but handling large equations is kinda the point.)

Are there ways to clean up the breqn layout?

Is there another package that would choose better breakpoints, or at least handle the paren matching automatically while I choose breakpoints manually?

Emacs will jump to a corresponding paren. Is there a way to account for \left. and \right. in its calculations?

I'm using "pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017)" and "breqn bundle: 2017/01/27 0.98e" on a Mac.

  • you should never have \it in a latex document, but why have you got these here, it means you are not using math italic anywhere? – David Carlisle Oct 23 '17 at 15:27
  • you could simply delete most of the \left and \right` as you don't need vertical stretching and you get better horizontal space if you do not use them. this would also make adding forced breask \\ for amsmath alignments much easier. – David Carlisle Oct 23 '17 at 15:29
  • I agree about \it - they're inserted by Maxima, not by me. They clutter the source code, but as nearly as I can tell, they don't affect the final document. – Jim Van Zandt Oct 23 '17 at 16:49
  • 1
    Yes they do affect the document, they stop the math italic font being used and force the text italic font to be used everywhere, they force digits to be in italic and generally ruin the output:-) If maxima is still being maintained it should be reported as a bug – David Carlisle Oct 23 '17 at 16:54
2

If you delete all the spurious \left, \right, \it and \, then it's often enough to set long computer algebra generated expressions as an inline math, allowing line breaking.

enter image description here

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\begin{align}
A_{21u} &= 
\parbox[t]{.75\textwidth}{\raggedright$
((-
 \sin {L_1}\sin {L_2}-\cos {L_1}\cos {L_2})
 \sin {a_{13}}\sin {a_{23}}\cos {l_1}\sin 
 {l_2}+\sin {a_{13}}\sin {a_{23}}\sin {l_1}
 \cos {l_2}+(\cos {L_1}\sin {L_2}-\sin {L_1}
 \cos {L_2})\sin {a_{13}}\cos {a_{23}}\cos 
 {l_1})\sin {r_{13}}+((\cos {L_1}
 \sin {L_2}-\sin {L_1}\cos {L_2})\sin 
 {a_{23}}\sin {l_2}+(\sin {L_1}\sin {L_2}+
 \cos {L_1}\cos {L_2})\cos {a_{23}})
 \cos {r_{13}}
$}\\
A_{32n} &= 
\parbox[t]{.75\textwidth}{\raggedright$
((((\sin {L_1}
 \sin {L_2}+\cos {L_1}\cos {L_2})\cos 
 {a_{13}}\sin {l_1}+(\sin {L_1}\cos {L_2}-
 \cos {L_1}\sin {L_2})\sin {a_{13}})
 \sin {l_2}+\cos {a_{13}}\cos {l_1}\cos {l_2}
 )\sin {r_{13}}+((-\sin {L_1}\sin 
 {L_2}-\cos {L_1}\cos {L_2})\cos {l_1}
 \sin {l_2}+\sin {l_1}\cos {l_2})\cos 
 {r_{13}})\sin {r_{23}}+((\cos {a_{13}}
 \cos {a_{23}}\cos {l_1}\sin {l_2}+((-
 \sin {L_1}\sin {L_2}-\cos {L_1}\cos {L_2})
 \cos {a_{13}}\cos {a_{23}}\sin {l_1}+(\cos 
 {L_1}\sin {L_2}-\sin {L_1}\cos {L_2})
 \sin {a_{13}}\cos {a_{23}})\cos {l_2})
 \sin {r_{13}}+(\cos {a_{23}}\sin {l_1}\sin 
 {l_2}+(\sin {L_1}\sin {L_2}+\cos {L_1}\cos 
 {L_2})\cos {a_{23}}\cos {l_1}\cos {l_2}
 )\cos {r_{13}})\cos {r_{23}}
$}
\end{align}
\end{document}

overlaps and violated margins
  • I decided to delete all the \left(, \right), and \it with a sed one-liner. Much simpler to use "align" now. Thanks! – Jim Van Zandt Oct 23 '17 at 16:55

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.