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.

Consider the following code:

\documentclass{memoir}
\newcommand{\cs}{\Sigma}
\title{Rings and Modules}
\author{}
\begin{document}
\maketitle
\end{document}

This fails to compile and I get the following error.

 ! LaTeX Error: Command \cs already defined.
           Or name \end... illegal, see p.192 of the manual.

 See the LaTeX manual or LaTeX Companion for explanation.
 Type  H <return>  for immediate help.
 ...                                              

 l.2 \newcommand{\cs}{\Sigma}

P.S. The code is perfectly fine with amsart class. Also, please tell me what is "the manual" referred to in the error message.

share|improve this question
3  
egreg mentions to me in the chat that: The "p. 192" refers to the LaTeX manual. -- "LaTeX, a document preparation system", by Leslie Lamport. –  kan Jul 19 '12 at 7:54
1  
I would also mention, that such short cuts make the code a lot harder to understand for others. –  daleif Jul 19 '12 at 9:58

2 Answers 2

up vote 8 down vote accepted

The file memoir.cls has this line

\DeclareRobustCommand{\cs}[1]{\texttt{\char`\\#1}}

which is meant to print control sequence names: \cs{cs} would print \cs. It doesn't seem a crucial command so you can use a known trick to redefine it without worries about it being defined or not:

\providecommand{\cs}{}
\renewcommand{\cs}{\Sigma}

This is safe both with the standard LaTeX classes, AMS classes and memoir. If you use another class, it's best to comment out the first line and see what happens. If the command is defined, try and look at its definition.

share|improve this answer
    
Thank you for the answer. A very enlightening answer from both you and @lockstep. –  kan Jul 19 '12 at 7:56
    
The solution here will sort, but I'd be wary of defining \cs other than for the reason memoir does. It's pretty commonly used, not just by memoir, so it's (almost) a 'standard' macro. –  Joseph Wright Jul 19 '12 at 8:26
1  
@JosephWright I guess that in a math paper one doesn't need to print control sequence names. :) –  egreg Jul 19 '12 at 8:31
1  
@egreg True, but in the spirit of a my LaTeX3 work I'm keen on the idea of a larger 'defined' set of commands which are defined irrespective of document class in use. This is an area that still needs thought, of course. –  Joseph Wright Jul 19 '12 at 8:33

The memoir class indeed includes the following definition of \cs:

\DeclareRobustCommand{\cs}[1]{\texttt{\char`\\#1}}

It is used to format in-text-examples of control sequences.

\documentclass{memoir}
%\newcommand{\cs}{\Sigma}
\title{Rings and Modules}
\author{}
\begin{document}
\maketitle
\cs{mycommand}
\end{document}

enter image description here

share|improve this answer
    
Thank you for your answer. It was indeed enlightening. –  kan Jul 19 '12 at 7:55

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.