# Is the space after the differential d operator canonical when using a Times font?

I have this simple code,

\documentclass[12pt]{book}
\usepackage{mathtools}
\usepackage{newtxtext}
\usepackage[lite]{mtpro2}
\begin{document}
$d\bar{p}$ and $dt$.
\end{document}


with this output,

I think it's a canonical space is due to the presence of the \bar{...} command? Sometimes to bring it back I insert a negative space \! to bring the p to the left near the d.

This little adjustment must always be done or I should create a particular macro. Which one could be always using the same command \bar? It gets a bit complicated for me in my book to change the original command \bar{...}. Thank you.

Using Steven Segletes' suggestion of \ooalign{$d\bar{#1}$\cr$d#1$}, one can see if the problem is universal across \bar. If the superposition produces a "thick" second letter, the kerning is not correct. (using newtxmath as Steven does not have mtpro2)

Unfortunately, that proves not to be the case, as some cases seem kerned correctly and others not:

\documentclass[12pt]{book}
\usepackage{mathtools}
\usepackage{newtxtext}
\newcommand\testkern[1]{%
\ooalign{$d\bar{#1}$\cr$d#1$}}
\textwidth 1in
\begin{document}
\noindent\testkern{a}
\testkern{b}
\testkern{c}
\testkern{d}
\testkern{e}
\testkern{f}
\testkern{g}
\testkern{h}
\testkern{i}
\testkern{j}
\testkern{k}
\testkern{l}
\testkern{m}
\testkern{n}
\testkern{o}
\testkern{p}
\testkern{q}
\testkern{r}
\testkern{s}
\testkern{t}
\testkern{u}
\testkern{v}
\testkern{w}
\testkern{x}
\testkern{y}
\testkern{z}
\end{document}


Applying a universal -1mu kern to \bar

\newcommand\xbar{\mkern-1mu\bar}
\newcommand\testkern[1]{%
\ooalign{$d\xbar{#1}$\cr$d#1$}}


therefore, may fix some letter combinations, but will inevitably break others:

• Without mtpro2, the space does not manifest. However, it does show, when, instead of mtpro2, one uses newtxmath. – Steven B. Segletes Apr 4 '19 at 10:18
• If the problem is universal with \bar in that font, you could always do \let\svbar\bar\renewcommand\bar{\mkern-1mu\svbar} – Steven B. Segletes Apr 4 '19 at 10:24
• Yes, if the two superimposed p's are "thick", that means the kerning is different between the two cases. If the superimposed p's look like one, then the kerning is correct. – Steven B. Segletes Apr 4 '19 at 10:26
• I removed some offtopic comments. (the conversation seemed to be finished anyway). Thanks. – Stefan Kottwitz Apr 7 '19 at 15:01
• @Sebastiano -- The present "title" of thiis question doesn't make much sense to me. Would you be willing to change it to the following: Is the space after the differential d operator canonical when using a Times font? – barbara beeton Aug 3 at 19:23

A proposal to renew the command of \bar as follows:

\let\svbar\bar
\renewcommand\bar[1]{%
#1\ThisStyle{\setbox0=\hbox{$\SavedStyle#1$}\kern-\wd0}\svbar{\,\phantom{#1}}\!}


This will guarantee proper kerning of the letter, as it is set first thing without the \bar. Then, I kern backward across the letter, and apply the \bar to a variant of the letter's \phantom. In this case, the variant is a shifted \phantom, which is then unshifted following the \bar, so as not to introduce any stray space.

Therefore, if there are residual kerning issues, they will be with the placement of the superimposed bar, relative to the underlying properly kerned letter.

The MWE uses the \ooalign test given in the question to judge the quality of the \bar macro, using letter boldness as an indicator for bad kerning. As you can see, there are no thick/boldened letters signifying a kern mismatch. Therefore, with this approach, one must merely judge if the placement of the bar relative to the letter is suitable or not.

While all examples are shown relative to the letter "d", the method, in fact, will perform similarly, regardless of the preceding letter.

EDITED to work across math styles.

\documentclass[12pt]{book}
\usepackage{mathtools}
\usepackage{newtxtext}
\usepackage{scalerel}
\let\svbar\bar
\renewcommand\bar[1]{%
#1\ThisStyle{\setbox0=\hbox{$\SavedStyle#1$}\kern-\wd0}\svbar{\,\phantom{#1}}\!}
\newcommand\testkern[2][]{%
\ooalign{$#1 d\bar{#2}$\cr$#1 d#2$}}
\textwidth 1in
\begin{document}
\noindent\testkern{a} \testkern{b} \testkern{c} \testkern{d}
\testkern{e} \testkern{f} \testkern{g} \testkern{h} \testkern{i}
\testkern{j} \testkern{k} \testkern{l} \testkern{m} \testkern{n}
\testkern{o} \testkern{p} \testkern{q} \testkern{r} \testkern{s}
\testkern{t} \testkern{u} \testkern{v} \testkern{w} \testkern{x}
\testkern{y} \testkern{z}

\noindent\testkern[\scriptstyle]{a} \testkern[\scriptstyle]{b}
\testkern[\scriptstyle]{c} \testkern[\scriptstyle]{d}
\testkern[\scriptstyle]{e} \testkern[\scriptstyle]{f}
\testkern[\scriptstyle]{g} \testkern[\scriptstyle]{h}
\testkern[\scriptstyle]{i} \testkern[\scriptstyle]{j}
\testkern[\scriptstyle]{k} \testkern[\scriptstyle]{l}
\testkern[\scriptstyle]{m} \testkern[\scriptstyle]{n}
\testkern[\scriptstyle]{o} \testkern[\scriptstyle]{p}
\testkern[\scriptstyle]{q} \testkern[\scriptstyle]{r}
\testkern[\scriptstyle]{s} \testkern[\scriptstyle]{t}
\testkern[\scriptstyle]{u} \testkern[\scriptstyle]{v}
\testkern[\scriptstyle]{w} \testkern[\scriptstyle]{x}
\testkern[\scriptstyle]{y} \testkern[\scriptstyle]{z}

\noindent$2 d\bar{p}^2\ne2d p^2$
\end{document}


• My always thanks from my first question I asked two and a half years ago :-) – Sebastiano Apr 4 '19 at 11:21
• @Sebastiano It has been my pleasure to assist you. – Steven B. Segletes Apr 4 '19 at 11:26
• Steven I can't get a green check mark. I'm sorry. The two answers are both beautiful. – Sebastiano Apr 4 '19 at 19:53
• @Sebastiano No problem. Sometimes, a question without a checkmark brings more eyes, from those thinking it is still unanswered. – Steven B. Segletes Apr 4 '19 at 19:54
• I really appreciate the answers. When I can't choose, they are rare for me, it's because I can't penalize one user over another. – Sebastiano Apr 4 '19 at 19:55

If I compile

\documentclass[12pt]{book}
\usepackage{mathtools}
\usepackage{newtxtext}
\usepackage[lite]{mtpro2}
\begin{document}

$d\bar{p}$

$dp$

\showoutput

\end{document}


I get, for the two formulas

....\mathon
....\LMP1/mtt/m/it/12 d
....\kern1.43999
....\vbox(7.88399+2.568)x7.98
.....\hbox(7.88399+0.0)x0.0, shifted 3.312
......\LMP2/mtt/m/n/12 N
.....\kern-5.484
.....\hbox(5.484+2.568)x7.98
......\LMP1/mtt/m/it/12 p
....\mathoff

....\mathon
....\LMP1/mtt/m/it/12 d
....\kern1.43999
....\kern-2.40001
....\LMP1/mtt/m/it/12 p
....\kern0.48
....\mathoff


After removing the call to mtpro2, I get

....\mathon
....\OML/cmm/m/it/12 d
....\vbox(6.77774+2.33331)x5.89717
.....\hbox(6.77774+0.0)x0.0, shifted 0.99028
......\OT1/cmr/m/n/12 ^^V
.....\kern-5.16667
.....\hbox(5.16667+2.33331)x5.89717
......\OML/cmm/m/it/12 p
....\mathoff

....\mathon
....\OML/cmm/m/it/12 d
....\OML/cmm/m/it/12 p
....\mathoff


The obvious difference is that d in the font \LMP1/mtt/m/it/12 (pointing to mt2mit at 12pt) has an italic correction, which isn't present in the \OML/cmm/m/it/12 font (pointing to cmsy10 at 12pt).

Indeed, if I do tftopl mt2mit, I get

(CHARACTER C d
(CHARWD R 0.551)
(CHARHT R 0.717)
(CHARIC R 0.12)
(COMMENT
(KRN O 0 R -0.06)
[...]
(KRN C p R -0.2)
[...]
(KRN C t R -0.04)
[...]
(KRN O 263 R -0.02)
)
)


and with tftopl cmsy10 I get

(CHARACTER O 100
(CHARWD R 0.611113)
(CHARHT R 0.694445)
)


As you can see, there is also a kerning pair with p or t, which moves in the character when there is no accent, but this is not possible when the next item is an Acc atom.

You can manually compute the appropriate kerning.

\documentclass[12pt]{book}
\usepackage{mathtools}
\usepackage{newtxtext}
\usepackage[lite]{mtpro2}

\newcommand{\dwithbar}[1]{%
d\computedaccentkern{#1}\bar{#1}%
}
\makeatletter
\newcommand{\computedaccentkern}[1]{%
\mathpalette\computedaccentkern@{#1}%
}
\newcommand{\computedaccentkern@}[2]{%
\begingroup
\sbox\z@{$\m@th#1d#2$}
\sbox\tw@{$\m@th#1d{\kern0pt#2}$}%
\kern\dimexpr\wd\z@-\wd\tw@\relax
\endgroup
}
\makeatother

\begin{document}

$d\bar{p}$ $\scriptstyle d\bar{p}$

$\dwithbar{p}$ $\scriptstyle \dwithbar{p}$

$dp$ $\scriptstyle dp$

$d\bar{t}$ $\scriptstyle d\bar{t}$

$\dwithbar{t}$ $\scriptstyle \dwithbar{t}$

$dt$ $\scriptstyle dt$

\end{document}


You can define similarly for other accents, say \dot:

\newcommand{\dwithdot}[1]{%
d\computedaccentkern{#1}\dot{#1}%
}


or a generic

\newcommand{\dwithacc}[2]{%
d\computedaccentkern{#2}#1{#2}%
}


to be called like \dwithacc\bar{p} or \dwithacc\dot{p}.

• Shocking :-) I dare say amazed. I don't understand almost anything (\mathon...\mathoff :-) where they come from, CHARACTER etc...) but I can imagine that it's a problem with encoding the different incompatible fonts that I'm using. – Sebastiano Apr 4 '19 at 11:20
• @Sebastiano The first part is the analysis of what TeX internally does with the input, in terms of boxes and glue. Then I looked at the metrics for the fonts, finding the correspondence with what we saw in the boxes and glue representation. – egreg Apr 4 '19 at 11:21
• Do i understand your solution correctly that it specifically addresses kerns following the letter "d", or is it universal for any letter combinations? – Steven B. Segletes Apr 4 '19 at 11:57
• @StevenB.Segletes It's specifically for d, but could be modified quite easily for other pairs. – egreg Apr 4 '19 at 12:02
• @egreg Doesn't know who to vote for the two questions to. If I don't, it's because they're both beautiful. – Sebastiano Apr 4 '19 at 19:52

This is more of a comment, but requires an example.

The problem described does not occur with Computer Modern, and the reason is the difference in the metrics in the .tfm file: the "d" in the alphabet used for math does not have an italic correction. This is by design, since "d" is most often used by Knuth for the differential operator; if he uses it as a variable, he would add a thin space following the "d" if needed.

Here is the example used in the question, set with Computer Modern.

\documentclass[12pt]{article}
\usepackage{amsmath}
\begin{document}
The differential $d$ as set using Computer Modern: \qquad
$d\bar{p}$ and $dt$.
\end{document}


In short, the space that is inserted (differently with and without diacritics on the letter following the "d") is the result of metrics for the "d" not being defined in the same manner used in Computer Modern. (This is not a problem when an upright "d" is used for the differential function.)

• Thank you very much for your precious answer and contribute. – Sebastiano Aug 3 at 18:52

This could be an intermediate solution, without macro, using diffcoeff package (I remember that derivative package - see pag. 29 - does not include the differential symbol as shown in this image) with the option ISO to have upright differential symbol.

In this case it is possible to observe that a bit of horizontal spacing has decreased.

\documentclass[a4paper,12pt]{article}
\usepackage[lite]{mtpro2}
\usepackage{derivative}
\usepackage[ISO]{diffcoeff}
\begin{document}
$$\frac{d\bar{p}}{dt}, \quad \diff{\bar{p}}{t} \,$$
\end{document}


For those who would like to compile the code and they haven't installed \usepackage[lite]{mtpro2} to replace it with \usepackage{newtxmath}. The only difference is the length of the \bar above the letter.