# How to break apart a huge fraction resulting from a symbolic calculation?

I'm trying to use a Computer Algebra System to learn something about an algebraic expression, and this is what it gives me as a result in LaTex:

\documentclass{article}
\usepackage{breqn}

\begin{document}

\begin{dmath}
\frac{e_{0} n_{0} \left(- n_{0} p_{0} + n_{0} r_{0} + n_{0} \left(p_{0} - q_{0}\right) - n_{1} p_{1} + n_{1} r_{1} + n_{1} \left(p_{1} - q_{1}\right) - n_{2} p_{2} + n_{2} r_{2} + n_{2} \left(p_{2} - q_{2}\right)\right) + e_{1} n_{1} \left(- n_{0} p_{0} + n_{0} r_{0} + n_{0} \left(p_{0} - q_{0}\right) - n_{1} p_{1} + n_{1} r_{1} + n_{1} \left(p_{1} - q_{1}\right) - n_{2} p_{2} + n_{2} r_{2} + n_{2} \left(p_{2} - q_{2}\right)\right) - e_{10} \left(\left(- p_{1} + r_{1}\right) \left(n_{0} \left(p_{0} - q_{0}\right) + n_{1} \left(p_{1} - q_{1}\right) + n_{2} \left(p_{2} - q_{2}\right)\right) + \left(p_{1} - q_{1}\right) \left(n_{0} p_{0} - n_{0} r_{0} + n_{1} p_{1} - n_{1} r_{1} + n_{2} p_{2} - n_{2} r_{2}\right)\right) - e_{11} \left(\left(- p_{2} + r_{2}\right) \left(n_{0} \left(p_{0} - q_{0}\right) + n_{1} \left(p_{1} - q_{1}\right) + n_{2} \left(p_{2} - q_{2}\right)\right) + \left(p_{2} - q_{2}\right) \left(n_{0} p_{0} - n_{0} r_{0} + n_{1} p_{1} - n_{1} r_{1} + n_{2} p_{2} - n_{2} r_{2}\right)\right) + e_{2} n_{2} \left(- n_{0} p_{0} + n_{0} r_{0} + n_{0} \left(p_{0} - q_{0}\right) - n_{1} p_{1} + n_{1} r_{1} + n_{1} \left(p_{1} - q_{1}\right) - n_{2} p_{2} + n_{2} r_{2} + n_{2} \left(p_{2} - q_{2}\right)\right) - e_{9} \left(\left(- p_{0} + r_{0}\right) \left(n_{0} \left(p_{0} - q_{0}\right) + n_{1} \left(p_{1} - q_{1}\right) + n_{2} \left(p_{2} - q_{2}\right)\right) + \left(p_{0} - q_{0}\right) \left(n_{0} p_{0} - n_{0} r_{0} + n_{1} p_{1} - n_{1} r_{1} + n_{2} p_{2} - n_{2} r_{2}\right)\right) + \left(e_{3} n_{0} + e_{4} n_{1} + e_{5} n_{2}\right) \left(n_{0} p_{0} - n_{0} r_{0} + n_{1} p_{1} - n_{1} r_{1} + n_{2} p_{2} - n_{2} r_{2}\right) - \left(e_{6} n_{0} + e_{7} n_{1} + e_{8} n_{2}\right) \left(n_{0} \left(p_{0} - q_{0}\right) + n_{1} \left(p_{1} - q_{1}\right) + n_{2} \left(p_{2} - q_{2}\right)\right)}{\left(n_{0} \left(p_{0} - q_{0}\right) + n_{1} \left(p_{1} - q_{1}\right) + n_{2} \left(p_{2} - q_{2}\right)\right)^{2}}
\end{dmath}

\end{document}


It is a huge fraction, that gets cut when I try to compile this to PDF:

Is there an automagic way to cut this fraction in multiple lines in LaTex? If you look at the LaTex source code, searching for sensible break points to be manually inserted in such expressions will not be fun.

Edit: The fraction looks like this:

You can barely see it, but there is a single denominator, and the numerator is huge. Is there a way to write the numerator automatically across multiple lines?

• Well, this is not a TeX's problem. Tell us how the result should look like and there should be a way how to accomplish this. However, with my typography hat on, there is no good solution that keeps the fraction as a fraction.
– yo'
Commented Jan 22, 2019 at 13:59

Not automagically, I'm afraid. First and foremost, don't use \left and \right sizing directives: Not only do they not succeed in enlarging any of the parentheses, they also prevent TeX from inserting line breaks within the scope of left-right pairs. Second, use a \parbox directive, and typeset the equation in inline-math mode (no \frac terms) inside the \parbox. Why inline-math mode? Because TeX allows line-breaking for inline-math material (as long as there are no \left-\right disturbances).

To set off the start and end of the numerator and denominator term, use curly braces .

Optionally, use square brackets -- [ and and ] -- instead of the "outer" round parentheses.

That said, I'm not sure what your readers are supposed to take away -- let alone remember for more than three seconds -- from looking at the following expression...

\documentclass{article}
\begin{document}

