summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/cleveref/cleveref.dtx
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2009-08-21 23:50:52 +0000
committerKarl Berry <karl@freefriends.org>2009-08-21 23:50:52 +0000
commit8a1d20ace83fcaff197c944f2704eec9ad3c3648 (patch)
treecaffc02fd19471668b0bde4d3a3e5a200e599d3c /Master/texmf-dist/source/latex/cleveref/cleveref.dtx
parent26818a7ca7d93f98a728445e3c48c6e22ac704b8 (diff)
cleveref 0.14.1 (21aug09)
git-svn-id: svn://tug.org/texlive/trunk@14804 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source/latex/cleveref/cleveref.dtx')
-rw-r--r--Master/texmf-dist/source/latex/cleveref/cleveref.dtx371
1 files changed, 253 insertions, 118 deletions
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
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<package>\ProvidesPackage{cleveref}
-%<package> [2009/07/26 v0.13.2 Intelligent cross-referencing]
+%<package> [2009/08/18 v0.14.1 Intelligent cross-referencing]
%
%<*driver>
\documentclass{ltxdoc}
@@ -62,7 +62,7 @@
%</driver>
% \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