0

When you \RequirePackage{foo} in a document class, this "loads" the package so you can start using it. But what if you don't want to do that? What if you only want to ensure it is available for loading, e.g. for other code to be able to \usepackage{foo} later on?

Is that possible?

Motivation: I'm going to be deferring the loading of a package within a document class, but I do want to fail immediately if the package isn't there so as not to confuse whoever is reading the logs.

einpoklum
  • 12,311
  • 3
    Use \IfFileExists, see https://tex.stackexchange.com/questions/98203/can-i-test-if-a-file-exists – egreg Sep 19 '17 at 23:32
  • @egreg: And the file must be foo.sty and nothing else? – einpoklum Sep 19 '17 at 23:34
  • \IfFileExists{foo.sty}{Do something if it exists}{Do something else otherwise} – egreg Sep 19 '17 at 23:36
  • Does \IfFileExists look in all of the places that \usepackage would? – Michael Palmer Sep 19 '17 at 23:51
  • 3
    What is the use-case for this? It seems pointless. Either the package will get loaded later or it isn't needed. Why does the class need to poke its nose into the business at all? A class is responsible for what it needs. It shouldn't go second-guessing what some other code might need, if we ever get there. – cfr Sep 20 '17 at 00:01
  • Why would it confuse the person reading the logs? This is a completely standard thing to do. If you want to make clear that your package is responsible for the load, use \IfFileExist{\Require...}{error...} in the deferred code. – cfr Sep 20 '17 at 00:45
  • 2
    @MichaelPalmer: Yes. As a matter of fact, \usepackage itself indirectly calls \IfFileExists to load the .sty file. – GuM Sep 20 '17 at 01:55
  • @GuM - thanks. I was under the impression that it only checked a single file name or path. – Michael Palmer Sep 20 '17 at 02:09
  • @koleygr: I agree. – einpoklum Sep 20 '17 at 08:18

0 Answers0