[texhax] choice of documentstyle upon \jobname

Uwe Lück uwe.lueck at web.de
Fri Dec 2 09:02:47 CET 2005


At 02:34 01.12.05, Reinhard Kotucha wrote:
> >>>>> "Susan" == Susan Dittmar <S.Dittmar at eureca.de> writes:
>
>   > \ifx\jobname{first}
>   >     \documentclass[first]{...}
>   > \else
>   >     \documentclass[second]{...}
>   > \fi
>
>It is more difficult than necessary to do it this way.  If you follow
>Phil's advice and try to understand how TeX works internally, you'll
>see that there are some quite nasty things.  An "f" is not just an "f"
>in TeX.  Look for "\catcode" in TeX by Topics.

The \catcode things would hardly have mattered.
The main thing to note is that Susan expected that
when \jobname "equals" `first' (in some sense!?!?)
the line containing `[first]' is executed.
However, looking into something like the TeXbook
(p. 210) is better than mere guessing (while I
sometimes find the TeXbook explanations often so
sloppy that it still leaves me guessing):
Susan's code just finds that (with usual settings,
i.e. here: \catcode`\{=1) \jobname doesn't have
the character and category code of left brace,
so the line containing `[second]' is executed.

The main message from Phil's proposal thus is:
In order to test whether some \testfirst expands
to `first', you might \edef\testsecond{first} and
then \ifx\testfirst\testsecond.

However, Susan wants LaTeX to "classify" job names,
which is a more difficult task. You may be interested
in the following CTAN announcement in this context:

 >>>>>
On Tue, 29 Nov 2005, Harald Harders submitted an update to the
substr package.
Location on CTAN: /macros/latex/contrib/substr
License: LPPL
 >From the README:
This package provides commands to deal with substrings in strings:
Determine if a string contains a substring, count appearances of a
substring in a string.
<<<<<

In testing, I find another problem: With my (La)TeX installation,
\jobname doesn't expand to `atest', but to the entire path
name of my atest.tex. Well, TeX can find out from the
path name what the file name is. Cf. TeXbook p. 375,
from which the above substr package probably starts.

Good luck,
   Uwe. 



More information about the texhax mailing list