TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to enforce that a certain version, or a later version, of a package is loaded when building the document? I've found that compiling a document on another platform, where the package versions differ, can cause problems that may or may not be hard to pinpoint. Thus, I would like to be able to say, in the document, that "you need at least this version of this package", and produce an explicit error about it when it doesn't hold true.

Is there any way of doing this?

share|improve this question
I think Is it possible to abort loading a package if it's too old? should answer that. Note that you can state a minimal version/date using the trailing optional argument of \usepackage[<options>]{<name>}[<min.date>] (or \RequirePackage). Then there is \@ifpackagelater{<name>}{<date>}{<yes>}{<no>} as shown in the linked thread. – Martin Scharrer Mar 12 '12 at 15:28
@MartinScharrer I think the present question is more general than the one you linked to. That said, your comment would make a fine answer. – lockstep Mar 12 '12 at 17:28
@lockstep: Ok, makes sense. I posted an answer. Thanks. – Martin Scharrer Mar 12 '12 at 18:16
up vote 17 down vote accepted

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

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.

    % Package is new enough
    \PackageError{<your package or document name>}{Package <name> is to old <...>}%

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.

share|improve this answer
After trying it, this answer is not entirely accurate as you must first load the package (i.e. do \usepackage) and then check whether it is too old (i.e. do \@ifpackagelater). The reason being that \@ifpackagelater checks a variable var@<package> which is not available (and will thus produce an error) until you've loaded the package. – gablin Aug 31 '12 at 12:52
@gablin: I corrected my answer now. Thanks for the feedback. – Martin Scharrer Nov 7 '12 at 10:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.