[Tex/LaTex] Extensible \vec instead of \overrightarrow

arrowskpfontsvector

Instead of changing to \overrightarrow{}, which uses a usual extensible arrow and puts it above the argument, I would like to get an extensible \vec{} symbol. My intention is to obtain a new command \vect{}, for instance, which is exactly the same as \overrightarrow{} but the head is the \vec symbol (and the extensible part is done with the aproppiate ā€œ\relbarsā€, which I don't know).

In my case I'm using kpfonts package.

\documentclass{scrartcl}
\usepackage{kpfonts}
\newcommand*{\vv}[1]{\vec{\mkern0mu#1}}
\begin{document}
\[
    \vec u,\ \vv u,\ \vv{OA},\ \vv{BC},\ \overrightarrow{AB}
\]
\end{document}

I defined the \vv{} command because the usual \vec gives you a misaligned arrow.

enter image description here

EDIT:
As @GonzaloMedina pointed, there exists the esvect package. But, in my opinion, it doesn't provide any arrow with a head matching the style of kpfonts.

Best Answer

Here I introduce \xshlongvec that takes an optional and mandatory argument. The mandatory is the text over which to lay the \vec. The optional is a number which represents the rightward kern (in points) applied to the vec arrow, since as the OP points out, the kerning of \vec is not the best.

In this MWE, I use the kpfonts mentioned by the OP. I first give the unaltered \vec followed by two instances of \xshlongvec. The one flaw that I note is that the left end of the arrow is not slanted like \vec, but is square as the result of being created by a \rule.

Thanks to Phillipe for pointing out a deficiency in the original answer, since repaired.

\documentclass[12pt]{scrartcl}
\usepackage{kpfonts}
\usepackage{stackengine}
\usepackage{calc}
\newlength\shlength
\newcommand\xshlongvec[2][0]{\setlength\shlength{#1pt}%
  \stackengine{-5.6pt}{$#2$}{\smash{$\kern\shlength%
    \stackengine{7.55pt}{$\mathchar"017E$}%
      {\rule{\widthof{$#2$}}{.57pt}\kern.4pt}{O}{r}{F}{F}{L}\kern-\shlength$}}%
      {O}{c}{F}{T}{S}}
\begin{document}
\centering
\[ \vec{A} \quad \xshlongvec[1]{ABC} \quad \xshlongvec[1]{xyz} \]
\end{document}

enter image description here


This EDITED solution below works across math styles, by using the scalerel package.

\documentclass[12pt]{scrartcl}
\usepackage{kpfonts}
\usepackage{stackengine,scalerel}
\usepackage{calc}
\newlength\shlength
\newcommand\xshlongvec[2][0]{\ThisStyle{\setlength\shlength{#1\LMpt}%
  \stackengine{-5.6\LMpt}{$\SavedStyle#2$}{\smash{$\kern\shlength%
    \stackengine{\dimexpr 1.3pt+6.25\LMpt}{$\SavedStyle\mathchar"017E$}%
      {\rule{\widthof{$\SavedStyle#2$}}{\dimexpr.1pt+.5\LMpt}\kern.4\LMpt}{O}{r}{F}{F}{L}\kern-\shlength$}}%
      {O}{c}{F}{T}{S}}}
\begin{document}
\centering
\[ \vec{A} \quad \xshlongvec[1]{ABC} \quad \xshlongvec[1]{xyz} \quad \xshlongvec{\Omega M} \]
\[ \scriptstyle \vec{A} \quad \xshlongvec[1]{ABC} \quad \xshlongvec[1]{xyz} \quad \xshlongvec{\Omega M}\]
\[ \scriptscriptstyle \vec{A} \quad \xshlongvec[1]{ABC} \quad \xshlongvec[1]{xyz} \quad \xshlongvec{\Omega M} \]
\end{document}

enter image description here

Related Question