6

Note that this question is about Plain TeX, not LaTeX. Consider the following example.

\pdfpagewidth 8.5 in
\pdfpageheight 11 in

foobar
\bye

Under pdftex, this will work fine. However, this will throw the following nasty error if I try to run tex on it.

! Undefined control sequence.
l.1 \pdfpagewidth
                  8.5 in

Is it possible to write my document so that it will not execute those two lines if it is running under tex rather than pdftex?

egreg
  • 1,121,712
merlin2011
  • 3,343
  • \ifdefined\pdfpagewidth\else\newdim\pdfpagewidth...\fi IIRC, \ifdefined is from eTeX, so wouldn't work on actual TeX. – morbusg Oct 04 '14 at 07:13
  • Note that the format here isn't really important: you can do engine conditionals in LaTeX or plain (or others as appropriate) – Joseph Wright Oct 04 '14 at 12:46

1 Answers1

6

The tex executable runs the “original Knuth TeX”, whereas \pdfpagewidth is a pdftex primitive.

The usual

\begingroup\expandafter\expandafter\expandafter\endgroup
  \expandafter\ifx\csname pdfpagewidth\endcsname\relax
  \else
    \pdfpagewidth 8.5 truein
    \pdfpageheight 11 truein
  \fi

will do. After it, \pdfpagewidth and \pdfpageheight will not be defined if they weren't to begin with.

Note that there are some LaTeX packages that can be used also with Plain TeX. Of these you could consider ifetex, because a distinctive feature of Knuth TeX is not having e-TeX extensions. So you could do

\input ifetex.sty

and do

\ifetex
  <code for non Knuth TeX>
\else
  <code for Knuth TeX>
\fi

The <code for non Knuth TeX> may distinguish from PDF and DVI output by using

\input ifpdf.sty

and the provided \ifpdf conditional. There are also ifxetex.sty and ifluatex.sty; all of them can be loaded in Plain with \input if<...>.sty.

There's also the “all-in-one” package iftex.sty, but its implementation is really basic with respect to ifpdf, ifxetex and ifluatex. It doesn't provide any way for checking e-TeX extensions.

egreg
  • 1,121,712