I am attempting to make a macro shortcut for the \mathrm
command from amsmath
.
My idea is that in lieu of writing, for example, \mathrm{R}
to get the Roman R
in math mode, I'd like to enter \RR
instead. Likewise, suppose I wanted Roman P
, I'd like instead to enter \PP
.
The following MWE gets me the Roman R
symbol, but I'd like this to be maximally flexible for any letter without having to define 52 separate \aa
, \bb
, \cc
commands.
\documentclass{book}
\usepackage{amsmath}
\newcommand{\RR}{\mathrm{R}}
\begin{document}
$ \RR$
\end{document}
Best Answer
Here, I used, to demonstrate, the three-letter sequence, since many two-letter combos are already taken.
For lower-case, an identical loop can be added with only the limits changed to
\foreach\i in{a,...,z}
.Percusse provided a more arcane version of the definition, which is nonetheless illustrative:
Nonetheless, David's suggestion of
\newcommand\R{\mathrm}
, which requires a slightly different syntax, is a better approach overall. I did it this way just to show it could be done.