1

I usually define some command of the kind

\newcommand{\paren}[#1]{\left(#1\right)}

to make the use of parentheses more agile. Now, if in the body of my document I do this

\begin{align}
z = \paren{y\\+z}
\end{align}

I get a long list of complaints on the last line of the align environment, while I would expect the same output as for the following code,

\begin{align}
z = \left(y\\+z\right)
\end{align}

Anybody can let me know how to make this sort of parentheses commands robust over line breaks?

\documentclass{article}
\usepackage{amsmath}

\newcommand{\paren}[1]{\left(#1\right)}



\begin{document}


% This works, but I don't like it.
\begin{align}
z = \left(y\right.\\
\left.+z\right)
\end{align}

% This is lovely, but does not work.
%\begin{align}
%z = \paren{y\\+z}
%\end{align}

% No complaints, of course, if the line break is removed
\begin{align}
z = \paren{y+z}
\end{align}

\end{document}
Antonio
  • 173
  • 2
    (1) Welcome, (2) in general using \left...\right every time is a bad idea. For one, it is unbreakable. Plus \left(\\\right) hides \\ from align, so it will never work. I'd say that in general such an approach is not worth it. – daleif Jan 13 '15 at 09:41
  • 2
    Welcome to TeX.SX! Your first example does not work and I would be very surprised if it does for you. If you use some \\ in between your parentheses, you have to end the first line by \right. and start the next line with \left. – LaRiFaRi Jan 13 '15 at 09:41
  • 2
    And the \left A \right. \\ \left. B \right approach may be faulty too, if A and B are not the same size. Manually scaling fences that are to be broken is almost always better. – daleif Jan 13 '15 at 09:44
  • @Antonio, try replacing y by \frac{1}{2} and you will see the problem with the approach – daleif Jan 13 '15 at 09:46
  • 2
    See the postings Is it ever bad to use \left and \right? and “(” or “\left(” parentheses? for a more in-depth examinaton of why it's not good practice to use \left( and \right) everywhere. – Mico Jan 13 '15 at 09:48
  • Thanks everybody. The reasons you mentioned are exactly why I would like to find a command for parentheses that allows line breaks, and - why not - handles parentheses dimensions correctly across line breaks. What I was asking is if there is such a command in some package or if I can make a macro that does the trick. – Antonio Jan 13 '15 at 09:51
  • It might be doable, but you will need some parsing, plus the macro will have to be made in such a manner that it does not hide & or \\ from envs like align. It might be doable. But as mentioned, I do not think it is worth ot, it will also make the code much less readable. – daleif Jan 13 '15 at 09:55
  • Your question's formulation is misleading: you seem to say that \begin{align} z = \left(y\\+z\right) \end{align} is ok, which it is not. –  Jan 26 '16 at 21:23

2 Answers2

4

As mentioned in the comments it is not recommended, and such a solution will make the code much less readable.

That being said, it can be done. This use a trick suggested by Sebastien Gouezel cited from the mathtools manual

\documentclass[a4paper]{memoir}
\usepackage{amsmath}

\newcommand\MTkillspecial[1]{% helper macro
  \bgroup
  \catcode`\&=9
  \let\\\relax%
  \scantokens{#1}%
  \egroup
}

\newcommand\paren[1]{
  \left(\vphantom{\MTkillspecial{#1}}\kern-\nulldelimiterspace\right.
  #1
  \left.\kern-\nulldelimiterspace\vphantom{\MTkillspecial{#1}}\right)
}


\begin{document}

\begin{align*}
  A  = {} & \paren{ \frac12 \\ & +3 } 
\end{align*}


\end{document}

I would still manually scale fences in such a situation, as in

\begin{align*}
  A = {} & \biggl( \frac12
  \\
  & +3 \biggr)
\end{align*}

which in my opinion is a lot more readable.

daleif
  • 54,450
0

The package mathtools offers a command \DeclarePairedDelimiter to be put in the preamble.

\documentclass[a4paper]{minimal}
\usepackage{amsmath}
\usepackage{mathtools}

\DeclarePairedDelimiter{\paren}{\lparen}{\rparen}

\begin{document}

\begin{equation}
\begin{aligned}
\paren{a+\\
b = 3
}
\end{aligned}
\end{equation}

However, one needs to manually resize the delimiter.

\begin{equation}
\begin{aligned}
\paren[\bigg]{a+\\
b = 3
}
\end{aligned}
\end{equation}

\end{document}
Antonio
  • 173