blob: 7f26397e5c500914aa59dd7ba979deb1baa61613 (
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
<head>
<title>UK TeX FAQ -- question label ifpdf</title>
</head><body>
<h3>Am I using PDFTeX?</h3>
<p/>It’s often useful to know whether your macros are operating within
PDFTeX or within (“normal”) TeX; getting the right answer is
surprisingly tricky.
<p/>Suppose you need to test whether your output will be PDF or
DVI. The natural thing is to check whether you have access to
some PDFTeX-only primitive; a good one to try (not least because it
was present in the very first releases of PDFTeX) is
<code>\</code><code>pdfoutput</code>. So you try
<blockquote>
<pre>
\ifx\pdfoutput\undefined
<not running PDFTeX>
\else
<running PDFTeX>
\fi
</pre>
</blockquote><p>
Except that neither branch of this conditional is rock-solid. The
first branch can be misleading, since the “awkward” user could have
written:
<blockquote>
<pre>
\let\pdfoutput\undefined
</pre>
</blockquote><p>
so that your test will falsely choose the first alternative. While
this is a theoretical problem, it is unlikely to be a major one.
<p/>More important is the user who loads a package that uses
LaTeX-style testing for the command name’s existence (for example,
the LaTeX <i>graphics</i> package, which is useful even to the
Plain TeX user). Such a package may have gone ahead of you, so the
test may need to be elaborated:
<blockquote>
<pre>
\ifx\pdfoutput\undefined
<not running PDFTeX>
\else
\ifx\pdfoutput\relax
<not running PDFTeX>
\else
<running PDFTeX>
\fi
\fi
</pre>
</blockquote><p>
If you only want to know whether some PDFTeX extension (such as
marginal kerning) is present, you can stop at this point: you know as
much as you need.
<p/>However, if you need to know whether you’re creating PDF
output, you also need to know about the value of <code>\</code><code>pdfoutput</code>:
<blockquote>
<pre>
\ifx\pdfoutput\undefined
<not running PDFTeX>
\else
\ifx\pdfoutput\relax
<not running PDFTeX>
\else
<running PDFTeX, with...>
\ifnum\pdfoutput>0
<...PDF output>
\else
<...DVI output>
\fi
\fi
\fi
</pre>
</blockquote><p>
The above is, in essence, what Heiko Oberdiek’s <i>ifpdf</i>
package does; the reasoning is the FAQ’s interpretation of
Heiko’s explanation.
<dl>
<dt><tt><i>ifpdf.sty</i></tt><dd>Distributed with Heiko Oberdiek’s packages <a href="ftp://cam.ctan.org/tex-archive/macros/latex/contrib/oberdiek.zip">macros/latex/contrib/oberdiek</a> (<a href="ftp://cam.ctan.org/tex-archive/macros/latex/contrib/oberdiek.tar.gz">gzipped tar</a>, <a href="http://www.tex.ac.uk/tex-archive/macros/latex/contrib/oberdiek/">browse</a>)
</dl>
<p/><p>This question on the Web: <a href="http://www.tex.ac.uk/cgi-bin/texfaq2html?label=ifpdf">http://www.tex.ac.uk/cgi-bin/texfaq2html?label=ifpdf</a>
</body>
|