In math mode one can do $\hbar$, which produces an h with a little line through the top of it. I want to do the same thing, except with the letter d instead. Is there a generalization of $\hbar$ that works for other letters besides just h?
- 2,596
- 243
3 Answers
You can create a specific command \dbar for this purpose.
\newcommand{\dbar}{d\hspace*{-0.08em}\bar{}\hspace*{0.1em}}
Full Code
\documentclass{article}
\newcommand{\dbar}{d\hspace*{-0.08em}\bar{}\hspace*{0.1em}}
\begin{document}
$\hbar$, $\dbar$.
\end{document}
produces

- 8,904
- 3
- 31
- 42
-
2A more convenient command could be
\mathchar '26 \mkern-11mu d. This is the same idea used in\hbar. – Sigur Sep 28 '14 at 00:44 -
-
-
1Also, in general, kerns are better than
\hspaces for things like this, because\hspacehas stretchable glue in it, whereas a\kernor\mkerndoes not. – Steven B. Segletes Sep 28 '14 at 01:17 -
-
2@StevenB.Segletes I'm afraid that both you and skpblack are wrong:
\hspace{...}becomes stretchable only if the argument contains stretch components, so\hspace{2pt}will never stretch. The\hspace*variant has nothing to do with stretching or shrinking per se, because it obeys the same rules as the normal command. The main difference between a skip (\hspace) and a kern is that the latter isn't considered a line break point. – egreg Oct 01 '14 at 06:34
There is code in the Comprehensive List of Symbols, but it's wrong: what's suggested is
\newcommand{\dbar}{{\mathchar'26\mkern-12mu d}}
but one needs to compensate the amount of backup, which is larger than the width of the bar by 3mu:
\documentclass{article}
\newcommand{\dbar}{{\mkern3mu\mathchar'26\mkern-12mu d}}
\begin{document}
$32\lambda^2 \dbar_w$
$32\lambda^2 d_w$
$32\lambda^2 \hat{d}_w$
\end{document}

The fact that the width is 9mu is confirmed by the definition of \hbar in Plain TeX:
\hbar:
macro:->{\mathchar '26\mkern -9muh}
Of course, different math fonts may need different amounts of spacing.
A possibly better definition is
\newcommand{\dbar}{{d\mkern-7mu\mathchar'26\mkern-2mu}}
so that the bar doesn't protrude as much on the right:
\documentclass{article}
\newcommand{\dbar}{{d\mkern-7mu\mathchar'26\mkern-2mu}}
\begin{document}
$d\dbar d$
$h\hbar h$
\end{document}
- 1,121,712
For PDFLaTeX:
As recommended by Sigur. You should load the package lmodern as well as the output will be pixeled with out it.
% arara: pdflatex
\documentclass{article}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\begin{document}
in text \dj{} and math $\textit{\dj}$
\end{document}
For Lua- or XeLaTeX:
The output is the same as above. You can use the unicode U+0111 or copy paste that symbol directly into your code.
% arara: lualatex
\documentclass{article}
\usepackage{fontspec}
\begin{document}
in text \symbol{"0111} and math $\textit{\symbol{"0111}}$
\end{document}
The package unicode-math does not contain this symbol yet. It just contains the unicode U+00F0 with the command $\matheth$ which could be an alternative.
You can find fonts that support that symbol on your system by clicking here. Here are some font examples. Choose one and write your macro like \newcommand*{\dbar}{{\fontspec{font_of_your_choice}\symbol{"0111}}}.
% arara: lualatex
\documentclass{article}
\usepackage{fontspec}
\usepackage{booktabs}
\begin{document}
\begin{tabular}{ll}\toprule
Font & Example\\\midrule
Latin Modern & \symbol{"0111}\\
Code2000 & \setmainfont{Code2000.ttf}\symbol{"0111}\\
Comic Sans MS & \setmainfont{comic.ttf}\symbol{"0111}\\
Consolas & \setmainfont{consola.ttf}\symbol{"0111}\\
DejaVu Sans & \setmainfont{DejaVuSans.ttf}\symbol{"0111}\\
EB Garamond & \setmainfont{EB Garamond}\symbol{"0111}\\
Linux Libertine &\setmainfont{Linux Libertine O}\symbol{"0111}\\
Quivira &\setmainfont{quivira.otf}\symbol{"0111}\\
XITS &\setmainfont{xits-regular.otf}\symbol{"0111}\\
\bottomrule
\end{tabular}
\end{document}

- 43,807
-
using
\textitin math mode feels rather wrong to me. And if it is left out the first example givesLaTeX Warning: Command \dj invalid in math mode on input line 8.– cgnieder Jul 01 '15 at 08:01 -
@clemens Yes of course this was a tweak. The command
\djis a textcommand. and therefore I used\textithere. – LaRiFaRi Jul 01 '15 at 08:05

\dj{}with\usepackage[T1]{fontenc}– Sigur Sep 28 '14 at 00:16\dj{}is a text-mode symbol. In math it would be$\text{\dj}$. You should load the packagelmodernas well in order to get that symbol unpixeld. – LaRiFaRi Oct 01 '14 at 06:24