6

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.

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

1 Answer 1

2

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.

output

\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!

2
  • +1 sounds pretty good. Could you provide some insight, why you wouldn't recommend that code?
    – grackkle
    Mar 9, 2013 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. Mar 9, 2013 at 19:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .