How to compare a given string with jobname ?

Skip to first unread message

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

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

\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

Donald Arseneau

Mar 8, 1992, 6:19:00 PM3/8/92
In article <>, 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

% 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

Reply all
Reply to author
0 new messages