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.

Given:

\documentclass{minimal}
\newcommand{\emrule}[1]{\rule[4pt]{#1em}{0.2pt}}
\newcommand{\endash}{\emrule{.5}}
\begin{document}
2000\endash2013
\end{document}

I get:

! LaTeX Error: Command \endash 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.3 \newcommand{\endash}{\emrule{.5}}

? 

So my first question is what manual---see p.192 of the manual.? Through experimentation I believe that what is going on here is a name clash. The processor sees \end and hits the brake with an attendent error message. For instance \EMdash and \enrule both work without error. Since I lack sufficient macro-foo, could someone with greater knowledge than I please clarify? BTW if I comment out the definition of \endash it fails with a message about \endash not defined:

! Undefined control sequence.
l.5 2000\endash
               2013
? 

Which leads me back to my contention that this is a name clash with just \end.

share|improve this question
    
You could try just changing the name. I tend to start my macros with an uppercase letter and a prefix -- although this is not guaranteed to always work, I haven't had a problem yet. So for example something like \HSEndash, \HSEmdash, \HSMyMacro, etc. –  Peter Grill Jan 22 '13 at 18:52
    
@PeterGrill note that I said that \EMdash or for that matter ENdash both work. I'm not looking for a fix, just an explanation, thanks though. –  hsmyers Jan 22 '13 at 18:54
    
:-) I guess I really should read the question. :-) –  Peter Grill Jan 22 '13 at 18:59
    
@PeterGrill Slashdot idiom would be RTFQ, but I've always found that a bit rude :) –  hsmyers Jan 22 '13 at 19:11
    
+1 for asking "What manual?" –  Ari Brodsky May 30 '13 at 5:53
add comment

1 Answer 1

up vote 9 down vote accepted

\newcommand explicitly refuses to define macros whose name begins with end. This may have been a disputable design decision, but the LaTeX kernel is kind of frozen and changing this behavior after so many years would open big problems. With \NewDocumentCommand from the xparse package you're freed from this restriction:

\usepackage{xparse}
\NewDocumentCommand{\endash}{}{\emrule{.5}}

Another way can be to test if the command already exists in a different way:

\unless\ifdefined\endash
  \def\endash{\emrule{.5}}
\fi

relying on lower level TeX constructions.

Are there any problems with this? Yes, there are. If you later on say

\newenvironment{ash}
 {something maybe related to cricket at the start}
 {something else at the end}

you'd find yourself in big trouble, because this declaration would silently redefine your \endash command: indeed the ash environment uses \ash and \endash at start and finish.

share|improve this answer
    
Extremely good to know! I've suffered from this disease in virtually every compiler I've used---And I've used a lot. Can't quite see why folks seem to miss the notion that they shouldn't place restrictions on users particularly by accident! <sigh/> BTW, I not particularly happy about no numbers is macro names either... –  hsmyers Jan 22 '13 at 19:00
1  
@hsmyers Numbers in macro names would pose difficult problems; remember that TeX is primarily a language for typesetting, so some limitations are present for reasons related to this primary task (or because of Knuth's view of it). The "end" restriction is due to how environments are implemented. If later you define an ash environment, you'd be in big troubles. –  egreg Jan 22 '13 at 19:03
    
Also good to know. Could you explain what manual the reference mentions? I'd guess LaTeX Companion, but I'd like to know for sure (likewise what edition). –  hsmyers Jan 22 '13 at 19:07
1  
@hsmyers The manual referred to is "LaTeX, a document preparation system" by L. Lamport (the original author of LaTeX). –  egreg Jan 22 '13 at 19:10
    
That would explain why the page didn't seem to be in context. Good thing I've got both :) –  hsmyers Jan 22 '13 at 19:13
add comment

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.