I'm currently writing a small tool which automatically generates latex code for equations. I stumbled over the following problem, which in extremely boiled-down form looks like this:
\begin{align*}
a
&=
\left( \left[ \left\{ \left( b
\vphantom{x} \right.
\vphantom{x} \right.
\vphantom{x} \right.
\vphantom{x} \right.
\\&\quad\;
%--------
c
\\&\quad\;
%--------
\left. \vphantom{x}
\left. \vphantom{x}
\left. \vphantom{x}
\left. \vphantom{x}
d
\right) \right\} \right] \right)
\\&\quad\;
%--------
\left. \left. \left. \left.
e
\right) \right\} \right] \right)
\end{align*}
The output contains some space for which I have no explanation:
Please let me guide you through this.
In the align environment, I have a left side (a) only in the first line, and right sides in all lines. I insert a \quad\;
at the beginning of each line (except for the first) to jump over the space of the =
character.
In the first line (a, b), I have four opening brackets with auto-scaling (\left
). The \vphantom
are required in my code to keep the vertical size of the brackets over the line breaks; they contain more complex text, but here I simply pass x
. I compensate the four opening brackets with for virtual closing brackets (\right.
).
In the second line (c), I just have c
which nicely aligns below the right side of the first line. This is what I want for the third line as well.
In the third line (d) (which is actually of the form that my code generates), I have four virtual opening brackets (\left.
) and four closing brackets. Now this line generates a lot of space before the d
.
In the fourth line (e) I deleted all the \vphantom
commands. Surprisingly, this reduces the space. The remaining space seems to be generated by the \left.
commands. I could understand if this would be the space occupied by the closing brackets, but it is smaller (please compare with the first line).
So, my problem is that I want to compensate for the unwanted space in the third line by inserting a negative space (e.g. \!
), but I have no clue how and why latex generates the space in the first place. Since the code is automatically generated and has an arbitrary number of brackets, I can't just use a negative space of fixed size.
I there anyone deeply familiar with the internal latex code to tell me what latex is doing in this case, such that I can compensate for the unwanted space? Thanks a lot!
Edit in response to campa: I included \setlength{\nulldelimiterspace}{0pt}
which seems to reduce the spacing, but doesn't eliminate it completely (second example):
\nulldelimiterspace
(the default is something more than 1pt IIRC).\nulldelimiterspace
to zero actually reduces the space, but doesn't eliminate it. I edited my answer.\vphantom{x}
and\left.
Besides\nulldelimiterspace
, this is another reason for not using indiscriminately\left
and\right
.