You can request a minimal version/date using the trailing optional argument of \usepackage[<options>]{<name>}[<min.date>]
(or \RequirePackage
). However, it will only print a warning text and not cause an error if the installed version is older than the requested version.
This feature is realized in the LaTeX core by the macro \@ifpackagelater{<name>}{<date>}{<yes>}{<no>}
, which you can also use yourself (\makeatletter
.. \makeatother
is required if not used inside a package or class file).
The <date>
must be in the format year/month/day
, e.g. 2022/08/10 for August 10th, 2022.
You can use the following code to cause an error if the package is older than the given date. However, this only works after the package was loaded.
\makeatletter
\usepackage{<name>}%
\@ifpackagelater{<name>}{<date>}{%
% Package is new enough
}{%
\PackageError{<your package or document name>}{Package <name> is to old <...>}%
}
\makeatother
Note that despite the name \@ifpackagelater
, AFAIK, the macro checks actually if the package date is later or equal. A more accurate name would be therefore ifpackagenotolder
. If you want to check if a package is actually newer than a last version known to you, than simply add one day to the date.
Here an example based on the mwe
package which also checks if the package is installed at all:
\IfFileExists{mwe.sty}{%
\RequirePackage{mwe}%
\@ifpackagelater{mwe}{2018/03/30}{%
% Package version new enough
}{%
% Package version too old
}
}{%
% Package not installed
}
\usepackage[<options>]{<name>}[<min.date>]
(or\RequirePackage
). Then there is\@ifpackagelater{<name>}{<date>}{<yes>}{<no>}
as shown in the linked thread.