diff options
Diffstat (limited to 'Master/texmf-dist/source/latex/caption/caption.dtx')
-rw-r--r-- | Master/texmf-dist/source/latex/caption/caption.dtx | 86 |
1 files changed, 59 insertions, 27 deletions
diff --git a/Master/texmf-dist/source/latex/caption/caption.dtx b/Master/texmf-dist/source/latex/caption/caption.dtx index 3b0a3968311..1bf48731430 100644 --- a/Master/texmf-dist/source/latex/caption/caption.dtx +++ b/Master/texmf-dist/source/latex/caption/caption.dtx @@ -2,7 +2,7 @@ % % This is file `caption.dtx'. % -% Copyright (C) 1994-2019 Axel Sommerfeldt (axel.sommerfeldt@f-m.fm) +% Copyright (C) 1994-2020 Axel Sommerfeldt (axel.sommerfeldt@f-m.fm) % % -------------------------------------------------------------------------- % @@ -25,7 +25,7 @@ % and the user manuals caption-deu.tex, caption-eng.tex, and caption-rus.tex. % % \fi -% \CheckSum{2974} +% \CheckSum{3006} % % \iffalse %<*driver> @@ -215,13 +215,13 @@ % % \begin{macrocode} \NeedsTeXFormat{LaTeX2e}[1994/12/01] -\ProvidesPackage{caption}[2019/10/18 v3.4a Customizing captions (AR)] +\ProvidesPackage{caption}[2020/01/01 v3.4c Customizing captions (AR)] % \end{macrocode} % % \section{Loading the kernel} % % \begin{macrocode} -\RequirePackage{caption3}[2019/09/09] % needs v1.8e or newer +\RequirePackage{caption3}[2019/12/31] % needs v1.8f or newer % \end{macrocode} % % \section{Check against unknown document classes} @@ -1311,15 +1311,6 @@ % \end{macrocode} % \end{macro} % -% \begin{macro}{\caption@typehook} -% Hook which will be used inside |\caption@set|\-|type|. -% It will be extended later on, e.g.~by our \package{float} package -% support. -% \begin{macrocode} -\newcommand*\caption@typehook{} -% \end{macrocode} -% \end{macro} -% % \begin{macro}{\caption@iftype} % \changes{v3.1}{2007/04/11}{This macro and its usage added} % Since we often need to check if |\@captype| is defined (means: we @@ -2600,6 +2591,7 @@ % \begin{macro}{\@float@setevery} % \changes{v3.1k}{2009/10/09}{Bugfix 08-12-05: \cs{color@begin/endgroup} added % to redefinition of \cs{caption@setfloatcapt}} +% \changes{v3.4b}{2019/12/16}{Usage of \cs{caption@float@setname} added} % |\@float@setevery|\marg{float type} is provided by the \package{float} % package; it's called every time a floating environment defined with % |\newfloat| or |\restylefloat| begins. @@ -2648,6 +2640,7 @@ % % \begin{macrocode} }{}% + \caption@float@setname{#1}% \caption@freezeHref % will be defrosted in \float@makebox \caption@ORI@float@setevery{#1}}% % \end{macrocode} @@ -2674,8 +2667,9 @@ % \end{macrocode} % \end{macro} % -% \begin{macro}{\caption@typehook} +% \begin{macro}{\caption@float@setname} % \changes{v3.1}{2007/07/08}{float package hook added} +% \changes{v3.4b}{2019/12/16}{Renamed from \cs{caption@typehook} to \cs{caption@float@setname}} % \LaTeX\ and almost every other packages use % |\|\meta{type}|name| % to provide a macro for the type resp.~environment name -- for example @@ -2693,7 +2687,7 @@ % \Note{If the float was not defined with \cs{newfloat} but with % \cs{restylefloat} instead, \cs{fname@}\meta{type} is not defined.} % \begin{macrocode} - \g@addto@macro\caption@typehook{% + \newcommand*\caption@float@setname[1]{% \expandafter\ifx\csname #1name\endcsname\relax \expandafter\let\csname #1name\expandafter\endcsname \csname fname@#1\endcsname @@ -3326,26 +3320,64 @@ % \changes{v3.1g}{2008/01/20}{Bugfix: Skips are handled correctly now} % \changes{v3.1k}{2008/03/29}{Bugfix 08-10-16-dctt: \texttt{rule=0} added} % \changes{v3.2}{2010/10/26}{Bugfix 10-07-20a: Set \cs{hsize} to \cs{linewidth}, if necessary} +% \changes{v3.4c}{2020/01/01}{Ugly workaround for usage in lists added} % To support the \package{listings} package we need to redefine % |\lst@MakeCaption| so the original stuff is nested with -% |\caption@begin| and |\caption@end| etc. -% \Note{This macro is always called twice (with `t' resp. `b' as -% parameter), therefore we need an extra group here.} +% |\caption@begin| and |\caption@end| etc.\par +% Unfortunately |\lst@MakeCaption| is sometimes used with |\linewidth| intact but sometimes with |\linewidth| adapted. +% So we either could write a bunch of very ugly code which is using internals of the \package{listings} package, or +% we could simply ignore this fact since |\hsize| will be left untouched by the \package{listings} package. +% (This is reason why the caption is mis-aligned when using one of the options |linewidth=|, |xleftmargin=|, |yleftmargin=|, or |resetmargins=|, +% even the \package{caption} package isn't used. This needs to be fixed within the \package{listings} package, for example by using +% |\lst@MakeCaption| inside a parbox of correct width.) +% +% The \package{listings} package calls |\lst@MakeCaption| sometimes with original |\linewidth|, sometimes with adapted |\linewidth|. +% So we need to detect if |\linewidth| is already adapted or not. +% We realize this by setting a flag inside the "Init" hook of the \package{listings} package (where the adaption takes place). +% \begin{macrocode} +%% \caption@setbool{lst@Init}{0}% +%% \lst@AddToHook{Init}{\caption@setbool{lst@Init}{1}}% +% \end{macrocode} % \begin{macrocode} \let\caption@ORI@lst@MakeCaption\lst@MakeCaption \def\lst@MakeCaption#1{% #1 is `t' or `b' +% \end{macrocode} +% This macro is always called twice by the \package{listings} package (with `t' resp. `b' as parameter), +% therefore we need an extra group here. +% \begin{macrocode} \begingroup % \end{macrocode} -% Workaround for bug in \package{listings} package: -% If |\hsize| seems not to be set correctly, we set it to |\linewidth|. -% \changes{v3.3}{2018/04/30}{Bugfix from Ulrike Fischer applied, see also \url{https://github.com/axelsommerfeldt/caption/issues/1}} % \begin{macrocode} - \@tempdima\linewidth - \advance\@tempdima\lst@xleftmargin - \advance\@tempdima\lst@xrightmargin - \ifdim\hsize>\@tempdima - \hsize\@tempdima - \fi +%% \caption@Debug{% +%% linewidth=\lst@linewidth, +%% xleftmargin=\lst@xleftmargin,\MessageBreak +%% xrightmargin=\lst@xrightmargin, +%% resetmargins=\lst@ifresetmargins true\else false\fi}% +% \end{macrocode} +% If |\linewidth| isn't adapted by the \package{listings} package yet, do the adaption here. +% \begin{macrocode} +%% \caption@iflst@Init{}{%\lsthk@PreInit\lsthk@Init => has unwanted side-effects (like an extra horizontal line) +%% \linewidth\lst@linewidth\relax +%% \lst@ifresetmargins +%% \advance\linewidth\@totalleftmargin +%% \advance\linewidth\rightmargin +%% \@totalleftmargin\z@ +%% \fi +%% \advance\linewidth-\lst@xleftmargin +%% \advance\linewidth-\lst@xrightmargin +%% \advance\@totalleftmargin\lst@xleftmargin\relax}% +% \end{macrocode} +% Inside lists the \package{listings} package ignores the left margin (|\@totalleftmargin|) for captions. +% We emulate this behaviour by adding a negativ skip which will be typeset ahead of |\caption@box|.\par +% This does not result in correct justification of the caption, but captions inside listings inside +% lists are not justified correctly anyway. (Again, this needs to be fixed by the \package{listings} package.)\par +% Note: We cannot use |\@totalleftmargin| here since it was usually resetted by the \package{listings} package. +% So we have to calculate the total left margin on our own which makes this code even more dirty. +% \begin{macrocode} + \l@addto@macro\caption@beginhook{% + \@tempdima\leftmargin + \multiply\@tempdima\@listdepth + \hskip-\@tempdima\relax}% % \end{macrocode} % First of all, we set |position=#1| and if it was set to `top', % we swap the skips so the default behavior of the \package{listings} package |