# Nested parenthesis automatic indentation in equation

Here is some code that produces a display equation with nested parentheses indented to different depths.

\documentclass{amsart}
\begin{document}
\begin{align*}
(\exists d)
&\biggl(
l'(u,d)
\wedge l'(v,d)
\wedge
\bigl(\forall z\bigr)
\bigl(l'(z,d)\to(z=u\vee z=v)\bigr)\\
&\hspace{34pt}\begin{array}{rl}
\wedge~
(\exists p)(\exists q)
&\Bigl(
cod(p)=d\wedge cod(q)=d
\wedge l'\bigl(dom(p),d\bigr)
\wedge l'\bigl(dom(q),d\bigr)\\
&\hspace{49pt}\begin{array}{rl}
\wedge~
(\forall t)
&\Bigl(
\bigl( cod(t)=d\wedge
l'(dom(t),d)\bigr)\\
&\hspace{33pt}\to\bigl(t=p\vee t=q\bigr)\\
&\hspace{7pt}\Bigr)
\end{array}\\
&\hspace{7pt}\Bigr)
\end{array}
\\&\hspace{7pt}\biggr)
\end{align*}
\end{document}


Is there an environment that can automatically handle parenthesis indentation like this? If not, is there a way to automate the indentation of parentheses so that the it does not need to be handled manually in this way? Thanks.

• It appears that alignment is performed, alternatingly, on parentheses and \wedge symbols. Is this impression correct? Separately, the terms cod and dom May be "operators" and thus should be typeset using upright letters; is this the case? – Mico Dec 27 '14 at 10:30
• Remember, you can use other parentheses/brackets too, to get more visual variation without sizes running wild. Depending on context [...{...(...)...}...] may be usable. – Andrew Swann Dec 27 '14 at 16:32
• @Mico -- that is correct, this example involves alternating indentation of parentheses and \wedge symbols. – Jasha Dec 27 '14 at 22:56

Not a fully automatic solution, but with code that's quite a bit simpler than in your posting. It uses only one type of alignment structure: aligned. The environment is used to perform alignment on both parentheses and on \wedge symbols.
The positioning of the closing large parentheses is fine-tuned using \mkern ("math-mode kern") directives. I also suggest setting "cod" and "dom" in an upright font if they're "operators".
\documentclass{amsart}
(\exists d) \begin{aligned}[t] &\biggl( l'(u,d) \begin{aligned}[t] &\wedge l'(v,d) \wedge \bigl(\forall z\bigr) \bigl(l'(z,d)\to(z=u\vee z=v)\bigr)\\ &\wedge (\exists p)(\exists q) \begin{aligned}[t] &\Bigl( \cod(p)=d \begin{aligned}[t] &\wedge \cod(q)=d \wedge l'\bigl(\dom(p),d\bigr) \wedge l'\bigl(\dom(q),d\bigr)\\ &\wedge (\forall t) \begin{aligned}[t] &\Bigl( \bigl( \cod(t)=d\wedge l'(\dom(t),d)\bigr)\\ &\qquad\qquad \to\bigl(t=p\vee t=q\bigr)\\ &\mkern2mu\Bigr) \end{aligned}\\ \end{aligned}\\ &\mkern2mu\Bigr) \end{aligned}\\ \end{aligned}\\ &\mkern2.5mu\biggr) \end{aligned}