Using \label inside \section command
KOMA-Script is a bundle of versatile LaTeX classes and packages
Brought to you by:
kohm
Up-to-date TL 23
\listfiles
\documentclass{scrbook}
\begin{document}
\section{foo\label{bar}}
foo
\end{document}
output with pdflatex:
(/usr/local/texlive/2023/texmf-dist/tex/latex/l3backend/l3backend-pdftex.def)
(./test-label.aux)
! TeX capacity exceeded, sorry [input stack size=10000].
\protect ->\noexpand \protect
\noexpand
l.5 \section{foo\label{bar}}! ==> Fatal error occurred, no output PDF file produced!
Transcript written on test-label.log.
Worked with TL2022
The issue is caused by a change in the LaTeX kernel. It does not happen with the current KOMA-Script release but LaTeX 2022/11/01, e.g., using
So you could use this rollback also as a workaround (and ignore the “suspicious rollback” warnings) as long, as I've not found how to change KOMA-Script to avoid the error.
Another workaround would be to place the
\label
behind the\section
argument or to add an optional argument:Note: It would not be a workaround to
\protect
the\label
, because this would result in a multiple defined label.Another workaround would be to load at least package
gettitlename
, because in this case\GetTitleName
would be used instead of the broken code.Last edit: Markus Kohm 2023-06-29
Fixed in [r4068]. Thank you for the report and Ulrike for the detection of the reason.
Related
Commit: [r4068]
I just wanted to mention, that there are some packages (at least
imakeidx
,indextools
andindex
) which redefine\index[optional]{mandatory}
. The local redefinition to\let\index\@gobble
(and maybe\let\glossary\@gobble
as well) is error-prone.I raised https://github.com/latex3/latex2e/issues/311 some time ago but nothing happened until today. For the meanwhile, I came up with
LaTeX itself does only use
\let\label\@gobble\let\index\@gobble\let\glossary\@gobble
, e.g., at\addtocontents
.With
nameref
(and thereforehyperref
) you could useAnd for the case of not using
nameref
orhyperref
but also need a correct\@currentlabelname
you can useSee [r4069] for the corresponding change.
However, even without doing so, there wouldn't be an error, but only an useless
\@currentlabelname
.And no, currently I won't document the hook, because if the LaTeX team would introduce a new hook or another solution, it would be better to also adapt that for KOMA-Script.
Related
Commit: [r4069]
Last edit: Markus Kohm 2023-06-29
That's way I raised the issue. But as I said, nothing happened so far.
I am doing right this. Actually, I also do add the redefinition to
\pdfstringdefDisableCommands
Thanks for clarification and your quick fix.
The problem for package authors in such cases is that they first wait for solutions in the LaTeX kernel. If they have to wait too long, they eventually implement their own solution. When a LaTeX kernel solution finally is available, their own solution often blows up in their face. Then, in addition to using the LaTeX kernel solution, they may have to see how to rebuild their solution to be backwards compatible if possible. In the end, that's a lot more work that would have been better spent on something else.
So, currently I'm in a new wait state with implementation of an undocumented workaround only for those, who have an issue, and hoping that nobody will have the issue, because without (at least)
nameref
the whole\@currentlabelname
feature does not make much sense.Most important: The reported bug is fixed. There should be no more errors with
\label
in the mandatory argument of\section
etc.Last edit: Markus Kohm 2023-06-29