5

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

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

else then \vv{arg}

2
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

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.