# Detecting which version of the LaTeX format is in use

ltxcmds provides \ltx@ifpackagelater, \ltx@ifclasslater, \ltx@iffilelater and there is \@ifpackagelater - but is there any "if TeX later" or some other way to (automatically) get the used TeX version (besides looking into the log file etc., of course)? After the comment of Joseph Wright I now know that I wanted to know the LaTeX format (not the TeX) version. (And he already gave the answer to this question). Cool: At tex.stackexchanges answers are provided to people who do not even know their question!

• Some more context might be useful. For example, are you wanting to check for features added to the engine, or for bug fixes? Versioning in TeX engines is somewhat more complicated than for LaTeX packages. – Joseph Wright Aug 20 '11 at 17:00
• @Joseph Wright: On the one hand it's general curiosity, on the other hand the latest TeX update changed some things (see dante.ctan.org/get/macros/latex/doc/ltnews20.pdf ) and by redefinition of \enddocument broke some packages. – Stephen Aug 20 '11 at 18:11
• Ah, you don't mean the TeX version at all, you mean the LaTeX format version. This is stored in the macro \fmtversion. I suspect the breakage you refer to is to do with option lists: there was a bug report a couple of days ago about an internal macro, \@in, that is relevant here. – Joseph Wright Aug 20 '11 at 19:08
• @Joseph Wright: Thanks! Sorry for confusing TeX and LaTeX format version - but I'm always learning additional things here. If you turn your last comment into an answer, I'll accept that. – Stephen Aug 21 '11 at 14:28

(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

• Additional info: After compiling a TeX file with pdflatex, in the log file it is written "LaTeX2e <2015/01/01> patch level 2", where it is LaTeX2e = \fmtname, 2015/01/01 = \fmtversion, and 2 = \patch@level. – Stephen Jul 22 '15 at 10:08

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!).

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.