# New command based on command name

I had this idea that would save me a considerable amount of time in writing my thesis. Here's the deal: I need to typeset lots of equations with vectors and matrices in them. I'd like my vectors in boldface, lowercase and my matrices in boldface, uppercase. For a vectors and matrices I've defined the following in my preamble:

\renewcommand{\v}[1]{\ensuremath{\boldsymbol{#1}}}
\newcommand{\m}[1]{\ensuremath{\boldsymbol{\uppercase{#1}}}}


In context, I use \v{x} to typeset a vector x, etc.

However, wouldn't it be nice to be able to typeset \vx to create that same vector x. Then, if I'm writing about a vector a, b and c, I can just write \va, \vb and \vc.

Is this possible in LaTeX?

-
It is possible to define all those macros but you could just do \v a and it would work without any extra definitions at all also note that for latin letters \mathbf{a} much more efficient than \boldsymbol{a} which has to generate a new math list and set the argument four times in different styles before choosing which to use. –  David Carlisle Nov 23 '12 at 13:21
I'd recommend against using command names such as \vx, \vy and so on. You're bound to forget very soon their meaning. I surely recommend against using \ensuremath for this kind of application. Use \renewcommand{\vec}[1]{\bm{#1}} (loading the bm package). Do not redefine \v (\vec is safe, instead). –  egreg Nov 23 '12 at 13:55
Running off of @egreg's suggestion, if the length of typing is the issue, I would just go ahead and actually do the \va, \vb, etc. (not necessarily defining them) and then just doing a regex-replace on them when you're ready to compile. –  Sean Allred Nov 24 '12 at 0:33
@DavidCarlisle sounds like an answer to me :) –  cmhughes Nov 24 '12 at 2:43

If you use extensively bold math italic for your vectors and matrices, the best solution is to define a new symbol font:

\DeclareMathAlphabet{\mathbmit}{OML}{cmm}{b}{it}


and then doing

\renewcommand{\vec}[1]{\mathbmit{#1}}
\let\matr\vec


(or, in the "macho programmer way", \renewcommand{\vec}{\mathbmit}). If a matrix is called "A", there is little sense in inputting it as \matr{a}, in my opinion.

Abbreviations such as \va, \vb and so on can be defined, but the biggest risk is to forget the commands' meaning in a short time. If you really want to follow this path, then here's how:

\documentclass{article}

\DeclareMathAlphabet{\mathbmit}{OML}{cmm}{b}{it}
\renewcommand{\vec}[1]{\mathbmit{#1}}
\let\matr\vec

\makeatletter
\@tfor\next:=abcdefghijklmnopqrstuvwxyxz\do
{\begingroup\edef\x{\endgroup
\noexpand\@namedef{v\next}{\noexpand\vec{\next}}%
}\x}
\@tfor\next:=ABCDEFGHIJKLMNOPQRSTUVWXYZ\do
{\begingroup\edef\x{\endgroup
\noexpand\@namedef{m\next}{\noexpand\matr{\next}}%
}\x}
\makeatother

\begin{document}
This is a vector $\vx$ and this is a matrix $\mA$.

This is a vector $\vec{x}$ and this is a matrix $\matr{A}$.

Also $\matr{\Gamma}$ works.
\end{document}


Using \ensuremath is, in my opinion, wrong, as these are mathematical entities and so they should always be in explicit math mode.

-