[texhax] Changing \DeclareOption of some other packages

Uwe Lueck uwe.lueck at web.de
Mon Jun 13 16:23:53 CEST 2011

"Vafa Khalighi" <vafa018 at gmail.com> wrote 13.06.2011 12:41:59:
> Sometimes package X loads package Y at the beginning of the document.
> Now I have a package that makes changes to package Y
> but since package X loads package Y at the beginning of the document,
> my changes to package Y is not applied. Something like the following:
> \usepackage{X} %which loads package Y at \begin{document}
> \usepackage{mypackage}
> If a user manually loads package Y  before mypackage,
> changes to package Y are applied:
> \usepackage{X}
> \usepackage{Y}
> \usepackage{mypackage}
> However if in my package I add the following,
> changes to package Y are not applied:
> \@ifpackageloaded{X}{\RequirePackage{Y}}{}
> and the user loads packages as:
> \usepackage{X} %which loads package Y at \begin{document}
> \usepackage{mypackage}
> [i] Why my changes are not applied?
> [ii] how can I fix it?
> [iii] Is there a better approach for applying changes to a package
> even though that package is loaded at the beginning of the document?

Now for [i]. Your description is not entirely clear to me.
I assume package Y has a certain assignment [v gets a],
and in your mypackage you want to override this assignment
by [v gets b]. Of course, package Y must be loaded before
mypackage for this purpose, or rather Y must be loaded
before mypackage executes [v gets b]. It seems your line

> \@ifpackageloaded{X}{\RequirePackage{Y}}{}

may have been made to ensure this. Of course, it is essential
that that line also is executed earlier than [v gets b].
Is it in your case?

If it is, there is some chance that it works as you want,
and if it doesn't, you should tell more about what packages
you are actually referring to and what you are trying to change.

The situation may be more complex than I tried to describe it
with the [v gets a] and [v gets b] assignments. One thing
should get special attention: while X postpones loading Y to
\AtBeginDocument, you are forcing that Y is loaded earlier.
There may be a good reason why X postpones Y to \AtBeginDocument,
and you may just be breaking the delicate procedure
that packages X and Y are trying to perform. Especially,
Y may really need to know about "all the other packages"
loaded, and it doesn't when you force it to be loaded earlier.
Or Y just needs to know whether a certain package Z is loaded
"at all" ...

An example is nameref for Y with hyperref for X. This was nasty
for lineno.sty that needs to know whether nameref is loaded
"at all". So there is some problematic competition about
placing the "really last command \AtBeginDocument"
(I hope for proper conventions and hooks for this situation).



More information about the texhax mailing list