It is known that the package scrhack should be loaded as late as possible to avoid some errors. See here for such a problem.
However, when writing a document class or a package, I would like to require packages (without necessarily requiring conflicting packages).
An example illustrates my problem:
% MyTheme.cls
\NeedsTeXFormat{LaTeX2e}[1996/12/01]
\newcommand{\classname}{MastersDoctoralThesis}
\ProvidesClass{\classname}[2020/08/24 v1.7 LaTeXTemplates.com]
\providecommand{\baseclass}{book}
\LoadClass{\baseclass}
\RequirePackage{scrhack}
% main.tex
\documentclass{MyTheme}
\usepackage{listings}
\usepackage[outputdir=build]{minted}
\begin{document}
Test
\end{document}
This will create the following error:
scrhack Error: extension `lol' already in use.
The problem is solved if I remove \RequirePackage{scrhack} in MyTheme.cls, or if I add \RequirePackage{minted} before \RequirePackage{scrhack}. However, I prefer to keep the dependency on scrhack explicit, and don't want to create unnecessary dependencies.
...but how? Is it possible to somehow request a package with \RequirePackage, but delay loading it?
\AtBeginDocument{\usepackage{scrhack}}in the document class solves my problem. – normanius Sep 28 '22 at 19:04\AddToHook{begindocument/before}{...}– Ulrike Fischer Sep 28 '22 at 19:11