# \newcommand with variable name

I am typesetting a long mathematical text (lecture notes), in which I use the alphabets

\mathbb A
\mathcal A
\mathfrak A


very often, so I decided to name them

\A \sA \fA


(For bb A, script A, fraktur A resp.). Now I want to shorten my preamble by creating a helper

\newcommand{\mathletter}[1]{%
\newcommand{\#1}{\mathbb #1}
\newcommand{\s#1}{\mathcal #1}
\newcommand{\f#1}{\mathfrak #1}
}


which doesn't work since the \#1 etc. seem to not be expanded.
How can I wirte a macro which defines those three commands given a single letter as input?

Thanks for any help.

• It is strange. Why not define 3 new commands? If your code works what would you type: \mathletter{A}? – Sigur Jan 27 '14 at 14:23
• Because that means 26*3 = 78 lines of code vs. 36+5 = 41 lines, about half and much more readable than a bunch of \newcommand{\X}{\mathbb X} lines – AlexR Jan 27 '14 at 14:26
• This might be what you're looking for: tex.stackexchange.com/questions/28704/… – Snicksie Jan 27 '14 at 14:30
• Does this suffice: \documentclass{article} \usepackage{amssymb} \def\B#1{\mathbb #1} \def\C#1{\mathcal #1} \def\F#1{\mathfrak #1} \begin{document} $\B A \C A \F A$ \end{document} – Steven B. Segletes Jan 27 '14 at 14:34
• @AlexR, you don't need to retype. You can use Find/Replace tools. – Sigur Jan 27 '14 at 14:37

Thanks to @Snicksie, I have been able to come up with the following:

Note that this is not really "beautiful" and that it overwrites the commands \H,\L,\O,\P,\S but I have confirmed that I need none of them and "manually" undefined them so I get errors when I oversee any other commands.

\newcommand{\mathletter}[1]{%
\expandafter\newcommand\csname #1\endcsname{\mathbb #1}
\expandafter\newcommand\csname s#1\endcsname{\mathcal #1}
\expandafter\newcommand\csname f#1\endcsname{\mathfrak #1}
}%
\let\H\undefined
\let\L\undefined
\let\O\undefined
\let\P\undefined
\let\S\undefined
\mathletter A
\mathletter B
\mathletter C
...
\mathletter Z


Another very elegant solution, thanks to @StevenB.Segelets is to define:

\def\B#1{\mathbb #1}
\def\C#1{\mathcal #1}
\def\F#1{\mathfrak #1}


And use those slighly different commands then. This doesn't redefine any existing macros and therefor is probably a cleaner solution, but requires to change previous syntax (\A, \sA, \fA) in all documents and thus requires some "rewriting".