A LaTeX class and package is provided which allows LaTeX diagrams or other LaTeX code to be compiled standalone or as part of a main document. Special support for pictures with beamer overlays is also provided.
Currently, .sta file, which (if exists) contains the collected sub-preambles, is read at begin of document (\AtBeginDocument). Since theses preambles may load packages by themselves, loading .sta in \AtBeginDocument maybe too late. See discussions in latex3/hyperref#242 and question 670638 on TeX-SX.
In LaTeX2e 2020-10-01, a hook management system is introduced hence \AtBeginDocument becomes a thin wrapper of \AddToHook{begindocument}. This hook system also provides a better position to load packages at the end of preamble: hook begindocument/before. In older LaTeX2e, this hook can be emulated by \AtEndPreamble from etoolbox package.
A proposal that only makes code changes (comment are not adapted):
diff --git a/standalone.sty b/standalone.sty
index 557f254..497a571 100644
--- a/standalone.sty
+++ b/standalone.sty
@@ -933,7 +933,11 @@
% The |standalone| macros are defined to be without effect. If `sorting' is enabled \cs{usepackage} is temporarily
% redefined to ignore any given options, which where already passed (\cs{PassOptionsToPackage}) beforehand.
% \begin{macrocode}
-\AtBeginDocument{%
+\providecommand\IfFormatAtLeastTF{\@ifl@t@r\fmtversion}
+\IfFormatAtLeastTF{2020-10-01}
+ {\AddToHook{begindocument/before}}
+ {\RequirePackage{etoolbox}\AtEndPreamble}
+{%
\let\subpreamble\@gobble
\let\endsubpreamble\relax
\let\standalonepreambles\relax
Currently,
.sta
file, which (if exists) contains the collected sub-preambles, is read at begin of document (\AtBeginDocument
). Since theses preambles may load packages by themselves, loading.sta
in\AtBeginDocument
maybe too late. See discussions in latex3/hyperref#242 and question 670638 on TeX-SX.In LaTeX2e 2020-10-01, a hook management system is introduced hence
\AtBeginDocument
becomes a thin wrapper of\AddToHook{begindocument}
. This hook system also provides a better position to load packages at the end of preamble: hookbegindocument/before
. In older LaTeX2e, this hook can be emulated by\AtEndPreamble
frometoolbox
package.A proposal that only makes code changes (comment are not adapted):