From 8a1d20ace83fcaff197c944f2704eec9ad3c3648 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Fri, 21 Aug 2009 23:50:52 +0000 Subject: cleveref 0.14.1 (21aug09) git-svn-id: svn://tug.org/texlive/trunk@14804 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/doc/latex/cleveref/cleveref.pdf | Bin 374504 -> 379464 bytes .../texmf-dist/source/latex/cleveref/cleveref.dtx | 371 ++++++++++++++------- Master/texmf-dist/tex/latex/cleveref/cleveref.sty | 229 ++++++++----- 3 files changed, 402 insertions(+), 198 deletions(-) (limited to 'Master') diff --git a/Master/texmf-dist/doc/latex/cleveref/cleveref.pdf b/Master/texmf-dist/doc/latex/cleveref/cleveref.pdf index 1f0d44b7622..656087f1da9 100644 Binary files a/Master/texmf-dist/doc/latex/cleveref/cleveref.pdf and b/Master/texmf-dist/doc/latex/cleveref/cleveref.pdf differ diff --git a/Master/texmf-dist/source/latex/cleveref/cleveref.dtx b/Master/texmf-dist/source/latex/cleveref/cleveref.dtx index 72c253be7de..cdb12ab0e85 100644 --- a/Master/texmf-dist/source/latex/cleveref/cleveref.dtx +++ b/Master/texmf-dist/source/latex/cleveref/cleveref.dtx @@ -21,7 +21,7 @@ % \iffalse %\NeedsTeXFormat{LaTeX2e}[1999/12/01] %\ProvidesPackage{cleveref} -% [2009/07/26 v0.13.2 Intelligent cross-referencing] +% [2009/08/18 v0.14.1 Intelligent cross-referencing] % %<*driver> \documentclass{ltxdoc} @@ -62,7 +62,7 @@ % % \fi % -% \CheckSum{7236} +% \CheckSum{7343} %% \CharacterTable %% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z %% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z @@ -119,12 +119,20 @@ % \textbackslash{}crefrangepostconjunction commands, needed by some % languages (such as Italian). Added babel support for Spanish and % Italian. Added notes about memoir (in)compatibility.} +% \changes{v0.14}{2009/08/07}{Fixed bug that caused labels containing +% components with values of 10 or higher to be sorted +% incorrectly. Fixed \textbackslash{}Cref to no longer capitalises all +% cross-reference names in a multi-reference, just the first one. The +% \option{capitalise} option is now provided to force capitalisation +% everywhere.} +% \changes{v0.14.1}{2009/08/18}{Added support for amsmath's subequations +% environment} % % % \GetFileInfo{cleveref.sty} % -% \def\fileversion{0.13.2} -% \def\filedate{26/07/2009} +% \def\fileversion{0.14.1} +% \def\filedate{18/08/2009} % % \title{The \package{cleveref} package\thanks{This document % corresponds to \textsf{cleveref}~\fileversion, dated @@ -342,6 +350,7 @@ % type-set text but without creating hyper-links. % % +% % \section{Sorting and Compressing} % \label{sec:sort&compress} % When \package{cleveref} type-sets lists of multiple cross-references, @@ -405,6 +414,17 @@ % % % +% \section{Capitalising All Cross-Reference Names} +% \label{sec:capitalise} +% Many authors prefer to always capitalise cross-reference names, +% regardless of where they appear in the sentence, writing Theorem~1 and +% Equation~3 (as opposed to theorem~1 and equation~3). If you count +% yourself among this group, you can pass the \option{capitalise} option +% to the \package{cleveref} package (\option{capitalize} also works). All +% cross-references will then be type-set using the \cmd{\Cref} variant. +% +% +% % \section{Customising the Cross-Reference Format} % \label{sec:customising} % The \package{cleveref} package allows you to take full control of the @@ -1323,6 +1343,23 @@ % \end{macro} % \end{macro} % \end{macro} +% +% \begin{macrocode} + \let\cref@old@subequations\subequations% + \let\cref@old@endsubequations\endsubequations% + \cref@resetby{equation}{\@result}% + \ifx\@result\relax\else% + \@addtoreset{parentequation}{\@result}% + \fi% + \renewenvironment{subequations}{% + \@addtoreset{equation}{parentequation}% + \cref@old@subequations% + }{% + \gdef\cl@parentequation{}% + \cref@old@endsubequations% + }% +% \end{macrocode} +% % \begin{macro}{\make@df@tag@@} % \begin{macro}{\make@df@tag@@@} % We override the internals of the \package{amsmath} \cmd{\tag} command @@ -1472,6 +1509,8 @@ % % % \subsection{Utility Macros} +% +% \subsubsection{aux file information} % \begin{macro}{\cref@getlabel} % \begin{macro}{\cref@gettype} % \begin{macro}{\cref@getcounter} @@ -1546,126 +1585,39 @@ % section, subsection\dots numbers that (ought to) make up the % formatted label produced by \cmd{\the\meta{counter}}. E.g. if % \cmd{\theequation} produces ``B.1.3'', this utility macro will return -% ``[2][1]'' (the ``3'' corresponds to the equation number itself, -% which is stored separately in \cmd{\@currentlabel}). The first -% argument is the counter in question; the return value is stored in -% the second argument, which should be a macro name. +% ``2,1'' (the ``3'' corresponds to the equation number itself, which +% is stored separately in \cmd{\@currentlabel}). The first argument is +% the counter in question; the return value is stored in the second +% argument, which should be a macro name. % % The real work is done by the recursive \cmd{\@cref@constructprefix} % macro, which works its way upwards through the counters' reset lists % until it reaches a counter that isn't reset by any other. % \begin{macrocode} \def\cref@constructprefix#1#2{% + \cref@stack@init{\@tmpstack}% % \end{macrocode} % We fully expand the first argument (the counter name) because sometimes % a counter name containing a macro gets passed to us. % \begin{macrocode} - \edef\@tmpa{\noexpand{\noexpand}\noexpand{#1\noexpand}}% + \edef\@tmpa{\noexpand{#1\noexpand}}% \expandafter\def\expandafter\@tmpa\expandafter{\@tmpa{#2}}% - \expandafter\@cref@constructprefix\@tmpa} -\def\@cref@constructprefix#1#2#3{% - \cref@resetby{#2}{#3}% - \ifx#3\relax% - \edef#3{#1}% + \expandafter\@cref@constructprefix\@tmpa% + \cref@stack@to@list{\@tmpstack}{\@tmpa}% + \expandafter\def\expandafter#2\expandafter{\@tmpa}} +\def\@cref@constructprefix#1#2{% + \cref@resetby{#1}{#2}% + \ifx#2\relax% \else% - \edef\@tmpa{{{\the\csname c@#3\endcsname}#1}{#3}}% + \edef\@tmpa{\the\csname c@#2\endcsname}% + \expandafter\cref@stack@push\expandafter{\@tmpa}{\@tmpstack}% + \edef\@tmpa{{#2}}% \expandafter\expandafter\expandafter\@cref@constructprefix% - \expandafter\@tmpa\expandafter{\expandafter#3\expandafter}% + \expandafter\@tmpa\expandafter{\expandafter#2\expandafter}% \fi} % \end{macrocode} % \end{macro} % -% \begin{macro}{\cref@countercmp} -% The \cmd{\cref@countercmp} macro compares two sets of counter data, -% as returned by \cmd{\cref@getcounter}, and \cmd{\chardef}'s its third -% argument to 0 if they're equal, 1 if the first comes earlier than the -% second, or 2 if the first comes later than the second. This is used -% later for sorting references. -% \begin{macrocode} -\def\cref@counter@first#1#2\@nil{#1} -\def\cref@counter@rest#1#2\@nil{#2} -\def\cref@countercmp#1#2#3{% - \begingroup% - \def\@tmpa{#1}% -% \end{macrocode} -% In order to ensure empty references end up in the right place when -% sorting lists of multiple references, we make the comparison macro -% sorts them before a non-empty reference. -% \begin{macrocode} - \ifx\@tmpa\@empty% - \def\@result{1}% - \else% - \def\@tmpa{#2}% - \ifx\@tmpa\@empty% - \def\@result{2}% - \else% -% \end{macrocode} -% Conversely, undefined references come after everything else. -% \begin{macrocode} - \expandafter\ifx\csname r@#1\endcsname\relax% - \def\@result{2}% - \else% - \expandafter\ifx\csname r@#2\endcsname\relax% - \def\@result{1}% - \else% -% \end{macrocode} -% The real work of comparing two references is done by -% \cmd{\@cref@countercmp}. -% \begin{macrocode} - \cref@getcounter{#1}{\@countera}% - \cref@getprefix{#1}{\@prefixa}% - \cref@getcounter{#2}{\@counterb}% - \cref@getprefix{#2}{\@prefixb}% - \edef\@tmpa{{\@prefixa{\@countera}}{\@prefixb{\@counterb}}}% - \expandafter\@cref@countercmp\@tmpa% - \fi% - \fi% - \fi% - \fi% - \expandafter\endgroup\expandafter% - \chardef\expandafter#3\expandafter=\@result\relax} -% \end{macrocode} -% \end{macro} -% \begin{macro}{\cref@countercmp} -% The \cmd{\@cref@countercmp} macro recursively compares counter -% components until it runs out of components for one of the references, -% or finds an two corresponding components that are unequel. -% \begin{macrocode} -\def\@cref@countercmp#1#2{% - \let\@iterate\relax% - \def\@counta{#1}% - \def\@countb{#2}% - \ifx\@counta\@empty% - \ifx\@countb\@empty% - \def\@result{0}% - \else% - \def\@result{1}% - \fi% - \else% - \ifx\@countb\@empty% - \def\@result{2}% - \else% - \edef\@counta{\cref@counter@first#1\@nil}% - \edef\@countb{\cref@counter@first#2\@nil}% - \ifnum\@counta<\@countb\relax% - \def\@result{1}% - \else% - \ifnum\@counta>\@countb\relax% - \def\@result{2}% - \else% - \edef\@counta{\cref@counter@rest#1\@nil}% - \edef\@countb{\cref@counter@rest#2\@nil}% - \edef\@counta{{\@counta}{\@countb}}% - \expandafter\def\expandafter\@iterate\expandafter{% - \expandafter\@cref@countercmp\@counta}% - \fi% - \fi% - \fi% - \fi% - \@iterate} -% \end{macrocode} -% \end{macro} -% % \begin{macro}{\cref@append@toks} % A basic utility macro for appending tokens to a token register. % \begin{macrocode} @@ -1675,12 +1627,15 @@ % \end{macrocode} % \end{macro} % +% +% \subsubsection{Stack data structures} % \begin{macro}{\cref@stack@init} % \begin{macro}{\cref@stack@top} % \begin{macro}{\cref@stack@pop} % \begin{macro}{\cref@stack@push} % \begin{macro}{\cref@stack@topandbottom} % \begin{macro}{\cref@stack@add} +% \begin{macro}{\cref@stack@to@list} % We treat multiple references, supplied as a comma-separated list to % \cmd{\cref} or \cmd{\Cref}, as a stack structure. So we define some % utility macros for manipulating stacks (\cmd{\@nil} is used as an @@ -1696,6 +1651,17 @@ \def\@cref@stack@push#1#2#3{\def#3{#2,#1}} \def\cref@stack@pull#1#2{\expandafter\@cref@stack@pull#2{#1}{#2}} \def\@cref@stack@pull#1\@nil#2#3{\def#3{#1#2,\@nil}} +\def\cref@stack@to@list#1#2{% + \cref@isstackfull{#1}% + \if@cref@stackfull% + \expandafter\expandafter\expandafter\def% + \expandafter\expandafter\expandafter#2% + \expandafter\expandafter\expandafter{% + \expandafter\@cref@stack@to@list#1}% + \else% + \def#2{}% + \fi} +\def\@cref@stack@to@list#1,\@nil{#1} \def\cref@stack@topandbottom#1#2#3{% \def#2{}% \def#3{}% @@ -1736,6 +1702,7 @@ % \end{macro} % \end{macro} % \end{macro} +% \end{macro} % % \begin{macro}{\if@cref@stackempty} % \begin{macro}{\if@cref@stackfull} @@ -1874,6 +1841,113 @@ % \end{macrocode} % \end{macro} % +% +% \subsubsection{Sorting and comparison of counters} +% \begin{macro}{\cref@countercmp} +% The \cmd{\cref@countercmp} macro compares two sets of counter data, +% as returned by \cmd{\cref@getcounter}, and \cmd{\chardef}'s its third +% argument to 0 if they're equal, 1 if the first comes earlier than the +% second, or 2 if the first comes later than the second. This is used +% later for sorting references. +% \begin{macrocode} +\def\cref@counter@first#1#2\@nil{#1} +\def\cref@counter@rest#1#2\@nil{#2} +\def\cref@countercmp#1#2#3{% + \begingroup% + \def\@tmpa{#1}% +% \end{macrocode} +% In order to ensure empty references end up in the right place when +% sorting lists of multiple references, we make the comparison macro +% sorts them before a non-empty reference. +% \begin{macrocode} + \ifx\@tmpa\@empty% + \def\@result{1}% + \else% + \def\@tmpa{#2}% + \ifx\@tmpa\@empty% + \def\@result{2}% + \else% +% \end{macrocode} +% Conversely, undefined references come after everything else. +% \begin{macrocode} + \expandafter\ifx\csname r@#1\endcsname\relax% + \def\@result{2}% + \else% + \expandafter\ifx\csname r@#2\endcsname\relax% + \def\@result{1}% + \else% +% \end{macrocode} +% The real work of comparing two references is done by +% \cmd{\@cref@countercmp}. +% \begin{macrocode} + \cref@getcounter{#1}{\@countera}% + \cref@getprefix{#1}{\@prefixa}% + \cref@getcounter{#2}{\@counterb}% + \cref@getprefix{#2}{\@prefixb}% + \cref@stack@init{\@countstacka}% + \expandafter\cref@stack@push\expandafter% + {\@countera}{\@countstacka}% + \ifx\@prefixa\@empty% + \else% + \expandafter\cref@stack@push\expandafter% + {\@prefixa}{\@countstacka}% + \fi% + \cref@stack@init{\@countstackb}% + \expandafter\cref@stack@push\expandafter% + {\@counterb}{\@countstackb}% + \ifx\@prefixb\@empty% + \else% + \expandafter\cref@stack@push\expandafter% + {\@prefixb}{\@countstackb}% + \fi% + \@cref@countercmp% + \fi% + \fi% + \fi% + \fi% + \expandafter\endgroup\expandafter% + \chardef\expandafter#3\expandafter=\@result\relax} +% \end{macrocode} +% \end{macro} +% \begin{macro}{\cref@countercmp} +% The \cmd{\@cref@countercmp} macro recursively compares counter +% components until it runs out of components for one of the references, +% or finds an two corresponding components that are unequel. +% \begin{macrocode} +\def\@cref@countercmp{% + \let\@iterate\relax% + \cref@isstackempty{\@countstacka}% + \if@cref@stackempty% + \cref@isstackempty{\@countstackb}% + \if@cref@stackempty% + \def\@result{0}% + \else% + \def\@result{1}% + \fi% + \else% + \cref@isstackempty{\@countstackb}% + \if@cref@stackempty% + \def\@result{2}% + \else% + \edef\@tmpa{\cref@stack@top{\@countstacka}}% + \cref@stack@pop{\@countstacka}% + \edef\@tmpb{\cref@stack@top{\@countstackb}}% + \cref@stack@pop{\@countstackb}% + \ifnum\@tmpa<\@tmpb\relax% + \def\@result{1}% + \else% + \ifnum\@tmpa>\@tmpb\relax% + \def\@result{2}% + \else% + \def\@iterate{\@cref@countercmp}% + \fi% + \fi% + \fi% + \fi% + \@iterate} +% \end{macrocode} +% \end{macro} +% % \begin{macro}{\if@cref@inresetlist} % \begin{macro}{\cref@isinresetlist} % \begin{macro}{\cref@resetby} @@ -1933,11 +2007,11 @@ % \begin{macrocode} \def\cref@resetby#1#2{% \let#2\relax% - \def\@tmpa{#1}% % \end{macrocode} % If counter in question is |subfigure| or |subtable|, check if it's % reset by |figure| or |table|, respectively. % \begin{macrocode} + \def\@tmpa{#1}% \def\@tmpb{subfigure}% \ifx\@tmpa\@tmpb% \cref@isinresetlist{#1}{figure}% @@ -1954,6 +2028,25 @@ \fi% \fi% % \end{macrocode} +% If counter in question is |equation|, and the counter |parentequation| +% is defined, check if it's reset by that (|parentequation| is used by +% \package{amsmath}'s |subequations| environment. Although +% \package{amsmath} doesn't implement |subequations| using counter reset +% lists, \package{cleveref}'s \package{amsmath} support (above) tweaks +% the reset lists inside |subequetions| environments to hook into this +% mechanism. We could dispense with all this particular check when +% \package{amsmath} isn't loaded, but it hardly seems worth it. +% \begin{macrocode} + \@ifundefined{cl@parentequation}{}{% + \def\@tmpa{#1}% + \def\@tmpb{equation}% + \ifx\@tmpa\@tmpb% + \cref@isinresetlist{#1}{parentequation}% + \if@cref@inresetlist% + \def#2{parentequation}% + \fi% + \fi}% +% \end{macrocode} % If counter in question is |enum|\meta{x}, check if it's reset by a % higher-level |enum|\meta{x}. % \begin{macrocode} @@ -2082,6 +2175,8 @@ % \end{macro} % \end{macro} % +% +% \subsubsection{Reference stack processing} % \begin{macro}{\cref@processgroup} % \cmd{\cref@processgroup} processes the first group of references from % the stack passed in argument |#1|, by moving references to the stack @@ -2343,14 +2438,18 @@ \begingroup% % \end{macrocode} % Initialise some things, and put all the references into a stack called -% \cmd{\@refstack}. +% \cmd{\@refstack}. Note that we fully expand the second argument, in +% case it contains commands that expand to label names rather than label +% names per se. % \begin{macrocode} \countdef\count@consecutive=0% \countdef\count@group=1% \count@group=1% + \def\cref@variant{#1}% \newif\if@secondref% \cref@stack@init{\@refstack}% - \cref@stack@push{#2}{\@refstack}% + \edef\@tmpa{#2}% + \expandafter\cref@stack@push\expandafter{\@tmpa}{\@refstack}% \cref@isstackfull{\@refstack}% % \end{macrocode} % Loop until the reference stack is empty. @@ -2384,6 +2483,11 @@ \fi% \fi% \advance\count@group 1% + \if@cref@capitalise% + \def\cref@variant{Cref}% + \else + \def\cref@variant{cref}% + \fi% \fi% % \end{macrocode} % @@ -2416,9 +2520,11 @@ \ifnum\count@consecutive=1\relax% \cref@isstackfull{\@refsubstack}% \if@cref@stackfull% - \expandafter\@setcref\expandafter{\@beginref}{#1}{@first}% + \expandafter\@setcref% + \expandafter{\@beginref}{\cref@variant}{@first}% \else% - \expandafter\@setcref\expandafter{\@beginref}{#1}{}% + \expandafter\@setcref% + \expandafter{\@beginref}{\cref@variant}{}% \fi% % \end{macrocode} % if there were only two consecutive references, type-set the first one @@ -2427,7 +2533,8 @@ % \begin{macrocode} \else% \ifnum\count@consecutive=2\relax% - \expandafter\@setcref\expandafter{\@beginref}{#1}{@first}% + \expandafter\@setcref% + \expandafter{\@beginref}{\cref@variant}{@first}% \expandafter\cref@stack@push\expandafter% {\@endref,}{\@refsubstack}% % \end{macrocode} @@ -2436,9 +2543,9 @@ \else% \edef\@tmpa{{\@beginref}{\@endref}}% \if@cref@stackempty% - \expandafter\@setcrefrange\@tmpa{#1}{}% + \expandafter\@setcrefrange\@tmpa{\cref@variant}{}% \else% - \expandafter\@setcrefrange\@tmpa{#1}{@first}% + \expandafter\@setcrefrange\@tmpa{\cref@variant}{@first}% \fi% \fi% \fi% @@ -2491,7 +2598,7 @@ % reference; % \begin{macrocode} \ifnum\count@consecutive=1\relax% - \edef\@tmpa{{\@beginref}{#1}{\@pos}}% + \edef\@tmpa{{\@beginref}{cref}{\@pos}}% \expandafter\@setcref\@tmpa% \else% % \end{macrocode} @@ -2500,14 +2607,14 @@ % \begin{macrocode} \ifnum\count@consecutive=2\relax% \expandafter\@setcref\expandafter% - {\@beginref}{#1}{@middle}% + {\@beginref}{cref}{@middle}% \expandafter\cref@stack@push\expandafter% {\@endref}{\@refsubstack}% % \end{macrocode} % otherwise, type-set a reference range. % \begin{macrocode} \else% - \edef\@tmpa{{\@beginref}{\@endref}{#1}{\@pos}}% + \edef\@tmpa{{\@beginref}{\@endref}{cref}{\@pos}}% \expandafter\@setcrefrange\@tmpa% \fi% \fi% @@ -4724,6 +4831,34 @@ % \end{macro} % % +% +% \subsection{Capitalise option} +% \begin{macro}{capitalise} +% \begin{macro}{\if@cref@capitalise} +% The \option{capitalise} option causes \package{cleveref} to always use +% the |\Cref|* variants for type-setting cross-references, so that +% cross-reference names are always capitalised. +% \begin{macrocode} +\newif\if@cref@capitalise +% \end{macrocode} +% Disabled by default. +% \begin{macrocode} +\@cref@capitalisefalse +% \end{macrocode} +% Option overrides default. +% \begin{macrocode} +\DeclareOption{capitalise}{% + \PackageInfo{cleveref}{always capitalise cross-reference names} + \@cref@capitalisetrue} +\DeclareOption{capitalize}{% + \PackageInfo{cleveref}{always capitalise cross-reference names} + \@cref@capitalisetrue} +% \end{macrocode} +% \end{macro} +% \end{macro} +% +% +% % \subsection{Language and \package{babel} Support} % \label{sec:code:babel} % Default reference formats for different languages are supported via diff --git a/Master/texmf-dist/tex/latex/cleveref/cleveref.sty b/Master/texmf-dist/tex/latex/cleveref/cleveref.sty index fa826b01a83..6bc15ab9691 100644 --- a/Master/texmf-dist/tex/latex/cleveref/cleveref.sty +++ b/Master/texmf-dist/tex/latex/cleveref/cleveref.sty @@ -22,7 +22,7 @@ %% version 1999/12/01 or later. \NeedsTeXFormat{LaTeX2e}[1999/12/01] \ProvidesPackage{cleveref} - [2009/07/26 v0.13.2 Intelligent cross-referencing] + [2009/08/18 v0.14.1 Intelligent cross-referencing] %% \CharacterTable %% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z %% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z @@ -71,6 +71,19 @@ \cref@old@label@in@display{[#1]{#2}}} \def\ltx@label#1{\cref@label#1} \let\cref@old@make@df@tag@@\make@df@tag@@ + \let\cref@old@subequations\subequations% + \let\cref@old@endsubequations\endsubequations% + \cref@resetby{equation}{\@result}% + \ifx\@result\relax\else% + \@addtoreset{parentequation}{\@result}% + \fi% + \renewenvironment{subequations}{% + \@addtoreset{equation}{parentequation}% + \cref@old@subequations% + }{% + \gdef\cl@parentequation{}% + \cref@old@endsubequations% + }% \def\make@df@tag@@#1{% \gdef\df@tag{\maketag@@@{#1}% \def\@currentlabel{[equation][][]#1}}} @@ -203,80 +216,22 @@ \@@cref@getprefix{\@@cref@getprefix[][][]}} \def\@@cref@getprefix[#1][#2][#3]#4\@nil#5{\def#5{#3}} \def\cref@constructprefix#1#2{% - \edef\@tmpa{\noexpand{\noexpand}\noexpand{#1\noexpand}}% + \cref@stack@init{\@tmpstack}% + \edef\@tmpa{\noexpand{#1\noexpand}}% \expandafter\def\expandafter\@tmpa\expandafter{\@tmpa{#2}}% - \expandafter\@cref@constructprefix\@tmpa} -\def\@cref@constructprefix#1#2#3{% - \cref@resetby{#2}{#3}% - \ifx#3\relax% - \edef#3{#1}% + \expandafter\@cref@constructprefix\@tmpa% + \cref@stack@to@list{\@tmpstack}{\@tmpa}% + \expandafter\def\expandafter#2\expandafter{\@tmpa}} +\def\@cref@constructprefix#1#2{% + \cref@resetby{#1}{#2}% + \ifx#2\relax% \else% - \edef\@tmpa{{{\the\csname c@#3\endcsname}#1}{#3}}% + \edef\@tmpa{\the\csname c@#2\endcsname}% + \expandafter\cref@stack@push\expandafter{\@tmpa}{\@tmpstack}% + \edef\@tmpa{{#2}}% \expandafter\expandafter\expandafter\@cref@constructprefix% - \expandafter\@tmpa\expandafter{\expandafter#3\expandafter}% + \expandafter\@tmpa\expandafter{\expandafter#2\expandafter}% \fi} -\def\cref@counter@first#1#2\@nil{#1} -\def\cref@counter@rest#1#2\@nil{#2} -\def\cref@countercmp#1#2#3{% - \begingroup% - \def\@tmpa{#1}% - \ifx\@tmpa\@empty% - \def\@result{1}% - \else% - \def\@tmpa{#2}% - \ifx\@tmpa\@empty% - \def\@result{2}% - \else% - \expandafter\ifx\csname r@#1\endcsname\relax% - \def\@result{2}% - \else% - \expandafter\ifx\csname r@#2\endcsname\relax% - \def\@result{1}% - \else% - \cref@getcounter{#1}{\@countera}% - \cref@getprefix{#1}{\@prefixa}% - \cref@getcounter{#2}{\@counterb}% - \cref@getprefix{#2}{\@prefixb}% - \edef\@tmpa{{\@prefixa{\@countera}}{\@prefixb{\@counterb}}}% - \expandafter\@cref@countercmp\@tmpa% - \fi% - \fi% - \fi% - \fi% - \expandafter\endgroup\expandafter% - \chardef\expandafter#3\expandafter=\@result\relax} -\def\@cref@countercmp#1#2{% - \let\@iterate\relax% - \def\@counta{#1}% - \def\@countb{#2}% - \ifx\@counta\@empty% - \ifx\@countb\@empty% - \def\@result{0}% - \else% - \def\@result{1}% - \fi% - \else% - \ifx\@countb\@empty% - \def\@result{2}% - \else% - \edef\@counta{\cref@counter@first#1\@nil}% - \edef\@countb{\cref@counter@first#2\@nil}% - \ifnum\@counta<\@countb\relax% - \def\@result{1}% - \else% - \ifnum\@counta>\@countb\relax% - \def\@result{2}% - \else% - \edef\@counta{\cref@counter@rest#1\@nil}% - \edef\@countb{\cref@counter@rest#2\@nil}% - \edef\@counta{{\@counta}{\@countb}}% - \expandafter\def\expandafter\@iterate\expandafter{% - \expandafter\@cref@countercmp\@counta}% - \fi% - \fi% - \fi% - \fi% - \@iterate} \def\cref@append@toks#1#2{\toks0={#2}% \edef\act{\noexpand#1={\the#1\the\toks0}}% \act}% @@ -290,6 +245,17 @@ \def\@cref@stack@push#1#2#3{\def#3{#2,#1}} \def\cref@stack@pull#1#2{\expandafter\@cref@stack@pull#2{#1}{#2}} \def\@cref@stack@pull#1\@nil#2#3{\def#3{#1#2,\@nil}} +\def\cref@stack@to@list#1#2{% + \cref@isstackfull{#1}% + \if@cref@stackfull% + \expandafter\expandafter\expandafter\def% + \expandafter\expandafter\expandafter#2% + \expandafter\expandafter\expandafter{% + \expandafter\@cref@stack@to@list#1}% + \else% + \def#2{}% + \fi} +\def\@cref@stack@to@list#1,\@nil{#1} \def\cref@stack@topandbottom#1#2#3{% \def#2{}% \def#3{}% @@ -400,6 +366,82 @@ \fi% \fi% \@iterate} +\def\cref@counter@first#1#2\@nil{#1} +\def\cref@counter@rest#1#2\@nil{#2} +\def\cref@countercmp#1#2#3{% + \begingroup% + \def\@tmpa{#1}% + \ifx\@tmpa\@empty% + \def\@result{1}% + \else% + \def\@tmpa{#2}% + \ifx\@tmpa\@empty% + \def\@result{2}% + \else% + \expandafter\ifx\csname r@#1\endcsname\relax% + \def\@result{2}% + \else% + \expandafter\ifx\csname r@#2\endcsname\relax% + \def\@result{1}% + \else% + \cref@getcounter{#1}{\@countera}% + \cref@getprefix{#1}{\@prefixa}% + \cref@getcounter{#2}{\@counterb}% + \cref@getprefix{#2}{\@prefixb}% + \cref@stack@init{\@countstacka}% + \expandafter\cref@stack@push\expandafter% + {\@countera}{\@countstacka}% + \ifx\@prefixa\@empty% + \else% + \expandafter\cref@stack@push\expandafter% + {\@prefixa}{\@countstacka}% + \fi% + \cref@stack@init{\@countstackb}% + \expandafter\cref@stack@push\expandafter% + {\@counterb}{\@countstackb}% + \ifx\@prefixb\@empty% + \else% + \expandafter\cref@stack@push\expandafter% + {\@prefixb}{\@countstackb}% + \fi% + \@cref@countercmp% + \fi% + \fi% + \fi% + \fi% + \expandafter\endgroup\expandafter% + \chardef\expandafter#3\expandafter=\@result\relax} +\def\@cref@countercmp{% + \let\@iterate\relax% + \cref@isstackempty{\@countstacka}% + \if@cref@stackempty% + \cref@isstackempty{\@countstackb}% + \if@cref@stackempty% + \def\@result{0}% + \else% + \def\@result{1}% + \fi% + \else% + \cref@isstackempty{\@countstackb}% + \if@cref@stackempty% + \def\@result{2}% + \else% + \edef\@tmpa{\cref@stack@top{\@countstacka}}% + \cref@stack@pop{\@countstacka}% + \edef\@tmpb{\cref@stack@top{\@countstackb}}% + \cref@stack@pop{\@countstackb}% + \ifnum\@tmpa<\@tmpb\relax% + \def\@result{1}% + \else% + \ifnum\@tmpa>\@tmpb\relax% + \def\@result{2}% + \else% + \def\@iterate{\@cref@countercmp}% + \fi% + \fi% + \fi% + \fi% + \@iterate} \newif\if@cref@inresetlist \def\cref@isinresetlist#1#2{% \begingroup% @@ -447,6 +489,15 @@ \def#2{table}% \fi% \fi% + \@ifundefined{cl@parentequation}{}{% + \def\@tmpa{#1}% + \def\@tmpb{equation}% + \ifx\@tmpa\@tmpb% + \cref@isinresetlist{#1}{parentequation}% + \if@cref@inresetlist% + \def#2{parentequation}% + \fi% + \fi}% \def\@tmpa{#1}% \def\@tmpb{enumii}% \ifx\@tmpa\@tmpb% @@ -727,9 +778,11 @@ \countdef\count@consecutive=0% \countdef\count@group=1% \count@group=1% + \def\cref@variant{#1}% \newif\if@secondref% \cref@stack@init{\@refstack}% - \cref@stack@push{#2}{\@refstack}% + \edef\@tmpa{#2}% + \expandafter\cref@stack@push\expandafter{\@tmpa}{\@refstack}% \cref@isstackfull{\@refstack}% \@whilesw\if@cref@stackfull\fi{% \cref@stack@init{\@refsubstack}% @@ -753,6 +806,11 @@ \fi% \fi% \advance\count@group 1% + \if@cref@capitalise% + \def\cref@variant{Cref}% + \else + \def\cref@variant{cref}% + \fi% \fi% \if@cref@compress% \cref@processconsecutive% @@ -774,21 +832,24 @@ \ifnum\count@consecutive=1\relax% \cref@isstackfull{\@refsubstack}% \if@cref@stackfull% - \expandafter\@setcref\expandafter{\@beginref}{#1}{@first}% + \expandafter\@setcref% + \expandafter{\@beginref}{\cref@variant}{@first}% \else% - \expandafter\@setcref\expandafter{\@beginref}{#1}{}% + \expandafter\@setcref% + \expandafter{\@beginref}{\cref@variant}{}% \fi% \else% \ifnum\count@consecutive=2\relax% - \expandafter\@setcref\expandafter{\@beginref}{#1}{@first}% + \expandafter\@setcref% + \expandafter{\@beginref}{\cref@variant}{@first}% \expandafter\cref@stack@push\expandafter% {\@endref,}{\@refsubstack}% \else% \edef\@tmpa{{\@beginref}{\@endref}}% \if@cref@stackempty% - \expandafter\@setcrefrange\@tmpa{#1}{}% + \expandafter\@setcrefrange\@tmpa{\cref@variant}{}% \else% - \expandafter\@setcrefrange\@tmpa{#1}{@first}% + \expandafter\@setcrefrange\@tmpa{\cref@variant}{@first}% \fi% \fi% \fi% @@ -823,16 +884,16 @@ \def\@pos{@middle}% \fi% \ifnum\count@consecutive=1\relax% - \edef\@tmpa{{\@beginref}{#1}{\@pos}}% + \edef\@tmpa{{\@beginref}{cref}{\@pos}}% \expandafter\@setcref\@tmpa% \else% \ifnum\count@consecutive=2\relax% \expandafter\@setcref\expandafter% - {\@beginref}{#1}{@middle}% + {\@beginref}{cref}{@middle}% \expandafter\cref@stack@push\expandafter% {\@endref}{\@refsubstack}% \else% - \edef\@tmpa{{\@beginref}{\@endref}{#1}{\@pos}}% + \edef\@tmpa{{\@beginref}{\@endref}{cref}{\@pos}}% \expandafter\@setcrefrange\@tmpa% \fi% \fi% @@ -2139,6 +2200,14 @@ \PackageInfo{cleveref}{neither sorting nor compressing references} \@cref@sortfalse \@cref@compressfalse} +\newif\if@cref@capitalise +\@cref@capitalisefalse +\DeclareOption{capitalise}{% + \PackageInfo{cleveref}{always capitalise cross-reference names} + \@cref@capitalisetrue} +\DeclareOption{capitalize}{% + \PackageInfo{cleveref}{always capitalise cross-reference names} + \@cref@capitalisetrue} \crefdefaultlabelformat{#2#1#3} \creflabelformat{equation}{\textup{(#2#1#3)}} \def\cref@addto#1#2{% -- cgit v1.2.3