5

I want to customize a command \myvec{arg}.

If the argument is a single character, then \bm{arg}

else then \vv{arg}

Alan Munn
  • 218,180

1 Answers1

10

Adapting code from:

the following seems to work:

\documentclass{article}
% This code by Hendrik Vogt https://tex.stackexchange.com/a/70562/2693
\newcommand*\ifsingle[3]{%
  \setbox0\hbox{$\mathaccent"0362{#1}^H$}%
  \setbox2\hbox{$\mathaccent"0362{\kern0pt#1}^H$}%
  \ifdim\ht0=\ht2 #3\else #2\fi
  }
\usepackage{bm}
\def\vv{} % define as needed
\newcommand*\myvec[1]{\ifsingle{#1}{\bm{#1}}{\vv{#1}}}
\begin{document}
$\myvec{a}$
$\myvec{aa}$
$\myvec{\alpha}$
$\myvec{\alpha\beta}$
\end{document}

output of code

Alan Munn
  • 218,180