TransWikia.com

Detecting which version of the LaTeX format is in use

TeX - LaTeX Asked on January 30, 2021

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!

4 Answers

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.

Answered by Martin Scharrer on January 30, 2021

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
defengineversion@#1#2.{%
  ifnum#2>9relax
    #1.#2.%
  else
    0.#1#2.%  
  fi
}
defengineversion@@#1#2#3{#1.#2#3}
edefengineversion{%
  ifxetex
    XeTeX:theXeTeXversionXeTeXrevision
  else
    ifluatex
      LuaTeX:[email protected]
    else
      pdfTeX:expandafterengineversion@@thepdftexversion.pdftexrevision
    fi
  fi
}
makeatother
showengineversion

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
      expandafterexpandafterexpandafter@secondoftwo
    else
      ifnum#1>pdftexversion
        expandafterexpandafterexpandafterexpandafter
          expandafterexpandafterexpandafter@secondoftwo
      else
        expandafterexpandafterexpandafterexpandafter
          expandafterexpandafterexpandafter@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!).

Answered by Joseph Wright on January 30, 2021

(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@rfmtversion}

This is used

@iflatexlater{2001/09/01}{TRUE}{FALSE} % TRUE, I hope!
@iflatexlater{2011/09/01}{TRUE}{FALSE} % FALSE

Answered by Joseph Wright on January 30, 2021

Since version 2020-10-01 the LaTeX kernel provides the command IfFormatAtLeastTF{<date>}{<true code>}{<false code>} which executes <true code> if the LaTeX version is <date> or newer and <false code> otherwise. Example:

documentclass{article}

IfFormatAtLeastTF{2021/05/01}{%
  newcommandVersionInfo{This document was compiled using LaTeX version 2021-05-01 or newer.}%
}{%
  newcommandVersionInfo{This document was compiled using a LaTeX version older than 2021-05-01.}%
}

begin{document}

VersionInfo

end{document}

Furthermore, similar commands IfClassAtLeastTF{<class name>}{<date>}{<true code>}{<false code>} and IfPackageAtLeastTF{<package name>}{<date>}{<true code>}{<false code>} are provided for class and package tests.

Answered by user227621 on January 30, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP