[texhax] choice of documentstyle upon \jobname
Reinhard Kotucha
reinhard.kotucha at web.de
Sun Dec 4 03:44:33 CET 2005
Hi,
I got the following mail from Susan. Though it is usually impolite to
put private mails on mailing lists, I think that the question is
interesting enough to be discussed here.
But the main reason I answer to this list is that I'm not sure that
everything I say is correct. On a mailing list I can make mistakes
and can be sure that people correct me if necessary.
>>>>> "Susan" == Susan Dittmar <S.Dittmar at eureca.de> writes:
>> \expandafter\def\csname first\endcsname{\documentclass[abc]{...}}
>> \expandafter\def\csname second\endcsname{\documentclass[xyz]{...}}
> Is it true that, in the case where first and second are completely
> composed of letters which TeX accepts for command name, that's
> equivalent to
> \def\first{\documentclass...}
> \def\second{\documentclass...} ?
Maybe not equivalent, but at least similar.
\csname...\endcsname doesn't care about catcodes. Instead of
\csname\jobname\endcsname you can better write
\csname\jobname:-)\endcsname to avoid name clashes.
You can't do it with \def so easy. \csname...\endcsname allows you to
define "private" macros which you cannot access accidentally.
Indeed you can say \def\foo{...} or \newcommand{\foo}{...} and can
either use this macro directly (\foo) or you can say
\csname foo\endcsname.
In latex it's easier to use \@namedef and \@nameuse.
There is one important difference between \foo and \csname foo\endcsname
(or \@nameuse{foo}):
If \foo is undefined you get an error message if you say \foo, while
\csname foo\endcsname doesn't complain if \foo doesn't exist.
You might wonder what this is good for.
I assume that you are working on a larger project which will not be
finished soon. So please put this into the preamble of your
document:
\expandafter\def\csname12:24\endcsname{\typeout{Merry Xmas!}}
\expandafter\def\csname1:1\endcsname{\typeout{Happy new year!}}
\csname\number\month:\number\day\endcsname
or
\makeatletter
\@namedef{12:24}{\typeout{Merry Xmas!}}
\@namedef{1:1}{\typeout{Happy new year!}}
\@nameuse{\number\month:\number\day}
\makeatother
It is a good exercise to find out why \expandafter is needed in the
first example. See "TeX by Topics".
Regards,
Reinhard
--
----------------------------------------------------------------------------
Reinhard Kotucha Phone: +49-511-4592165
Marschnerstr. 25
D-30167 Hannover mailto:reinhard.kotucha at web.de
----------------------------------------------------------------------------
Microsoft isn't the answer. Microsoft is the question, and the answer is NO.
----------------------------------------------------------------------------
More information about the texhax
mailing list