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
Best Answer
If you are using
unicode-math
, your best option is to insert đ (U+0111, Latin small letter d with stroke) from a text font that supports it. If your main font does not, you can use\setmathrm
or\setmathsf
to change your\mathrm
or\mathsf
alphabet to one that does, or define a new math alphabet that does with\setmathfontface
.The
\text
commands I use are somewhat complicated, because they leave the weight unchanged but set every other axis, but you can probably get away with\textnormal{đ}
If you are compiling with legacy TeX instead, you can technically use the same approach there too, because the 8-bit T3 encoding supports this character. You can select a font family (Computer Modern Roman, Computer Modern Sans Serif, Times, Helvetica, Junicode or Linguistics Pro), and some of these support slanted shapes.