Take the 2-minute tour ×
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.

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
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. –  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. –  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. –  barbara beeton Feb 28 '13 at 13:24
add comment

2 Answers

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
add comment

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

\documentclass{article}
\begin{document}
  \begingroup
    \makeatletter
      \renewcommand{\usepackage}[1]{\input{#1}}
      \renewcommand{\NeedsTeXFormat}[1]{}
      \renewcommand{\ProvidesPackage}[1]{}
      \usepackage{fixltx2e.sty}
    \makeatother
  \endgroup
\end{document}
share|improve this answer
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... –  Brent.Longborough Feb 28 '13 at 18:43
add comment

Your Answer

 
discard

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.