How to compare a given string with jobname ?

225 views
Skip to first unread message

schi...@prl.philips.nl

unread,
Mar 8, 1992, 8:23:34 AM3/8/92
to

A simple question that I do not manage to solve.
How can I test that a string is equal to the \jobname ?
I would like something like

\def\mystring{....}
\ifx\mystring\jobname ...\fi

But this and similar things do not work. Why not ?
Is there a trick to do this ?


Thanks a lot !


Christoph Schiller

schi...@prl.philips.nl

Donald Arseneau

unread,
Mar 8, 1992, 6:19:00 PM3/8/92
to
In article <51...@prles2.prl.philips.nl>, schi...@prl.philips.nl writes...

>How can I test that a string is equal to the \jobname ?

This is a really tricky question because TeX gives all the characters of
\jobname the catcode "other". So to compare with a string, we have to
convert that string to "other" characters. Both \romannumeral and
\string also produce other characters, but \string only works on the
next token...but wait! If we first make the string into a \csname,
and we can use \string if we just get rid of the silly backslash.

\def\gobble#1{}% LaTeX already has \@gobble
\edef\tempj{\jobname}% \jobname gives "other" characters
% Convert an arbitrary string to "other" characters:
% do \csname, \string, then \gobble
\edef\temps{\expandafter \expandafter \expandafter \gobble
\expandafter \string \csname string\endcsname}
\ifx\tempj\temps ...

These can be put in a macro; use \if\thisjob{string}...\else...\fi

\def\@gobble#1{}% if necessary

\def\thisjob#1{..\fi\begingroup
\edef\jobA{\jobname}%
% Convert an arbitrary string to "other" characters:
% do \csname, \string, then \@gobble
\edef\jobB{\expandafter \expandafter \expandafter \@gobble
\expandafter \string \csname #1\endcsname}%
\expandafter \endgroup \ifx\jobA\jobB}

The strange incantation of \if\thisjob and ..\fi allows \if\thisjob
to appear in skipped text without an unbalanced \fi. The equally
arcane \expandafter\endgroup\ifx\jobA\jobB compares the strings
outside the group, but restores their normal value (probably undefined)
after the macro. These hacks aren't absolutely necessary, but they
help. The triple \expandafter with \string etc. is not the only way
to set up the comparison, but I can't think of a way that doesn't
look dirty.

$ $ <-- double dangerous. Exercise 1.1 Solve this problem using \meaning.

$ $ Exercise 1.2 Make both solutions work for jobnames with ~ and #
characters in them.

--- Donald as...@reg.triumf.ca

Reply all
Reply to author
Forward
0 new messages