The correct way to write parentheses in LaTeX

Updated:

Update: It has come to my attention that the package mathtools has the command \DeclarePairedDelimiter that does exactly what I describe below. For example

\DeclarePairedDelimiter\p{(}{)}

Normal parentheses: \p{1+2}
Left-right parentheses: \p*{1+2}
Sized-control parentheses: \p[\Big]{1+2}


I like numbers to control the size of the parentheses more, but the mathtools solution is just as good. I am also not sure how to replicate the \en command in mathtools for dynamic selection of delimiters.

I really like LaTeX. The concept of focusing on content and leaving formatting to a software tool really appeals to me. However, I feel that not everything in LaTeX follows that model and things can be considerably improved.

Consider the following latex code

\begin{align}
&\left(\left(\frac{ \frac{1}{p_0}-2} {r_{\mathrm{det}}(s) +
\frac{1}{p_0} - \frac{1}{p_s}}\right) r^{[\alpha]}(s) +
1\right)^{-1} \\
&= \left(1 + \left( \frac{1}{p_0}-2 \right) \left( 1 +
\frac{1}{r^{[\alpha)}(s)} \Bigg( \frac{1}{p_0} - \frac{1}{p_s}
\right)^{-1}\right)^{-1}
\end{align}


This renders as

Admittingly, this is an ugly expression. However, such expression with nested parenthesis, braces and brackets are not uncommon in mathematical papers, especially in proofs.

Even with a sophisticated editor (I use Emacs), it is still difficult to track where the left or right of those parenthesis are. Even more difficult is to change the parentheses to braces or add \left, \right pairs or \Big to them, or remove the parenthesis all together. Moreover, if you wrongly close or open a parenthesis it can be frustrating to find and correct the mistake. For example, see how long it takes you to find and correct the mistake in the previous expression.

To resolve these issues I wrote a new command, \en for enclose. The command is really simple. It takes three arguments (a,b,c) and outputs (a,c,b). So instead of writing ( complicated expression ), one writes \en(){complicated expression}. The idea of this command is to declare from the beginning of the expression what type of parenthesis you want and then use the LaTeX syntax (braces) to ensure the balancing of the parenthesis. Since the opening and closing parenthesis are close to each other, it is relatively easier to change the parenthesis to brackets, for example, without digging in the expression: \en[]{complicated expression}. Finally, changing the expression to {complicated expression} easily removes the parenthesis from the final output and leaves behind harmless braces in TeX.

To add parenthesis signifiers, you can write \en1, \en2, \en3 or \en4 to get \big, \Big, \bigg or \Bigg, respectively. Moreover, you can write \en* to get a \left-\right kind of parenthesis.

I believe this is a better way of writing parenthesis. The only problem is that it involves writing more characters. However, using \defenclose{\p}() you can define a new command, \p, with the same features as \en except that you do not need to specify () every time. So one writes, for example, \p*{complicated expression} to get \left( complicated expression \right). I also like to define similar commands for \norm and \abs.

The previous expression can be written like

\begin{align}
& \p*{\p*{ \frac{ \frac{1}{p_0}-2}
{r^{\en[]{\alpha}}(s) + \frac{1}{p_0} - \frac{1}{p_s}}}
r^{\en[]{\alpha}}\p{s} + 1}^{-1} \\
&= \p*{1 + \p*{\frac{1}{p_0}-2}
\p*{1 + \frac{1}{r^{\en[]{\alpha}} \p{s}}
\p*{\frac{1}{p_0} - \frac{1}{p_s}})}^{-1}}^{-1}
\end{align}