12

I'm in the process of cleaning up my class file and I'm unclear as for the proper order of some lines. For example (replacing \RequirePackage with \usepackage and putting this in a MWE):

\documentclass{article}
\usepackage{mathtools}
\usepackage{tabularray}
\UseTblrLibrary{amsmath}

\begin{document}
foo
\end{document}

Line 2, mathtools loads and patches amsmath. After that, line 4, according to its documentation, tabularray loads amsmath to provide additional features.

I guess that the modifications to amsmath provided by mathtools aren't overwritten by the latter, but I haven't found a way to confirm that there's no drawback to have some package try to load amsmath again.

The couple of packages used here are just an example, since I have similar concerns with packages that trigger loading of tikz or hyperref. So my question isn't (hopefully) about those specific examples. Thanks in advance.

1
  • Packages are never reloaded (terms and conditions may apply) Commented Jun 6, 2022 at 0:02

1 Answer 1

14

Packages are never reloaded (to the exception of fontenc, which is rather special). The code in \usepackage ensures that a package is loaded only once, and any further attempt to load it again is either ignored, or raises an error. That means any change you do to a package's macros are not overwritten.

If you just do \usepackage twice, the second call is just ignored. If you call \usepackage with options to the package, and the options differ between one call and the next, an “Option clash” error is raised (there's a bit more to it, but essentially this is what happens).

3
  • Thank you. Just to be sure, is there a difference between \usepackage and \RequirePackage with regards to this?
    – Miyase
    Commented Jun 6, 2022 at 0:49
  • 2
    @Miyase The only practical difference between them is that \usepackage cannot be used before \documentclass, while \RequirePackage can, otherwise they are identical. \usepackage is the user interface, that should be used in a document, whereas \RequirePackage is the programmer interface, to be used in packages and classes, but it's more of a philosophical difference Commented Jun 6, 2022 at 0:55
  • OK, that I got that right at least. Now I can reorder my class file a bit with some peace of mind. Thans again.
    – Miyase
    Commented Jun 6, 2022 at 0:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .