I develop a package whose main part consists of fixes and patches to other document classes and packages. Naturally, I only want to apply a patch if the class or package in question has been loaded. Furthermore, there can be patches that apply to several classes/packages, and there can be patches that apply to a class/package only if some other class/package has not been loaded (for example, hyperref
modifies many things in the standard classes, and if I were to modify them too, I would have to use two versions, depending on if hyperref
has been loaded). Since I don't want to force any particular loading order, I also want to run the package detection/patching part AtBeginDocument.
One thing that comes to mind is to extend the \@ifclassloaded
and \@ifpackageloaded
commands to accept a comma-separated list of names using \@for
. Then I would say
\PatchClassIfLoaded{article,report,book}{<commands>}
and so on. But then <commands>
have to be inside an argument and will be "read" twice (pardon my insufficient TeX knowledge to describe it better), which I don't like. While this would be necessary for package patches because of \AtBeginDocument
, this is not required for classes.
I would better like a construct such as
\IfClassLoaded{article,report,book}
<commands>
\fi
I know I can program it if I go one level lower than \@ifclassloaded
. But this feels more like a hack which shouldn't be relied on.
The above was just an example of what I'm trying to achieve. The question itself is broader: Are there different solutions to the problem? Is there a package implementing similar things? What methods do packages like hyperref
and caption
use to accommodate for a large variety of classes and packages?
babel
/polyglossia
is that I'm doing heavier things which are not supposed to be reverted by another language switch. That is, the code is supposed to be for the case where this language is the main language of the document. (I also plan to contact thepolyglossia
author to enquire whether it's possible to integrate this type of code inpolyglossia
). – Andrey Vihrov Jul 14 '11 at 16:02\xpg@main@language
, set up your code and hope that not other language does something that interferes. – Ulrike Fischer Jul 14 '11 at 16:54\xpg@main@language
. This could prove really useful! – Andrey Vihrov Jul 14 '11 at 17:01