TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
Definining commands/abbreviations that contain numbers
newcommand name cannot include numbers for example \Mycomand123

It seems like command names starting with a numeral are not valid when using \newcommand but are valid when using \def. Are there any reasons not to define commands starting with a numeral? For example:

\newcommand{\123MHz}{\SI{123}{MHz}\xspace}  % Causes errors
\def\123MHz{\SI{123}{MHz}}   % seems to work fine
share|improve this question

marked as duplicate by egreg, Loop Space, Peter Grill, Tom Bombadil, diabonas Sep 21 '12 at 9:47

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

they can not have a digit anywhere in the name, it is not just a restriction on starting with a digit. (It is possible to change the catcode of digit to 11 so they become letters then you can use them in names but you can not use them in lengths and other places.) – David Carlisle Sep 21 '12 at 8:58
Is this only a restriction of \newcommand? This code works fine for \def. – Mike Sep 21 '12 at 8:59
Don't do it. Use only letters for command names. Your \def doesn't define \123MHz but \1 with special parameters. If you would add a definition for e.g. \145MHz the first definition will break. – Ulrike Fischer Sep 21 '12 at 9:01
@DavidCarlisle provides a good solution here at question 66666: newcommand name cannot include numbers for example \Mycomand123 for commands with numbers (although don't think they can start with a number). – Peter Grill Sep 21 '12 at 9:11
@Mike: I would gave the numbers names that reflect their meaning. \pi is imho a much better command name than \3.14. Also in case you got the number wrong you won't have to change all the \123 to \132. – Ulrike Fischer Sep 21 '12 at 9:17
up vote 2 down vote accepted

As far as I know, command names should use only letters, and as such, numbers are considered valid command delimiters.

For example:

\newcommand{\foo123}{blabla} % should raise an error
\newcommand{\foo}[1]{Argument is #1 ;} % typing \foo123 will be typeset as : "Argument is 1 ;23"

I can only assume the first definition is rejected by the compiler in order not to conflict with the second.

share|improve this answer
The first is rejected because it's syntactically incorrect. The first argument to \newcommand should be a backslash followed either by any number of letters (A-Za-z) or by a single nonletter. – egreg Sep 21 '12 at 9:09
@egreg: OP's question was about the reasons behind this syntactic restriction. – T. Verron Sep 21 '12 at 9:12
@t.verron should he perhaps be referred to the tex book? it was knuth's decision, so any rationalisation by us is probably useless. – wasteofspace Sep 21 '12 at 9:56

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