This is a follow-up to my previous question How can I get an upright \hbar using unicode-math?. I am experimenting with making a d with a bar through it like one would use in physics to denote an inexact differential (see also How to enter symbol for inexact differential in xelatex? and How can I call unicode characters in LaTeX or LyX? and d with a little line through the top of it). I see the bar on the d glyph seems to shift relative to the letter whereas I don't see that behavior with the h character. Is this behavior real and, if so, what causes it? Does it vary with different fonts? Can it be overcome?
Experimenting with the values of \mkern did not make the shift go away.
Here is my MWE:
% !TEX program = lualatexmk
% !TEX encoding = UTF-8 Unicode
\documentclass{article}
\usepackage{unicode-math}
\makeatletter
\AtBeginDocument{%
\DeclareRobustCommand{\hbar}{{\mathpalette\hbar@\relax\symup{h}}}%
}
\newcommand{\hbar@}[2]{%
\makebox[0pt][l]{\raisebox{-0.07\height}{(\m@th#1\mkern-2mu\mathchar"AF)}}%
}
\makeatother
% Let's try a \dbar glyph for inexact differentials.
\makeatletter
\AtBeginDocument{%
\DeclareRobustCommand{\dbar}{{\mathpalette\dbar@{\relax}{\symsfup{d}}}}%
}
\newcommand{\dbar@}[2]{%
\makebox[0pt][l]{\raisebox{-0.09\height}{(\m@th#1\mkern+3mu\mathchar"AF)}}%
}
\makeatother
\begin{document}
( \hbar \scriptstyle\hbar \scriptscriptstyle\hbar )
( \dbar \scriptstyle\dbar \scriptscriptstyle\dbar )
\end{document}
Here is the MWE output:
UPDATE: After much experimentation, the following seems to work but I can't completely explain why. If I change [c] to [r] I notice that the bar doesn't move regardless of what I provide for \mkern.
\makeatletter
\AtBeginDocument{%
\DeclareRobustCommand{\dbar}{{\symsfup{d}\mathpalette\dbar@\relax\relax}}%
}
\newcommand*{\dbar@}[2]{%
\makebox[0pt][c]{\raisebox{-0.07\height}{\(\m@th#1\mkern-6mu\mathchar"AF\)}}%
}
\makeatother





\documentclass{article}\begin{document}\Large^^^^0111 \textsf{^^^^0111} \textsf{\textbf{^^^^0111}} \textbf{^^^^0111}\end{document}– David Carlisle Aug 29 '21 at 22:16