# position of the slash in hatted \slashed

So I want to denote the Dirac operator with a hat, and I tried both \hat{\slashed{D}} and \slashed{\hat{D}}: the first one has the $^$ rather distant to the $\slashed{D}$, while the second one has the slash much too to the left of the $D$, almost coincide the semi-vertical stroke of the letter $D$.

Is there any way to adjust the position of the hat or slash?

• – Werner Mar 18 '14 at 19:45

Just overlap the symbol with the hat with the slashed version of itself.

\documentclass{standalone}
\usepackage{mathtools,slashed}
\newcommand\hatslashed[1]{{\hat{#1}\mathllap{\slashed{#1}}}}
\begin{document}
$\hat{\slashed{D}}$
$\slashed{\hat{D}}$
$\hatslashed{D}_{\hatslashed{D}_{\hatslashed{D}}}$
\end{document}


You can use \phantom in the following way to prevent double striking the glyph, but AFAIK \phantom doesn't detect cramped style and shifts the hat to the right.

\newcommand\hatslashed[1]{{\hat{\phantom{#1}}\mathllap{\slashed{#1}}}}

• Was working a stack, but I like your answer better (+1). I note that you double-strike the D. Interestingly, in an effort to avoid that, I found that using \phantom{#1} on either the \hat or the \slashed elements also caused distortion. Thus, the overstrike proved the only reliable method. – Steven B. Segletes Mar 18 '14 at 19:48
• @StevenB.Segletes Thank you for your appreciation! I will ask in chat about that strange interference. I'm still interested in your stackengine solution, please post it. My upvote is yours :-) – Henri Menke Mar 18 '14 at 19:51
• Better recheck that phantom... – Steven B. Segletes Mar 18 '14 at 20:11
• @StevenB.Segletes Hm. Why does \phantom shift the slash? Does \phantom change back to horizontal mode, instead of staying in math mode? – Henri Menke Mar 18 '14 at 20:18
• This \newcommand\hatslashedB[1]{{\,\hat{\phantom{\!#1}}\mathllap{\slashed{#1}}}} is closer to the overstriked solution, note the \! and \,. By the way, the phantom is shifting the \hat, I think, not the slash. – Steven B. Segletes Mar 18 '14 at 20:20

Without character overlapping:

\documentclass[border=3,varwidth]{standalone}
\usepackage{mathtools,slashed}

\makeatletter
\def\pslashed#1{%
\expandafter\ifx\csname psla@\string#1\endcsname\relax
{\mathpalette{\sla@/00}{\phantom{#1}}}%
\else
\csname psla@\string#1\endcsname
\fi}
\def\declarepslashed#1#2#3#4#5{%
\expandafter\def\csname psla@\string#5\endcsname{%
#1{\mathpalette{\sla@{#2}{#3}{#4}}{\phantom{#5}}}}}
\makeatother
\declarepslashed{}{/}{.08}{0}{D}

\newcommand\hatslashed[1]{\mathrlap{\hat{#1}}\slashed{#1}}
\begin{document}
$\hat{D}$

$\slashed{D}$

$\hatslashed{D}_{\hatslashed{D}_{\hatslashed{D}}}$
\end{document}


I define a command \pslashed that mimicks \slashed, but over a phantom.

Why doesn't \hat{\phantom{D}} give a good result? Because \hat cannot get the font metric information about the character D, because it's over a box containing nothing. So we set the accented character (in \mathrlap) and then set the slash as if it were across a D.

• Thanks for clarifying the mystery. I may have more questions... – Steven B. Segletes Mar 19 '14 at 1:54
• Your solution was very much tailored to the particular problem at hand. Maybe a question is a better forum than a comment, but is it possible to generalize \phantom to somehow contain vestigial font metric information of what was phantomed? In a related question, is there such a thing as what I will call \leavetrace{D}, which prints nothing, but makes whatever follows next in the input stream think a D had just preceded it? – Steven B. Segletes Mar 19 '14 at 2:15
• @StevenB.Segletes That's a very tough question: several operation in math mode are performed differently when the nucleus of a atom is a character or something else (a box, a skip, …). When you have a box rather than a character, the metric information has been lost: there is no “mathbox”, only \hbox and \vbox (\vtop, \vcenter). – egreg Mar 19 '14 at 9:51

This turned out a lot more interesting as an exercise, than I anticipated. In the first row of my answer, I give the basic elements we are working with, the D, the hatted D, and the slashed D.

Then, on the second line, I confirm the OP's observations that creating composite glyphs \hat{\slashed{D}} and \slashed{\hat D} cause distortions in the result. That's not too surprising, I guess.

So I figured this was tailor-made for a stack, wherein I could superimpose two of the basic elements atop each other to achieve the result. I first confirmed that the basic elements were all the same width, not augmented laterally in some way by the decoration. Of course, I wanted to avoid, if possible, double-striking the letter D, so I used a \phantom of D in one of the two elements of the stack. And I found, very surprisingly to myself, that the phantom distorted the results, as well.

About this time, Henri posted his solution, far superior to my own approach, since it naturally scales with mathstyle (whereas I would have to add the apparatus of scalerel on top of my solution to achieve that). I abandoned my solution, voted for Henri, and left him a comment of my \phantom observation. But then he asked for the stackengine result, so I continue.

The third line of my result shows those phantom results, with the hat being shifted left in the first, and the stroke being shifted left in the second. I figured it might have something to do with letter-specific kerns, lost with the phantom.

So, on the fourth line, I just lived with the double-striked D, same as Henri. But, this approach does not, in its current form, scale with the mathstyle.

\documentclass{article}
\usepackage{slashed}
\usepackage{stackengine}
\def\stackslashA#1#2{\def\stacktype{L}\stackon[0pt]{$#1{\phantom{#2}}$}{$\slashed{#2}$}}
\def\stackslashB#1#2{\def\stacktype{L}\stackon[0pt]{$#1{#2}$}{$\slashed{\phantom{#2}}$}}
\def\stackslash#1#2{\def\stacktype{L}\stackon[0pt]{$#1{#2}$}{$\slashed{#2}$}}
\begin{document}
Basic Elements: $D \hat D \slashed D$

Derived Elements:$\hat{\slashed{D}} \slashed{\hat D}$ (ugh!)

Stacked Phantoms: $\stackslashA{\hat}{D} \stackslashB{\hat}{D}$ (slight shifts)

Stacked Element: $\stackslash{\hat}{D}$ (double-stroked D)
\end{document}


• You can use \phantom inside the accent, here \hat, but not inside \slashed. Maybe you want to include this to prevent double striking. – Henri Menke Mar 18 '14 at 20:03
• @HenriMenke As a follow up, the phantom version is horizontally off by (approximately) a \! – Steven B. Segletes Mar 18 '14 at 20:17