Welcome to the UK List of
TeX Frequently Asked Questions
on the Web

Searching

The index of Frequently Asked Questions about TeX is searchable.

Please enter your keyword here:   then press here: ,    or:
Google

Comparing the “job name”

The token \jobname amusingly produces a sequence of characters whose category code is 12 (‘other’), regardless of what the characters actually are. Since one inevitably has to compare a macro with the contents of another macro (using \ifx, somewhere) one needs to create a macro whose expansion looks the same as the expansion of \jobname. We find we can do this with \meaning, if we strip the “\show command” prefix.

The full command looks like:

\def\StripPrefix#1>{}
\def\jobis#1{FF\fi
  \def\predicate{#1}%
  \edef\predicate{\expandafter\StripPrefix\meaning\predicate}%
  \edef\job{\jobname}%
  \ifx\job\predicate
}

And it’s used as:

\if\jobis{mainfile}%
  \message{YES}%
\else
  \message{NO}%
\fi

Note that the command \StripPrefix need not be defined if you’re using LaTeX — there’s already an internal command \strip@prefix that you can use.


Go to previous question, or next question

Go to FAQ home.

URL for this question: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=compjobnam

Comments, suggestions, or error reports? - see “how to improve the FAQ”.

This is FAQ version 3.27, released on 2013-06-07.