Detect whether running on pdfTeX or Knuth's TeX for conditional include

You can use the iftex "package". According to the documentation

This very simple package, for both Plain TeX and LaTeX, defines the \ifPDFTeX, \ifXeTeX, and \ifLuaTeX boolean for testing whether PDFTeX, or XeTeX, or LuaTeX is being used for typesetting.


Something like this?

Since \csname foo\endcsname expands to \relax if \foo is not defined, it's possible use \ifx.... to compare the command sequence to be equal to \relax. This does not need e-TeX at all.

\newif\ifknuthtex
\expandafter\ifx\csname pdfpagewidth\endcsname\relax
\knuthtextrue
\else
\pdfpagewidth 8.5 true in
\pdfpageheight 11 true in
\fi

This is \ifknuthtex Knuth's \TeX\else pdfTeX\fi
\bye

Compiling with tex gives the image below.

enter image description here


If you only plan to distinguish between Knuth TeX and pdftex (or LuaTeX), this does it:

\begingroup\escapechar=-1
\edef\undefined{\string\undefined}%
\edef\test{\meaning\pdftexversion}%
\expandafter\endgroup\expandafter\let\expandafter\ifknuthtex
\csname if\ifx\undefined\test true\else false\fi\endcsname

\ifknuthtex
  \message{Knuth TeX}
\else
  \message{Not Knuth TeX}
\fi

One assumption is made: that no previous macro file or loaded format defines \pdftexversion. If you want that \ifknuthtex returns the correct truth value also with XeTeX, you can load ifxetex:

\input ifxetex.sty
\begingroup\escapechar=-1
\edef\undefined{\string\undefined}%
\edef\test{\meaning\pdftexversion}%
\expandafter\endgroup\expandafter\let\expandafter\ifknuthtex
\csname if%
  \ifnum 0=%
    \ifx\undefined\test 0\else 1\fi
    \ifxetex 1\fi
    true\else false\fi
\endcsname

\ifknuthtex
  \message{Knuth TeX}
\else
  \message{Not Knuth TeX}
\fi