# Raise hat operator without inserting rule

I've looked around for a while before posting but I didn't find a solution on my own neither on the web, so I'm asking here.

Basically I have to write down some operators and I wanted a \mathbf aspect with a bold hat on the top, such as

\newcommand{\op}[1]{\mathop{}\!\mathbf{\hat{#1}}}
% ...
\op{O}


which is more or less exactly what I want:

Here come the troubles.

1. For some letters, let pick the most problematic one, e.g. the "X", I'have this awful behaviour:

when looking at it at a big distance, the symbol appears too close, so that it superimpose on the X generating an annoying aliasing (also it's not completely clear at first sight).

1. When I've to indicate the adjoint (with a dagger) if I have the rule which is recommended on the net to raise the hat (thing that I don't like as it's raised for the same amount for every letter) I get some problems with the \dagger symbol:

\newcommand{\opdag}[1]{\mathop{}\!\mathbf{\hat{\rule{0pt}{1.5ex}#1}^{\dag}}}
% ...
\opdag{X}


So the dagger is getting too high, and I really don't like it.

Summing up, I would like to find a way to raise a little bit the hat above the letters, but with a variable stretching factor depending on what's below the hat and doe not interfere with superscript. Basically if it would possible to redefine the height of the hat above the letter each one of these goal would be achieved.

Thanks for helping!

• I can't reproduce the problem. I'm not sure these should be defined with the \mathop{} trick either, but that depends on how you want to use them. Please, make a compilable example showing the issue. – egreg Oct 23 '17 at 20:15
• why \mathop{}\! rather than putting mathop around the operator? – David Carlisle Oct 23 '17 at 20:22
• \mathop{}\! Reproduces the exact space I wanted, as the mathop command on its own was taking too horizontal space... Do you have a better form for that? I need also for the d of the differentials, I use the same form, but if you know a better one I'd be happy. The problem is that operatorname or the declaremathoperator leave too much space after the symbol... – GiuTeX Oct 24 '17 at 9:29

Using a stack allows the vertical gap to the hat to be adjusted...\smashing it allows it to not [greatly] affect subsequent superscripts.

\documentclass{article}
\usepackage{stackengine}
\newcommand{\op}[1]{\mathop{}\!\ensurestackMath{\stackon[-.95ex]{%
\mathbf{#1}}{\smash{\mathbf{\hat{}}}}}}
\newcommand{\opdag}[1]{\mathop{}\!\op{#1}^{\dag}}
\begin{document}

$\mathbf{O} \op{O} \opdag{O} \mathbf{O}^\dag$

$\mathbf{X} \op{X} \opdag{X} \mathbf{X}^\dag$

$\mathbf{x} \op{x} \opdag{x} \mathbf{x}^\dag$

\end{document}


To make \op and \opdag totally impervious to superscript placement, one could \smash the whole thing and use a \vphantom. Also, just to demonstrate, I changed the stack gap from -.95ex to -1.1ex to show the adjustability of the hat placement:

\documentclass{article}
\usepackage{stackengine}
\newcommand{\op}[1]{\mathop{}\!\ensurestackMath{\smash{\stackon[-1.1ex]{%
\mathbf{#1}}{\mathbf{\hat{}}}}}\vphantom{#1}}
\newcommand{\opdag}[1]{\mathop{}\!\op{#1}^{\dag}}
\begin{document}

$\mathbf{O} \op{O} \opdag{O} \mathbf{O}^\dag$

$\mathbf{X} \op{X} \opdag{X} \mathbf{X}^\dag$

$\mathbf{x} \op{x} \opdag{x} \mathbf{x}^\dag$

\end{document}


• you are very excellent user. +1 is always. – Sebastiano Oct 23 '17 at 20:34
• @Sebastiano You are too kind. – Steven B. Segletes Oct 23 '17 at 22:29
• @opisthofulax It was for Steven. He is very excellent user. – Sebastiano Nov 8 '17 at 18:08
• I think the mutual admiration society is getting out of hand, here. – Steven B. Segletes Nov 8 '17 at 20:20
• @StevenB.Segletes Very kindly I just said the truth. I appreciate and almost always share your excellent answers. – Sebastiano Nov 9 '17 at 20:18