Question

How can I break long formulas in LyX into two (or more) lines? I know how to write several lines of equations in one "math box" but I'm looking for a solution to break lines even in the middle of a parenthesis.

I'm using LyX 1.6.4 and currently, when the formula is too big, it doesn't do anything (it just doesn't print the last segment of it, which is "beyond" the page).

Is this possible in LyX?

Was it helpful?

Solution

Yes, but you have to do it by hand.

Check out:

  1. How can I have linebreaks in my long LaTeX equations?
  2. Latex Multiline Equations

Lyx has an "Insert -> Math -> AMS multline environment" control, or you can use the solutions recommended above by entering Latex directly using the Insert Latex control.

Note on breqn

Michael Downes has done some extraordinary Tex coding with this package, but it is not robust enough for general use - it is mostly incompatible with Amsmath, for instance, breaks in hard-to-understand ways, and makes some demonstrably unsound linebreaks in formulae.

Automatic line-breaking in display formulae was listed as one of the top open research problems in Tex.

OTHER TIPS

If you include \usepackage{breqn} in the LyX "LaTeX Preamble" (plus the following code) then the standard "equation" environment (Displayed Formula) will automatically break like you want.

% Add support for automatic equation breaking
\gdef\wrap@breqn@environ#1#2{
    \expandafter\let\csname breqn@oldbegin@#1\expandafter\endcsname\csname #1\endcsname
    \expandafter\let\csname breqn@oldend@#1\expandafter\endcsname\csname end#1\endcsname
    \expandafter\gdef\csname breqn@begin@#1\endcsname{%
        \expandafter\let\csname #1\expandafter\endcsname\csname breqn@oldbegin@#1\endcsname%
        \begin{#2}%
    }
    \expandafter\gdef\csname breqn@end@#1\endcsname{%
        \expandafter\let\csname end#1\expandafter\endcsname\csname breqn@oldend@#1\endcsname%
        \end{#2}%
        \expandafter\let\csname #1\expandafter\endcsname\csname breqn@begin@#1\endcsname%
        \expandafter\let\csname end#1\expandafter\endcsname\csname breqn@end@#1\endcsname%
    }
    \expandafter\let\csname #1\expandafter\endcsname\csname breqn@begin@#1\endcsname
    \expandafter\let\csname end#1\expandafter\endcsname\csname breqn@end@#1\endcsname
}
\wrap@breqn@environ{equation}{dmath}
\wrap@breqn@environ{equation*}{dmath*}

Added 2016-12-08:

If you wish to override the default (unnumbered) LyX equation environment then also add the following:

\DeclareRobustCommand\[{\begin{equation*}}
\DeclareRobustCommand\]{\end{equation*}}

You might want to try the breqn package. It provides automatic line breaking for big formulas. This way there is no need for manually fixing your delimiters or choosing the break points. Of course, this is no actual LyX functionality but it does exactly what you want.

Insert -> Math-> AMS Multiline Environment

write your equation and click 'Ctrl+Enter' where you want to split Then Right click the equation and select number whole formula

Very recently I had to deal with the very same problem. My simple solution (don't know if best) is to use ctrl+enter for multiple lines and, for the parentheses problem, you can use the button right after the parentheses, brackets and braces, which opens a window with these and many other options and, importantly, the option to have different choices at the same time, (like this}. In particular, you can chose "none" and only have either "(" or ")" for each line, (like +/this) Hope it helps.

My way of "breaking long formula lines in lyx" is to use breqn on demand. The method is demonstrated in this post.

In the LyX "LaTeX Preamble" put the following

\usepackage{amsmath}
\usepackage{etoolbox} 
\usepackage{breqn}

\newcommand{\breqnoverloadothers}
{% 
    \renewenvironment{equation}{\ignorespaces\begin{dmath}}{\end{dmath}\ignorespacesafterend}%
    \renewenvironment{equation*}{\ignorespaces\begin{dmath*}}{\end{dmath*}\ignorespacesafterend}%
    \renewenvironment{multline}{\ignorespaces\begin{dmath}}{\end{dmath}\ignorespacesafterend}%
    \renewenvironment{multline*}{\ignorespaces\begin{dmath*}}{\end{dmath*}\ignorespacesafterend}%

}

\newcommand\breqnundefineothers
{%  
    \renewenvironment{equation}{}{}%
    \renewenvironment{equation*}{}{}%
    \renewenvironment{multline}{}{}%
    \renewenvironment{multline*}{}{}%

}

\AtBeginEnvironment{dmath}{\breqnundefineothers}
\AtBeginEnvironment{dmath*}{\breqnundefineothers}

\AtBeginEnvironment{dgroup}{\def\breqnundefineothers{}\breqnoverloadothers}
\AtBeginEnvironment{dgroup*}{\def\breqnundefineothers{}\breqnoverloadothers}

In Lyx, for long equations for which you want to apply breqn, just 1) typeset the equations using any of math environments that have been overloaded above, i.e., equation/equation*/multline/multline*, and 2) surround the equation(s) using the dmath environment or the dgroup environment, like:

\begin{dmath}
    hit ctrl+shift+M to insert a long equation here, and number the equation
\end{dmath} 

or

\begin{dgroup}
    hit ctrl+shift+M to insert a long equation here, and number the equation
    hit ctrl+shift+M again to insert another long equation here, and number the equation
\end{dgroup} 

Now you can export to PDF and see that the long equations are handled "automatically" by breqn. Equations not enclosed in dmath or dgroup won't be influenced.

Screenshots are generated but I do not have the 10-point reputation to upload them.

I know this is a bit old, but someone might still need this info like I did not too long ago. I recently had similar issues to this, breaking a numbered line in the middle. (lyx 2.04 and higher). I used the lyx eqn array. Put the equation, all of it into the right box of the eqn array (there are two of them) At the point that you want to break the equation, press CTRL+Enter. This splits your equation into two lines. If you have a numbered equation array, toggle the upper line with: Alt+M Shift+N to remove the equation number, leaving you with only one equation on two lines.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top