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.
  • 5
    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.
    – user10274
    Feb 28 '13 at 4:58
  • It is probably easier to adjust your definition of \mf instead of trying to load breqn locally.
    – cgnieder
    Feb 28 '13 at 11:16
  • 2
    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. 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.


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

  • 8
    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
  • 5
    @egreg You're very polite. I would have said that this solution looks a bit like calibrating your dosimeter with a hydrogen bomb... Feb 28 '13 at 18:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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