\providecommand{\s2}{\ensuremath{\sigma_{2}}\xspace}
triggers
! LaTeX Error: Missing \begin{document}.
The problem goes away if I change my command from \s2 to \stwo, so it's
clear that LaTeX has a probelm wiht a numeral used like this. It looks
like numeral is not recognized as part of the command, and everthing
goes to pieces after that. Is there a good workaround for this?
Thanks, Eric
No.
--
Morten
It has no problem: it doesn't accept s2 as a macro name, that's all. You
can use only letter for a multiletter macro name. For LaTeX, a letter is
a..z and A..Z (by default).
> It looks
> like numeral is not recognized as part of the command,
Indeed.
> and everthing
> goes to pieces after that. Is there a good workaround for this?
You can define and use macro which "strange" name. For that,
\@namedef define this kind of macro and \@nameuse... use thess macros.
You have to enclose the code between \makeatletter and \makeatother (to
"make @ a letter" and "make @ a other = noletter"). Example:
\makeatletter
\@namedef{s2}{my definition}
...
\@nameuse{s2}
...
\makeatletter
Nevertheless, it's a bad idea to use this syntax inside your document.
It's only for internal use (preambles, packages, or classes). Inside the
document, a better idea is to use parameters. Example:
\newcommand*\s[1]{\ensuremath{\sigma_{#1}}\xspace}
Jean-Côme Charpentier
snip...
> You can define and use macro which "strange" name. For that,
> \@namedef define this kind of macro and \@nameuse... use thess macros.
> You have to enclose the code between \makeatletter and \makeatother (to
> "make @ a letter" and "make @ a other = noletter"). Example:
>
> \makeatletter
> \@namedef{s2}{my definition}
> ...
> \@nameuse{s2}
> ...
> \makeatletter
>
> Nevertheless, it's a bad idea to use this syntax inside your document.
> It's only for internal use (preambles, packages, or classes). Inside the
> document, a better idea is to use parameters. Example:
>
> \newcommand*\s[1]{\ensuremath{\sigma_{#1}}\xspace}
Ouch. I use paramemters like the above all the time, but for some
reason I was looking right past that simple solution. Seeing the
alternatives, I'll take your suggestion. Thanks. EMA
\documentclass{article}
\newcommand\s[1]{\ensuremath{\sigma_{#1}}\xspace}
\begin{document}
The first expression is $\s a$, the second sigma is \s2 and the last one is
\s{n^2}.
\end{document}
The only 'problem' would be when the argument to the sigma is more than one
character or a non-number, you will need a space or {brackets} respectively.
Regards
Michael.
: The problem goes away if I change my command from \s2 to \stwo, so it's
: clear that LaTeX has a probelm wiht a numeral used like this. It looks
: like numeral is not recognized as part of the command, and everthing
: goes to pieces after that. Is there a good workaround for this?
You have a catcode problem; in normal text, numbers are not allowed as part
of a command name. You can build a control sequence by saying
\csname s2\endcsname
but this will not help because in normal text parsing of the control sequence
name \s2 stops before the digit begins.
You can parametrize your command so that the digit becomes its argument, you
can also resort to roman numerals, if that is of any help to you and you
really absolutely need numbered control sequence names.
Oliver.
--
Dr. Oliver Corff e-mail: co...@zedat.fu-berlin.de
Numbers have never been allowed in macro names. So, use letters.
This is not a bug, it is a feature.