[Tex/LaTex] ConTeXt : equivalent to LaTeX esvect

contextvector

When using LaTeX, I used the esvect package, which has the following interesting features :

  • very well lengthed vector arrows
  • a lot of arrow versions
  • a particular attention given to vectors with subscripts

I can't find any equivalent in ConTeXt. I've found this conversation, but the result doesn't suit me, especially with the subscript case.
I tried to use directly esvect's code, but it seems to use LaTeX programming utilities (so it is not Plain TeX, and not usable as-is in ConTeXt). I've tried adapting it (the package is about 20 lines of code, so I thought it would be feasible), but since I'm not a TeX programmer at all, I quickly abandoned.

Is there a Plain TeX programmer who would be able to make such a small translation ? Or any other satisfying alternative ?

EDIT

I understand that I poorly asked the question : my aim is to use the features of the esvect package with ConTeXt. I asked for a Plain TeX version because I (wrongly, as Henri Menke explained in the comments) thought it was usable as-is with ConTeXt, and that it might be easier to produce or reach more programmers. Henri Menke provided a perfectly working Plain TeX version, but since it isn't usable with ConTeXt, it is not what I seeked in the end. Is it possible to have a ConTeXt version of this package ? Since I am neither a TeX programmer nor a metapost user, I don't know what should be the best way to handle it…
Thanks in advance.

SECOND EDIT

Since @Aditya asked me to explain my problem in a more clear way, I made a comparison (with the Palatino font, since it is the one I use) of what I can acheive with esvect, what is with done basically by LaTeX and by ConTeXt. Below are the codes, then the snapshots, then the details :

%% LaTeX code
\documentclass[11pt]{article}
\usepackage[sc]{mathpazo}
\linespread{1.05}
\usepackage{multicol}
\usepackage{amsmath}
\usepackage[g]{esvect}
\begin{document}
\begin{multicols}{2}
  esvect package
  \begin{equation*}
    \vv{F}_{\text{spring}\to M} = -k(x-\ell_{0})\vv*{u}{x}
  \end{equation*}
  \begin{equation*}
    \text{correct } \vv{AB}, \vv{\imath}
  \end{equation*}
  \begin{equation*}
    \vv*{u}{x} \text{ more adapted than } \vv{u}_{x}
  \end{equation*}
  \begin{equation*}
    \vv{v} = -\vv{grad}\phi
  \end{equation*}

  out of the box
  \begin{equation*}
    \vec{F}_{\text{spring}\to M} = -k(x-\ell_{0})\vec{u}_{x}
  \end{equation*}
  \begin{equation*}
    \text{awful }\vec{AB}, \text{ correct } \vec{\imath}
  \end{equation*}
  \begin{equation*}
    \vv*{u}{x} \text{ better arrow, worse spacing than } \vec{u}_{x}
  \end{equation*}
  \begin{equation*}
    \vec{v} = -\vec{grad}\phi
  \end{equation*}
\end{multicols}
\end{document}

% ConTeXt code
\usemodule[simplefonts]
\definefontfeature[default][default][onum=yes]
\setupbodyfont[11pt,palatino]

\starttext
\startformula
  \vec{F}_{\text{spring}\to M} = -k(x-\ell_{0})\vec{u}_{x}
\stopformula
\startformula
  \text{correct } \vec{AB}, \vec{\imath}
\stopformula
\startformula
  \text{neither } \vec{u}_{x} \text{ nor } \vec{u_{x}}
\stopformula
\startformula
  \vec{v} = -\vec{grad}\phi
\stopformula
\stoptext

Below is the result with LaTeX:
enter image description here

And below is the result with ConTeXT
enter image description here

Finally, what I seek in esvect can be summarized as this :

  • On one-letter vectors, the arrow is a bit longer on both sides, and I find it much more readable
  • On vectors with subscripts, it still makes arrows a bit longer, but also correct the spacing, so that the subscript is already under the arrow tip (I think the correction could be a bit stronger though, but I'm not thinking that this level of detail is important now)
  • On multi-letters vectors, it behaves naturally as \overrightarrow, which ConTeXt does out of the box
  • Some special cases such as the grad or ìmath are not perfect but acceptable in my opinion
  • I prefer esvect's arrow look, but palatino's is fine by me

Maybe I could use TikZ to create my vector commands, but even if I have experience of TikZ I never did this kind of programming (I only drawed pre-defined plots).

Best Answer

I managed to convert esvect to Plain TeX. However, I couldn't get it to work in ConTeXt.

\catcode`@=11

% load fonts
\font\tenvec=vect10 at 10pt
\font\sevenvec=vect7 at 7pt
\font\fivevec=vect5 at 5pt

%% define new family
\newfam\vecfam
\textfont\vecfam=\tenvec
\scriptfont\vecfam=\sevenvec
\scriptscriptfont\vecfam=\fivevec

%% convert count register to hex
\def\thehex#1{\ifcase#1 0\or 1\or 2\or 3\or 4\or 5\or 6\or 7\or 8\or 9\or
  A\or B\or C\or D\or E\or F\fi}

%% define symbols
\mathchardef\fldr="3\thehex\vecfam 12 % adjust here to select another arrow
\mathchardef\montraita="3\thehex\vecfam 20
\mathchardef\montraitd="3\thehex\vecfam 23

%% copied from esvect.sty (with little adjustments)
\def\relbareda{\mathrel{\mathpalette\mathsm@sh\montraita}}
\def\relbaredd{\mathrel{\mathpalette\mathsm@sh\montraitd}}
\def\vv{\futurelet\ifstar\dovv}
\def\dovv{\ifx*\ifstar\expandafter\vvstar\else\expandafter\ESV@vecteur\fi}
\def\vvstar*#1#2{\ESV@vecteur{#1}_{\mkern-1mu\relax#2}}
\def\ESV@vecteur{\mathpalette{\overvect@\vectfill@}}
\def\vectfill@{\traitfill@\relbaredd\relbareda\fldr}
\def\traitfill@#1#2#3#4{%
  $\m@th\mkern2mu\relax#4#1\mkern-1.5mu%on met \relbaredd au d\'ebut
   \cleaders\hbox{$#4\mkern0mu#2\mkern0mu$}\hfill%remplit avec relbareda
   \mkern-1.5mu#3$%
}
\def\overvect@#1#2#3{\vbox{\ialign{##\crcr%
 \noalign{\kern-.7pt\nointerlineskip}#1#2\crcr%
 \noalign{\kern-.3pt\nointerlineskip}$\m@th\hfil#2#3\hfil$\crcr}}}

%% We'd need these from plain.tex if we would run in ConTeXt
%\def\m@th{\mathsurround\zeropoint}
%\def\mathsm@sh#1#2{\setbox\z@\hbox{$\m@th #1{#2}$}\finsm@sh}
%\def\finsm@sh{\ht\z@\z@ \dp\z@\z@ \box\z@}

\catcode`@=12

%% Test:

Some examples from the manual:

$\vv{E}$, $\vv{AB}$, $\vv{\imath}$ and $\vv{u}$

$\vv*{e}{r}$ and $\vv*{L}{\Delta}$

$\vv{E}_{\vv{u}_{\vv{u}}}$

\bye

enter image description here

Related Question