Skip to content

caption-koma.sto should be updated for KOMA-Script v3.46 and later

I've added a new implementation of caption above/below feature to tocbasic and replaced most parts of that implementation in the classes scrartcl, scrbook and scrreprt by just using the implementation in tocbasic. The new implementation does no longer use \if@captionabove, \if@figurecaptionabove or \if@tablecaptionabove and does actively support caption by using \captionsetup (and \clearcaptionsetup) if defined.

There is a new tocbasic option enablepatch=caption to not only provide \captionabove, \captionbelow, \captionof, \captionofbelow and \captionofabove, but also modify \caption and \captionof. This option is automatically activated, when loading tocbasic from scrartcl, scrbook or scrreprt.

Just a note: Support of \captionabove and \captionbelow within longtable still needs a KOMA-Script class, but all other parts also work with the standard classes – with and without caption. The longtable code of the KOMA-Script classes may change in future and an adaption of the code may be moved to tocbasic.

Unfortunately there are two issues with caption-koma.sto:

  1. The patch and usage of \@figurecaptionabovetrue, \@figurecaptionabovefalse and \if@figurecaptionabove is secure by using \@ifundefined{@figurecaptionabovetrue}{}{…}, but the analogues code for \@tablecaptionabovetrue, \@tablecaptionabovefalse and \if@tablecaptionabove does not unfortunately not use \@ifundefined{@tablecaptionabovetrue}{}{…}.
  2. For some reason you are deactivating options figureposition and tableposition. AFAIK option figureposition just delegates the value to \captionsetup*[figure]{position=…} and this is explicitly used for the extension of \@figurecaptionabove(true|false). Same for table. So I don't really understand, why you are doing this. And with the new code in tocbasic this results in several warnings about figureposition=default and tableposition=default have not effect.

To solve these issues, currently I use in the new versions of the classes:

\BeforeFile{caption-koma.sto}{%
  \newif\if@tablecaptionabove
  \let\KOMAAtCaptionPackage\AtCaptionPackage
  \let\AtCaptionPackage\@gobble
}
\AfterFile{caption-koma.sto}{%
  \let\AtCaptionPackage\KOMAAtCaptionPackage
}

But this also breaks the redefinition of \caption@setcapwidth@opt and therefore is not really a good idea. So it would suggest to use something like

\IfPackageAtLeastT{tocbasic}{2025/06/13}{\endinput}

before line

\g@addto@macro\@captionabovetrue{\caption@setposition{t}}

If you'd do so, I could remove the dangerous patches from the KOMA-Script classes.

If you are interested in testing the new KOMA-Script code of tocbasic and/or the classes, try, i.e. KOMA-Script revision 4180. If you like, I can also show a (somehow large) test file.

BTW1: Neither the KOMA-Script classes nor tocbasic use \scr@caption any longer. But the classes still define it, to activate the automatic loading of caption-koma.sto. Theoretically I could remove \scr@caption and add all the useful code of caption-koma.sto to the classes. But I don't like to use internal commands of caption.

BTW2: I'm reworking several parts of KOMA-Script and try to reduce the number of internal auxiliary commands using \NewDocumentCommand. Examples for candidates at the caption code of KOMA-Script are the auxiliary commands \@setcapmargin, \@@setcapmargin, \@setcaptionalignment and \@captionbeside, \@@captionbeside, \@@@captionbeside, \@@@@captionbeside. So if you need any of them, we should talk about. Maybe defining a socket to be able to use different plugs would be an option for the future. But there may be several other alternatives.

Ich hoffe, es ist mir gelungen, das Problem verständlich zu machen. Sonst kann ich es auch noch einmal auf Deutsch schildern.

Edited by Markus Kohm