TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

When I tried to use the breqn package suggested by an answer to the question

How do I break a long equation over lines

It managed to break a whole bunch of unrelated equations (equations that did not use its functionality), including a definition for the control sequence \mf which I had previously defined myself.

Is there a way to limit the scope of a \usepackage declaration so that its (positive and negative) effects are limited to a particular segment of a document?

I have tried putting it inside an environment, but get the following error:

! LaTeX Error: Can be used only in preamble.
share|improve this question
You can only load a package in the preamble. The scope starts where you import the package and lasts until the end of the document environment. – Marc van Dongen Feb 28 '13 at 4:58
It is probably easier to adjust your definition of \mf instead of trying to load breqn locally. – clemens Feb 28 '13 at 11:16
If you can provide the parts of the code that are failing (a full working example), we might be able to help in fixing the code so everything compiles correctly. – Mythio Feb 28 '13 at 11:31
although the question as phrased has global interest, this case is likely to be specific to breqn, so i added that as a tag. – barbara beeton Feb 28 '13 at 13:24

Perhaps for some small package this could be possible, but the general answer is no. In particular, breqn and its companion package flexisym do very extensive changes to the normal setup of math formulas which are, in some cases, global; therefore, even if it were possible to load them in a group, the changes would be performed also at the outer level. The same is true for many other packages.

It's not to be neglected that many commands that are used in packages are disabled after \begin{document} and this makes quite difficult to cope with the task of loading a package after the document has begun.

share|improve this answer

If instead of using \usepackage you use \input, you can limited the scope of the package. It will require redefining some commands and patching others, but it should be technically possible. For example

share|improve this answer
Perhaps this can work for some packages, but there are many commands that are disabled after \begin{document} and that are used in packages, for instance \RequirePackage. Global definitions performed by a package may disrupt the working of the whole system. – egreg Feb 28 '13 at 14:35
@egreg You're very polite. I would have said that this solution looks a bit like calibrating your dosimeter with a hydrogen bomb... – Brent.Longborough Feb 28 '13 at 18:43

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.