Menu

#55 Using \label inside \section command

KOMA-Script 3.41
closed
2023-06-29
2023-06-28
No

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

Discussion

  • Markus Kohm

    Markus Kohm - 2023-06-29

    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

    \listfiles
    \RequirePackage[2022/11/01]{latexrelease}
    \documentclass{scrbook}
    \begin{document}
    
    \section{foo\label{bar}}
    foo
    \end{document}
    

    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:

    \listfiles
    \documentclass{scrbook}
    \begin{document}
    
    \section[foo]{foo\label{bar}}
    foo
    \end{document}
    

    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
  • Markus Kohm

    Markus Kohm - 2023-06-29
    • labels: \label in \section --> bug, section, label, scrbook, scrreprt, scrartcl
    • status: open --> closed
    • assigned_to: Markus Kohm
     
  • Markus Kohm

    Markus Kohm - 2023-06-29

    Fixed in [r4068]. Thank you for the report and Ulrike for the detection of the reason.

     

    Related

    Commit: [r4068]

  • tudscr

    tudscr - 2023-06-29

    I just wanted to mention, that there are some packages (at least imakeidx, indextools and index) 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

    \ProvideExpandableDocumentCommand\@gobbleopt@one{o m}{}
    ...
    \begingroup
    \let\index\@gobbleopt@one
    \let\glossary\@gobbleopt@one
    ...
    \endgroup
    
     
    • Markus Kohm

      Markus Kohm - 2023-06-29

      LaTeX itself does only use \let\label\@gobble\let\index\@gobble\let\glossary\@gobble, e.g., at \addtocontents.

      With nameref (and therefore hyperref) you could use

      \GetTitleStringDisableCommands{%
        \let\index\@gobbleopt@one
        …
      }
      

      And for the case of not using nameref or hyperref but also need a correct \@currentlabelname you can use

      \AddToHook{\KOMAClassName/option/section/reference/fallback}{%
        \RenewExpandableDocumentCommand\index{om}{}%}
      

      See [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
      • tudscr

        tudscr - 2023-06-29

        LaTeX itself does only use...

        That's way I raised the issue. But as I said, nothing happened so far.

        With nameref (and therefore hyperref) you could use...

        I am doing right this. Actually, I also do add the redefinition to \pdfstringdefDisableCommands

        Thanks for clarification and your quick fix.

         
        • Markus Kohm

          Markus Kohm - 2023-06-29

          That's way I raised the issue. But as I said, nothing happened so far.

          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.

           
          👍
          1

          Last edit: Markus Kohm 2023-06-29

Log in to post a comment.