Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
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

1 Answer 1

up vote 2 down vote accepted

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!

share|improve this answer
    
+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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.