iftex
Provides tools for detecting and conditionally responding to different TeX engines during document compilation.
Overview
Enables intelligent engine detection and conditional code execution in both Plain TeX and LaTeX documents, helping authors create engine-specific implementations and ensure compatibility.
- Offers conditional tests to determine if a document is being processed by pdfTeX, XeTeX, or LuaTeX.
- Includes requirement commands to enforce specific engine usage when necessary.
- Particularly valuable for package developers and authors creating documents that need to work across multiple TeX engines.
- Commonly used in template development, cross-platform documentation, and specialized typesetting workflows where engine-specific features are needed.
Getting Started
To use iftex
, include it in your document preamble:
\documentclass{article}
\usepackage{iftex}
This package works with both Plain TeX and LaTeX, and allows you to detect which TeX engine is being used. For example:
\ifPDFTeX
% Code for pdfTeX
\else
\ifXeTeX
% Code for XeTeX
\else
\ifLuaTeX
% Code for LuaTeX
\fi
\fi
\fi
Examples
Detecting the TeX engine and conditionally executing code based on the engine in use.
\noindent Here is the result of engine detection:\par
\ifPDFTeX
This document is being processed with pdf\TeX.
\fi
\ifXeTeX
This document is being processed with Xe\TeX.
\fi
\ifLuaTeX
This document is being processed with Lua\TeX.
\fi
Using the requirement commands to ensure a document is compiled with the correct engine.
\documentclass{article}
\usepackage{iftex}
\RequirePDFTeX % This will throw an error if not compiled with pdfTeX
\begin{document}
This document requires pdf\TeX to compile correctly.
\end{document}
Creating engine-specific content with different formatting options.
\documentclass{article}
\usepackage{iftex}
\ifXeTeX
\usepackage{fontspec}
\setmainfont{Arial}
\else
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\fi
\begin{document}
\noindent Engine-specific formatting:\par
\ifXeTeX
This text is formatted using the Arial font via fontspec (Xe\TeX only).
\else
This text is formatted using Latin Modern via the standard font system.
\fi
\end{document}