blob: 616e7d9ecc005ce6e65af2224224356f4c79f404 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
<head>
<title>UK TeX FAQ -- question label compjobnam</title>
</head><body>
<h3>Comparing the “job name”</h3>
<p/>The token <code>\</code><code>jobname</code> 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 <code>\</code><code>ifx</code>, somewhere) one needs to
create a macro whose expansion looks the same as the expansion of
<code>\</code><code>jobname</code>. We find we can do this with <code>\</code><code>meaning</code>, if we strip
the “<code>\</code><code>show</code> command” prefix.
<p/>The full command looks like:
<blockquote>
<pre>
\def\StripPrefix#1>{}
\def\jobis#1{FF\fi
\def\predicate{#1}%
\edef\predicate{\expandafter\StripPrefix\meaning\predicate}%
\edef\job{\jobname}%
\ifx\job\predicate
}
</pre>
</blockquote><p>
And it’s used as:
<blockquote>
<pre>
\if\jobis{mainfile}%
\message{YES}%
\else
\message{NO}%
\fi
</pre>
</blockquote><p>
Note that the command <code>\</code><code>StripPrefix</code> need not be defined if you’re
using LaTeX — there’s already an
<a href="FAQ-atsigns.html">internal command</a> <code>\</code><code>strip@prefix</code> that you can
use.
<p/><p>This question on the Web: <a href="http://www.tex.ac.uk/cgi-bin/texfaq2html?label=compjobnam">http://www.tex.ac.uk/cgi-bin/texfaq2html?label=compjobnam</a>
</body>
|