5

This question adds another reason why one shouldn’t abuse the \left and \right pair

Automatic delimiter sizing through a \left and \right pair should always be avoided, with few exceptions (e.g., cases, matrices, etc.). In fact, pages 146 – 149 of The TeXbook showcase many examples where manual sizing is used. Using \left and \right in those examples would no doubt produce sub-optimal or even ugly output.

There is also the problem of spacing: A \left and \right pair effectively creates a \mathinner object, which follows different spacing rules (e.g., $\sin(x)$ versus $\sin\left(x\right)$). However, even after one has made \left<delimiter>...\right<delimiter> to behave like \mathopen<delimiter>...\mathclose<delimiter>, there still are potential problems.

The current problem

I have used this technique from Philipp Stephani mentioned in this post: Spacing around \left and \right. For strange reasons, there is still superfluous space between certain letters and the opening delimiter.

Note: The following MWE is of no practical use by its own. However, I think it serves as one of many reasons why one shouldn’t abuse \left and \right, even after they are “fixed”.

\documentclass{article}
\usepackage{amsmath}
\usepackage{newtxtext}
\usepackage[lite]{mtpro2}
\begin{document}
\begin{alignat*}{4}
&f\left(x\right) \quad                  &&\vert\left(x\right) \\
&f\mathopen{}\mathclose{\left(x\right)} &&\vert\mathopen{}\mathclose{\left(x\right)} \\
&f(x)                                   &&\vert(x)
\end{alignat*}
\end{document}

superfluous space

Why is there superfluous space, and how can I fix it?

Ruixi Zhang
  • 9,553

1 Answers1

5

Let's look at a simpler situation:

\documentclass{article}
\usepackage{amsmath}
\usepackage{newtxtext}
\usepackage[lite]{mtpro2}
\begin{document}

$f(x)$

$f\mathopen{}\mathclose{(x)}$

$f\mathopen{}\mathclose{\left(x\right)}$

\showoutput

\end{document}

The output for the first formula is

....\mathon
....\LMP1/mtt/m/it/10 f
....\kern2.4
....\kern-0.8
....\LMP1/mtt/m/it/10 .
....\LMP1/mtt/m/it/10 x
....\kern0.5
....\LMP1/mtt/m/it/10 /
....\mathoff

For the second formula it is

....\mathon
....\LMP1/mtt/m/it/10 f
....\kern2.4
....\hbox(0.0+0.0)x0.0
....\hbox(7.17+2.13998)x13.42998
.....\LMP1/mtt/m/it/10 .
.....\LMP1/mtt/m/it/10 x
.....\kern0.5
.....\LMP1/mtt/m/it/10 /
....\mathoff

For the final one it is

....\mathon
....\LMP1/mtt/m/it/10 f
....\kern2.4
....\hbox(0.0+0.0)x0.0
....\hbox(7.17497+2.13501)x13.42998
.....\hbox(7.17497+2.13501)x13.42998
......\hbox(7.17+2.13998)x3.73, shifted -0.00497
.......\LMP1/mtt/m/it/10 .
......\LMP1/mtt/m/it/10 x
......\kern0.5
......\hbox(7.17+2.13998)x3.73, shifted -0.00497
.......\LMP1/mtt/m/it/10 /
....\mathoff

What's the difference? Just a \kern-0.8.

By rule, TeX adds the italic correction after f (\kern2.4); in the first formula the f is followed by a left parenthesis (which is at the slot for . in the math symbol font of mtpro2) and a kerning is defined for this pair, exactly \kern-0.8.

In the second and third formula the kerning cannot be applied.

I add the picture from the code above for the few people who can't see it from the symbolic representations above. It can be seen that the positioning of ( and x is the same, but in the second and third rows the parenthesis is a bit to the right with respect to the first one (by the precise amount of 0.8pt, the missing kern).

enter image description here

With \vert the problem doesn't show, because no kerning is defined between | and (.

Just for checking:

\documentclass{article}
\usepackage{amsmath}
\usepackage{newtxtext}
\usepackage[lite]{mtpro2}
\begin{document}

\sbox0{$f(x)$} % define the math fonts

{\the\textfont1 f.}
{\the\textfont1 f\/}

\showoutput

\end{document}

We get (reduced)

....\LMP1/mtt/m/it/10 f
....\kern-0.8
....\LMP1/mtt/m/it/10 .

....\LMP1/mtt/m/it/10 f
....\kern 2.4

Can you do better? Yes, not using \left and \right.

egreg
  • 1,121,712
  • 1
    +1 for "not using \left and \right". :-) – Mico Sep 09 '18 at 21:41
  • Could you please clarify which output belongs to which formula? There are 3 outputs but only 2 formulae. – Ruixi Zhang Sep 10 '18 at 01:16
  • 1
    @RuixiZhang Oh, sorry, I forgot to add one in the middle. Fixed. – egreg Sep 10 '18 at 07:48
  • Your formulas are not in same order as image in OP, so it would be nice to get an image here too matching the order as in your answer. –  Sep 10 '18 at 09:43
  • 1
    @jfbu They are different on purpose: I'm comparing $f(x)$, $f\mathopen{}\mathclose{(x)}$ and $f\mathopen{}{\mathclose{\left(x\right)}$, in order to show that the culprit is \mathopen{}. – egreg Sep 10 '18 at 09:44
  • no pity for the visual type persons who only understand via images? hmm... I wonder if the didactic committee properly examined your records as professor! –  Sep 10 '18 at 09:49
  • 1
    @jfbu It was pretty difficult to show pictures of rings and modules and the committee agreed. ;-) But I added the image for those few people who can't figure out the output from the symbolic representation of “boxes and glue”. ;-) – egreg Sep 10 '18 at 09:56
  • some people like to fancy spec Z as 3-dimensional but the real difficulty comes with the geometry over the field with 1 element ;-) –  Sep 10 '18 at 10:01