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 it possible to emit a warning if a package hasn't been loaded?

If possible, I would prefer that the solution not require \usepackage{ifthen} as it couldn't emit the warning that it was missing the ifthen package.

EDIT: Thanks Martin and Joseph for the responses. I would like to clarify my question: is it possible do to this from within the body of a document?

The \AtBeginDocument, \RequirePackage and \@ifpackageloaded are only available in the preamble. The ltxcmds package makes \ltx@ifpackageloaded available in the body but then the ltxcmds package is required for this to work.

The situation where I would like this is I am generating tables with the xtable package in R and when the floating.environment='sidewaystable' argument is used, the rotating package is required. To make this easy for users, I would like to allow them to simply \input{<path_to_xtable>}. However, if the rotating package isn't loaded pdflatex give an error message like

l.3 \begin{sidewaystable}

I would prefer that it issue a more informative warning that the rotating package is missing. Is this possible?

share|improve this question
Related: Test if a package is loaded and Is there any way to generate custom errors/warnings in LaTeX? (in combination). If you want to test if a package is installed see Conditional "if a package is available". – Martin Scharrer Jan 22 '13 at 21:56
these are helpful references, also tex.stackexchange.com/questions/35282/… – momeara Jan 23 '13 at 3:07
@momeara I've updated my answer, but I still don't see why you don't simply require the support package you need. – Joseph Wright Jan 23 '13 at 7:03
Do you mean by using \RequirePackage? Or some other method? – momeara Jan 23 '13 at 13:05

Most of the time you don't test in this way but simply require those packages you need, but of course there are cases where load-order is awkward and a test is useful. The standard way to do this would be to test at the start of the document

  \@ifpackageloaded{OtherPackage}% Fill in name here
    {}% Nothing to say
         {You have not loaded the 'OtherPackage' package!}%

To allow a check in the document body, the usual way is to define a conditional

  \@ifpackageloaded{OtherPackage}% Fill in name here
    {\my@check@OtherPackage@loadedtrue}% Nothing to say

and then to use that conditional to check for the package being available.

share|improve this answer

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.