Debian Codegraph @

texmf-dist/source/latex/caption/caption-koma.dtx

raw
1 % \iffalse meta-comment
2 %
3 % This is file `caption-koma.dtx'.
4 %
5 % Copyright (C) 2004-2023 Axel Sommerfeldt ([email protected])
6 %
7 % --------------------------------------------------------------------------
8 %
9 % This work may be distributed and/or modified under the
10 % conditions of the LaTeX Project Public License, either version 1.3
11 % of this license or (at your option) any later version.
12 % The latest version of this license is in
13 % http://www.latex-project.org/lppl.txt
14 % and version 1.3 or later is part of all distributions of LaTeX
15 % version 2003/12/01 or later.
16 %
17 % This work has the LPPL maintenance status "maintained".
18 %
19 % This Current Maintainer of this work is Axel Sommerfeldt.
20 %
21 % This work consists of the files
22 % caption.ins, caption.dtx, caption-light.dtx, caption2.dtx, caption3.dtx,
23 % caption-ams-smf.dtx, caption-beamer.dtx, caption-elsarticle.dtx,
24 % caption-koma.dtx, caption-memoir.dtx, caption-ntg.dtx,
25 % caption-thesis.dtx, bicaption.dtx, ltcaption.dtx, subcaption.dtx,
26 % the derived files
27 % caption.sty, caption-light.sty, caption2.sty, caption3.sty,
28 % caption-ams-smf.sto, caption-beamer.sto, caption-elsarticle.sto,
29 % caption-koma.sto, caption-memoir.sto, caption-ntg.sto,
30 % caption-thesis.sto, bicaption.sty, ltcaption.sty, subcaption.sty.
31 %
32 % \fi
33 %
34 % \CheckSum{262}
35 %
36 % \iffalse
37 %<*driver>
38 \NeedsTeXFormat{LaTeX2e}[1994/12/01]
39 \ProvidesFile{caption-koma.drv}[2023/07/10 v2.0 Implementation of the caption-koma package]
40 %\errorcontextlines=3
41 %
42 \documentclass{captiondoc}
43 \hypersetup{pdfkeywords={LaTeX, package, caption-koma}}
44 %
45 \begin{document}
46 \DocInput{caption-koma.dtx}
47 \end{document}
48 %</driver>
49 % \fi
50 %
51 % \GetFileInfo{caption-koma.drv}
52 % \let\docdate\filedate
53 % \let\docversion\fileversion
54 % \GetFileInfo{caption-koma.sto}
55 %
56 % \title{\texorpdfstring
57 % {The adaption of the \pkg{caption} package to the \KOMAScript\ document classes\thanks{%^^A
58 % This adaption has version number \docversion.}}%^^A
59 % {The adaption of the caption package to the KOMA-Script document classes}}
60 % \author{Axel Sommerfeldt\\
61 % \url{https://gitlab.com/axelsommerfeldt/caption}}
62 % \date{\docdate}
63 % \maketitle
64 %
65 % \begin{abstract}
66 % This package adapts the \pkg{caption} package to the \KOMAScript\ document classes.
67 % \end{abstract}
68 %
69 % \section*{User manual}
70 %
71 % This document is describing the code implementation only.
72 % The user documentation can be found in
73 % \nopagebreak\begin{quote}
74 % \begin{tabular}{ll}
75 % \href{http://mirror.ctan.org/macros/latex/contrib/caption/caption.pdf}%
76 % {\texttt{caption.pdf}} & The caption package documentation \\
77 % \end{tabular}
78 % \end{quote}
79 %
80 % \section*{State of this package}
81 %
82 % Please note that the last major revision of this code was done in the year 2007,
83 % afterwards the \KOMAScript\ support was adapted to changes in the \pkg{caption} package only.
84 %
85 % So nearly everything which has changed in the caption support of \KOMAScript\ since 2007 is not reflected here.
86 % (So for example |\set|\-|cap|\-|dyn|\-|width| is not emulated yet etc.)
87 %
88 % \StopEventually{}
89 % \iffalse
90 % \clearpage
91 % \tableofcontents
92 % \fi
93 %
94 % \iffalse
95 % --------------------------------------------------------------------------- %
96 % \fi
97 %
98 % \DoNotIndex{\\,\_,\ ,\@@par}
99 % \DoNotIndex{\@bsphack}
100 % \DoNotIndex{\@car,\@cdr,\@classoptionslist,\@cons,\@currext,\@currname}
101 % \DoNotIndex{\@ehc,\@ehd,\@empty,\@esphack,\@expandtwoargs}
102 % \DoNotIndex{\@for,\@firstofone,\@firstoftwo}
103 % \DoNotIndex{\@gobble,\@gobblefour,\@gobbletwo,\@hangfrom}
104 % \DoNotIndex{\if@minipage,\@ifnextchar,\@ifpackagelater,\@ifpackageloaded}
105 % \DoNotIndex{\@ifstar,\@ifundefined,\@latex@error,\@minipagefalse,\@minipagetrue}
106 % \DoNotIndex{\@namedef,\@nameuse}
107 % \DoNotIndex{\@onlypreamble,\@parboxrestore,\@plus,\@ptionlist}
108 % \DoNotIndex{\@removeelement,\@restorepar,\@secondoftwo,\@setminipage,\@setpar}
109 % \DoNotIndex{\@tempa,\@tempboxa,\@tempdima,\@tempdimb,\@tempdimc,\@tempb,\@tempc}
110 % \DoNotIndex{\@testopt}
111 % \DoNotIndex{\@undefined,\@unprocessedoptions,\@unusedoptionlist}
112 % \DoNotIndex{\p@,\z@}
113 % \DoNotIndex{\active,\addtocounter,\addtolength,\advance,\aftergroup}
114 % \DoNotIndex{\baselineskip,\begin,\begingroup,\bfseries,\box}
115 % \DoNotIndex{\catcode,\centering,\changes,\csname,\def,\divide,\do,\downarrow}
116 % \DoNotIndex{\edef,\else,\empty,\end,\endcsname,\endgraf,\endgroup,\expandafter}
117 % \DoNotIndex{\fi,\footnotesize,\global}
118 % \DoNotIndex{\hangindent,\hbox,\hfil,\hsize,\hskip,\hspace,\hss}
119 % \DoNotIndex{\ifcase,\ifdim,\ifnum,\ifodd,\ifvoid,\ifvmode}
120 % \DoNotIndex{\ifx,\ignorespaces,\itshape}
121 % \DoNotIndex{\kernel@ifnextchar}
122 % \DoNotIndex{\Large,\large,\leavevmode,\leftmargini,\leftskip,\let,\linewidth}
123 % \DoNotIndex{\llap,\long,\m@ne,\margin,\mdseries,\message}
124 % \DoNotIndex{\newcommand,\newdimen,\newlength,\newline,\newif,\newsavebox}
125 % \DoNotIndex{\next,\nobreak,\nobreakspace,\noexpand,\noindent,\numberline}
126 % \DoNotIndex{\normalcolor,\normalfont,\normalsize,\or,\par,\parbox,\parfillskip}
127 % \DoNotIndex{\parindent,\parskip,\prevdepth,\protect,\protected@edef,\protected@write}
128 % \DoNotIndex{\providecommand,\quad}
129 % \DoNotIndex{\raggedleft,\raggedright,\relax,\renewcommand,\RequirePackage}
130 % \DoNotIndex{\rightskip,\rmfamily}
131 % \DoNotIndex{\sbox,\scriptsize,\scshape,\setbox,\setlength,\sffamily,\slshape}
132 % \DoNotIndex{\small,\string,\space,\strut}
133 % \DoNotIndex{\textheight,\the,\toks@,\typeout,\ttfamily}
134 % \DoNotIndex{\unvbox,\uparrow,\upshape,\usebox,\usepackage}
135 % \DoNotIndex{\value,\vbox,\vsize,\vskip,\wd,\width,\z@skip}
136 % \DoNotIndex{\AtBeginDocument,\AtEndOfPackage,\CurrentOption,\DeclareOption}
137 % \DoNotIndex{\ExecuteOptions,\GenericWarning,\IfFileExists,\InputIfFileExists}
138 % \DoNotIndex{\NeedsTeXFormat,\MessageBreak}
139 % \DoNotIndex{\PackageError,\PackageInfo,\PackageWarning,\PackageWarningNoLine}
140 % \DoNotIndex{\PassOptionsToPackage,\ProcessOptions,\ProvidesPackage}
141 %
142 % \iffalse
143 % --------------------------------------------------------------------------- %
144 % \fi
145 %
146 % \setlength{\parskip}{0pt plus 1pt}
147 % \newcommand*\Note[2][Note]{\par{\small\emph{#1:} #2}\par}
148 %
149 % \changes{v1.0a}{2004/01/18}{Minimum adaptation to \KOMAScript\ added}
150 % \changes{v1.0h}{2005/08/22}{\KOMAScript\ compatibility options added}
151 % \changes{v1.0i}{2005/11/17}{\KOMAScript\ compatibility commands added}
152 % \changes{v1.0l}{2007/02/18}{\KOMAScript\ compatibility revised}
153 % \changes{v1.1}{2007/03/17}{\KOMAScript\ compatibility options removed}
154 % \changes{v1.1}{2007/03/31}{\KOMAScript\ classes support added}
155 % \changes{v1.1}{2007/04/05}{\KOMAScript\ compatibility revised \& enhanced}
156 % \changes{v2.0}{2020/07/27}{\KOMAScript\ class support adapted to \pkg{caption3}~\version{2.0}}
157 %
158 % \iffalse
159 % --------------------------------------------------------------------------- %
160 % \fi
161 %
162 % \clearpage
163 %
164 % \iffalse
165 %<*package>
166 % \fi
167 %
168 % \section{Identification}
169 %
170 % \begin{macrocode}
171 \NeedsTeXFormat{LaTeX2e}[1994/12/01]
172 \ProvidesFile{caption-koma.sto}[2023/09/08 v2.0e Adaption of the caption package to the KOMA-Script document classes (AR)]
173 % \end{macrocode}
174 %
175 % \section{Margin or width}
176 %
177 % \begin{macro}{\setcapwidth}
178 % \changes{v1.9}{2018/12/26}{Bugfix: Missing curly braces added}
179 % Patch |\setcapwidth| so it will set the \pkg{caption3} width setting, too.
180 % \begin{macrocode}
181 \expandafter\let\expandafter\caption@koma@setcapwidth
182 \csname\string\setcapwidth\endcsname
183 \@namedef{\string\setcapwidth}[#1]#2{%
184 \caption@koma@setcapwidth[{#1}]{#2}%
185 \caption@setcapwidth@opt{#1}%
186 \caption@setcapwidth}
187 % \end{macrocode}
188 % The optional argument of \cs{setcapwidth} if not supported (yet),
189 % so we issue a warning if used.
190 % (Since this does not seem to have an negative effect when used
191 % by the \texttt{captionbeside} environment, we suppress the warning here.)
192 % \begin{macrocode}
193 \newcommand*\caption@setcapwidth@opt[1]{}
194 \AtCaptionPackage{\renewcommand*\caption@setcapwidth@opt[1]{%
195 \ifx\\#1\\\else
196 \caption@ifdefined\cap@margin{%
197 \def\@tempa{captionbeside}%
198 \ifx\@tempa\@currenvir\else\caption@Warning{%
199 Ignoring optional argument [#1] of \string\setcapwidth\MessageBreak}%
200 \fi}{}%
201 \fi}}
202 % \end{macrocode}
203 % \begin{macrocode}
204 \newcommand*\caption@setcapwidth{%
205 \captionsetup{width=\cap@width}}
206 % \end{macrocode}
207 % \begin{macrocode}
208 \def\caption@tempa{\hsize}%
209 \ifx\caption@tempa\cap@width \else
210 \caption@setcapwidth
211 \fi
212 % \end{macrocode}
213 % \end{macro}
214 %
215 % \emph{TODO:} |\setcapdynwidth|
216 %
217 % \begin{macro}{\setcapmargin}
218 % Patch |\setcapmargin| so it will set the \pkg{caption3} margin setting, too.
219 % \begin{macrocode}
220 \expandafter\let\expandafter\caption@koma@setcapmargin
221 \csname\string\@setcapmargin\endcsname
222 \@namedef{\string\@setcapmargin}[#1]#2{%
223 \caption@koma@setcapmargin[{#1}]{#2}%
224 \caption@setcapmargin}
225 % \end{macrocode}
226 % \begin{macrocode}
227 \expandafter\let\expandafter\caption@koma@@setcapmargin
228 \csname\string\@@setcapmargin\endcsname
229 \@namedef{\string\@@setcapmargin}[#1]#2{%
230 \caption@koma@@setcapmargin[{#1}]{#2}%
231 \caption@setcapmargin}
232 % \end{macrocode}
233 % \begin{macrocode}
234 \newcommand*\caption@setcapmargin{%
235 \begingroup
236 \let\onelinecaptionsfalse\relax
237 \def\@twoside{0}%
238 \def\if@twoside{\def\@twoside{1}\iffalse}%
239 \cap@margin
240 \def\@tempa{\endgroup}%
241 \ifx\cap@left\hfill\else\ifx\cap@right\hfill\else
242 \def\hspace##1##{\@firstofone}%
243 \edef\@tempa{\endgroup
244 \noexpand\captionsetup{%
245 twoside=\@twoside,slc=0,%
246 margin={\cap@left,\cap@right}}}%
247 \fi\fi
248 \@tempa}
249 % \end{macrocode}
250 % \begin{macrocode}
251 \ifx\cap@margin\relax \else
252 \caption@setcapmargin
253 \fi
254 % \end{macrocode}
255 % \end{macro}
256 %
257 % \section{Indentions}
258 %
259 % \begin{macro}{\setcapindent}
260 % Patch |\setcapindent| so it will set the \pkg{caption3} indention setting, too.
261 % \begin{macrocode}
262 \let\caption@koma@setcapindent\@setcapindent
263 \renewcommand*\@setcapindent[1]{%
264 \caption@koma@setcapindent{#1}%
265 \caption@setcapindent}
266 % \end{macrocode}
267 % \begin{macrocode}
268 \let\caption@koma@@setcapindent\@@setcapindent
269 \renewcommand*\@@setcapindent[1]{%
270 \caption@koma@@setcapindent{#1}%
271 \caption@setcapindent}
272 % \end{macrocode}
273 % \begin{macrocode}
274 \newcommand*\caption@setcapindent{%
275 \captionsetup{indent=\ifdim\cap@indent<\z@\z@\else\cap@indent\fi}}
276 % \end{macrocode}
277 % \end{macro}
278 %
279 % \begin{macrocode}
280 \caption@ifdefined\cap@indent{\caption@setcapindent}{}
281 % \end{macrocode}
282 %
283 % \section{Single-line-check}
284 %
285 % \begin{macro}{\ifonelinecaptions}
286 % \changes{v1.1g}{2008/03/01}{\cs{def} changed to \cs{g@addto@macro}}
287 % \changes{v2.0d}{2023/09/08}{Re-written using \cs{DeclareCaptionSinglelinecheck} and \cs{SetCaptionDefault}}
288 % Define an own single-line-check which depends on |\ifonelinecaptions| offered by \KOMAScript.
289 % \begin{macrocode}
290 \DeclareCaptionSinglelinecheck{koma}{%
291 \ifonelinecaptions
292 \expandafter\@firstoftwo
293 \else
294 \expandafter\@secondoftwo
295 \fi}
296 % \end{macrocode}
297 % Make this new single-line-check the default one.
298 % \begin{macrocode}
299 \SetCaptionDefault{singlelinecheck}{koma}
300 % \end{macrocode}
301 % Patch |\onelinecaptionstrue| and |onelinecaptionsfalse| so they will set the corresponding \pkg{caption3} setting, too.
302 % \begin{macrocode}
303 \g@addto@macro\onelinecaptionstrue{\caption@setsinglelinecheck{koma}}
304 \g@addto@macro\onelinecaptionsfalse{\caption@setsinglelinecheck{koma}}
305 % \end{macrocode}
306 % \end{macro}
307 %
308 % \section{Format}
309 %
310 % The `koma' caption format was taken from \KOMAScript\ \cs{@makecaption} and adapted.
311 % \begin{macrocode}
312 \DeclareCaptionFormat{koma}[#1#2#3\par]{%
313 \ifdofullc@p
314 \caption@useformat{hang}{#1}{#2}{#3}%
315 \else
316 #1#2%
317 \ifdim\cap@indent<\z@
318 \par
319 \noindent\hspace*{-\cap@indent}%
320 \else\if@capbreak
321 \par
322 \fi\fi
323 #3\par
324 \fi}
325 % \end{macrocode}
326 % \begin{macrocode}
327 \SetCaptionDefault{format}{koma}
328 % \end{macrocode}
329 %
330 % \section{Label format}
331 %
332 % \begin{macrocode}
333 \DeclareCaptionLabelFormat{koma}{\bothIfFirst{#1}{\nobreakspace}#2\autodot}
334 % \end{macrocode}
335 % The `fallback' caption label format maps to `koma'.
336 % \begin{macrocode}
337 \SetCaptionFallback{labelformat}{koma}
338 % \end{macrocode}
339 %
340 % \section{Label separator}
341 %
342 % The `default' caption label separator maps to \cs{captionformat}.
343 % \begin{macrocode}
344 \DeclareCaptionLabelSeparator{koma}{\captionformat}
345 % \end{macrocode}
346 % \begin{macrocode}
347 \SetCaptionDefault{labelseparator}{koma}
348 % \end{macrocode}
349 %
350 % \section{Fonts}
351 %
352 % The `default' fonts map to \cs{scr@fnt@caption} or \cs{scr@fnt@captonlabel}.
353 % \begin{macrocode}
354 \DeclareCaptionFont{scr@font}{\scr@fnt@caption}
355 \DeclareCaptionFont{scr@labelfont}{\scr@fnt@captionlabel}
356 \SetCaptionDefault{font}{scr@font}
357 \SetCaptionDefault{labelfont}{scr@labelfont}
358 % \end{macrocode}
359 %
360 % \section{Positioning}
361 %
362 % Here we patch the caption related \KOMAScript\ commands to set \pkg{caption} package settings as well.
363 % Furthermore we take over the caption related settings from the \KOMAScript\ classes.
364 %
365 % \begin{macro}{\if@captionabove}
366 % \changes{v1.0j}{2006/03/21}{Bugfix 2006-03-21: \cs{let}\cs{caption@setposition}\cs{@gobble} added}
367 % \changes{v1.0n}{2006/03/09}{Accidentally this got broken in \version{1.0m}, fixed}
368 % \changes{v1.1}{2007/03/31}{We redefine \cs{captionabovetrue/false} now instead of \cs{captionabove/below}}
369 % \changes{v1.1a}{2007/09/14}{Bugfix 2007-09-14: Redefinition of \cs{@captionabovetrue} \& \cs{@captionabovefalse} for \env{longtable} added}
370 % \changes{v1.1g}{2008/03/01}{\cs{def} changed to \cs{g@addto@macro}}
371 % \changes{v1.1k}{2009/10/09}{\opt{figureposition} and \opt{tableposition} will issue a warning now}
372 % \changes{v1.8e}{2019/09/11}{\opt{figureposition} and \opt{tableposition} will now set the position anyway since it could be used by other packages}
373 % \changes{v2.0a}{2020/09/12}{Faulty \cs{AtBeginCaption} replaced with correct \cs{AfterCaptionPackage}}
374 % Patch |\@captionabovetrue| and |\@captionabovefalse| so they will set the \pkg{caption3} position setting, too.
375 % Note that these are stronger than the \opt{position} setting, therefore we override the options
376 % \opt{figureposition} and \opt{tableposition} to typeout a warning.
377 % \begin{macrocode}
378 \g@addto@macro\@captionabovetrue{\caption@setposition{t}}%
379 \g@addto@macro\@captionabovefalse{\caption@setposition{b}}%
380 % \end{macrocode}
381 % \begin{macrocode}
382 \if@captionabove
383 \@captionabovetrue
384 \else
385 \@captionabovefalse
386 \fi
387 % \end{macrocode}
388 % |\captionabove| \& |\captionbelow| for longtable:
389 % \begin{macrocode}
390 \AfterCaptionPackage{\caption@AtBeginLongtable{%
391 \def\@captionabovetrue{\LT@captionsetup{position=t}}%
392 \def\@captionabovefalse{\LT@captionsetup{position=b}}}}
393 % \end{macrocode}
394 % \end{macro}
395 %
396 % \begin{macro}{\if@tablecaptionabove}
397 % \changes{v1.1g}{2008/03/01}{\cs{def} changed to \cs{g@addto@macro}}
398 % Patch |\@tablecaptionabovetrue| and |\@tablecaptionabovefalse| so they will set the \pkg{caption3} position setting, too.
399 % \begin{macrocode}
400 \g@addto@macro\@tablecaptionabovetrue{\captionsetup*[table]{position=t}}%
401 \g@addto@macro\@tablecaptionabovefalse{\captionsetup*[table]{position=b}}%
402 % \end{macrocode}
403 % \begin{macrocode}
404 \if@tablecaptionabove
405 \@tablecaptionabovetrue
406 \else
407 \@tablecaptionabovefalse
408 \fi
409 % \end{macrocode}
410 % \end{macro}
411 %
412 % \begin{macro}{\if@figurecaptionabove}
413 % \changes{v1.5}{2013/02/15}{Support of \cs{if@figurecaptionabove} added}
414 % Patch |\@figurecaptionabovetrue| and |\@figurecaptionabovefalse| so they will set the \pkg{caption3} position setting, too.
415 % \begin{macrocode}
416 \@ifundefined{@figurecaptionabovetrue}{}{%
417 \g@addto@macro\@figurecaptionabovetrue{\captionsetup*[figure]{position=t}}%
418 \g@addto@macro\@figurecaptionabovefalse{\captionsetup*[figure]{position=b}}%
419 % \end{macrocode}
420 % \begin{macrocode}
421 \if@figurecaptionabove
422 \@figurecaptionabovetrue
423 \else
424 \@figurecaptionabovefalse
425 \fi}
426 % \end{macrocode}
427 % \end{macro}
428 %
429 % Since the \KOMAScript\ position setting overwrites the one from the \pkg{caption} package,
430 % we re-define the options |figure|\-|position| and |table|\-|position| to issue a warning.
431 % \Note{But we set the value anyway since it will be used by sub-captions.}
432 %
433 % \begin{macrocode}
434 \AtCaptionPackage{%
435 \let\caption@koma@figureposition\KV@caption@figureposition
436 \DeclareCaptionOption{figureposition}{%
437 \caption@WarningNoLine{%
438 Option `figureposition=#1' has no effect\MessageBreak
439 when used with a KOMA-Script document class}%
440 \caption@koma@figureposition{#1}}
441 % \end{macrocode}
442 % \begin{macrocode}
443 \let\caption@koma@tableposition\KV@caption@tableposition
444 \DeclareCaptionOption{tableposition}{%
445 \caption@WarningNoLine{%
446 Option `tableposition=#1' has no effect\MessageBreak
447 when used with a KOMA-Script document class}%
448 \caption@koma@tableposition{#1}}}
449 % \end{macrocode}
450 %
451 % \section{Adaption of \cs{caption} command}
452 %
453 % \begin{macro}{\scr@caption}
454 % \KOMAScript\ contains the code
455 % |\AtBeginDocument{\let\scr@caption\caption}|
456 % so we need to update |\scr@caption| after the \pkg{caption} package has re-defined |\caption|.
457 % \begin{macrocode}
458 \AtBeginDocument{\let\scr@caption\caption}
459 % \end{macrocode}
460 % \end{macro}
461 %
462 % \iffalse
463 %</package>
464 % \fi
465 %
466 % \iffalse
467 % --------------------------------------------------------------------------- %
468 % \fi
469 %
470 % \clearpage
471 % \Finale
472 %
473 \endinput
474