5

This question should really ask what is the best way to implement a version-specific package dependency. However, if I try to ask that, the system threatens to close my question.


In this answer, Martin Scharrer explains how to load a package conditional on its version by redefining \ProvidesPackage. However, that question is quite old so, since the solution is not exactly ideal, I hope it is worth asking whether there is any better option available at this time.

I would ideally like my package to do this:

  1. Test whether otherpackage is older than version X.
  2. If otherpackage is older than version X, issue an error rather than continuing.
  3. If otherpackage is newer than version X, issue a warning and continue.
  4. If otherpackage is at version X, continue.

Obviously, the issuing of errors and warnings and stopping and so on is unproblematic. The problem is doing those things conditionally depending on the version of otherpackage.

A Minimal Working Non-Example would be

\ProvidesPackage{mypackage}[v0.1]
\RequirePackage{otherpackage}[2015/11/01]
\endinput

which obviously does no testing at all except that it will issue a warning if otherpackage is at version prior to 2015/11/01. That is, it will still continue in this case, and it will say nothing whatsoever if otherpackage is at a version later than 2015/11/01.

cfr
  • 198,882

1 Answers1

4
\RequirePackage{longtable}
\makeatletter

\@ifpackagelater{longtable}{2013/10/28}
  {\PackageWarning{mypkg}{Longtable newer or = to 2013/10/28}}
  {\PackageWarning{mypkg}{Longtable is older than 2013/10/28}}

\@ifpackagelater{longtable}{2014/10/28}
  {\PackageWarning{mypkg}{Longtable newer or = to 2014/10/28}}
  {\PackageWarning{mypkg}{Longtable is older than 2014/10/28}}


\@ifpackagelater{longtable}{2015/10/28}
  {\PackageWarning{mypkg}{Longtable newer or = to 2015/10/28}}
  {\PackageWarning{mypkg}{Longtable is older than 2015/10/28}}


\stop

Produces

Package mypkg Warning: Longtable newer or = to 2013/10/28 on input line 6.


Package mypkg Warning: Longtable newer or = to 2014/10/28 on input line 10.


Package mypkg Warning: Longtable is older than 2015/10/28 on input line 15.
David Carlisle
  • 757,742
  • So the only way to conditionally avoid loading the package is still the redefinition of \ProvidesPackage in the answer I linked? – cfr Nov 08 '15 at 02:13
  • @cfr If you really want to avoid loading the file then you need to know the version number in advance, for example from the ctan catalogue or the tlmgr database files, then you could not load it if the installed version was wrong, but that seems like a lot of work. Otherwise you have to load the file somewhere and then either run to the end, as here, or hack some command to stop it . – David Carlisle Nov 08 '15 at 10:16