summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/cleveref
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2007-07-16 15:55:33 +0000
committerKarl Berry <karl@freefriends.org>2007-07-16 15:55:33 +0000
commitfba6aeb2879447d0ab08ac86032e72bc8002d2e1 (patch)
treeb30974ad2257589ad2eed706dd0f03487a661c75 /Master/texmf-dist/source/latex/cleveref
parent095c21ac9a136a78a974cb1bdcb06215f815eb64 (diff)
cleveref update (13jul07)
git-svn-id: svn://tug.org/texlive/trunk@4601 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source/latex/cleveref')
-rw-r--r--Master/texmf-dist/source/latex/cleveref/cleveref.dtx524
1 files changed, 390 insertions, 134 deletions
diff --git a/Master/texmf-dist/source/latex/cleveref/cleveref.dtx b/Master/texmf-dist/source/latex/cleveref/cleveref.dtx
index 43db80451bc..0c5ddd3fa12 100644
--- a/Master/texmf-dist/source/latex/cleveref/cleveref.dtx
+++ b/Master/texmf-dist/source/latex/cleveref/cleveref.dtx
@@ -21,16 +21,17 @@
% \iffalse
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<package>\ProvidesPackage{cleveref}
-%<package> [2007/11/06 v0.6 Automatic cross-reference formatting]
+%<package> [2007/10/07 v0.8 Automatic cross-reference formatting]
%
%<*driver>
-\documentclass[draft]{ltxdoc}
+\documentclass{ltxdoc}
+%\documentclass[draft]{ltxdoc}
\usepackage{url}
\usepackage{cleveref}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
-%%\newcommand{\package}[1]{\texttt{#1.sty}}
+%%\newcomman{\package}[1]{\texttt{#1.sty}}
%\newcommand{\package}[1]{\texttt{#1}}
\newcommand{\package}[1]{\texttt{#1}}
\newcommand{\file}{\texttt}
@@ -59,7 +60,7 @@
%</driver>
% \fi
%
-% \CheckSum{1914}
+% \CheckSum{2163}
%% \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
@@ -79,14 +80,21 @@
% \changes{v0.1}{2006/29/06}{Initial version}
% \changes{v0.2}{2007/18/04}{Complete rewrite}
% \changes{v0.3}{2007/26/04}{Added reference ranges}
-% \changes{v0.4}{2007/26/05}{Renamed "cleveref"}
+% \changes{v0.4}{2007/26/05}{Renamed "cleveref" -- first public release}
% \changes{v0.5}{2007/31/05}{Added poorman option}
-% \changes{v0.5}{2007/11/06}{Poorman no longer writes extra .tmp file}
+% \changes{v0.6}{2007/11/06}{Poorman no longer writes extra .tmp file}
+% \changes{v0.7}{2007/21/06}{Allow prevention of reference range collapsing}
+% \changes{v0.8}{2007/10/07}%
+% {Made referencing commands robust, improved default formats, made
+% starred versions of referencing commands for hyperref, allowed
+% multiple consecutive empty references in list to prevent range
+% collapsing, and fixed bugs. Phew!}
+%
%
% \GetFileInfo{cleveref.sty}
%
-% \def\fileversion{0.6}
-% \def\filedate{11/06/2007}
+% \def\fileversion{0.8}
+% \def\filedate{10/07/2007}
%
% \title{The \textsf{cleveref} package\thanks{This document
% corresponds to \textsf{cleveref}~\fileversion, dated
@@ -118,32 +126,32 @@
% more charitable attitude, that the programmer is pleased with the
% sophisticated processing that he has managed to encapsulate in code,
% relieving the user of some complicated by tedious task. On the other
-% hand, at the heart of the \LaTeX philosophy is the idea that it is
+% hand, at the heart of the \LaTeX{} philosophy is the idea that it is
% clever to delegate as much of the typesetting as possible to the
% computer, in order to achieve a beautiful, but above all consistent,
% visual appearance.
%
% Both these points of view are valid with respect to the
% \package{cleveref} package. It's goals are two-fold: to use the
-% information that \LaTeX inherently has about labels as
+% information that \LaTeX{} inherently has about labels as
% intelligently as possible in order to type-set references to them
% (clever processing); and to enable you to produce an attractive,
% consistent formatting of references throughout your document, with
% the minimum of effort (you'd be clever to use it!).
%
-% The \package{cleveref} package enhances \LaTeX's cross-referencing
+% The \package{cleveref} package enhances \LaTeX{}'s cross-referencing
% facility by allowing references to be formatted automatically
% according to the type of object they refer to (chapter, section,
% equation, theorem, etc.). It can also automatically format
% references to multiple labels.
%
-% In standard \LaTeX, you have almost certainly found yourself
+% In standard \LaTeX{}, you have almost certainly found yourself
% writing things like |Eq.~(\ref{eq1})| and |Theorem~\ref{thm1}| over
% and over again. This isn't just tedious. What happens if you later
% decide you want equation references to be typeset as
% |Equation~\ref{eq1}| instead? What happens if you decide to change
-% the theorem labelled |thm1| into a lemma? You have to search
-% through the entire \LaTeX source of your document, modifying all
+% the theorem labelled |thm1| into a lemma? You have to search through
+% the entire \LaTeX{} source of your document, modifying all
% references to equations, or changing all references to |thm1|.
%
% \package{cleveref} allows you to define the format for references
@@ -158,9 +166,11 @@
% for each and every reference.
%
% A number of other packages provide similar features, most notably
-% \package{varioref}, \package{fancyref} and (for theorem-like
-% environments) \package{ntheorem} (with the \option{thref}
-% option). However, all have certain deficiencies which
+% \package{varioref}, \package{fancyref}, \package{hyperref}'s
+% |\autoref| command, and (for theorem-like environments)
+% \package{ntheorem} (with the \option{thref} option). (There are many
+% others, but these come closest to providing similar features to
+% \package{cleveref}.) However, all have certain deficiencies which
% \package{cleveref} attempts to overcome.
%
% The \package{fancyref} package doesn't automatically determine the
@@ -183,20 +193,31 @@
% significantly, it makes it impossible to typeset multiple references
% automatically; you are back typesetting
% |Eqs.~(\ref{eq1}) and~(\ref{eq2})| or
-% |Eqs.~(\ref{eq1})--(\ref{eq3})| by hand.
+% |Eqs.~(\ref{eq1})--(\ref{eq3})| by hand. (Not to mention automatic
+% collapsing of consecutive references, \package{ntheorem} support, or
+% any of the other additional \package{cleveref} features.)
+%
+% The \package{hyperref} package's |\autoref| command typesets a
+% (customisable) name before a reference, based on the reference
+% type. This is less flexible than \package{cleveref}'s fully
+% customisable reference formatting, but when combined with
+% \package{varioref}, the two packages working together come
+% close. However, even with \package{hyperref}, it is impossible to
+% customise precisely which part of the reference is made into a
+% hyper-link in PDF documents; this is very easy with
+% \package{cleveref}. And it still remains impossible to typeset
+% multiple references, have consecutive references collapsed, etc.
%
% The \package{ntheorem} package (with the \option{thref} option) does
% things right\ldots except that it only works for theorem-like
% environments. It is possible to use it for other environments, but
% only in a bastardized form, by manually supplying an optional
% argument to |\label| commands telling it the label
-% type. \package{cleveref} essentially extends the \package{ntheorem}
-% theorem referencing feature to work for all objects. (Although the
-% implementation details differ, and \package{cleveref} can be used
-% independently of \package{ntheorem}.) \package{cleveref} provides a
-% number extra features too, such as multiple references, automatic
-% collapsing of reference ranges, and control over the placement of
-% hyper-links.
+% type. \package{cleveref} works equally well when referencing any
+% type of object, as well as fully supporting
+% \package{ntheorem}. \package{cleveref} also provides a number extra
+% features too, such as multiple references, automatic collapsing of
+% reference ranges, control over the placement of hyper-links, etc.
%
%
%
@@ -209,8 +230,7 @@
% \end{quote}
% in your document's preamble. However, care must be taken when using
% \package{cleveref} in conjunction with other packages that modify
-% \LaTeX's referencing system (see
-% \cref{sec:other_packages}).
+% \LaTeX{}'s referencing system (see \cref{sec:other_packages}).
%
%
%
@@ -224,7 +244,7 @@
% can instead be used to typeset multiple references (see below).
%
% \DescribeMacro\Cref
-% As it is very difficult for \LaTeX to determine whether a
+% As it is very difficult for \LaTeX{} to determine whether a
% reference appears at the beginning of a sentence or not, a
% capitalised version exists: |\Cref{|\meta{label}|}|. By default,
% this typesets the reference with the first letter capitalised,
@@ -270,9 +290,9 @@
% \end{quote}
% The references will be typeset in the order in which they appear in
% the list, and sequences of consecutive references will be collapsed
-% into a reference range. It is up to you to put the labels in the
-% order you require. This is especially significant if the labels
-% refer to different types of object, or to consecutive sequences of
+% to a reference range. It is up to you to put the labels in the order
+% you require. This is especially significant if the labels refer to
+% different types of object, or to consecutive sequences of
% labels. For example, if |eq*| are equation labels, and |thm*| are
% theorem labels,
% \begin{quote}
@@ -291,6 +311,39 @@
% Eqs.~(1) and~(2), Theorems~1 and~2, and Eq.~(3)
% \end{quote}
%
+% To prevent a sequence of consecutive references from being collapsed
+% to a reference range, you can separate the references in the list by
+% one or more empty references, at the point where you want to prevent
+% collapsing. For example,
+% \begin{quote}
+% |\cref{eq1,eq2,eq3,,eq4}|
+% \end{quote}
+% will be typeset as
+% \begin{quote}
+% Eqs.~(1)--(3), and (4)
+% \end{quote}
+% or
+% \begin{quote}
+% |\cref{eq1,eq2,,eq3,eq4,eq5,,eq6,eq7,eq8}|
+% \end{quote}
+% will be typeset as
+% \begin{quote}
+% Eqs.~(1), (2), (3)--(5), and (6)--(7)
+% \end{quote}
+% You can safely put an empty references between references that would
+% never be collapsed anyway; they will simply be ignored.
+%
+% \DescribeMacro{\cref*}
+% \DescribeMacro{\Cref*}
+% \DescribeMacro{\crefrange*}
+% \DescribeMacro{\Crefrange*}
+% When \package{cleveref} is used along with the \package{hyperref}
+% package (see \cref{sec:customising,sec:other_packages}), additional
+% starred variants of all the referencing commands are available. The
+% standard referencing commands will make references into hyper-links;
+% the starred variants prevent this, producing the same typeset text
+% but without creating hyper-links.
+%
%
% \subsection{Customising the Reference Formats}
% \label{sec:customising}
@@ -336,7 +389,7 @@
% start. If the first letter is a special construct, such as an
% accented character, you will need to surround everything whose case
% should be changed by braces. If the first thing in the format is not
-% a letter (e.g.\ if it is a \LaTeX command, or a hyper-link
+% a letter (e.g.\ if it is a \LaTeX{} command, or a hyper-link
% argument, see below), you will get strange and fatal errors when
% processing the document.
%
@@ -348,7 +401,7 @@
% because \package{ntheorem} allows different theorem-like
% environments to use a common counter.
%
-% The \meta{format} argument can be any valid \LaTeX code, though
+% The \meta{format} argument can be any valid \LaTeX{} code, though
% you will need to |\protect| fragile commands. It can (and almost
% certainly should!) contain three arguments, |#1|, |#2| and |#3|. The
% first argument is the formatted version of the label counter (e.g.\
@@ -401,7 +454,7 @@
% corresponding other-capitalisation variant is not already defined,
% it will be defined automatically.
%
-% The \meta{format} argument can again be any valid \LaTeX code,
+% The \meta{format} argument can again be any valid \LaTeX{} code,
% with fragile commands |\protect|ed. However, this time it should
% contain \emph{six} arguments, |#1|--|#6|. The first two (|#1| and
% |#2|) are the formatted versions of the label counters, the next two
@@ -462,7 +515,7 @@
%
% Be careful to get the spaces at the beginning and end of the
% formatting code correct: the \meta{first}, \meta{middle} and
-% \meta{last} \LaTeX code is typeset one after another in a
+% \meta{last} \LaTeX{} code is typeset one after another in a
% multi-reference, with no space separating them. You may or may not
% want spaces at the beginning and end of the formatting code,
% depending on the formatting you desire. For example, with the
@@ -502,9 +555,9 @@
%
%
% \subsection{Poor Man's \package{cleveref}}
-% Sometimes you may need to send your \LaTeX source to someone who
+% Sometimes you may need to send your \LaTeX{} source to someone who
% can't install the \package{cleveref} package themselves. For
-% example, many academic journals accept papers in \LaTeX format, but
+% example, many academic journals accept papers in \LaTeX{} format, but
% only support a subset of the packages available on CTAN. The
% \option{poorman} option was designed specifically to help in this
% situation.
@@ -512,7 +565,7 @@
% When the \option{poorman} option is supplied, your document will be
% processed as normal. But in addition, a {\tt sed} script will
% automatically be written, containing rules for replacing all the
-% \cmd{\cref} commands with the \LaTeX code that they would produce,
+% \cmd{\cref} commands with the \LaTeX{} code that they would produce,
% and using the standard \cmd{\ref} command to produce the
% cross-reference numbers themselves. I.e.\ the script rewrites your
% document as you would have done if you had had to do it manually!
@@ -523,7 +576,7 @@
% document that you want to send elsewere, you can process it through
% the script to remove the \package{cleveref} dependency.
%
-% The script is written to the same directory as the \LaTeX source
+% The script is written to the same directory as the \LaTeX{} source
% file, and given the same name as the source file but with the
% extension \file{.sed}. To process your document through the script,
% all you need to do is run the following from your shell:
@@ -531,11 +584,11 @@
% sed -f \meta{name}\file{.sed} \
% \meta{name}\file{.tex} > \meta{newname}\file{.tex}
% \end{quote}
-% where \meta{name} is the name of the file containing your \LaTeX
+% where \meta{name} is the name of the file containing your \LaTeX{}
% source file minus the \file{.tex} extension, and \meta{newname} is
% whatever you want to call the new version. \emph{Do not} make
% \meta{newname} the same as \meta{name}. (It's in any case wise to
-% keep the original \LaTeX source file containing the
+% keep the original \LaTeX{} source file containing the
% \package{cleveref} commands, in case you need to produce an updated
% version of your document in the future. Think of the
% \meta{newname}\file{.tex} file as being rather like a \file{DVI}
@@ -546,7 +599,7 @@
% \section{Interaction with Other Packages}
% \label{sec:other_packages}
% Since \package{cleveref} redefines many internal commands involved
-% in \LaTeX's referencing system, it can interact badly with other
+% in \LaTeX{}'s referencing system, it can interact badly with other
% packages that do the same. In general, \package{cleveref} should be
% loaded \emph{last}, and the appropriate options must be supplied if
% the \package{hyperref} and/or \package{ntheorem} packages are also
@@ -581,7 +634,7 @@
% Note that you can still use the other features of \package{varioref}
% and \package{ntheorem} whilst using \package{cleveref}.
%
-% Other packages which alter the \LaTeX referencing system are
+% Other packages which alter the \LaTeX{} referencing system are
% unlikely to work properly with \package{cleveref}.
%
%
@@ -589,16 +642,13 @@
% \section{Known Bugs}
% \begin{itemize}
% \item \package{cleveref} will not work properly with the standard
-% \LaTeX |eqnarray| environment. The |eqnarray| environment is
+% \LaTeX{} |eqnarray| environment. The |eqnarray| environment is
% poorly implemented, making it somewhat difficult to get it to work
% properly with \package{cleveref}. You're better off using the
% \package{amsmath} replacements in any case, such as |gather|,
% |align|, |multine| and |split|, which \emph{do} work properly with
% \package{cleveref}. (See
% \url{http://www.tug.org/pracjourn/2006-4/madsen/}).
-% \item \package{cleveref}'s referencing features currently may or may
-% not work properly with references to list items. (This should be
-% fixed in a future version.)
% \item \package{cleveref} breaks \package{hyperref}'s
% \option{backref} option, and probably also the \package{backref}
% package when used by itself. (This should be fixed in a future
@@ -614,9 +664,6 @@
%
% \section{Future Improvements}
% \begin{itemize}
-% \item Allow selective disabling of reference-range collapsing in
-% multiple references, e.g.\ by the addition of an extra comma
-% between the labels in the label list.
% \item Allow reference-range collapsing to be disabled entirely via a
% package option
% \end{itemize}
@@ -643,14 +690,14 @@
% itself, and the formatted version of the counter that causes the
% label's counter to be reset, which we call the ``prefix'' from now
% on). \cmd{\@currentlabel} eventually gets written to the aux file as
-% an argument to \cmd{\newlabel} by the usual \LaTeX
+% an argument to \cmd{\newlabel} by the usual \LaTeX{}
% mechanisms. This involves less hacking to get everything else
% working again, since very few macros other than \cmd{\ref} use this
% particular \cmd{\newlabel} argument (nor are other packages likely
% to, given that \package{varioref} is a required package).
%
%
-% \subsection{Redefinitions of \LaTeX kernel macros}
+% \subsection{Redefinitions of \LaTeX{} kernel macros}
% We store the original \cmd{\refstepcounter} in
% \cmd{\old@refstepcounter}, then redefine \cmd{\refstepcounter} so
% that it first calls the old version and then adds the extra
@@ -683,17 +730,20 @@
% want. Therefore, we redefine \cmd{\cref} to recover the original
% behaviour. We have to defer redefinition of \cmd{\ref} till the
% beginning of the document, in case other packages (such as
-% \package{ntheorem}) modify it after \package{cleveref} is loaded.
+% \package{ntheorem}) modify it after \package{cleveref} is
+% loaded. For some reason, \cmd{\DeclareRobustCommand} doesn't work
+% here, so we make it robust manually.
% \begin{macrocode}
\def\cref@label#1#2{\@result}
\AtBeginDocument{%
- \def\ref#1{%
- \expandafter\ifx\csname r@#1\endcsname\relax%
- \let\@result\relax%
- \else%
- \cref@getlabel{#1}{\@result}%
- \fi%
- \expandafter\@setref\csname r@#1\endcsname{\cref@label}{#1}}%
+ \expandafter\def\csname ref \endcsname#1{%
+ \expandafter\ifx\csname r@#1\endcsname\relax%
+ \let\@result\relax%
+ \else%
+ \cref@getlabel{#1}{\@result}%
+ \fi%
+ \expandafter\@setref\csname r@#1\endcsname{\cref@label}{#1}}%
+ \def\ref{\expandafter\protect\csname ref \endcsname}
}
% \end{macrocode}
%
@@ -760,10 +810,13 @@
\newif\ifstackempty
\newif\ifstackfull
\def\isstackempty#1{%
- \expandafter\ifx#1\@nil\stackemptytrue%
- \else\stackemptyfalse\fi}
+ \def\@tmpa{\@nil}%
+ \ifx#1\@tmpa\stackemptytrue%
+ \else\stackemptyfalse\fi
+}
\def\isstackfull#1{%
- \expandafter\ifx#1\@nil\stackfullfalse%
+ \def\@tmpa{\@nil}%
+ \ifx#1\@tmpa\stackfullfalse%
\else\stackfulltrue\fi}
% \end{macrocode}
%
@@ -844,10 +897,10 @@
% Define the main referencing macros \cmd{\cref} and the
% start-of-sentence variant \cmd{\Cref}.
% \begin{macrocode}
-\newcommand{\cref}[1]{\@cref{cref}{#1}}
-\newcommand{\Cref}[1]{\@cref{Cref}{#1}}
-\newcommand{\crefrange}[2]{\@setcrefrange{#1}{#2}{cref}{}}
-\newcommand{\Crefrange}[2]{\@setcrefrange{#1}{#2}{Cref}{}}
+\DeclareRobustCommand{\cref}[1]{\@cref{cref}{#1}}
+\DeclareRobustCommand{\Cref}[1]{\@cref{Cref}{#1}}
+\DeclareRobustCommand{\crefrange}[2]{\@setcrefrange{#1}{#2}{cref}{}}
+\DeclareRobustCommand{\Crefrange}[2]{\@setcrefrange{#1}{#2}{Cref}{}}
% \end{macrocode}
% To save duplicating code, the referencing macros pass an argument
% determining the variant to an auxilliary macro \cmd{\@cref}, which
@@ -864,6 +917,7 @@
% called \cmd{\@refstack}.
% \begin{macrocode}
\countdef\count@consecutive=0%
+ \def\@empty{}%
\newif\if@firstgroup%
\stack@init{\@refstack}%
\stack@push{#2}{\@refstack}%
@@ -894,14 +948,19 @@
\def\@nexttype{\relax}%
\else%
\edef\@nextref{\stack@top{\@refstack}}%
- \expandafter\ifx\csname r@\@nextref\endcsname\relax%
- \def\@currenttype{\@undefined}%
+ \ifx\@nextref\@empty%
+ \let\@currenttype\@nexttype%
\else%
- \expandafter\cref@gettype\expandafter%
- {\@nextref}{\@currenttype}%
+ \expandafter\ifx\csname r@\@nextref\endcsname\relax%
+ \def\@currenttype{\@undefined}%
+ \else%
+ \expandafter\cref@gettype\expandafter%
+ {\@nextref}{\@currenttype}%
+ \fi%
\fi%
\fi}%
% \end{macrocode}
+%
% Typeset appropriate conjunction between groups of reference types.
% \begin{macrocode}
\if@firstgroup%
@@ -915,6 +974,7 @@
\fi%
\@firstgroupfalse%
% \end{macrocode}
+%
% Process first group of consecutive references from substack.
% \begin{macrocode}
\edef\@nextref{\stack@top{\@refsubstack}}%
@@ -936,11 +996,36 @@
\expandafter\ifx\csname r@\@beginref\endcsname\relax%
\refconsecutivefalse%
\else%
- \expandafter\ifx\csname r@\@nextref\endcsname\relax%
+% \end{macrocode}
+% If next reference in substack is empty, it indicates that no
+% further collapsing should take place. Having served its
+% purpose, the empty reference and any consecutive empty
+% references are removed from the substack.
+% \begin{macrocode}
+ \ifx\@nextref\@empty%
\refconsecutivefalse%
- \else%
- \edef\@tmpa{{\@beginref}{\@nextref}}%
- \expandafter\isrefconsecutive\@tmpa%
+ \@whilesw\ifx\@nextref\@empty\fi{%
+ \stack@pop{\@refsubstack}%
+ \isstackempty{\@refsubstack}%
+ \ifstackempty%
+ \let\@nextref\relax%
+ \else%
+ \edef\@nextref{\stack@top{\@refsubstack}}%
+ \fi%
+ }%
+ \ifnum\count@consecutive=2%
+ \edef\@endref{\@endref,}%
+ \fi%
+% \end{macrocode}
+% Otherwise, test whether next reference is consecutive or not.
+% \begin{macrocode}
+ \else
+ \expandafter\ifx\csname r@\@nextref\endcsname\relax%
+ \refconsecutivefalse%
+ \else%
+ \edef\@tmpa{{\@beginref}{\@nextref}}%
+ \expandafter\isrefconsecutive\@tmpa%
+ \fi%
\fi%
\fi%
\@whilesw\ifrefconsecutive\fi{%
@@ -952,11 +1037,33 @@
\refconsecutivefalse%
\else%
\edef\@nextref{\stack@top{\@refsubstack}}%
- \expandafter\ifx\csname r@\@nextref\endcsname\relax%
+% \end{macrocode}
+% Test whether next reference is empty;
+% \begin{macrocode}
+ \ifx\@nextref\@empty%
\refconsecutivefalse%
- \else%
- \edef\@tmpa{{\@endref}{\@nextref}}%
- \expandafter\isrefconsecutive\@tmpa%
+ \@whilesw\ifx\@nextref\@empty\fi{%
+ \stack@pop{\@refsubstack}%
+ \isstackempty{\@refsubstack}%
+ \ifstackempty%
+ \let\@nextref\relax%
+ \else%
+ \edef\@nextref{\stack@top{\@refsubstack}}%
+ \fi%
+ }%
+ \ifnum\count@consecutive=2%
+ \edef\@endref{\@endref,}%
+ \fi%
+% \end{macrocode}
+% otherwise, test whether next reference is consecutive or not.
+% \begin{macrocode}
+ \else
+ \expandafter\ifx\csname r@\@nextref\endcsname\relax%
+ \refconsecutivefalse%
+ \else%
+ \edef\@tmpa{{\@endref}{\@nextref}}%
+ \expandafter\isrefconsecutive\@tmpa%
+ \fi%
\fi%
\fi}%
% \end{macrocode}
@@ -986,7 +1093,9 @@
\fi%
\fi%
% \end{macrocode}
-% Loop until substack is empty.
+%
+% Process further groups of consecutive references, until substack
+% is empty.
% \begin{macrocode}
\isstackfull{\@refsubstack}%
\@whilesw\ifstackfull\fi{%
@@ -1005,11 +1114,33 @@
\else%
\edef\@nextref{\stack@top{\@refsubstack}}%
\count@consecutive=1%
- \expandafter\ifx\csname r@\@nextref\endcsname\relax%
+% \end{macrocode}
+% Test whether next reference is empty;
+% \begin{macrocode}
+ \ifx\@nextref\@empty%
\refconsecutivefalse%
- \else%
- \edef\@tmpa{{\@beginref}{\@nextref}}%
- \expandafter\isrefconsecutive\@tmpa%
+ \@whilesw\ifx\@nextref\@empty\fi{%
+ \stack@pop{\@refsubstack}%
+ \isstackempty{\@refsubstack}%
+ \ifstackempty%
+ \let\@nextref\relax%
+ \else%
+ \edef\@nextref{\stack@top{\@refsubstack}}%
+ \fi%
+ }%
+ \ifnum\count@consecutive=2%
+ \edef\@endref{\@endref,}%
+ \fi%
+% \end{macrocode}
+% otherwise, test whether next reference is consecutive or not.
+% \begin{macrocode}
+ \else
+ \expandafter\ifx\csname r@\@nextref\endcsname\relax%
+ \refconsecutivefalse%
+ \else%
+ \edef\@tmpa{{\@beginref}{\@nextref}}%
+ \expandafter\isrefconsecutive\@tmpa%
+ \fi%
\fi%
\@whilesw\ifrefconsecutive\fi{%
\advance\count@consecutive 1%
@@ -1020,11 +1151,33 @@
\refconsecutivefalse%
\else%
\edef\@nextref{\stack@top{\@refsubstack}}%
- \expandafter\ifx\csname r@\@nextref\endcsname\relax%
+% \end{macrocode}
+% Test whether next reference is empty;
+% \begin{macrocode}
+ \ifx\@nextref\@empty%
\refconsecutivefalse%
- \else%
- \edef\@tmpa{{\@endref}{\@nextref}}%
- \expandafter\isrefconsecutive\@tmpa%
+ \@whilesw\ifx\@nextref\@empty\fi{%
+ \stack@pop{\@refsubstack}%
+ \isstackempty{\@refsubstack}%
+ \ifstackempty%
+ \let\@nextref\relax%
+ \else%
+ \edef\@nextref{\stack@top{\@refsubstack}}%
+ \fi%
+ }%
+ \ifnum\count@consecutive=2%
+ \edef\@endref{\@endref,}%
+ \fi%
+% \end{macrocode}
+% otherwise, test whether next reference is consecutive or not.
+% \begin{macrocode}
+ \else
+ \expandafter\ifx\csname r@\@nextref\endcsname\relax%
+ \refconsecutivefalse%
+ \else%
+ \edef\@tmpa{{\@endref}{\@nextref}}%
+ \expandafter\isrefconsecutive\@tmpa%
+ \fi%
\fi%
\fi}%
% \end{macrocode}
@@ -1051,8 +1204,10 @@
% first one, and return the second one to the substack,
% \begin{macrocode}
\ifnum\count@consecutive=2%
- \edef\@tmpa{{\@beginref}{#1}{\@pos}}%
- \expandafter\@setcref\@tmpa%
+ \expandafter\@setcref\expandafter%
+ {\@beginref}{#1}{@middle}%
+ \expandafter\stack@push\expandafter%
+ {\@endref}{\@refsubstack}%
% \end{macrocode}
% otherwise, typeset a reference range.
% \begin{macrocode}
@@ -1250,7 +1405,7 @@
\def\@crefformat#1#2#3{%
\expandafter\def\csname #1@#2@format\endcsname##1##2##3{#3}%
% \end{macrocode}
-% Note that these \cmd{@tmpa} macros makes use of the fact that the
+% Note that these \cmd{\@tmpa} macros makes use of the fact that the
% first character of \#1 is ``c'' for lower-case, ``C'' for
% upper-case.
% \begin{macrocode}
@@ -1282,7 +1437,7 @@
\expandafter\def\csname #1@#2@format\endcsname%
##1##2##3##4##5##6{#3}%
% \end{macrocode}
-% Note that these \cmd{@tmpa} macros make use of the fact that the
+% Note that these \cmd{\@tmpa} macros make use of the fact that the
% first character of \#1 is ``c'' for lower-case, ``C'' for
% upper-case.
% \begin{macrocode}
@@ -1315,7 +1470,7 @@
\expandafter\def\csname #1@#2@format@middle\endcsname##1##2##3{#4}%
\expandafter\def\csname #1@#2@format@last\endcsname##1##2##3{#5}%
% \end{macrocode}
-% Note that these \cmd{@tmpa} macros make use of the fact that the
+% Note that these \cmd{\@tmpa} macros make use of the fact that the
% first character of \#1 is ``c'' for lower-case, ``C'' for
% upper-case.
% \begin{macrocode}
@@ -1364,8 +1519,9 @@
\expandafter\def\csname #1@#2@format@last\endcsname%
##1##2##3##4##5##6{#5}%
% \end{macrocode}
-% Note that these \cmd{@tmpa} macros make use of the fact that the first
-% character of \#1 is ``c'' for lower-case, ``C'' for upper-case.
+% Note that these \cmd{\@tmpa} macros make use of the fact that the
+% first character of \#1 is ``c'' for lower-case, ``C'' for
+% upper-case.
% \begin{macrocode}
\def\@tmpa##1##2\@nil{%
\if##1c \def\@other{C##2}%
@@ -1407,15 +1563,15 @@
%
%
% \subsection{Default Reference Formats}
-% Define the default reference formats, appropriate for \LaTeX
+% Define the default reference formats, appropriate for \LaTeX{}
% documents written in English. We define the lowercase and
% capitalised versions separately, rather than relying on the
% automatic definitions, because the code produced by the poor man's
% sed script is then slightly tidier.\\
% To-Do: add babel support
% \begin{macrocode}
-\crefformat{equation}{eq.~#2(#1)#3}
-\Crefformat{equation}{Eq.~#2(#1)#3}
+\crefformat{equation}{eq.~\textup{(#2#1#3)}}
+\Crefformat{equation}{Equation~\textup{(#2#1#3)}}
\crefformat{chapter}{chapter~#2#1#3}
\Crefformat{chapter}{Chapter~#2#1#3}
\crefformat{section}{section~#2#1#3}
@@ -1427,13 +1583,26 @@
\crefformat{subsubsubsection}{section~#2#1#3}
\Crefformat{subsubsubsection}{Section~#2#1#3}
\crefformat{figure}{fig.~#2#1#3}
-\Crefformat{figure}{Fig.~#2#1#3}
+\Crefformat{figure}{Figure~#2#1#3}
\crefformat{theorem}{theorem~#2#1#3}
\Crefformat{theorem}{Theorem~#2#1#3}
+\crefformat{enumi}{item~#2#1#3}
+\Crefformat{enumi}{Item~#2#1#3}
+\crefformat{enumii}{item~#2#1#3}
+\Crefformat{enumii}{Item~#2#1#3}
+\crefformat{enumiii}{item~#2#1#3}
+\Crefformat{enumiii}{Item~#2#1#3}
+\crefformat{enumiv}{item~#2#1#3}
+\Crefformat{enumiv}{Item~#2#1#3}
+%
\crefmultiformat{equation}%
- {eqs.~#2(#1)#3}{, #2(#1)#3}{ and~#2(#1)#3}
+ {eqs.~\textup{(#2#1#3)}}%
+ {, \textup{(#2#1#3)}}%
+ { and~\textup{(#2#1#3)}}
\Crefmultiformat{equation}%
- {Eqs.~#2(#1)#3}{, #2(#1)#3}{ and~#2(#1)#3}
+ {Equations~\textup{(#2#1#3)}}%
+ {, \textup{(#2#1#3)}}%
+ { and~\textup{(#2#1#3)}}
\crefmultiformat{chapter}%
{chapters~#2#1#3}{, #2#1#3}{ and~#2#1#3}
\Crefmultiformat{chapter}%
@@ -1457,14 +1626,32 @@
\crefmultiformat{figure}%
{figs.~#2#1#3}{, #2#1#3}{ and~#2#1#3}
\Crefmultiformat{figure}%
- {Figs.~#2#1#3}{, #2#1#3}{ and~#2#1#3}
+ {Figures~#2#1#3}{, #2#1#3}{ and~#2#1#3}
\crefmultiformat{theorem}%
{theorems~#2#1#3}{, #2#1#3}{ and~#2#1#3}
\Crefmultiformat{theorem}%
{Theorems~#2#1#3}{, #2#1#3}{ and~#2#1#3}
-%
-\crefrangeformat{equation}{eqs.~#3(#1)#4--#5(#2)#6}
-\Crefrangeformat{equation}{Eqs.~#3(#1)#4--#5(#2)#6}
+\crefmultiformat{enumi}%
+ {items~#2#1#3}{, #2#1#3}{ and~#2#1#3}
+\Crefmultiformat{enumi}%
+ {Items~#2#1#3}{, #2#1#3}{ and~#2#1#3}
+\crefmultiformat{enumii}%
+ {items~#2#1#3}{, #2#1#3}{ and~#2#1#3}
+\Crefmultiformat{enumii}%
+ {Items~#2#1#3}{, #2#1#3}{ and~#2#1#3}
+\crefmultiformat{enumiii}%
+ {items~#2#1#3}{, #2#1#3}{ and~#2#1#3}
+\Crefmultiformat{enumiii}%
+ {Items~#2#1#3}{, #2#1#3}{ and~#2#1#3}
+\crefmultiformat{enumiv}%
+ {items~#2#1#3}{, #2#1#3}{ and~#2#1#3}
+\Crefmultiformat{enumiv}%
+ {Items~#2#1#3}{, #2#1#3}{ and~#2#1#3}
+%
+\crefrangeformat{equation}{%
+ eqs.~\textup{(#3#1#4)}--\textup{(#5#2#6)}}
+\Crefrangeformat{equation}{%
+ Equations~\textup{(#3#1#4)}--\textup{(#5#2#6)}}
\crefrangeformat{chapter}{chapters~#3#1#4--#5#2#6}
\Crefrangeformat{chapter}{Chapters~#3#1#4--#5#2#6}
\crefrangeformat{section}{sections~#3#1#4--#5#2#6}
@@ -1476,17 +1663,26 @@
\crefrangeformat{subsubsubsection}{sections~#3#1#4--#5#2#6}
\Crefrangeformat{subsubsubsection}{Sections~#3#1#4--#5#2#6}
\crefrangeformat{figure}{figs.~#3#1#4--#5#2#6}
-\Crefrangeformat{figure}{Figs.~#3#1#4--#5#2#6}
+\Crefrangeformat{figure}{Figures~#3#1#4--#5#2#6}
\crefrangeformat{theorem}{theorems~#3#1#4--#5#2#6}
\Crefrangeformat{theorem}{Theorems~#3#1#4--#5#2#6}
+\crefrangeformat{enumi}{items~#3#1#4--#5#2#6}
+\Crefrangeformat{enumi}{Items~#3#1#4--#5#2#6}
+\crefrangeformat{enumii}{items~#3#1#4--#5#2#6}
+\Crefrangeformat{enumii}{Items~#3#1#4--#5#2#6}
+\crefrangeformat{enumiii}{items~#3#1#4--#5#2#6}
+\Crefrangeformat{enumiii}{Items~#3#1#4--#5#2#6}
+\crefrangeformat{enumiv}{items~#3#1#4--#5#2#6}
+\Crefrangeformat{enumiv}{Items~#3#1#4--#5#2#6}
+%
\crefrangemultiformat{equation}%
- {eqs.~#3(#1)#4--#5(#2)#6}%
- {, #3(#1)#4--#5(#2)#6}%
- { and~#3(#1)#4--#5(#2)#6}
+ {eqs.~\textup{(#3#1#4)}--\textup{(#5#2#6)}}%
+ {, \textup{(#3#1#4)}--\textup{(#5#2#6)}}%
+ { and~\textup{(#3#1#4)}--\textup{(#5#2#6)}}
\Crefrangemultiformat{equation}%
- {Eqs.~#3(#1)#4--#5(#2)#6}%
- {, #3(#1)#4--#5(#2)#6}%
- { and~#3(#1)#4--#5(#2)#6}
+ {Equations~\textup{(#3#1#4)}--\textup{(#5#2#6)}}%
+ {, \textup{(#3#1#4)}--\textup{(#5#2#6)}}%
+ { and~\textup{(#3#1#4)}--\textup{(#5#2#6)}}
\crefrangemultiformat{chapter}%
{chapters~#3#1#4--#5#2#6}%
{, #3#1#4--#5#2#6}%
@@ -1528,11 +1724,11 @@
{, #3#1#4--#5#2#6}%
{ and~#3#1#4--#5#2#6}
\crefrangemultiformat{figure}%
- {figs~#3#1#4--#5#2#6}%
+ {figs.~#3#1#4--#5#2#6}%
{, #3#1#4--#5#2#6}%
{ and~#3#1#4--#5#2#6}
\Crefrangemultiformat{figure}%
- {Figs~#3#1#4--#5#2#6}%
+ {Figures~#3#1#4--#5#2#6}%
{, #3#1#4--#5#2#6}%
{ and~#3#1#4--#5#2#6}
\crefrangemultiformat{theorem}%
@@ -1543,6 +1739,38 @@
{Theorems~#3#1#4--#5#2#6}%
{, #3#1#4--#5#2#6}%
{ and~#3#1#4--#5#2#6}
+\crefrangemultiformat{enumi}%
+ {items~#3#1#4--#5#2#6}%
+ {, #3#1#4--#5#2#6}%
+ { and~#3#1#4--#5#2#6}
+\Crefrangemultiformat{enumi}%
+ {Items~#3#1#4--#5#2#6}%
+ {, #3#1#4--#5#2#6}%
+ { and~#3#1#4--#5#2#6}
+\crefrangemultiformat{enumii}%
+ {items~#3#1#4--#5#2#6}%
+ {, #3#1#4--#5#2#6}%
+ { and~#3#1#4--#5#2#6}
+\Crefrangemultiformat{enumii}%
+ {Items~#3#1#4--#5#2#6}%
+ {, #3#1#4--#5#2#6}%
+ { and~#3#1#4--#5#2#6}
+\crefrangemultiformat{enumiii}%
+ {items~#3#1#4--#5#2#6}%
+ {, #3#1#4--#5#2#6}%
+ { and~#3#1#4--#5#2#6}
+\Crefrangemultiformat{enumiii}%
+ {Items~#3#1#4--#5#2#6}%
+ {, #3#1#4--#5#2#6}%
+ { and~#3#1#4--#5#2#6}
+\crefrangemultiformat{enumiv}%
+ {items~#3#1#4--#5#2#6}%
+ {, #3#1#4--#5#2#6}%
+ { and~#3#1#4--#5#2#6}
+\Crefrangemultiformat{enumiv}%
+ {Items~#3#1#4--#5#2#6}%
+ {, #3#1#4--#5#2#6}%
+ { and~#3#1#4--#5#2#6}
%
\def\crefmiddleconjunction{, }
\def\creflastconjunction{, and }
@@ -1594,9 +1822,9 @@
% \end{macrocode}
%
% The original \cmd{\refstepcounter}, as stored earlier in
-% \cmd{\old@refstepcounter} already calls \H@refstepcounter if
+% \cmd{\old@refstepcounter}, already calls \H@refstepcounter if
% \package{hyperref} is loaded, and we just redefined it to store the
-% type information. so we only need to change \cmd{\@currentlabel} in
+% type information. So we only need to change \cmd{\@currentlabel} in
% our \cmd{\refstepcounter} if an optional argument was supplied.
% \begin{macrocode}
\def\refstepcounter@noarg#1{\old@refstepcounter{#1}}
@@ -1610,22 +1838,51 @@
[#1][\arabic{#2}][\@tempreset]\@templabel}}
% \end{macrocode}
%
-% Redefine \@@setcref and \@@setrangeref to create hyperlinks, using
-% the extra arguments supplied in \cmd{r@\meta{label}} (via the aux
-% file) by \package{hyperref}.
+% Redefine \cmd{\cref} and all the others to allow starred variants,
+% which don't create hyper-links. The starred variants simply set a
+% flag, which is tested in \cmd{\@@setcref} and \cmd{\@@setrangeref}
+% (below).
+% \begin{macrocode}
+\newif\if@crefstarred
+\DeclareRobustCommand{\cref}{%
+ \@ifstar{\@crefstar{cref}}{\@crefnostar{cref}}}
+\DeclareRobustCommand{\Cref}{%
+ \@ifstar{\@crefstar{Cref}}{\@crefnostar{Cref}}}
+\DeclareRobustCommand{\crefrange}{%
+ \@ifstar{\@crefrangestar{cref}}{\@crefrangenostar{cref}}}
+\DeclareRobustCommand{\Crefrange}{%
+ \@ifstar{\@crefrangestar{Cref}}{\@crefrangenostar{Cref}}}
+\def\@crefnostar#1#2{\@cref{#1}{#2}}
+\def\@crefstar#1#2{\@crefstarredtrue\@cref{#1}{#2}\@crefstarredfalse}
+\def\@crefrangenostar#1#2#3{\@setcrefrange{#2}{#3}{#1}{}}
+\def\@crefrangestar#1#2#3{%
+ \@crefstarredtrue\@setcrefrange{#2}{#3}{#1}{}\@crefstarredfalse}
+% \end{macrocode}
+%
+% Redefine \@@setcref and \@@setrangeref to create hyper-links (unless
+% the starred flag is set), using the extra arguments supplied in
+% \cmd{\r@\meta{label}} (via the aux file) by \package{hyperref}.
% \begin{macrocode}
\def\@@setcref#1#2{%
\cref@getlabel{#2}{\@templabel}%
- \edef\@templink{\cref@hyperref{#2}}%
- #1{\@templabel}{\hyper@linkstart{link}{\@templink}}{\hyper@linkend}}
+ \if@crefstarred%
+ #1{\@templabel}{}{}%
+ \else%
+ \edef\@templink{\cref@hyperref{#2}}%
+ #1{\@templabel}{\hyper@linkstart{link}{\@templink}}{\hyper@linkend}%
+ \fi}
\def\@@setcrefrange#1#2#3{%
\cref@getlabel{#2}{\@labela}%
\cref@getlabel{#3}{\@labelb}%
- \edef\@linka{\cref@hyperref{#2}}%
- \edef\@linkb{\cref@hyperref{#3}}%
- #1{\@labela}{\@labelb}%
- {\hyper@linkstart{link}{\@linka}}{\hyper@linkend}%
- {\hyper@linkstart{link}{\@linkb}}{\hyper@linkend}}
+ \if@crefstarred%
+ #1{\@labela}{\@labelb}{}{}{}{}%
+ \else%
+ \edef\@linka{\cref@hyperref{#2}}%
+ \edef\@linkb{\cref@hyperref{#3}}%
+ #1{\@labela}{\@labelb}%
+ {\hyper@linkstart{link}{\@linka}}{\hyper@linkend}%
+ {\hyper@linkstart{link}{\@linkb}}{\hyper@linkend}%
+ \fi}
} % end of hyperref option
% \end{macrocode}
%
@@ -1636,7 +1893,7 @@
\PackageInfo{cleveref}{option `ntheorem' loaded}
% \end{macrocode}
%
-% We modify \package{ntheorem}'s version of the \cmd{@thm} macro very
+% We modify \package{ntheorem}'s version of the \cmd{\@thm} macro very
% slightly, to have it call \cmd{\refstepcounter} with an optional
% argument containing the theorem type.
% \begin{macrocode}
@@ -1764,7 +2021,7 @@
% characters, and defining them to expand to their escaped form. This
% involves a lot of juggling of catcodes and lccodes!
%
-% Both \cmd{DeclareOption} and \cmd{\AtEndDocument} store their
+% Both \cmd{\DeclareOption} and \cmd{\AtEndDocument} store their
% arguments in token lists, so all the following \TeX code is already
% tokenised long before it is expanded and evaluated. Thus there is no
% (easy) way to change the catcodes of the characters appearning here
@@ -1778,11 +2035,11 @@
% correct char- and catcodes.
%
% We get around this by creating the unusual charcode/catcode
-% combinations using the \cmd{lowercase} trick (\cmd{lowercase}
+% combinations using the \cmd{\lowercase} trick (\cmd{\lowercase}
% changes the charcodes of all characters in its argument to their
% lccodes, but \emph{leaves} their catcodes alone). That way, the
% argument of \cmd{\AtEndDocument} is tokenised correctly, and when it
-% comes to be expanded and evaluated, the \cmd{lowercase} commands
+% comes to be expanded and evaluated, the \cmd{\lowercase} commands
% create tokens with the correct char- and catcodes.
% \begin{macrocode}
\AtEndDocument{%
@@ -1811,7 +2068,7 @@
\lccode`~=0 \lccode`/=0 \catcode`~=12
% \end{macrocode}
% Read lines from the temporary script file, expand them to escape
-% regexp special characters, and store them in \cmd{cref@text}.
+% regexp special characters, and store them in \cmd{\cref@text}.
% \begin{macrocode}
\def\cref@text{}%
\immediate\read\@crefscript to \@tmpa%
@@ -1824,7 +2081,6 @@
\@whilesw\if@not@eof\fi{%
\expandafter\g@addto@macro\expandafter\cref@text\expandafter{%
\@tmpa^^J}%
- \show\cref@text%
\immediate\read\@crefscript to \@tmpa%
\edef\@tmpa{\@tmpa}%
\ifx\@tmpa\@eof%
@@ -1836,9 +2092,9 @@
\immediate\closein\@crefscript%
% \end{macrocode}
% Add some rules to remove likely \package{cleveref} preamble
-% commands. We use the \cmd{lowercase} trick again for writing the
+% commands. We use the \cmd{\lowercase} trick again for writing the
% $\backslash$, \{ and \} characters. (This could be done in other
-% ways, but since we're in \cmd{lowercase} mood, why not go with it!)
+% ways, but since we're in \cmd{\lowercase} mood, why not go with it!)
% \begin{macrocode}
\begingroup%
\lccode`|=92 \lccode`<=123 \lccode`>=125 \lccode`C=67