I have some latex code that goes a bit like this:
% Sp defines a generic command for an arbitrary space,
% and all of the others just delegate the bulk of their
% work to it so that when I decide to change the formatting,
% I can in one place.
\newcommand{\Sp}[2]{\textrm{#1}\left(#2\right)}
\newcommand{\Nul}[1]{\Sp{Nul}{#1}}
\newcommand{\Col}[1]{\Sp{Col}{#1}}
\newcommand{\Row}[1]{\Sp{Row}{#1}}
% Some common vectors, so I don't have to repeatedly type
% \vec{x}_1:
\newcommand{\u}{\vec{u}}
\newcommand{\v}{\vec{v}}
\newcommand{\w}{\vec{w}}
\newcommand{\x}{\vec{x}}
\newcommand{\y}{\vec{y}}
The work I'm doing is in linear algebra, where I need to use these vectors a lot. So, defining shorter commands seems pretty natural. But when papers start getting longer, I end up with either half the alphabet being defined as different commands -- one for each letter.
So I tried to define a command that just defines another command so that I could just put it in a loop...
\newcommand{\MkVec}[1]{\expandafter\def\#1{\vec{#1}}}
and several variations thereupon... But the closest I came to a working model was when the error that the compiler gave me changed to missing \begin{document}
.
Can someone explain or give a source to learn more about what I should be doing (or if there's a better way after all) to define dynamic commands? Note that this specific instance is just one example. I'm interested in doing LaTeX metaprogramming, not rendering vectors nicely specifically.