# sagetex with breqn ? break line sagetex equations

When using sagetex, it often produces very long equations that are not visible anymore because they go over the page width.

How to fix that?

I could work around it by loading the .sagetex.sage into a sage session, then produce latex code with latex(functionname) and then break this code manually but it would be against the spirit of sagetex.

I tried the breqn environment but it does not work, i.e.

\documentclass{article}
\usepackage{sagetex}
\usepackage{breqn}

\begin{document}

\begin{sagesilent}
var('d,epsilon,mu,z,M,e,m')
delta =  (1-z)*( gamma(2-d/2)/( (1-z)^2*m^2+z*M^2 )^(2-d/2) *(2-epsilon)^2/2 + gamma(3-d/2)/( (1-z)^2*m^2+z*M^2 )^(3-d/2) * ( 2*(1-4*z+z^2)-epsilon*(1-z)^2 )*m^2  )
\end{sagesilent}

\begin{dmath}
\sage{delta.diff(m).subs(m==mu)}
\end{dmath}

\end{document}


produces an equation that has no line breaks. I cannot use environments like split or align to fix it because I cannot directly modify the latex code, or, if I would via sage, it would not be convenient anymore to use sagetex.

Any help would be appreciated. Thank you!

For the comment I also add the generated latex-Code below. Thanks for the comment!

\frac{1}{2} \, {\left(\frac{2 \, {\left(\epsilon {\left(z - 1\right)}^{2} - 2 \, z^{2} + 8 \, z - 2\right)} {\left(\mu^{2} {\left(z - 1\right)}^{2} + M^{2} z\right)}^{-\frac{1}{2} \, d + 2} {\left(d - 6\right)} \mu^{3} {\left(z - 1\right)}^{2} \Gamma\left(-\frac{1}{2} \, d + 3\right)}{{\left({\left(\mu^{2} {\left(z - 1\right)}^{2} + M^{2} z\right)}^{-\frac{1}{2} \, d + 3}\right)}^{2}} - \frac{{\left(\mu^{2} {\left(z - 1\right)}^{2} + M^{2} z\right)}^{-\frac{1}{2} \, d + 1} {\left(d - 4\right)} {\left(\epsilon - 2\right)}^{2} \mu {\left(z - 1\right)}^{2} \Gamma\left(-\frac{1}{2} \, d + 2\right)}{{\left({\left(\mu^{2} {\left(z - 1\right)}^{2} + M^{2} z\right)}^{-\frac{1}{2} \, d + 2}\right)}^{2}} + \frac{4 \, {\left(\epsilon {\left(z - 1\right)}^{2} - 2 \, z^{2} + 8 \, z - 2\right)} \mu \Gamma\left(-\frac{1}{2} \, d + 3\right)}{{\left(\mu^{2} {\left(z - 1\right)}^{2} + M^{2} z\right)}^{-\frac{1}{2} \, d + 3}}\right)} {\left(z - 1\right)}

• is it possible to also show the generated latex that gets passed to latex, for those of us who haven't got sage(tex) installed? had to debug otherwise. – David Carlisle Jul 4 '15 at 11:01
• Thanks for the comment. I know now that the reason for the non line break is that the generated latex code from sage contains a lot of {\left and \right)} that are interpreted by dmath as "please dont break the line here". But I cant write any macro in Latex that removes "{" because they are themselves trigger parameters... So the deletion of { and } should come from sage before handing the code to latex. Any suggestions on how to do that? Thanks! – exchange Jul 19 '15 at 8:08

The main problem is not with the \left...\right constructs, breqn can break these, but stems from the fractions \frac which breqn can not split up. Compare the following:

\documentclass{article}

\usepackage{breqn}

\begin{document}

\begin{dmath}
\frac{1}{2} \, {\left(\frac{2 \, {\left(\epsilon {\left(z -
1\right)}^{2} - 2 \, z^{2} + 8 \, z - 2\right)} {\left(\mu^{2}
{\left(z - 1\right)}^{2} + M^{2} z\right)}^{-\frac{1}{2} \, d +
2} {\left(d - 6\right)} \mu^{3} {\left(z - 1\right)}^{2}
\Gamma\left(-\frac{1}{2} \, d + 3\right)}{{\left({\left(\mu^{2}
{\left(z - 1\right)}^{2} + M^{2} z\right)}^{-\frac{1}{2} \, d
+ 3}\right)}^{2}} - \frac{{\left(\mu^{2} {\left(z -
1\right)}^{2} + M^{2} z\right)}^{-\frac{1}{2} \, d + 1}
{\left(d - 4\right)} {\left(\epsilon - 2\right)}^{2} \mu {\left(z
- 1\right)}^{2} \Gamma\left(-\frac{1}{2} \, d +
2\right)}{{\left({\left(\mu^{2} {\left(z - 1\right)}^{2} + M^{2}
z\right)}^{-\frac{1}{2} \, d + 2}\right)}^{2}} + \frac{4 \,
{\left(\epsilon {\left(z - 1\right)}^{2} - 2 \, z^{2} + 8 \, z -
2\right)} \mu \Gamma\left(-\frac{1}{2} \, d +
3\right)}{{\left(\mu^{2} {\left(z - 1\right)}^{2} + M^{2}
z\right)}^{-\frac{1}{2} \, d + 3}}\right)} {\left(z - 1\right)}
\end{dmath}

\begin{dmath}
\left( \left(x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x\right)
-
\left(y+y+y+y+y+y+y+y+y+y+y+y+y+y+y+y+y+y+y+y+y+y+y+y+y+y+y\right)
\right)
\end{dmath}

\begin{dmath}
\left( \frac{x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x}{5} -
\frac{y+y+y+y+y+y+y+y+y+y+y+y+y+y+y+y+y+y+y+y+y+y+y+y+y+y+y}{7}
\right)
\end{dmath}

\end{document}


Exactly why your example (the first one) does not break at the minus sign, whereas equation (3) does, is not clear to me. However, the breqn package is alpha code and has many open issues.