latex2e icon indicating copy to clipboard operation
latex2e copied to clipboard

error if packages are loaded in a group

Open u-fischer opened this issue 2 years ago • 1 comments

Brief outline of the bug

Packages should not be loaded in a group as this can lead to misbeheaviour that can be hard to detect or understand. As an example hyperref fails with an internal socket error if a group has been opened by mistake: https://github.com/latex3/hyperref/issues/315.

\usepackage and \RequirePackage should check the group level and error directly.

u-fischer avatar Nov 21 '23 18:11 u-fischer

This issue has been automatically marked as stale because it has not had recent activity.

github-actions[bot] avatar Mar 16 '24 08:03 github-actions[bot]

Sorry to be "that guy", but this broke font packages that conditionally require other packages based on package options (e.g., notomath). Is this known, and are there mitigation strategies?

clason avatar Jun 03 '24 11:06 clason

@clason do you have an example where notomath breaks? I don't see a package loaded in a group there.

u-fischer avatar Jun 03 '24 11:06 u-fischer

Sure, give me a minute to extract the issue (it happens in a beamer theme).

clason avatar Jun 03 '24 11:06 clason

\documentclass{article}
\usepackage[sfdefault]{notomath}
\begin{document}
Test
\end{document}

The sfdefault option is what triggers the error:

This is pdfTeX, Version 3.141592653-2.6-1.40.26 (TeX Live 2024) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./style.tex
LaTeX2e <2024-06-01>
L3 programming layer <2024-05-08>
(/usr/local/texlive/2024/texmf-dist/tex/latex/base/article.cls
Document Class: article 2024/02/08 v1.4n Standard LaTeX document class
(/usr/local/texlive/2024/texmf-dist/tex/latex/base/size10.clo))
(/usr/local/texlive/2024/texmf-dist/tex/latex/notomath/notomath.sty
(/usr/local/texlive/2024/texmf-dist/tex/latex/base/fontenc.sty)
(/usr/local/texlive/2024/texmf-dist/tex/latex/fontaxes/fontaxes.sty)
(/usr/local/texlive/2024/texmf-dist/tex/latex/xkeyval/xkeyval.sty
(/usr/local/texlive/2024/texmf-dist/tex/generic/xkeyval/xkeyval.tex
(/usr/local/texlive/2024/texmf-dist/tex/generic/xkeyval/xkvutils.tex
(/usr/local/texlive/2024/texmf-dist/tex/generic/xkeyval/keyval.tex))))
(/usr/local/texlive/2024/texmf-dist/tex/latex/base/textcomp.sty)

! LaTeX Error: Loading a class or package in a group.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...

l.67 \usepackage
                {noto-serif}

Just ignoring that recurses and throws further (identical) errors there about packages required in noto-serif.sty (and packages required by those packages, and so on -- elephants all the way down).

(Let me know if I should open a new issue.)

clason avatar Jun 03 '24 11:06 clason

Seems to be this line in notomath.sty that is the culprit:

\ifnoto@sfdefault{\noto@MO{notosans}\else\noto@MO{noto}\fi

(which is defined by \newif\ifnoto@sfdefault \noto@sfdefaultfalse).

I don't quite see why, but commenting it out removes the error. (Voodoo debugging at its finest!)

clason avatar Jun 03 '24 12:06 clason

Oh, of course, that's a typo (missing brace closing the first clause). 🤦

Thanks for rubber-ducking, and sorry for wasting your time! Looks like this PR is doing its work already ;) I'll notify the maintainer.

clason avatar Jun 03 '24 12:06 clason

well that is a clear bug in the package. The stray brace after \ifnoto@sfdefault shouldn't be there at all, and in earlier versions it would have lead to ### simple group (level 1) entered at line 54 ({). Notify the author.

u-fischer avatar Jun 03 '24 12:06 u-fischer