[Tex/LaTex] Half arrow esvect

arrows

I use \vv{} from esvect for arrows above letters. I would like to make a half-arrow, with only half the ending arrow, similarly to \overrightharpoon (Half arrow) but that has a shape and length compatible with \vv (Like this).

I looked at the code for \vv but I do not understand it…

Note: I don't have to use esvect, I can use another package with nice looking arrows.

Best Answer

The metrics in \hvec are font dependent and the method likely has additional drawbacks. For example, the horizontal kerning is not quite right on the A as can be seen. But that said...

\documentclass{article}
\usepackage{mathtools,trimclip,stackengine,scalerel}
\newsavebox\tmpbox
\newcommand\hvec[1]{\ThisStyle{%
  \setbox0=\hbox{$\SavedStyle#1$}
  \setbox2=\hbox{$%
    \clipbox{0pt{} \dimexpr\ht0+1.68\LMpt{} -.2\LMpt{} 0pt}{%
      $\SavedStyle\mathaccent"017E{\phantom{\SavedStyle #1}}$}\kern-.2\LMpt$}
    \ensurestackMath{\stackengine{1.3\LMpt}{\SavedStyle#1}{\copy2}{O}{c}{F}{F}{S}}
}}
\begin{document}
$\vec A \vec a ^2 \scriptscriptstyle \vec A \sqrt{\vec a} $

$\hvec A \hvec a  ^2\scriptscriptstyle \hvec A \sqrt{\hvec a} $
\end{document}

enter image description here

Here is the variant compatible with the \vv style. Similar disclaimers apply:

\documentclass{article}
\usepackage{mathtools,trimclip,stackengine,scalerel,esvect}
\newsavebox\tmpbox
\newcommand\hvv[1]{\ThisStyle{%
  \setbox0=\hbox{$\SavedStyle#1$}
  \setbox2=\hbox{$%
    \clipbox{0pt{} \dimexpr\ht0+2.05\LMpt{} 0pt -1pt}{%
      $\SavedStyle\vv{\phantom{\SavedStyle #1}}$}$}
    \ensurestackMath{\stackengine{1.7\LMpt}{\SavedStyle#1}{\copy2}{O}{c}{F}{F}{S}}
}}
\begin{document}
$\vv A \vv a ^2 \scriptscriptstyle \vv A \sqrt{\vv a} $

$\hvv A \hvv a  ^2\scriptscriptstyle \hvv A \sqrt{\hvv a} $
\end{document}

enter image description here