-
-
Notifications
You must be signed in to change notification settings - Fork 276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LaTeX ‘Loading a class or package in a group’ error triggered in unrelated situations? #1626
Comments
The error was raised when loading
A simpler example which reproduces the same error: \RequirePackage{latexbug} % <--should be always the first line (see CONTRIBUTING)!
\documentclass{article}
\usepackage{graphics}
\AddToHook{env/document/begin}{\begingroup} % I know, this is a misuse of the `env/document/begin` hook
\AddToHook{env/document/end}{\endgroup}
\begin{document}
Foo
\end{document} log
So the error is detected correctly, just with a vague error message. |
You are definitively using the wrong hook. This hook is executed at a time when packages can (and are) still be loaded (e.g. in the following hooks), so you should not put code there that opens a group. |
It sure is the wrong hook, but I don't understand what you are attempting to do there with a tcolorbox, what do you intend the tcolorbox to contain? Right now as written you put the initialization code of By the way, if you already know that what you do is wrong (as your comment indicates) then opening a bug report here isn't really the right thing to do. Better put such questions in front of the TeX community, e.g. on StackExchange. |
Well, some silly things 😉: in a class of mine based on the \AddToHook{cmd/sa@cls@afterbegindocument/after}{
\begin{tcolorbox}
}
That's not how I understood:
For me: \newenvironment{⟨env⟩}{%
\begin{tcolorbox}
}{
...
} puts the
Indeed.
That's what I did at first, but then I changed my mind because, although it was a misuse, I had the impression that the error that was triggering was causing an inappropriate message and that, perhaps, it was some kind of bug. |
@dbitouze Your understanding may not be wrong, just the Roughly speaking, \UseHook{env/⟨env⟩/before}
\begingroup % if ⟨env⟩ is not "document"
\UseHook{env/⟨env⟩/begin}
\⟨env⟩ The general hook
But for the
|
so basically, the standalone class kills the standard hooks in the document environment, because begindocument/end would have been the right hook to use. I guess standalone should not patch but use Finally, I succeeded with:
yes that would work (sort of patch on top of patch). But as I said standalone shouldn't make that patch and if so you could have then simply said
if necessary with a hook rule if the order is not right (but if used in the preamble it would be).
No, it does not put it "inside" The only difference between env/.../before and env/.../begin is that the latter happens after
yes I missread the second part of your hook code, mea culpa
yeah ok, I see how it came about, but it hasn't been a bug: The correct way to use the hooks in cat case would have been
but as you found that doesn't quite work with the standalone class (but perhaps they should seriously consider using the hooks and not patching |
Many thanks for this detailed comment!
BTW, would using
You are very welcome!
I just suggested this on the repository of |
it might be but I doubt it. tcolorbox has to wrap everything in a box (which is a group of its own(. Anyway, it would still be wrongm as you start typesetting before \document has finished. So don't experiment with that.
good. It is actually more than a recommendation really, because standalone breaks the documented interfaces of LaTeX, e.g. |
BTW, the comments of this answer on TeX.SE are:
|
Brief outline of the enhancement
If
begin{tcolorbox}
from thetcolorbox
package (I know, it's a third-party package, but the following problem may still be worth mentioning) is added, not explicitly at the beginning of the document, but through\AddToHook{env/document/begin}
, compilation fails with the following error:when neither the class nor any package seems to be loaded in a group.
Perhaps something is wrong with the way a class or a package loaded in a group is detected.
Minimal example showing the current behaviour
The text was updated successfully, but these errors were encountered: