Menu

#93 Version 3.46 gives inconsistent document command for \caption

KOMA-Script 3.48
closed
2025-08-29
2025-08-29
No

Following the ticket 81, the \caption and \captionof commands were redefined in version 3.46. Looking at the tocbasic code, these redefinitions were done through \cs_set_eq:NN

\cs_set_eq:NN \__tocbasic_saved_caption:w \caption
...
\cs_set_eq:NN \caption \__tocbasic_caption:w
\cs_set_eq:NN \captionof \__tocbasic_caption_of:w

However, \__tocbasic_caption:w and \__tocbasic_caption_of:w are document commands (created with \NewDocumentCommand). Their code are stored in auxiliary macros. For example

\NewDocumentCommand {\mydocumentcommand} { m } {Test: #1}
\show\mydocumentcommand

gives

> \mydocumentcommand=\protected macro:
->\__cmd_start_optimized: \mydocumentcommand code .

The code is stored in the macro \mydocumentcommand code (including the space). \cs_set_eq:NN doesn't copy the auxiliary macro.

For example:

\show\caption

gives

> \caption=\protected macro:
->\__cmd_start:nNNnnn {sO{##3}m}\__tocbasic_caption:w  \__tocbasic_caption:w code {\__cmd_grab_t:w *\__cmd_grab_D:w []\__cmd_grab_m_1:w }{\c_novalue_tl {\prg_do_nothing: ##3}\c_novalue_tl }{}.

where it should be

> \caption=\protected macro:
->\__cmd_start:nNNnnn {sO{##3}m}\caption  \caption code {\__cmd_grab_t:w *\__cmd_grab_D:w []\__cmd_grab_m_1:w }{\c_novalue_tl {\prg_do_nothing: ##3}\c_novalue_tl }{}.

As a consequence, this simple code doesn't work

\documentclass{scrartcl}

\begin{document}

\begin{figure}
  \caption{caption}
\end{figure}

\NewCommandCopy \mycaption \caption
\ShowCommand\mycaption

\begin{figure}
  \mycaption{mycaption}
\end{figure}

\end{document}

Indeed \ShowCommand\mycaption shows that \mycaption does nothing (because \caption code doesn't exist).

Using

\DeclareCommandCopy { \caption } { \__tocbasic_caption:w }

fixes this issue. With \DeclareCommandCopy, the \caption definition is consistent with the document command scheme (the macro \caption code is defined). \ShowCommand\caption shows

> \caption=document command:
  #1:s
  #2:O{##3}
  #3:m
->\group_begin: \__tocbasic_tocbasic_caption_setup: \exp_last_unbraced:Ne
\__tocbasic_saved_caption:w {\IfBooleanT {#1}*}[{#2}]{#3}\group_end: .

It correctly uses the KOMA-Script redefinition.

I suggest then to replace the \cs_set_eq:NN in tocbasic by \NewCommandCopy, \RenewCommandCopy or \DeclareCommandCopy (including for \cs_set_eq:NN \__tocbasic_saved_caption:w \caption, in the case where\caption was previoulsly defined with \NewDocumentCommand).

Discussion

  • Markus Kohm

    Markus Kohm - 2025-08-29
    • labels: --> bug, tocbasic
    • summary: Vesion 3.46 gives inconsistent document command for \caption --> Version 3.46 gives inconsistent document command for \caption
    • status: open --> closed
    • assigned_to: Markus Kohm
     
  • Markus Kohm

    Markus Kohm - 2025-08-29

    You are absolutely right. Thanks for letting me know. Should be fixed in [r4217] resp. [r4218].

     

    Related

    Commit: [r4217]
    Commit: [r4218]


    Last edit: Markus Kohm 2025-08-29
  • Julien Labbé

    Julien Labbé - 2025-08-29

    Thank you for your responsiveness.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.