wspr / breqn

Automatic line breaking in LaTeX equations
18 stars 2 forks source link

breqn is not breaking long expressions with an exponent #56

Open WolfgangBritz opened 4 months ago

WolfgangBritz commented 4 months ago

Dear authors,

First of all thanks for this great package. I am using an automated equation documentation tool from www.gams.com called model2Tex which generates LaTex output. I have now integrated breqn into the code of model2Tex and get far better output.

Basically the only remaining issue are long expressions such as multiple sums which are jointly subject to an exponent. I attach an example below. I would have expected that the three sums will be distributed to different lines, but this does not happen. Even introducing \newline before the sums does not help. Perhaps I am simply too stupid to find the right solution.

Thanks for looking into this,

Wolfgang Britz, University Bonn

\begin{dmath} 0 = ( \textcolor{blue}{\text{$pD^{aezN}$}}{r, aez, aezN, t} - { ( \displaystyle \sum{{aezN_a}{aezN,aezA}} ( \textcolor{teal}{\text{$\gamma^{aez}$}}{r, aez, aezA, t} \cdot {\textcolor{blue}{\text{$p^{Aez}$}}{r, aez, aezA, t}}^{ ( 1 [ \textcolor{brown}{\text{typ}}{aezN, \texttt{CET}} \vee ( \neg \textcolor{teal}{\text{$\omega^{aez}$}}{r, aez, aezN} ) ] + \textcolor{teal}{\text{$\omega^{aez}$}}{r, aez, aezN} ) } ) + \displaystyle \sum{{aezN_n}{aezN,aezN1}} ( \textcolor{teal}{\text{$\gamma^{aez}$}}{r, aez, aezN1, t} \cdot {\textcolor{blue}{\text{$p^{aezN}$}}{r, aez, aezN1, t}}^{ ( 1 [ \textcolor{brown}{\text{typ}}{aezN, \texttt{CET}} \vee ( \neg \textcolor{teal}{\text{$\omega^{aez}$}}{r, aez, aezN} ) ] + \textcolor{teal}{\text{$\omega^{aez}$}}{r, aez, aezN} ) } ) + \displaystyle \sum{{aezN_n}{aezN,aezN1}} ( \textcolor{teal}{\text{$\gamma^{aez}$}}{r, aez, aezN1, t} \cdot {\textcolor{blue}{\text{$p^{aezN}$}}{r, aez, aezN1, t}}^{ ( 1 [ \textcolor{brown}{\text{typ}}{aezN, \texttt{CET}} \vee ( \neg \textcolor{teal}{\text{$\omega^{aez}$}}{r, aez, aezN} ) ] + \textcolor{teal}{\text{$\omega^{aez}$}}{r, aez, aezN} ) } ) ) }^{ \frac{1}{1 [ \textcolor{brown}{\text{typ}}{aezN, \texttt{CET}} \vee ( \neg \textcolor{teal}{\text{$\omega^{aez}$}}{r, aez, aezN} ) ] + \textcolor{teal}{\text{$\omega^{aez}$}}{r, aez, aezN}} } ) [ \textcolor{teal}{\text{$\omega^{aez}$}}{r, aez, aezN} \hiderel \neq inf ] + ( \textcolor{blue}{\text{$x^{aezN}$}}{r, aez, aezN, t} - \displaystyle \sum{{aezN_a}{aezN,aezA}} ( \textcolor{teal}{\text{$\gamma^{aez}$}}{r, aez, aezA, t} \cdot \textcolor{blue}{\text{$x^{Aez}$}}{r, aez, aezA, t} ) - \displaystyle \sum{{aezN_n}{aezN,aezN1}} ( \textcolor{teal}{\text{$\gamma^{aez}$}}{r, aez, aezN1, t} \cdot \textcolor{blue}{\text{$x^{aezN}$}}{r, aez, aezN1, t} ) ) [ \textcolor{teal}{\text{$\omega^{aez}$}}{r, aez, aezN} \hiderel = inf ] \end{dmath}

davidcarlisle commented 4 months ago

Mostly it's because you wrapped the term in {...} preventing line breaking. I removed that and also removed the nested \text{$.. which didn't seem to be preventing line breaking in this case (but would in general) and making breqn's job somewhat harder with unnecessary switching to nested text with nested math. It's still a bit wide but all on the page

image

\documentclass{article}

\usepackage{xcolor,breqn}

\begin{document}

\begin{dmath*}
0 = ( \mathcolor{blue}{pD^{aezN}}{r, aez, aezN, t} -  (\sum{{aezN_a}{aezN,aezA}}
( \mathcolor{teal}{\gamma^{aez}}{r, aez, aezA, t} \cdot {\mathcolor{blue}{p^{Aez}}{r, aez, aezA, t}}^{ ( 1 [ \mathcolor{brown}{\text{typ}}{aezN, \texttt{CET}} \vee ( \neg \mathcolor{teal}{\omega^{aez}}{r, aez, aezN} ) ] + \mathcolor{teal}{\omega^{aez}}{r, aez, aezN} ) } ) + \sum_{{aezN_n}{aezN,aezN1}}
( \mathcolor{teal}{\gamma^{aez}}{r, aez, aezN1, t} \cdot {\mathcolor{blue}{p^{aezN}}{r, aez, aezN1, t}}^{ ( 1 [ \mathcolor{brown}{\text{typ}}{aezN, \texttt{CET}} \vee ( \neg \mathcolor{teal}{\omega^{aez}}{r, aez, aezN} ) ] + \mathcolor{teal}{\omega^{aez}}{r, aez, aezN} ) } ) + \sum_{{aezN_n}{aezN,aezN1}}
( \mathcolor{teal}{\gamma^{aez}}{r, aez, aezN1, t} \cdot {\mathcolor{blue}{p^{aezN}}{r, aez, aezN1, t}}^{ ( 1 [ \mathcolor{brown}{\text{typ}}{aezN, \texttt{CET}} \vee ( \neg \mathcolor{teal}{\omega^{aez}}{r, aez, aezN} ) ] + \mathcolor{teal}{\omega^{aez}}{r, aez, aezN} ) } ) ) ^{ \frac{1}{1 [ \mathcolor{brown}{\text{typ}}{aezN, \texttt{CET}} \vee ( \neg \mathcolor{teal}{\omega^{aez}}{r, aez, aezN} ) ] + \mathcolor{teal}{\omega^{aez}}{r, aez, aezN}} } ) [ \mathcolor{teal}{\omega^{aez}}{r, aez, aezN} \hiderel \neq inf ] + ( \mathcolor{blue}{x^{aezN}}{r, aez, aezN, t} -  \sum{{aezN_a}{aezN,aezA}}
( \mathcolor{teal}{\gamma^{aez}}{r, aez, aezA, t} \cdot \mathcolor{blue}{x^{Aez}}{r, aez, aezA, t} ) -  \sum{{aezN_n}{aezN,aezN1}}
( \mathcolor{teal}{\gamma^{aez}}{r, aez, aezN1, t} \cdot \mathcolor{blue}{x^{aezN}}{r, aez, aezN1, t} ) ) [ \mathcolor{teal}{\omega^{aez}}{r, aez, aezN} \hiderel = inf ]
\end{dmath*}
\end{document}