# How to warn if a package hasn't been loaded

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}
[ht]
?


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

-
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

\AtBeginDocument{%
{}% Nothing to say
{%
\PackageWarning{MyPackage}
{You have not loaded the 'OtherPackage' package!}%
}%
}


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

\newif\ifmy@check@OtherPackage@loaded
\AtBeginDocument{%