summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/caption/caption3.dtx
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2020-01-05 03:00:30 +0000
committerNorbert Preining <norbert@preining.info>2020-01-05 03:00:30 +0000
commitd703bc2777b69363e791c0ec50045947b1a399da (patch)
tree518c616bdf53da2c5dccf1bbd0a17ba14d4b7c7a /macros/latex/contrib/caption/caption3.dtx
parent46d85b2b8e0282e241f8a41c6c0cd190c495eab0 (diff)
CTAN sync 202001050300
Diffstat (limited to 'macros/latex/contrib/caption/caption3.dtx')
-rw-r--r--macros/latex/contrib/caption/caption3.dtx249
1 files changed, 164 insertions, 85 deletions
diff --git a/macros/latex/contrib/caption/caption3.dtx b/macros/latex/contrib/caption/caption3.dtx
index 9837f72142..5cd6a8d9ea 100644
--- a/macros/latex/contrib/caption/caption3.dtx
+++ b/macros/latex/contrib/caption/caption3.dtx
@@ -2,7 +2,7 @@
%
% This is file `caption3.dtx'.
%
-% Copyright (C) 1994-2019 Axel Sommerfeldt (axel.sommerfeldt@f-m.fm)
+% Copyright (C) 1994-2020 Axel Sommerfeldt (axel.sommerfeldt@f-m.fm)
%
% --------------------------------------------------------------------------
%
@@ -18,14 +18,17 @@
%
% This Current Maintainer of this work is Axel Sommerfeldt.
%
-% This work consists of the files caption.ins, caption.dtx, caption2.dtx,
-% caption3.dtx, bicaption.dtx, ltcaption.dtx, subcaption.dtx, and newfloat.dtx,
-% the derived files caption.sty, caption2.sty, caption3.sty,
-% bicaption.sty, ltcaption.sty, subcaption.sty, and newfloat.sty,
-% and the user manuals caption-deu.tex, caption-eng.tex, and caption-rus.tex.
+% This work consists of the files
+% caption.ins, caption.dtx, caption2.dtx, caption3.dtx,
+% bicaption.dtx, ltcaption.dtx, subcaption.dtx, totalcount.dtx,
+% the derived files
+% caption.sty, caption2.sty, caption3.sty,
+% bicaption.sty, ltcaption.sty, subcaption.sty, totalcount.sty,
+% and the user manuals
+% caption-deu.tex, caption-eng.tex, caption-rus.tex.
%
% \fi
-% \CheckSum{3405}
+% \CheckSum{3476}
%
% \iffalse
%<*driver>
@@ -188,7 +191,7 @@
%
% \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}[1994/12/01]
-\ProvidesPackage{caption3}[2019/12/31 v1.8f caption3 kernel (AR)]
+\ProvidesPackage{caption3}[2020/01/03 v1.8h caption3 kernel (AR)]
% \end{macrocode}
%
% \section{Workaround for bug in package \package{arabtex}}
@@ -724,6 +727,7 @@
% \changes{v1.2}{2007/11/16}{Bugfix 07-11-09: `space hack' added}
% \changes{v1.2a}{2008/01/12}{\cs{ifcaptionsetup@star} will be set now}
% \changes{v1.5}{2012/04/09}{Support of multiple optional arguments added}
+% \changes{v1.8h}{2020/01/03}{Syntax check of saved options added}
% |\captionsetup|\oarg{type}\ldots\marg{keyval-list of options}\\
% |\captionsetup*|\oarg{type}\ldots\marg{keyval-list of options}\par
% If the optional argument `type' is specified, we simply save or append
@@ -753,18 +757,38 @@
% \end{macrocode}
% \begin{macrocode}
\newcommand*\caption@setup@options@i[4]{%
- \caption@setup@options@{#1}{#2}%
- \caption@declare@option{#2}[]{\captionsetup#3{#4}}}
+ \caption@declare@option{#2}[]{\captionsetup#3{#4}}%
+ \caption@setup@options@{#1}{#2}}
% \end{macrocode}
% \begin{macrocode}
\newcommand*\caption@setup@options@[2]{%
\@bsphack
\ifcaptionsetup@star\captionsetup@starfalse\else\caption@addtooptlist{#1}\fi
+ \caption@checkoptions{#2}%
\expandafter\caption@l@addto@list\csname caption@opt@#1\endcsname{#2}%
\@esphack}
% \end{macrocode}
% \end{macro}
%
+% \begin{macro}{\caption@checkoptions}
+% \changes{v1.8h}{2020/01/03}{This macro added}
+% Check the syntax of the given options by executing them inside a group.
+% (This way the \package{ragged2e} package check will be done for these options, too.)
+% \begin{macrocode}
+\newcommand*\caption@checkoptions[1]{%
+ \begingroup
+ \caption@prepare@optioncheck
+ \caption@setup{#1}%
+ \endgroup}
+% \end{macrocode}
+% Some caption options depend on the definition of |\@captype|,
+% so we set it to |figure| before executing them.
+% \begin{macrocode}
+\newcommand*\caption@prepare@optioncheck{%
+ \def\@captype{figure}}
+% \end{macrocode}
+% \end{macro}
+%
% \begin{macro}{\clearcaptionsetup}
% \changes{v1.1}{2007/07/29}{Optional argument added}
% \changes{v1.1}{2007/08/17}{Starred variant added}
@@ -1864,16 +1888,20 @@
% \section{Fonts}
%
% \begin{macro}{\DeclareCaptionFont}
-% \changes{v1.0a}{2004/01/22}{%
-% Bugfix: Multi token arguments are allowed now}
-% \changes{v1.1}{2007/05/07}{%
-% Internal: Uses \cs{caption@fnt} instead of \cs{caption@temp} now}
+% \changes{v1.0a}{2004/01/22}{Bugfix: Multi token arguments are allowed now}
+% \changes{v1.1}{2007/05/07}{Internal: Uses \cs{caption@fnt} instead of \cs{caption@temp} now}
+% \changes{v1.8h}{2020/01/03}{Check for \package{ragged2e} package related options added}
% |\DeclareCaptionFont|\marg{name}\marg{code}
% \begin{macrocode}
\newcommand*\DeclareCaptionFont[2]{%
- \define@key{caption@fnt}{#1}[]{\l@addto@macro\caption@fnt{#2}}}
+ \define@key{caption@fnt}{#1}[]{\caption@addto@fnt{#2}}}
\@onlypreamble\DeclareCaptionFont
% \end{macrocode}
+% \begin{macrocode}
+\newcommand*\caption@addto@fnt[1]{%
+ \caption@check@ragged{#1}%
+ \l@addto@macro\caption@fnt{#1}}
+% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\DeclareCaptionDefaultFont}
@@ -2061,9 +2089,15 @@
\DeclareCaptionFont{singlespacing}{%
\caption@ifdefined\setspace@singlespace{%
\setstretch\setspace@singlespace}{}}% normally 1
-\DeclareCaptionFont{onehalfspacing}{\onehalfspacing}
-\DeclareCaptionFont{doublespacing}{\doublespacing}
-\DeclareCaptionFont{stretch}{\setstretch{#1}}
+\DeclareCaptionFont{onehalfspacing}{%
+ \caption@setspace{onehalfspacing}\onehalfspacing\relax}
+\DeclareCaptionFont{doublespacing}{%
+ \caption@setspace{doublespacing}\doublespacing\relax}
+\DeclareCaptionFont{stretch}{%
+ \caption@setspace{stretch}\setstretch\@gobble{#1}}
+% \end{macrocode}
+% \begin{macrocode}
+\newcommand*\caption@setspace{\caption@ifpackageloaded{setspace}}
% \end{macrocode}
%
% \begin{macrocode}
@@ -2171,31 +2205,33 @@
%
% \subsection{The ragged2e package}
% \changes{v1.0b}{2004/05/16}{Improved \package{ragged2e} package support}
+% \changes{v1.8h}{2020/01/03}{Revised \package{ragged2e} package support}
%
% We also support the upper-case commands offered by the \package{ragged2e}
% package.
% Note that these just map to their lower-case variants if the
% \package{ragged2e} package is not available.
% \begin{macrocode}
-\DeclareCaptionJustification{Centering}{%
- \caption@ragged\Centering\centering}
-\DeclareCaptionJustification{RaggedLeft}{%
- \caption@ragged\RaggedLeft\raggedleft}
-\DeclareCaptionJustification{RaggedRight}{%
- \caption@ragged\RaggedRight\raggedright}
+\DeclareCaptionJustification{Centering}{\caption@Centering}
+\DeclareCaptionJustification{RaggedLeft}{\caption@RaggedLeft}
+\DeclareCaptionJustification{RaggedRight}{\caption@RaggedRight}
+% \end{macrocode}
+% \begin{macrocode}
+\newcommand*\caption@Centering{%
+ \caption@ragged{Centering}\Centering\centering}
+\newcommand*\caption@RaggedLeft{%
+ \caption@ragged{RaggedLeft}\RaggedLeft\raggedleft}
+\newcommand*\caption@RaggedRight{%
+ \caption@ragged{RaggedRight}\RaggedRight\raggedright}
% \end{macrocode}
%
% \begin{macro}{\caption@ragged}
-% \changes{v1.0n}{2007/04/07}{The `ragged2e' package will now only been
-% loaded when needed}
-% \changes{v1.0o}{2007/04/11}{Bugfix: Usage of \cs{caption@Info} replaced
-% by \cs{caption@Debug}}
+% \changes{v1.0n}{2007/04/07}{The `ragged2e' package will now only been loaded when needed}
+% \changes{v1.0o}{2007/04/11}{Bugfix: Usage of \cs{caption@Info} replaced by \cs{caption@Debug}}
% \changes{v1.1}{2007/04/16}{A different warning will be given on first \LaTeX\ run}
-% \changes{v1.4f}{2012/01/12}{Uses \cs{caption@IfPackageLoaded} now}
+% \changes{v1.4f}{2012/01/12}{Uses \cs{caption@ifpackageloaded} now}
% |\caption@ragged|\marg{yes-code}\marg{no-code}
-% executes the \meta{yes-code} if the \package{ragged2e} package is loaded
-% and \meta{no-code} if not. Additionally it tries to load the \package{ragged2e}
-% package.
+% executes the \meta{yes-code} if the \package{ragged2e} package is loaded and \meta{no-code} if not.
% \begin{macrocode}
\newcommand*\caption@ragged{\caption@ifpackageloaded{ragged2e}}
% \end{macrocode}
@@ -2203,61 +2239,80 @@
%
% \begin{macro}{\caption@ifpackageloaded}
% \changes{v1.4f}{2012/01/12}{This macro added}
-% |\caption@ifpackageloaded|\marg{package}\marg{yes-code}\marg{no-code}
-% executes the \meta{yes-code} if the given package is loaded
-% and \meta{no-code} if not. Additionally it tries to load the package.
-% \begin{macrocode}
-\newcommand*\caption@ifpackageloaded[1]{%
- \@ifundefined{caption@ifpkg@#1}%
- {\caption@RequirePackage{#1}%
- \caption@pkg@true{#1}}%
- {}%
- \caption@ifpkg{#1}}
-% \end{macrocode}
+% \changes{v1.8h}{2020/01/03}{Does not load the package anymore but issue an error message instead}
+% |\caption@ifpackageloaded|\marg{package}\marg{option}\marg{yes-code}\marg{no-code}
+% executes the \meta{yes-code} if the given package is loaded and \meta{no-code} if not.
% \begin{macrocode}
-\AtBeginDocument{\renewcommand*\caption@ifpackageloaded[1]{%
- \@ifundefined{caption@ifpkg@#1}%
- {\caption@addto@pkg@list{#1}%
- \caption@pkg@false{#1}%
- \caption@Warning{%
- `#1' support has been changed.\MessageBreak
- Rerun to get captions right}}%
- {}%
- \caption@ifpkg{#1}}}
-% \end{macrocode}
-% \begin{macrocode}
-\newcommand*\caption@ifpkg[1]{%
- \csname caption@ifpkg@#1\endcsname}
-\newcommand*\caption@pkg@true[1]{%
- \global\expandafter\let\csname caption@ifpkg@#1\endcsname\@firstoftwo}
-\newcommand*\caption@pkg@false[1]{%
- \global\expandafter\let\csname caption@ifpkg@#1\endcsname\@secondoftwo}
+\newcommand*\caption@ifpackageloaded[4]{%
+ \caption@ifdefined#3#3{%
+ \caption@Error{Option `#2' requires the `#1' package\MessageBreak
+ (or an alternative definition of \string#3)}%
+ #4}}
% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\caption@pkg@list}
+% \changes{v1.4f}{2012/01/12}{This macro added}
+% We use this as list of packages loaded |\AtBeginDocument|.
+% (Note: Old |.aux| files could contain |\@cons|\-|\caption@pkg@list|\-|{{|\meta{package}|}}|,
+% so this macro should always be defined, even if we change the following code in the future.)
% \begin{macrocode}
\newcommand*\caption@pkg@list{}
-\newcommand*\caption@addto@pkg@list[1]{%
- \protected@write\@auxout{}{%
- \string\@cons\string\caption@pkg@list{{#1}}}}
% \end{macrocode}
% \begin{macrocode}
-\AtBeginDocument{%
+\caption@AtBeginDocument{%
\def\caption@tempa{\endgroup}%
\begingroup
\def\@elt#1{%
\g@addto@macro\caption@tempa{%
- \caption@RequirePackage{#1}%
- \@namedef{caption@ifpkg@#1}{%
- \caption@addto@pkg@list{#1}%
- \caption@pkg@true{#1}%
- \caption@ifpkg{#1}}}}%
+ \caption@InfoNoLine{Load package `#1'}%
+ \RequirePackage{#1}\relax}}%
\caption@pkg@list
\caption@tempa}
% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\caption@check@ragged}
+% \changes{v1.4h}{2020/01/03}{This macro added}
+% In the past we tried to load the \package{ragged2e} package automatically if needed.
+% But since we have dropped this unreliable code users will get an error message instead.
+% To compensate for this change we try to detect the usage of the \package{ragged2e}
+% at least within the preamble of the document.
+% (Note: Checking the name of the option is not sufficient here since it could have
+% been re-defined by the user. So we have to check the option code instead.)
+% \begin{macrocode}
+\@ifpackageloaded{ragged2e}{\let\caption@check@ragged\@gobble}{%
+% \end{macrocode}
+% \begin{macrocode}
+ \newcommand*\caption@check@ragged[1]{%
+ \begingroup
+ \def\caption@tempa{#1}%
+ \caption@check@ragged@{Centering}%
+ \caption@check@ragged@{RaggedLeft}%
+ \caption@check@ragged@{RaggedRight}%
+ \endgroup}%
+% \end{macrocode}
+% \begin{macrocode}
+ \newcommand*\caption@check@ragged@[1]{%
+ \expandafter\def\expandafter\caption@tempb\expandafter{\csname caption@#1\endcsname}%
+ \ifx\caption@tempa\caption@tempb % our definition of `ragged2e' option?
+ \@ifundefined{#1}{%
+ \caption@Info{Usage of `ragged2e' command \expandafter\string\csname #1\endcsname\space detected}%
+ \@cons\caption@pkg@list{{ragged2e}}% load `ragged2e' package later on
+ \global\let\caption@check@ragged\@gobble}{}%
+ \fi
+ }%
+% \end{macrocode}
% \begin{macrocode}
-\newcommand*\caption@RequirePackage[1]{%
- \caption@Info{We need package `#1'}%
- \RequirePackage{#1}}
-\@onlypreamble\caption@RequirePackage
+ \caption@AtBeginDocument{%
+ \let\caption@check@ragged\@gobble
+ \let\caption@check@ragged@\@undefined}}
+% \end{macrocode}
+% Make the \package{subfig} package documentation compile.
+% \begin{macrocode}
+%%\@ifl@aded{dtx}{subfig}{\RequirePackage{ragged2e}\relax}{} % not needed
+\DeclareCaptionOption{lofdepth}[2]{\caption@ifdefined\c@lofdepth{\setcounter{lofdepth}{#1}}{}}
+\DeclareCaptionOption{lotdepth}[2]{\caption@ifdefined\c@lotdepth{\setcounter{lotdepth}{#1}}{}}
% \end{macrocode}
% \end{macro}
%
@@ -3604,10 +3659,10 @@
\caption@ifdefined\ForEachFloatingEnvironment
{\ForEachFloatingEnvironment{#1}}%
{\def\@elt##1{#1}%
- \caption@ifdefined\c@figure\@elt\@gobble{figure}%
- \caption@ifdefined\c@table\@elt\@gobble{table}%
- \let\@elt\relax
- \newfloat@addtohook{#1}}}
+ \caption@ifdefined\c@figure\@elt\@gobble{figure}%
+ \caption@ifdefined\c@table\@elt\@gobble{table}%
+ \let\@elt\relax
+ \newfloat@addtohook{#1}}}
% \end{macrocode}
% \begin{macrocode}
\providecommand\newfloat@addtohook[1]{%
@@ -3629,6 +3684,7 @@
% \changes{v1.5}{2011/12/29}{Usage of \cs{caption@addtoreset} replaced by \cs{@addtoreset}}
% \changes{v1.5}{2013/01/10}{Bugfix: Definition of autoref string corrected}
% \changes{v1.6}{2013/06/17}{Bugfix: \cs{c@tocdepth} will be set (locally) now}
+% \changes{v1.8g}{2020/01/02}{Check revised if the sub-type is already defined or not}
% |\DeclareCaptionSubType|\oarg{numbering scheme}\marg{type}\\
% |\DeclareCaptionSubType*|\oarg{numbering scheme}\marg{type}\par
% The starred variant provides the numbering format
@@ -3649,15 +3705,19 @@
\@ifundefined{c@#3}%
{\caption@Error{No float type '#3' defined}}%
% \end{macrocode}
+% Check if the sub-type was already defined by |\Declare|\-|Sub|\-|Type|.
+% If not, define the counter and list entry.
% \begin{macrocode}
- {\@ifundefined{c@sub#3}%
- {\caption@Debug{New subtype `sub#3'}%
- \newcounter{sub#3}%
- \@addtoreset{sub#3}{#3}%
- \@namedef{ext@sub#3}{\csname ext@#3\endcsname}%
- \caption@declaresublistentry{#3}%
- \@cons\caption@subtypelist{{#3}}}%
- {\caption@Debug{Modify caption `sub#3'}}%
+ {\caption@ifsubtype{sub#3}%
+ {\caption@Debug{Modify subtype `sub#3'}}%
+ {\caption@Debug{New subtype `sub#3'}%
+ \@ifundefined{c@sub#3}%
+ {\newcounter{sub#3}\relax}%
+ {\caption@Warning{Using already defined counter `sub#3'}}%
+ \@addtoreset{sub#3}{#3}%
+ \@namedef{ext@sub#3}{\csname ext@#3\endcsname}%
+ \caption@declaresublistentry{#3}%
+ \@cons\caption@subtypelist{{#3}}}%
% \end{macrocode}
% Support of \package{titletoc} package
% \begin{macrocode}
@@ -3745,6 +3805,25 @@
% \end{macrocode}
% \end{macro}
%
+% \begin{macro}{\caption@ifsubtype}
+% \changes{v1.8g}{2020/01/02}{This macro added}
+% This macro checks if the given subtype was defined
+% with |\Declare|\-|Caption|\-|Sub|\-|Type| or not.
+% \begin{macrocode}
+\newcommand*\caption@ifsubtype[1]{%
+ \begingroup
+ \let\next\@secondoftwo
+ \edef\@tempa{#1}%
+ \def\@elt##1{%
+ \def\@tempb{sub##1}%
+ \ifx\@tempa\@tempb
+ \let\next\@firstoftwo
+ \fi}%
+ \caption@subtypelist
+ \expandafter\endgroup\next}
+% \end{macrocode}
+% \end{macro}
+%
% Unfortunately the \class{memoir} document class resets the
% \texttt{subfigure} resp.~\texttt{subtable} counter at the begin
% of floating environments, i.e.~at |\@float|.