$\parbox{0.8\textwidth}{\bigl\{ e_0 n_0 [- n_0 (p_0 - r_0) + n_0 (p_0 - q_0) - n_1 (p_1 - r_1) + n_1 (p_1 - q_1) - n_2 (p_2 - r_2) + n_2 (p_2 - q_2)] + e_1 n_1 [- n_0 (p_0 - r_0) + n_0 (p_0 - q_0) - n_1 (p_1 - r_1) + n_1 (p_1 - q_1) - n_2 (p_2 - r_2) + n_2 (p_2 - q_2)] - e_{10} [(- p_1 + r_1) [n_0 (p_0 - q_0) + n_1 (p_1 - q_1) + n_2 (p_2 - q_2)] + (p_1 - q_1) [n_0 (p_0 - r_0) + n_1 (p_1 - r_1) + n_2 (p_2 - r_2)]] - e_{11} [(- p_2 + r_2) [n_0 (p_0 - q_0) + n_1 (p_1 - q_1) + n_2 (p_2 - q_2)] + (p_2 - q_2) [n_0 (p_0 - r_0) + n_1 (p_1 - r_1) + n_2 (p_2 - r_2)]] + e_2 n_2 [- n_0 (p_0 - r_0) + n_0 (p_0 - q_0) - n_1 (p_1 - r_1) + n_1 (p_1 - q_1) - n_2 (p_2 - r_2) + n_2 (p_2 - q_2)] - e_9 [(- p_0 + r_0) [n_0 (p_0 - q_0) + n_1 (p_1 - q_1) + n_2 (p_2 - q_2)] + (p_0 - q_0) [n_0 (p_0 - r_0) + n_1 (p_1 - r_1) + n_2 (p_2 - r_2)]] + [e_3 n_0 + e_4 n_1 + e_5 n_2] [n_0 (p_0 - r_0) + n_1 (p_1 - r_1) + n_2 (p_2 - r_2)] - [e_6 n_0 + e_7 n_1 + e_8 n_2] [n_0 (p_0 - q_0) + n_1 (p_1 - q_1) + n_2 (p_2 - q_2)] \bigr\}\big/\bigl\{ n_0 (p_0 - q_0) + n_1 (p_1 - q_1) + n_2 (p_2 - q_2) \bigr\}^2 }$

\end{document}


Not automagically. I removed the \left and \right around long expressions, keeping them only for the differences pi – qi and similar.

\documentclass{article}
\usepackage{amsmath}

\begin{document}

$$\begin{gathered} \frac{ \; \parbox{0.8\displaywidth}{\raggedright\leftskip=1em\hspace{-1em} e_{0} n_{0} (- n_{0} p_{0} + n_{0} r_{0} + n_{0} \left(p_{0} - q_{0}\right) - n_{1} p_{1} + n_{1} r_{1} + n_{1} \left(p_{1} - q_{1}\right) - n_{2} p_{2} + n_{2} r_{2} + n_{2} \left(p_{2} - q_{2}\right)) + e_{1} n_{1} (- n_{0} p_{0} + n_{0} r_{0} + n_{0} \left(p_{0} - q_{0}\right) - n_{1} p_{1} + n_{1} r_{1} + n_{1} \left(p_{1} - q_{1}\right) - n_{2} p_{2} + n_{2} r_{2} + n_{2} \left(p_{2} - q_{2}\right)) - e_{10} (\left(- p_{1} + r_{1}\right) (n_{0} \left(p_{0} - q_{0}\right) + n_{1} \left(p_{1} - q_{1}\right) + n_{2} \left(p_{2} - q_{2}\right)) + \left(p_{1} - q_{1}\right) (n_{0} p_{0} - n_{0} r_{0} + n_{1} p_{1} - n_{1} r_{1} + n_{2} p_{2} - n_{2} r_{2})) - e_{11} (\left(- p_{2} + r_{2}\right) (n_{0} \left(p_{0} - q_{0}\right) + n_{1} \left(p_{1} - q_{1}\right) + n_{2} \left(p_{2} - q_{2}\right)) + \left(p_{2} - q_{2}\right) (n_{0} p_{0} - n_{0} r_{0} + n_{1} p_{1} - n_{1} r_{1} + n_{2} p_{2} - n_{2} r_{2})) + e_{2} n_{2} (- n_{0} p_{0} + n_{0} r_{0} + n_{0} \left(p_{0} - q_{0}\right) - n_{1} p_{1} + n_{1} r_{1} + n_{1} \left(p_{1} - q_{1}\right) - n_{2} p_{2} + n_{2} r_{2} + n_{2} \left(p_{2} - q_{2}\right)) - e_{9} (\left(- p_{0} + r_{0}\right) (n_{0} \left(p_{0} - q_{0}\right) + n_{1} \left(p_{1} - q_{1}\right) + n_{2} \left(p_{2} - q_{2}\right)) + \left(p_{0} - q_{0}\right) (n_{0} p_{0} - n_{0} r_{0} + n_{1} p_{1} - n_{1} r_{1} + n_{2} p_{2} - n_{2} r_{2})) + (e_{3} n_{0} + e_{4} n_{1} + e_{5} n_{2}) (n_{0} p_{0} - n_{0} r_{0} + n_{1} p_{1} - n_{1} r_{1} + n_{2} p_{2} - n_{2} r_{2}) - (e_{6} n_{0} + e_{7} n_{1} + e_{8} n_{2}) (n_{0} \left(p_{0} - q_{0}\right) + n_{1} \left(p_{1} - q_{1}\right) + n_{2} \left(p_{2} - q_{2}\right)) }\; }{ (n_{0} (p_{0} - q_{0}) + n_{1} (p_{1} - q_{1}) + n_{2} (p_{2} - q_{2}))^{2} } \end{gathered}$$

\end{document}