Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have the following:

\newcommand{\makeWord}[1]{%
\newcommand{\#1}{\textrm{#1}}}

\makeWord{AdditiveGroup}
\newcommand{\AdditiveGroup}{\textrm{AdditiveGroup}}

Unfortunately, I did not properly define the makeWord macro. How do I fix this?

share|improve this question

1 Answer 1

up vote 12 down vote accepted
\newcommand{\makeWord}[1]{%
\newcommand{\#1}{\textrm{#1}}}

\#1 is the two tokens \# (which would typeset a #) and 1 so is a syntax error as the first argument of \newcommand.

Try

\newcommand{\makeWord}[1]{%
  \expandafter\newcommand\csname#1\endcsname{\textrm{#1}}}

Note this will make a mathord token if used in math. If you want to make an operator like \log it needs to be

\newcommand{\makeWord}[1]{%
  \expandafter\newcommand\csname#1\endcsname{\mathop{\mathrm{#1}}}}

or use the amsopn \DeclareMathOperator command.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.