Document Classes ⇒ conditional \RequirePackage
conditional \RequirePackage
February but never got a response.
Is there a conditional expression I can put in a style file
by means of which I can execute \RequirePackage only if know
that a package has not already been Provided?
We have a standard package we use with most of our
documentation with the command:
\RequirePackage{fancyhdr}
Meanwhile, I was trying to do create a template using the
newlfm package that includes its own instance of
\RequirePackage{fancyhdr}, so that when I do
\documentclass{newlfm}
\uspackage{ourstylefile}
it stops and tells me that commands from the fancyhdr
package are already defined.
This is fine, and I can alter our style package to retrieve
fancyhdr only if it's not already defined ... but I don't
know how to specify a test for that. I assume this must be
possible?
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
conditional \RequirePackage
Code: Select all
\IfFileExists{file}{then-code}{else-code}
\InputIfFileExists{file}{then-code}{else-code}
conditional \RequirePackage
My problem is one of wanting to \RequirePackage in a style file, which I gather is functionally equivalent to \usepackage in a LaTeX document file, only if that package has not already been loaded.
To provide a comparison from Lisp (Emacs Lisp in this case): packages often have a line at the end that says (provide 'packagename), which I understand to be pretty much the same as \ProvidesPackage in a style file. It's just a label that is presumably added to some list which indicates that the package has been successfully loaded. Therefore, in Lisp, you would do:
Code: Select all
(if (featurep 'somepackage)
(do-this-if-true)
(do-this-if-false))
I don't mean to confuse the issue here; I'm just trying to understand it by comparing what I know.
Since LaTeX includes a \ProvidesPackage command for style files, my assumption is that it would have no purpose if there was no way to test it, e.g., by a corresponding command that might be named \IfPackageProvided. Therefore, one might be able to do something like:
Code: Select all
\IfPackageProvided{somepackage}{true-code-maybe-do-nothing}{\RequirePackage{somepackage}}
Thanks.