41

I have two variables: \vec{x} and another one which is somehow dual to the first. Therefore I would like to symbolize the second with something similar but a leftarrow on top of the x. I already tried \stackrel{leftarrow}{x} but it looks to different (too big gap between x and the arrow, and too big arrow).

Is there a way to define a \cev command which does what I want?

cknoll
  • 715

7 Answers7

23

A \cev command that seems to give good results on most letters and works correctly (apart a very small drift) in subscripts and superscripts.

\documentclass{article}
\usepackage{graphicx,accents}

\makeatletter
\DeclareRobustCommand{\cev}[1]{%
  \mathpalette\do@cev{#1}%
}
\newcommand{\do@cev}[2]{%
  \fix@cev{#1}{+}%
  \reflectbox{$\m@th#1\vec{\reflectbox{$\fix@cev{#1}{-}\m@th#1#2\fix@cev{#1}{+}$}}$}%
  \fix@cev{#1}{-}%
}
\newcommand{\fix@cev}[2]{%
  \ifx#1\displaystyle
    \mkern#23mu
  \else
    \ifx#1\textstyle
      \mkern#23mu
    \else
      \ifx#1\scriptstyle
        \mkern#22mu
      \else
        \mkern#22mu
      \fi
    \fi
  \fi
}

\makeatother

\begin{document}
$Xx$

$X\cev{x}_{\cev{x}_{\cev{x}}}$ $\cev{a}\cev{b}\cev{m}\cev{X}$

$X\vec{x}_{\vec{x}_{\vec{x}}}$ $\vec{a}\vec{b}\vec{m}\vec{X}$

$\cev{\imath}$

$\vec{\imath}$
\end{document}

enter image description here

A different implementation:

\documentclass{article}
\usepackage{graphicx}

\makeatletter
\DeclareRobustCommand{\cev}[1]{%
  {\mathpalette\do@cev{#1}}%
}
\newcommand{\do@cev}[2]{%
  \vbox{\offinterlineskip
    \sbox\z@{$\m@th#1 x$}%
    \ialign{##\cr
      \hidewidth\reflectbox{$\m@th#1\vec{}\mkern4mu$}\hidewidth\cr
      \noalign{\kern-\ht\z@}
      $\m@th#1#2$\cr
    }%
  }%
}
\makeatother

\begin{document}
$Xx$

$X\cev{x}_{\cev{x}_{\cev{x}}}$ $\cev{a}\cev{b}\cev{m}\cev{X}$

$X\vec{x}_{\vec{x}_{\vec{x}}}$ $\vec{a}\vec{b}\vec{m}\vec{X}$

$\cev{\imath}$

$\vec{\imath}$

$\cev{\sigma}\cev{x}$
$\vec{\sigma}\vec{x}$
\end{document}

enter image description here

egreg
  • 1,121,712
21

This may not be the best way, but two \reflectbox commands will do the trick:

\documentclass{article}
\usepackage{graphicx}
\newcommand{\cev}[1]{\reflectbox{\ensuremath{\vec{\reflectbox{\ensuremath{#1}}}}}}
\begin{document}
\[
\vec{a} \quad \cev{a} \quad \vec{b} \quad \cev{b}
\]
\end{document}
Ian Thompson
  • 43,767
  • Thanks, but this causes problems with subscripts: Example On the right hand side the t is marked using \cev{t_{\mathring{r}}} and s is marked using \cev{s}_{\mathring{r}} I'd like to have the arrow centered over the whole symbol (including subscript) as it is in the case of t on the left. – C-Otto May 26 '14 at 07:26
  • In your example, the arrow over the t on the left does not appear to be centred over the whole symbol including the superscript to me. On the other hand, \cev{t_{\mathring{r}}} seems to give exactly what you want. – Ian Thompson May 26 '14 at 11:25
  • \cev{t_{\mathring{r}}} is shown on the right. And \cev{t_r} is shown on the left, where the arrow is a bit more centered than in the case of \cev{t}_r. I'm happy with the looks on the left side, but the right side obviously is wrong. – C-Otto May 26 '14 at 15:09
  • This could be a problem with the font you are using; the result of \cev{t_{\mathring{r}}} on my machine looks nothing like yours! Please post a new question with a complete example code that reproduces the problem. – Ian Thompson May 27 '14 at 07:41
  • I can't use \cev in figure captions? – Matt Feb 13 '20 at 07:45
  • 1
    @Matt --- try \protect\cev{x} – Ian Thompson Feb 13 '20 at 11:25
  • @IanThompson, that did the trick. Cheers – Matt Feb 13 '20 at 11:30
11

The extensible \overleftarrow might do the trick. The problem is that the arrow is bigger than the one used for \vec, as shown by \[\overleftarrow{a}\overrightarrow{a}\vec{a}\] . To have consistent arrows, you should redefine $\vec$ :

\documentclass{minimal}
\renewcommand\vec[1]{\overrightarrow{#1}}
\newcommand\cev[1]{\overleftarrow{#1}}

\begin{document}
\[\cev{a}\vec{a}\]
\end{document}

Edited to add:

Another solution is the \overset command from amsmath, used with \leftarrow. However, the arrow is still bigger than the one from the \vec command.

\documentclass{minimal}
\usepackage{amsmath}
\begin{document}
\[\overset{\leftarrow}{v}\overset{\rightarrow}{v}\vec{v}\]
\end{document}

*Edited to add * Using \shortleftarrow from the stmaryrd package slightly improves the above construction.

egreg
  • 1,121,712
6

I have a little to add to Frederic's solution:

\usepackage{stmaryrd}

\overset{\shortleftarrow}{a} \quad \vec{a} \quad \overset{{}_{\shortleftarrow}}{a}

Basically, the arrow in the subscript makes it smaller and reduces the vertical space between it and the variable. Unfortunately, nesting doesn't seem to work.

enter image description here

percusse
  • 157,807
Herng Yi
  • 615
6

The \vec is an accent (and its own symbol; hence all \leftarrow and similar constructs look different), and the default Computer Modern font doesn't have a symbol which would be its mirror.

In addition to rotating/mirroring the vec accent symbol, as shown by Ian, you could make use of one provided by, say, STIX/XITS (if you use XeTeX). Then you could define:

\def\cev{\XeTeXmathaccent"0"1"20D6}
% The first number ("0) denotes the math type (0=Ord,1=Op,2=Bin,3=Rel,etc.)
% The second number ("1) denotes the math family (0=Roman,1=Italic,etc.)
% The last number ("20D6) denotes the actual glyph slot
$\cev a \qquad \vec a$

Which could look like: cevvec

morbusg
  • 25,490
  • 4
  • 81
  • 162
0

Eberhard Mattes provided in the 90s an extra font called emsy containing the missing arrow. The file is downloadable here

https://www.pcorner.com/list/EMTEX

Anyway, it's not easy to use since you have to put the .mf and .tfm files in the correct directory. Once this is done, you may define

\newcommand{\cev}[1]{\mathaccent"7A00{\mkern1mu{#1}}}
Stefan Pinnow
  • 29,535
0

(Copied from What is to `\vec` as `\overleftarrow` is to `\overrightarrow`?)

The standard Computer Modern Math font only has a right arrow (in position "7E or 126 in decimal). It has however no left arrow. enter image description here

The STIX font provides both a left arrow (in position "91 or 145 in decimal) and a right arrow (in position "92 or 146 in decimal). enter image description here

\documentclass{article}

\DeclareFontEncoding{LS1}{}{} \DeclareFontSubstitution{LS1}{stix}{m}{n} \DeclareSymbolFont{stixletters}{LS1}{stix}{m}{it} \DeclareMathAccent{\cev}{\mathord}{stixletters}{"91} \DeclareMathAccent{\vec}{\mathord}{stixletters}{"92} \DeclareMathAccent{\vecev}{\mathord}{stixletters}{"95}

\begin{document}

$\vec{a}, \cev{a}$

$\vec{A}, \cev{A}$

Bonus: $\vecev{a}, \vecev{A}$

\end{document}

enter image description here

user94293
  • 4,254
  • Seems interesting. However if I run this on debian 12 with texlive installed I get the error: The nfss system isn't set up properly. The answer should mention some non-standard dependency. – cknoll Aug 21 '23 at 18:41