Detecting which version of the LaTeX format is in use
Recent versions of pdfTeX, and I think all versions of XeTeX and LuaTeX, provide 'version' data for the engine. Something like
\documentclass{article}
\usepackage{ifluatex,ifxetex}
\makeatletter
\def\engineversion@#1#2.{%
\ifnum#2>9\relax
#1.#2.%
\else
0.#1#2.%
\fi
}
\def\engineversion@@#1#2#3{#1.#2#3}
\edef\engineversion{%
\ifxetex
XeTeX:\the\XeTeXversion\XeTeXrevision
\else
\ifluatex
LuaTeX:\expandafter\engineversion@\the\luatexversion.\luatexrevision
\else
pdfTeX:\expandafter\engineversion@@\the\pdftexversion.\pdftexrevision
\fi
\fi
}
\makeatother
\show\engineversion
will show it in a 'nice' way. What this warns you about is that telling what engine version is in use also means worrying about which engine is in use. Without more context, it's hard to be sure quite what effect is required. One possible approach is something like
\def\@ifpdftexlater#1{%
\ifxetex
\expandafter\@secondoftwo
\else
\ifluatex
\expandafter\expandafter\expandafter\@secondoftwo
\else
\ifnum#1>\pdftexversion
\expandafter\expandafter\expandafter\expandafter
\expandafter\expandafter\expandafter\@secondoftwo
\else
\expandafter\expandafter\expandafter\expandafter
\expandafter\expandafter\expandafter\@firstoftwo
\fi
\fi
\fi
}
% Use cases
\@ifpdftexlater{150}{\TRUE}{\FALSE} % TRUE on my system
\@ifpdftexlater{150}{\TRUE}{\FALSE} % FALSE on my system
which tests the major pdfTeX version, and is TRUE for any major version greater or equal to the given argument, and FALSE for older versions or for the wrong engine begin used. (This needs the ifluatex
and ifxetex
packages.) Tests for minor revision is a bit more complex, but the same approach applies.
If you actually want the TeX version, then the banner or similar is the only way to go. Knuth did not provide a \texversion
macro, and while it's possible to tell TeX2 from TeX3, that is not much use (as TeX3 was released in 1982!).
(Second answer, as it seems the question was not really about TeX version.)
The LaTeX format version is stored in the macro \fmtversion
. LaTeX does not provide a direct interface to do a date test on this, but it not too hard to put one together:
\newcommand*\@iflatexlater{\@ifl@t@r\fmtversion}
This is used
\@iflatexlater{2001/09/01}{\TRUE}{\FALSE} % TRUE, I hope!
\@iflatexlater{2011/09/01}{\TRUE}{\FALSE} % FALSE
If you use pdftex
in either PDF or DVI mode (i.e. pdflatex
or latex
with a modern LaTeX) you could adapt Herbert's answer to my question
Is there a way to detect from inside a package that MiKTeX is used? to extract the TeX version instead.
It uses the primitive \pdftexbanner
which prints something like:
This is pdfTeX, Version 3.1415926-2.3-1.40.12 (TeX Live 2011) kpathsea version 6.0.1
The 3.1415926
is the TeX version and can be extracted as shown in the above link. However, this wouldn't work, in general, with a very old TeX where pdftex
isn't used in DVI mode.