Extensible \vec instead of \overrightarrow

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


The \vec command uses \mathchar"017E as the arrow, while \overrightarrow uses \mathchar"3221. Both look like scaled versions of each other to me. So we can replicate \overrightarrow with the arrow tip of \vec. I propose two versions, a LaTeX one, and one following the amsmath route. For the amsmath version I give another variant that scales the minus horizontally to make it thinner.

\documentclass{article}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{kpfonts}
\newcommand*{\vv}[1]{\vec{\mkern0mu#1}}


\makeatletter
\newcommand{\vect}[1]{%
  \vbox{\m@th \ialign {##\crcr
  \vectfill\crcr\noalign{\kern-\p@ \nointerlineskip}
  $\hfil\displaystyle{#1}\hfil$\crcr}}}
\def\vectfill{%
  $\m@th\smash-\mkern-7mu%
  \cleaders\hbox{$\mkern-2mu\smash-\mkern-2mu$}\hfill
  \mkern-7mu\raisebox{-3.81pt}[\p@][\p@]{$\mathord\mathchar"017E$}$}

\newcommand{\amsvect}{%
  \mathpalette {\overarrow@\vectfill@}}
\def\vectfill@{\arrowfill@\relbar\relbar{\raisebox{-3.81pt}[\p@][\p@]{$\mathord\mathchar"017E$}}}

\newcommand{\amsvectb}{%
  \mathpalette {\overarrow@\vectfillb@}}
\newcommand{\vecbar}{%
  \scalebox{0.8}{$\relbar$}}
\def\vectfillb@{\arrowfill@\vecbar\vecbar{\raisebox{-4.35pt}[\p@][\p@]{$\mathord\mathchar"017E$}}}
\makeatother

\begin{document}
\begin{align}
  \mathchar"017E, \mathchar"3221\\
  \vec u,\ \vv u,\ \vv{OA},\ \vv{BC},\ \overrightarrow{AB} \\
  \vect{u}, \vect{OA}, \vect{BC}, \vect{AB}\\
  \amsvect{u}, \amsvect{OA}, \amsvect{BC}, \amsvect{AB}\\
  \amsvectb{u}, \amsvectb{OA}, \amsvectb{BC}, \amsvectb{AB}
\end{align}
\end{document}

sample output

Note that this kind of building extensible accents with minus signs and short arrows shows the typical LaTeX weakness that those accents render oddly on certain resolutions. The raise parameter -3.81pt is the best approximation I found to mitigate this problem. You might want to fiddle with it to get better results. Also, the third variant with scaled minus has yet another parameter (the 0.8 scaling factor) that probably needs fine-tuning.

The vertical space between the arrows and the letters is governed by the use of \overarrow@ from amsmath, so the space you get is the same as for \overrightarrow. If we want it a little lower, we make a new version of \overarrow@ and use that in \amsvect and \amsvectb:

\makeatletter
\def\my@overarrow@#1#2#3{\vbox{\ialign{##\crcr #1#2\crcr \noalign{\kern-\p@\nointerlineskip}$\m@th \hfil #2#3\hfil $\crcr}}}

\newcommand{\amsvect}{%
  \mathpalette {\my@overarrow@\vectfill@}}
\def\vectfill@{\arrowfill@\relbar\relbar{\raisebox{-3.81pt}[\p@][\p@]{$\mathord\mathchar"017E$}}}

\newcommand{\amsvectb}{%
  \mathpalette {\my@overarrow@\vectfillb@}}
\newcommand{\vecbar}{%
  \scalebox{0.8}{$\relbar$}}
\def\vectfillb@{\arrowfill@\vecbar\vecbar{\raisebox{-4.35pt}[\p@][\p@]{$\mathord\mathchar"017E$}}}
\makeatother

The magic number here is the \kern-\p@ in \my@overarrow, which pushes the arrow one point deeper. Again, this is open for fine tuning. Note that this is the same value that is already used in \vect.