I provide two TikZ solutions.
- The first one uses uses an empty node before and after the formula that belongs under the wide hat.
- Disadvantage: The added vertical height will not be taken into calculation
- Advantage: Math style (display, text, script, scriptscript) is not effected (other then in the
\vphantom
.
- The second one is a node.
- Disadvantage: Math style is lost. (Change the first
\frac
into a \tfrac
to realize.)
- Advantage: Vertical height is known to math mode.
Another disadvantage over \widehat
is, that the line width doesn't change over the course of the path.
MWE
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{calc,arrows}
% Solution 1
\newcounter{tikzmark}
\newcommand{\tikzmark}[2][]{\tikz[baseline, inner sep=0, overlay, remember picture] \node[anchor=base] (#2) {\vphantom{#1}};}
\newcommand{\widehatarrow}[1]{%
\tikzmark[#1]{widehatarrow\thetikzmark} #1 \tikzmark[#1]{endwidehatarrow\thetikzmark}%
\tikz[overlay, remember picture] \draw[-to] (widehatarrow\thetikzmark.north)++(.05em,.4ex) -- ($(widehatarrow\thetikzmark.north)!.5!(endwidehatarrow\thetikzmark.north)+(.05em,.8ex)$) -- ($(endwidehatarrow\thetikzmark.north)+(.05em,.4ex)$);%
\stepcounter{tikzmark}%
}
% Solution 2
\newcommand{\Widehatarrow}[1]{%
\tikz[baseline] {
\node[inner sep=0, anchor=base] (widehatarrow){$#1$};
\draw[-to] (widehatarrow.north west)++(.05em,.4ex) -- ($(widehatarrow.north west)!.5!(widehatarrow.north east)+(.05em,.8ex)$) -- ($(widehatarrow.north east)+(.05em,.4ex)$);%
}%
}
\begin{document}
\begin{equation} % Solution 1
\widehatarrow{A, B} \cdot \widehatarrow{x, y} = \widehatarrow{A, y, B, x}
\end{equation}
\begin{equation} % Solution 2
\Widehatarrow{A, B} \cdot \Widehatarrow{x, y} = \Widehatarrow{A, y, B, x}
\end{equation}
\begin{equation} % Compare both solutions
\frac{1}{\widehatarrow{A, B} \cdot \Widehatarrow{A, B}} = \frac{1}{\widehatarrow{A, B} \cdot \widehatarrow{A, B}} = \frac{1}{\Widehatarrow{A, B} \cdot \Widehatarrow{A, B}}
\end{equation}
\end{document}
Output
(By egreg) It's possible to overcome the limitations with \Widehatarrow
, by using a \vphantom
and \mathpalette
:
\newcommand{\Widehatarrow}[1]{\mathpalette\Widehatarrowaux{#1}}
\newcommand{\Widehatarrowaux}[2]{%
\vphantom{#1\widehat{#2}}
\tikz[baseline] {
\node[inner sep=0, anchor=base] (widehatarrow){$#1#2$};
\draw[-to] (widehatarrow.north west)++(.05em,.4ex)
-- ($(widehatarrow.north west)!.5!(widehatarrow.north east)+(.05em,.8ex)$)
-- ($(widehatarrow.north east)+(.05em,.4ex)$);%
}%
}
Now the height of \Widehatarrow{AB}
will be the same as the height of \widehat{AB}
and the sizes will be respected, as shown by trying
$\Widehatarrow{AB}=A_{\Widehatarrow{XY}}$