Menu

Error_ifpdftex

! Undefined control sequence ... \ifpdftex
or
! Undefined control sequence ... \ifVTeX

Starting with version 3.28, older documents using KOMA-Script may cause an error message like:

! Undefined control sequence.
l.4 \ifpdftex
             {...}{...}

or

! Undefined control sequence.
l.4 \ifVTeX
             {...}{...}

The line number (in the example 4) can of course be arbitrarily different.

For almost 20 years in part, KOMA-Script contained the LaTeX instructions \ifpdftex and \ifVTeX. Both worked as commands with two arguments.However, since version 1.0 the package iftex and thus also the new versions of the wrapper packages ifpdf, ifvtex, ifluatex etc. based on it define these two statements as TeX branches of the form \if... ... \else ... \fi. These definitions are incompatible. The earlier long-standing agreement between package authors has thus been abandoned by the iftex author in favor of standardization.

From The LaTeX Project Team came the urgent recommendation to start only TeX-style branches \if... ... \else ... \fi with \if... and to use for LaTeX statements with argument like \IfFileExists a command name with \If..., i.e. capitalized "I" at the beginning. Although a workaround has been built into iftex, this still leaves the risk that other packages and Internet solutions based on the instructions redefined by iftex will become incompatible with KOMA-Script in the long run. To avoid this and to follow the recommendation of The LaTeX Project Team, compatibility of KOMA-Script from version 3.28 with earlier versions of KOMA-Script has been abandoned at this point. The two statements are no longer defined by scrbase.

If there is a branch in existing documents like:

\documentclass{scrartcl}
\ifpdftex{%
  \pdfcompresslevel=9
}{%
  \typeout{This is not PDFTeX!}
}

it is recommended to use the package iftex in current version instead:

\documentclass{scrartcl}
\usepackage{iftex}
\ifPDFTeX
  \pdfcompresslevel=9
\else
  \typeout{This is not PDFTeX!}
\fi

The two-argument command must therefore be converted to TeX syntax with \else and \fi as shown in the example. If the second argument was previously empty, the \else (but never \fi) can also be omitted.

Of course, it would be altogether better not to test for the TeX engine PDFTeX at all in the example shown, but to test for the existence of \pdfcompresslevel:

\documentclass{scrartcl}
\Ifundefinedorrelax{pdfcompresslevel}{%
  \typeout{This is not PDFTeX!}
}{%
  \pdfcompresslevel=9
}

By the way, the \Ifundefinedorrelax statement used in this example is also a result of the change, and the obsolete \ifundefinedorrelax is now undefined as well. But it is also possible without KOMA-Script with LaTeX means:

\documentclass{article}
\makeatletter
\@ifundefined{pdfcompresslevel}{%
  \typeout{This is not PDFTeX!}
}{%
  \pdfcompresslevel=9
}
\makeatother

Of course, I am aware that such tests are not possible in every case, and sometimes testing for the TeX engine is indeed the only reasonable option.

If the corresponding code is contained in classes or packages based on scrbase, first check if there is already a new version without this problem. Otherwise the corresponding class or package author is to be informed and asked for remedy. If this fails, and only then, the following code can be used as an absolute emergency solution even before loading a possibly affected class:

% ATTENTION: Emergency solution! Please use only as a last resort and for a short time!
\RequirePackage{iftex}
\makeatletter
\def\ifpdftex{\ifPDFTeX \expandafter\@firstoftwo \else \expandafter\@secondoftwo \fi}
\def\ifVTeX{\ifvtex \expandafter\@firstoftwo \else \expandafter\@secondoftwo \fi}
\makeatother

However, in the long run this code can cause the problems mentioned at the beginning with new packages or new versions of packages or code from the Internet or other sources. Therefore, I advise against the permanent use of this stopgap solution!


Related

Wiki (English): Messages

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.