# Automatic linebreak in align environment in macros

I have given a selfdefined command like

\newcommand{\AND}[2]{\left(#1 \vee #2 \right)}


which makes sure that I always give the correct number of parameters to my formula and which handles the parentheses as well. Now, when I use this command in a align environment and the arguments become very long, then a linebreak becomes nessecary.

Here's the problem: In the align environment I have to set linebreaks myself, however between \left and \right linebreaks aren't allowed.

So, is there any way to have a automatic linebreak here, which also keeps the correct size of the parentheses?

My only workaround so far is not to use the macro in these situations, which results in unclean code.

The breqn package doesn't seem to fix this problem.

\documentclass[11pt, draft]{scrbook}
\usepackage{amsmath}
\usepackage{breqn}

\newcommand{\AND}[2]{\ensuremath{\left(#1\vee#2\right)}}

\begin{document}
\begin{align*}
aaa&= \AND{\sum^a_b \AND{\AND{\AND{\AND{\AND{\AND{\AND{\AND{\AND{\AND{a}{b}}{b}}{b}}{b}}{\AND{\AND{a}{\AND{a}{b}}}{\AND{a}{\AND{a}{b}}}}}{b}}{b}}{a}}{\AND{a}{\AND{\AND{a}{b}}{b}}}}{\frac{a}{\frac{a}{b}}}}{\sum^a_b \AND{c}{\frac{a}{\frac{a}{b}}}}\\
&= b
\end{align*}
\end{document}


EDIT: After fiddling around for a while, I came up with a small workaround that solves a part of the problem, but not all. I defined a new command which inserts a linebreak and handles the parenthesis for this linebreak:

\documentclass[11pt, draft]{scrbook}
\usepackage{amsmath}
\usepackage{mathtools}

\newcommand{\AND}[2]{\ensuremath{\left(#1\vee#2\right)}}
\newcommand{\ANDbr}[2]{\ensuremath{%
\begin{lgathered}[t]%
\left(#1 \vee \vphantom{#2} \right. \\
\left.\vphantom{#1\vee}#2\right)
\end{lgathered}%
}}

\begin{document}
\begin{align*}
aaa&= \ANDbr{\AND{\AND{\AND{a}{b}}{\AND{\frac{a}{b}}{c}}}{\AND{\AND{\sum_a^b a}{p}}{\AND{a}{b}}}}{\AND{\AND{\AND{a}{b}}{\AND{a}{b}}}{\AND{\AND{a}{b}}{\AND{a}{b}}}}\\
&= b
\end{align*}
\end{document}


This seems to work as long as I need only one linebreak. Inserting \ANDbr for a second time messes things up however.

EDIT2: I tried to add \allowbreak into the definition of \AND, but it didn't change anything.

-
align* never breaks lines of its own initiative. Would you please make a more "real life" example? –  egreg Jan 15 '13 at 18:53
In this case, is there a way to simulate align with linebreaking? –  bln-tom Jan 16 '13 at 15:03

I don't recommend using the following code, but it seems to do what you want: I define a command \breaktowidth where you have to specify how wide the block should be inside which line breaks are possible. Then of course \left and \right have to be used in a way such that they don't prevent the line breaks; this is done with a separate command \delimiterswithbreaks.

\documentclass[11pt,draft]{scrbook}
\usepackage{mathtools}
\newcommand{\delimiterswithbreaks}[3]{%
\mathopen{\left#1\vphantom{#3}\right.\hskip-\nulldelimiterspace}
#3
\mathclose{\hskip-\nulldelimiterspace\left.\vphantom{#3}\right#2}
}
\newcommand{\breaktowidth}[2]{\vtop{\hsize#1\noindent$#2$}}
\newcommand{\AND}[2]{\delimiterswithbreaks{(}{)}{#1\vee#2}}
\begin{document}
\begin{align*}
aaa &= \breaktowidth{6cm}{\AND{\AND{\AND{\AND{a}{b}}{\AND{\frac{a}{b}}{c}}}{\AND{\AND{\sum_a^b a}{p}}{\AND{a}{b}}}}{\AND{\AND{\AND{a}{b}}{\AND{a}{b}}}{\AND{\AND{a}{b}}{\AND{a}{b}}}}} \\
&= b
\end{align*}
\end{document}


Note: mathtools automatically loads amsmath!

-
+1 sounds pretty good. Could you provide some insight, why you wouldn't recommend that code? –  bln-tom Mar 9 '13 at 12:35
@bln-tom: I think that it's better to do the line breaking manually in displayed formulas. You'll choose more sensible break points than TeX since you understand the meaning of the formula. –  Hendrik Vogt Mar 9 '13 at 19:53