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 unload a LaTeX package?

I have a preamble file which I use for most documents. Now suppose I want to use a preamble file preamble.tex and explicitly don't want to use one of the packages loaded in it. For example in this file there is a line:


and then I want to have a file test.tex which contains something like this:

\usepackage{myotherpackage} %myotherpackage can only be loaded when mypackage is not present
share|improve this question
no, it is a special problem ... – Herbert Dec 27 '11 at 10:56
No, you can't unload any packages. TeX does not have namespaces so it isn't possible to know what macros got defined by which package. – Martin Scharrer Dec 27 '11 at 11:27
up vote 18 down vote accepted

You can fool LaTeX into believing that it has already loaded package foo with options bar and baz by defining a command with name "ver@foo.sty" and one with name "opt@foo.sty" in a suitable way; so


will prevent both loading the package and also keep LaTeX happy with the options possibly passed to it.

However, \dontusepackage[bar,baz]{foo} must be issued before \input{preamble}.

I'm in general contrary to "do-it-once-and-for-always" preambles, which raise problems such as this one. There's no such thing as a universal preamble and later developments make some packages obsolete or at least superseded by new ones.

Just copy preamble.tex into the working directory and change it for what's needed for the current document you're writing.

share|improve this answer
@egreg I think it is useful to emphasize that, to avoid option clash later, bar and baz must be the only options for package foo. This will require knowing all the options of foo. This also assumes that foo wasn't loaded before \dontusepackage. – Ahmed Musa Dec 27 '11 at 19:25
I've chosen to pass also the options used in preamble.tex in order to raise an error if some other package tries to load it with different options. However it's not that important. – egreg Dec 27 '11 at 20:21

Tell your preamble that mypackage is already "loaded". Packages are not loaded twice:

\@namedef{ver@mypackage.sty}{}% a fake for a "loaded" package
\usepackage{myotherpackage} %myotherpackage can only be loaded when mypackage is not present
share|improve this answer
I know this old, but could one not achieve something with boolean variables that would affect the loading or not loading of packages? – Louis Aug 3 '12 at 8:56

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.