24

I would like to be able to automatically determine which release of TeXLive that I am running. I sometimes encounter a problem where it is useful to test that the file compiled correctly in an older release first, before trying to debug the problem.

Currently, I have updated my code to use the new features of the the datatool package as per No room for a new \count with datatool. Along with the datatool update, I updated all the other packages and am now encountering a problem that at least seemed to have worked properly for over a year now.

But it is not simple to switch back to running the older TeXLive2011 as it does not have the new packages. And of course updating the packages of the 2011 would kind of defeat the purpose of here. :-)

The MWE below runs fine with the latest updated TeXLive2012 (Version 2.13 of datatool or later). But, in order for this to run with an older release, one needs to manually edit the \def\TeXLiveVersion version to something other than 2012.

References:

Notes:

  • For the MWE to be useful, an older release is required as there is no issue here with the current TeXLive2012. Or, if you have not updated your packages lately and have v2.12 (or older) version of datatool package (in which case this won't run unless you manually edit the \TeXLiveVersion to:

      \def\TeXLiveVersion{2011}%
    
  • Here is an older question where I had a problem with TeXLive2011 (but the file compiled fine with TeXLive2010): Debugging Advice: TeX Capacity Exceeded with TeXLive2011 (but not with TeXLive2010). At that time I had manually changed the preamble, but again that is a case where an automated solution would have been useful.

  • In case it is not obvious, the actual output of the MWE here is not important. It is a cooked up example to show a case where I need to know which version of TeXLive I am using, and a way to test that the proposed solution of determining the version actually worked.

Code:

\def\TeXLiveVersion{2012}% <--- Don't want to have to manually specify this

\documentclass{article}
\usepackage{datatool}
\usepackage{pgffor}
\usepackage{xstring}
\usepackage{letltxmacro}

%\usepackage{filecontents}% Commented to prevent overwriting MyData.csv
\begin{filecontents*}{MyData.csv}
    Directory, Color
    ../dirB,    red
    ../dirC,    yellow
\end{filecontents*}

\LetLtxMacro\MyDTLcleardb{\DTLcleardb}% Default to 2012 and future
\IfEq{\TeXLiveVersion}{2012}{%
}{%
    \newif\ifDTLnewdbonload%
    \LetLtxMacro\MyDTLcleardb{\DTLdeletedb}%
}%

\begin{document}

\DTLnewdb{MyDB}
\DTLnewdbonloadfalse% don't let \DTLloaddb create a new database 

\foreach \x in {1,...,5}{% Read DB numerous times
    \typeout{count=\x}%
    \MyDTLcleardb{MyDB}% clear database
    \DTLloadrawdb[keys={Directory,Color}]{MyDB}{MyData.csv}%
}%

\par\noindent\DTLdisplaydb{MyDB}% Some output to have a PDF
\end{document}
2
  • 3
    Testing versions of TeX Live won't help here: you are interested in package versions. People tend to think that the version of TeX Live they use covers everything, but unless you only use the DVD versions then there is no easy correspondence between TL and package versions.
    – Joseph Wright
    Feb 3, 2013 at 9:08
  • 1
    @JosephWright: Yes I understand that and reverting to earlier versions of packages would also be useful as well. Ideally if I would like to be able to create a snapshot and say run "TeXLive2012 with packages as of Jan 1, 2013". However, it is still useful to be able to run with an older known good release to see if it is indeed a new problem or not. Feb 3, 2013 at 9:13

1 Answer 1

21
+50

With pdflatex or lualatex it's possible, because TeX Live programs advertise the release year in their banner:

\documentclass{article}

\makeatletter
\def\getversion{\expandafter\get@version\pdftexbanner\@nil}
\def\get@version#1201#2)#3\@nil{\def\TeXLiveVersion{201#2}}
\makeatother
\getversion

\begin{document}
This has been run with \TeX~Live~\TeXLiveVersion.

\texttt{\pdftexbanner}
\end{document}

enter image description here

This might be fooled by other "201" strings in the banner, but one should analyze banners produced by different packagings of TeX Live (Debian modifies it, for instance) in order to find a robust scheme.

However, testing just for the release year is not sufficient; it's better to rely on looking at package versions with \@ifpackagelater.

Update

Oh, well, the decade has changed! Here's a possibly more robust code that relies on the string returned by \pdftexbanner to be of the form

<characters>TeX Live 20??<characters>)<characters>

Some tricks have to be used in order to stringify TeX Live.

\documentclass{article}

\makeatletter
\begingroup
\edef\get@@version{\def\noexpand\get@version##1\detokenize{TeX Live}##220##3##4##5)##6\noexpand\@nil}
\get@@version{\gdef\TeXLiveVersion{20#3#4}}
\expandafter\get@version\pdftexbanner\@nil
\endgroup
\makeatother

\begin{document}

This has been run with \TeX~Live~\TeXLiveVersion.

\texttt{\pdftexbanner}

\end{document}

zzz

The output if run with TeX Live 2018

enter image description here

Alternative version

We can exploit the fact that TeX Live stores its files in .../texlive/20??/.

\documentclass{article}
\usepackage{catchfile}

\makeatletter
\begingroup
\CatchFileDef{\banner}{|"kpsewhich plain.tex"}{}
\def\extractfrombanner#1/20#2#3/#4\extractfrombanner{%
  \gdef\TeXLiveVersion{20#2#3}%
}
\expandafter\extractfrombanner\banner\extractfrombanner
\endgroup

\begin{document}

This has been run with \TeX~Live~\TeXLiveVersion.

\texttt{\pdftexbanner}

\end{document}

The earliest working version of TeX Live on my machine is 2013 and, with pdflatex I get the expected result.

This should work also with XeLaTeX, but, unfortunately, a long standing bug in xetex packaged for macOS prevents this until recent years (2018).

5
  • With TeXLive 2020, should be \def\get@version#120#2#3)#4\@nil{\def\TeXLiveVersion{20#2#3}}... May 31, 2020 at 5:51
  • @PaulGaborit Yes, it’s going to be more difficult now.
    – egreg
    May 31, 2020 at 7:59
  • @PaulGaborit: Yeah, I tried that. May 31, 2020 at 8:22
  • 1
    @PeterGrill I'll leave to others adapting this for TeX Live 2100.
    – egreg
    May 31, 2020 at 8:44
  • @egreg a bit short term, what about Tex Live 3000? ;-) Oh and also later ones ....
    – albert
    May 31, 2020 at 9:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .