summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/cleveref
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2007-06-17 21:35:59 +0000
committerKarl Berry <karl@freefriends.org>2007-06-17 21:35:59 +0000
commit624dfe31cdca8a3356ee08faa7edbacf2ea512b3 (patch)
treed8f95264bb21bab4d0646e6f70fd91108ac133a9 /Master/texmf-dist/source/latex/cleveref
parentc4ae47344ef52c976c8de09bd07d290cd2bb983f (diff)
cleveref update (17jun07)
git-svn-id: svn://tug.org/texlive/trunk@4451 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source/latex/cleveref')
-rw-r--r--Master/texmf-dist/source/latex/cleveref/cleveref.dtx579
1 files changed, 490 insertions, 89 deletions
diff --git a/Master/texmf-dist/source/latex/cleveref/cleveref.dtx b/Master/texmf-dist/source/latex/cleveref/cleveref.dtx
index 995031bf2b5..43db80451bc 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> [2007/26/04 v0.4 Automatic cross-reference formatting]
+%<package> [2007/11/06 v0.6 Automatic cross-reference formatting]
%
%<*driver>
\documentclass[draft]{ltxdoc}
@@ -59,7 +59,7 @@
%</driver>
% \fi
%
-% \CheckSum{1405}
+% \CheckSum{1914}
%% \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,12 +79,14 @@
% \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/04}{Renamed "cleveref"}
+% \changes{v0.4}{2007/26/05}{Renamed "cleveref"}
+% \changes{v0.5}{2007/31/05}{Added poorman option}
+% \changes{v0.5}{2007/11/06}{Poorman no longer writes extra .tmp file}
%
% \GetFileInfo{cleveref.sty}
%
-% \def\fileversion{0.4}
-% \def\filedate{26/05/2007}
+% \def\fileversion{0.6}
+% \def\filedate{11/06/2007}
%
% \title{The \textsf{cleveref} package\thanks{This document
% corresponds to \textsf{cleveref}~\fileversion, dated
@@ -107,6 +109,8 @@
% fully customisable.
% \end{abstract}
%
+%
+%
% \section{Introduction}
%
% When ``clever'' is used in the name of a computer program, it
@@ -209,6 +213,7 @@
% \cref{sec:other_packages}).
%
%
+%
% \subsection{Typesetting References}
%
% \DescribeMacro\cref
@@ -496,6 +501,48 @@
% \end{quote}
%
%
+% \subsection{Poor Man's \package{cleveref}}
+% 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
+% only support a subset of the packages available on CTAN. The
+% \option{poorman} option was designed specifically to help in this
+% situation.
+%
+% 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,
+% 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!
+%
+% The advantage, of course, is that you \emph{don't} have to do it
+% manually. Instead, you can use all the features of
+% \package{cleveref}, and once you've created a version of your
+% 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
+% 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:
+% \begin{quote}
+% 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
+% 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
+% \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}
+% file: something you can always reproduce from the original source.)
+%
+%
+%
% \section{Interaction with Other Packages}
% \label{sec:other_packages}
% Since \package{cleveref} redefines many internal commands involved
@@ -538,6 +585,7 @@
% unlikely to work properly with \package{cleveref}.
%
%
+%
% \section{Known Bugs}
% \begin{itemize}
% \item \package{cleveref} will not work properly with the standard
@@ -563,6 +611,7 @@
% \end{itemize}
%
%
+%
% \section{Future Improvements}
% \begin{itemize}
% \item Allow selective disabling of reference-range collapsing in
@@ -570,14 +619,6 @@
% between the labels in the label list.
% \item Allow reference-range collapsing to be disabled entirely via a
% package option
-% \item Implement a ``poor-man's'' \package{cleveref}, for situations
-% in which you are able to install and use \package{cleveref}
-% locally, but annother party can not (e.g.\ when submitting the
-% \LaTeX source of a paper to a journal). When this option is set,
-% \package{cleveref} would generate a sed or awk script through
-% which the original source could be processed, generating a version
-% of the source with all the \package{cleveref} references replaced
-% by the text they would generate plus standard |\ref| commands.
% \end{itemize}
%
%
@@ -586,7 +627,6 @@
%
%
%
-%
% \section{Implementation}
%
% Essentially, the core of the implementation consists of causing an
@@ -824,10 +864,10 @@
% called \cmd{\@refstack}.
% \begin{macrocode}
\countdef\count@consecutive=0%
- \newif\iffirstgroup%
+ \newif\if@firstgroup%
\stack@init{\@refstack}%
\stack@push{#2}{\@refstack}%
- \firstgrouptrue%
+ \@firstgrouptrue%
\isstackfull{\@refstack}%
% \end{macrocode}
% Loop until the reference stack is empty.
@@ -857,22 +897,23 @@
\expandafter\ifx\csname r@\@nextref\endcsname\relax%
\def\@currenttype{\@undefined}%
\else%
- \expandafter\cref@gettype\expandafter{\@nextref}{\@currenttype}%
+ \expandafter\cref@gettype\expandafter%
+ {\@nextref}{\@currenttype}%
\fi%
\fi}%
% \end{macrocode}
% Typeset appropriate conjunction between groups of reference types.
% \begin{macrocode}
- \iffirstgroup%
+ \if@firstgroup%
\else%
\isstackfull{\@refstack}%
\ifstackfull%
- \crefmiddleconjunction%
+ \@setcref@middleconjunction%
\else%
- \creflastconjunction%
+ \@setcref@lastconjunction%
\fi%
\fi%
- \firstgroupfalse%
+ \@firstgroupfalse%
% \end{macrocode}
% Process first group of consecutive references from substack.
% \begin{macrocode}
@@ -924,11 +965,11 @@
% \begin{macrocode}
\ifx\@endref\relax%
\expandafter\@setcref\expandafter{\@beginref}{#1}{@first}%
- \else%
% \end{macrocode}
% if there were only two consecutive references, typeset the first
-% one and return the second to the substack,
+% one and return the second to the substack;
% \begin{macrocode}
+ \else%
\ifnum\count@consecutive=2%
\expandafter\@setcref\expandafter{\@beginref}{#1}{@first}%
\expandafter\stack@push\expandafter{\@endref}{\@refsubstack}%
@@ -1022,10 +1063,10 @@
\fi%
\fi%
\isstackfull{\@refsubstack}%
- }%
+ }% end loop over reference substack
\fi%
\isstackfull{\@refstack}%
- }%
+ }% end loop over main reference stack
\endgroup}
% \end{macrocode}
%
@@ -1147,7 +1188,7 @@
% non-identical type.)
% \begin{macrocode}
\ifx\formata\formatb%
- \@@setcrefrange{\@formata}{#1}{#2}%
+ \expandafter\@@setcrefrange\expandafter{\@formata}{#1}{#2}%
\else%
\protect\G@refundefinedtrue%
\nfss@text{\reset@font\bfseries ??}~\@labela--\@labelb%
@@ -1170,6 +1211,14 @@
% \end{macrocode}
%
%
+% The typesetting of conjunctions is also separated out into separate
+% macros, for the same reason.
+% \begin{macrocode}
+\def\@setcref@middleconjunction{\crefmiddleconjunction}
+\def\@setcref@lastconjunction{\creflastconjunction}
+% \end{macrocode}
+%
+%
%
% \subsection{Reference Format Customisation Commands}
% \cmd{\crefformat} et al.\ are user-level commands used to define the
@@ -1201,80 +1250,111 @@
\def\@crefformat#1#2#3{%
\expandafter\def\csname #1@#2@format\endcsname##1##2##3{#3}%
% \end{macrocode}
-% Note that the \cmd{@tmpa} macro makes 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 makes 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}%
\else\def\@other{c##2}\fi}%
\@tmpa#1\@nil%
-% \end{macrocode}
-% Note that the \cmd{@tmpa} macro makes 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\@changecase{\MakeUppercase}%
- \else\def\@changecase{\MakeLowercase}\fi}%
- \@tmpa#1\@nil%
\@ifundefined{\@other @#2@format}{%
- \expandafter\edef\csname\@other @#2@format\endcsname##1##2##3{%
- \expandafter\noexpand\@changecase\csname #1@#2@format\endcsname%
- {##1}{##2}{##3}}}{}}
+ \def\@tmpa##1##2\@nil{%
+ \if##1c\def\@changecase{\MakeUppercase}%
+ \else\def\@changecase{\Makelowercase}\fi}%
+ \@tmpa#1\@nil%
+ \newtoks\@toksa%
+ \@toksa={\def\@tmpa##1##2##3}%
+ \expandafter\expandafter\expandafter\the%
+ \expandafter\expandafter\expandafter\@toksa%
+ \expandafter\expandafter\expandafter{%
+ \csname#1@#2@format\endcsname{##1}{##2}{##3}}%
+ \expandafter\the\expandafter\@toksa\expandafter{%
+ \expandafter\MakeUppercase\@tmpa{##1}{##2}{##3}}%
+ \@toksa={%
+ \expandafter\def\csname\@other @#2@format\endcsname##1##2##3}%
+ \expandafter\the\expandafter\@toksa\expandafter{%
+ \@tmpa{##1}{##2}{##3}}%
+ }{}%
+}
%
\def\@crefrangeformat#1#2#3{%
- \expandafter\def\csname #1@#2@format\endcsname##1##2##3##4##5##6{#3}%
+ \expandafter\def\csname #1@#2@format\endcsname%
+ ##1##2##3##4##5##6{#3}%
% \end{macrocode}
-% Note that the \cmd{@tmpa} macro makes 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}%
\else\def\@other{c##2}\fi}%
\@tmpa#1\@nil%
-% \end{macrocode}
-% Note that the \cmd{@tmpa} macro makes 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\@changecase{\MakeUppercase}%
- \else\def\@changecase{\MakeLowercase}\fi}%
- \@tmpa#1\@nil%
\@ifundefined{\@other @#2@format}{%
- \expandafter\edef%
- \csname\@other @#2@format\endcsname##1##2##3##4##5##6{%
- \expandafter\noexpand\@changecase\csname #1@#2@format\endcsname%
- {##1}{##2}{##3}{##4}{##5}{##6}}}{}}
+ \def\@tmpa##1##2\@nil{%
+ \if##1c\def\@changecase{\MakeUppercase}%
+ \else\def\@changecase{\Makelowercase}\fi}%
+ \@tmpa#1\@nil%
+ \newtoks\@toksa%
+ \@toksa={\def\@tmpa##1##2##3##4##5##6}%
+ \expandafter\expandafter\expandafter\the%
+ \expandafter\expandafter\expandafter\@toksa%
+ \expandafter\expandafter\expandafter{%
+ \csname#1@#2@format\endcsname{##1}{##2}{##3}{##4}{##5}{##6}}%
+ \expandafter\the\expandafter\@toksa\expandafter{%
+ \expandafter\MakeUppercase\@tmpa{##1}{##2}{##3}{##4}{##5}{##6}}
+ \@toksa={\expandafter\def%
+ \csname\@other @#2@format\endcsname##1##2##3##4##5##6}%
+ \expandafter\the\expandafter\@toksa\expandafter{%
+ \@tmpa{##1}{##2}{##3}{##4}{##5}{##6}}%
+ }{}%
+}
%
\def\@crefmultiformat#1#2#3#4#5{%
\expandafter\def\csname #1@#2@format@first\endcsname##1##2##3{#3}%
\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 the \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}
+ \newtoks\@toksa%
\def\@tmpa##1##2\@nil{%
\if##1c \def\@other{C##2}%
\else\def\@other{c##2}\fi}%
\@tmpa#1\@nil%
- \def\@tmpa##1##2\@nil{%
- \if##1c\def\@changecase{\MakeUppercase}%
- \else\def\@changecase{\MakeLowercase}\fi}%
- \@tmpa#1\@nil%
\@ifundefined{\@other @#2@format@first}{%
- \expandafter\edef%
- \csname\@other @#2@format@first\endcsname##1##2##3{%
- \expandafter\noexpand\@changecase%
- \csname #1@#2@format@first\endcsname%
- {##1}{##2}{##3}}}{}%
+ \def\@tmpa##1##2\@nil{%
+ \if##1c\def\@changecase{\MakeUppercase}%
+ \else\def\@changecase{\Makelowercase}\fi}%
+ \@tmpa#1\@nil%
+ \@toksa={\def\@tmpa##1##2##3}%
+ \expandafter\expandafter\expandafter\the%
+ \expandafter\expandafter\expandafter\@toksa%
+ \expandafter\expandafter\expandafter{%
+ \csname#1@#2@format@first\endcsname{##1}{##2}{##3}}%
+ \expandafter\the\expandafter\@toksa\expandafter{%
+ \expandafter\MakeUppercase\@tmpa{##1}{##2}{##3}}%
+ \@toksa={%
+ \expandafter\def\csname\@other @#2@format@first\endcsname%
+ ##1##2##3}%
+ \expandafter\the\expandafter\@toksa\expandafter{%
+ \@tmpa{##1}{##2}{##3}}%
+ }{}
\@ifundefined{\@other @#2@format@middle}{%
- \expandafter\edef%
- \csname\@other @#2@format@middle\endcsname##1##2##3{%
- \csname #1@#2@format@middle\endcsname{##1}{##2}{##3}}}{}%
+ \@toksa={%
+ \expandafter\let\csname\@other @#2@format@middle\endcsname}%
+ \expandafter\the\expandafter\@toksa%
+ \csname #1@#2@format@middle\endcsname%
+ }{}%
\@ifundefined{\@other @#2@format@last}{%
- \expandafter\edef%
- \csname\@other @#2@format@last\endcsname##1##2##3{%
- \csname #1@#2@format@last\endcsname{##1}{##2}{##3}}}{}}
+ \@toksa={%
+ \expandafter\let\csname\@other @#2@format@last\endcsname}%
+ \expandafter\the\expandafter\@toksa%
+ \csname #1@#2@format@last\endcsname%
+ }{}%
+}
%
\def\@crefrangemultiformat#1#2#3#4#5{%
\expandafter\def\csname #1@#2@format@first\endcsname%
@@ -1284,106 +1364,185 @@
\expandafter\def\csname #1@#2@format@last\endcsname%
##1##2##3##4##5##6{#5}%
% \end{macrocode}
-% Note that the \cmd{@tmpa} macros make use of the fact that the first
+% 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}%
\else\def\@other{c##2}\fi}%
\@tmpa#1\@nil%
- \def\@tmpa##1##2\@nil{%
- \if##1c\def\@changecase{\MakeUppercase}%
- \else\def\@changecase{\MakeLowercase}\fi}%
- \@tmpa#1\@nil%
\@ifundefined{\@other @#2@format@first}{%
- \expandafter\edef%
- \csname\@other @#2@format@first\endcsname##1##2##3##4##5##6{%
- \expandafter\noexpand\@changecase%
- \csname #1@#2@format@first\endcsname%
- {##1}{##2}{##3}{##4}{##5}{##6}}}{}%
+ \def\@tmpa##1##2\@nil{%
+ \if##1c\def\@changecase{\MakeUppercase}%
+ \else\def\@changecase{\MakeLowercase}\fi}%
+ \@tmpa#1\@nil%
+ \@toksa={\def\@tmpa##1##2##3##4##5##6}%
+ \expandafter\expandafter\expandafter\the%
+ \expandafter\expandafter\expandafter\@toksa%
+ \expandafter\expandafter\expandafter{%
+ \csname#1@#2@format@first\endcsname%
+ {##1}{##2}{##3}{##4}{##5}{##6}}%
+ \expandafter\the\expandafter\@toksa\expandafter{%
+ \expandafter\MakeUppercase\@tmpa{##1}{##2}{##3}{##4}{##5}{##6}}%
+ \@toksa={%
+ \expandafter\def\csname\@other @#2@format@first\endcsname%
+ ##1##2##3##4##5##6}%
+ \expandafter\the\expandafter\@toksa\expandafter{%
+ \@tmpa{##1}{##2}{##3}{##4}{##5}{##6}}%
+ }{}%
\@ifundefined{\@other @#2@format@middle}{%
- \expandafter\edef%
- \csname\@other @#2@format@middle\endcsname##1##2##3##4##5##6{%
+ \@toksa={%
+ \expandafter\let\csname\@other @#2@format@middle\endcsname}%
+ \expandafter\the\expandafter\@toksa%
\csname #1@#2@format@middle\endcsname%
- {##1}{##2}{##3}{##4}{##5}{##6}}}{}%
+ }{}%
\@ifundefined{\@other @#2@format@last}{%
- \expandafter\edef%
- \csname\@other @#2@format@last\endcsname##1##2##3##4##5##6{%
+ \@toksa={%
+ \expandafter\let\csname\@other @#2@format@last\endcsname}%
+ \expandafter\the\expandafter\@toksa%
\csname #1@#2@format@last\endcsname%
- {##1}{##2}{##3}{##4}{##5}{##6}}}{}}
+ }{}%
+}
% \end{macrocode}
%
%
% \subsection{Default Reference Formats}
% Define the default reference formats, appropriate for \LaTeX
-% documents written in English.\\
+% 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{chapter}{chapter~#2#1#3}
+\Crefformat{chapter}{Chapter~#2#1#3}
\crefformat{section}{section~#2#1#3}
+\Crefformat{section}{Section~#2#1#3}
\crefformat{subsection}{section~#2#1#3}
+\Crefformat{subsection}{Section~#2#1#3}
\crefformat{subsubsection}{section~#2#1#3}
+\Crefformat{subsubsection}{Section~#2#1#3}
\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{theorem}{theorem~#2#1#3}
+\Crefformat{theorem}{Theorem~#2#1#3}
\crefmultiformat{equation}%
{eqs.~#2(#1)#3}{, #2(#1)#3}{ and~#2(#1)#3}
+\Crefmultiformat{equation}%
+ {Eqs.~#2(#1)#3}{, #2(#1)#3}{ and~#2(#1)#3}
\crefmultiformat{chapter}%
{chapters~#2#1#3}{, #2#1#3}{ and~#2#1#3}
+\Crefmultiformat{chapter}%
+ {Chapters~#2#1#3}{, #2#1#3}{ and~#2#1#3}
\crefmultiformat{section}%
{sections~#2#1#3}{, #2#1#3}{ and~#2#1#3}
+\Crefmultiformat{section}%
+ {Sections~#2#1#3}{, #2#1#3}{ and~#2#1#3}
\crefmultiformat{subsection}%
{sections~#2#1#3}{, #2#1#3}{ and~#2#1#3}
+\Crefmultiformat{subsection}%
+ {Sections~#2#1#3}{, #2#1#3}{ and~#2#1#3}
\crefmultiformat{subsubsection}%
{sections~#2#1#3}{, #2#1#3}{ and~#2#1#3}
+\Crefmultiformat{subsubsection}%
+ {Sections~#2#1#3}{, #2#1#3}{ and~#2#1#3}
\crefmultiformat{subsubsubsection}%
{sections~#2#1#3}{, #2#1#3}{ and~#2#1#3}
+\Crefmultiformat{subsubsubsection}%
+ {Sections~#2#1#3}{, #2#1#3}{ and~#2#1#3}
\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}
\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}
\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}
+\Crefrangeformat{section}{Sections~#3#1#4--#5#2#6}
\crefrangeformat{subsection}{sections~#3#1#4--#5#2#6}
+\Crefrangeformat{subsection}{Sections~#3#1#4--#5#2#6}
\crefrangeformat{subsubsection}{sections~#3#1#4--#5#2#6}
+\Crefrangeformat{subsubsection}{Sections~#3#1#4--#5#2#6}
\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{theorem}{theorems~#3#1#4--#5#2#6}
+\Crefrangeformat{theorem}{Theorems~#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}
+\Crefrangemultiformat{equation}%
+ {Eqs.~#3(#1)#4--#5(#2)#6}%
+ {, #3(#1)#4--#5(#2)#6}%
+ { and~#3(#1)#4--#5(#2)#6}
\crefrangemultiformat{chapter}%
{chapters~#3#1#4--#5#2#6}%
{, #3#1#4--#5#2#6}%
{ and~#3#1#4--#5#2#6}
+\Crefrangemultiformat{chapter}%
+ {Chapters~#3#1#4--#5#2#6}%
+ {, #3#1#4--#5#2#6}%
+ { and~#3#1#4--#5#2#6}
\crefrangemultiformat{section}%
{sections~#3#1#4--#5#2#6}%
{, #3#1#4--#5#2#6}%
{ and~#3#1#4--#5#2#6}
+\Crefrangemultiformat{section}%
+ {Sections~#3#1#4--#5#2#6}%
+ {, #3#1#4--#5#2#6}%
+ { and~#3#1#4--#5#2#6}
\crefrangemultiformat{subsection}%
{sections~#3#1#4--#5#2#6}%
{, #3#1#4--#5#2#6}%
{ and~#3#1#4--#5#2#6}
+\Crefrangemultiformat{subsection}%
+ {Sections~#3#1#4--#5#2#6}%
+ {, #3#1#4--#5#2#6}%
+ { and~#3#1#4--#5#2#6}
\crefrangemultiformat{subsubsection}%
{sections~#3#1#4--#5#2#6}%
{, #3#1#4--#5#2#6}%
{ and~#3#1#4--#5#2#6}
+\Crefrangemultiformat{subsubsection}%
+ {Sections~#3#1#4--#5#2#6}%
+ {, #3#1#4--#5#2#6}%
+ { and~#3#1#4--#5#2#6}
\crefrangemultiformat{subsubsubsection}%
{sections~#3#1#4--#5#2#6}%
{, #3#1#4--#5#2#6}%
{ and~#3#1#4--#5#2#6}
+\Crefrangemultiformat{subsubsubsection}%
+ {Sections~#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}%
{, #3#1#4--#5#2#6}%
{ and~#3#1#4--#5#2#6}
+\Crefrangemultiformat{figure}%
+ {Figs~#3#1#4--#5#2#6}%
+ {, #3#1#4--#5#2#6}%
+ { and~#3#1#4--#5#2#6}
\crefrangemultiformat{theorem}%
{theorems~#3#1#4--#5#2#6}%
{, #3#1#4--#5#2#6}%
{ and~#3#1#4--#5#2#6}
+\Crefrangemultiformat{theorem}%
+ {Theorems~#3#1#4--#5#2#6}%
+ {, #3#1#4--#5#2#6}%
+ { and~#3#1#4--#5#2#6}
%
\def\crefmiddleconjunction{, }
\def\creflastconjunction{, and }
@@ -1464,7 +1623,8 @@
\cref@getlabel{#3}{\@labelb}%
\edef\@linka{\cref@hyperref{#2}}%
\edef\@linkb{\cref@hyperref{#3}}%
- #1{\@labela}{\@labelb}{\hyper@linkstart{link}{\@linka}}{\hyper@linkend}%
+ #1{\@labela}{\@labelb}%
+ {\hyper@linkstart{link}{\@linka}}{\hyper@linkend}%
{\hyper@linkstart{link}{\@linkb}}{\hyper@linkend}}
} % end of hyperref option
% \end{macrocode}
@@ -1505,44 +1665,285 @@
% Default formats for new theorem-like environments defined by ntheorem.
% \begin{macrocode}
\crefformat{lemma}{lemma~#2#1#3}
+\Crefformat{lemma}{Lemma~#2#1#3}
\crefformat{corrollary}{corrollary~#2#1#3}
+\Crefformat{corrollary}{Corrollary~#2#1#3}
\crefformat{proposition}{proposition~#2#1#3}
+\Crefformat{proposition}{Proposition~#2#1#3}
\crefformat{definition}{definition~#2#1#3}
+\Crefformat{definition}{Definition~#2#1#3}
\crefformat{result}{result~#2#1#3}
+\Crefformat{result}{Result~#2#1#3}
\crefrangeformat{lemma}{lemma~#3#1#4--#5#2#6}
+\Crefrangeformat{lemma}{Lemma~#3#1#4--#5#2#6}
\crefrangeformat{corrollary}{corrollary~#3#1#4--#5#2#6}
+\Crefrangeformat{corrollary}{Corrollary~#3#1#4--#5#2#6}
\crefrangeformat{proposition}{proposition~#3#1#4--#5#2#6}
+\Crefrangeformat{proposition}{Proposition~#3#1#4--#5#2#6}
\crefrangeformat{definition}{definition~#3#1#4--#5#2#6}
+\Crefrangeformat{definition}{Definition~#3#1#4--#5#2#6}
\crefrangeformat{result}{result~#3#1#4--#5#2#6}
+\Crefrangeformat{result}{Result~#3#1#4--#5#2#6}
\crefmultiformat{lemma}%
{lemmas~#2#1#3}{, #2#1#3}{ and~#2#1#3}
+\Crefmultiformat{lemma}%
+ {Lemmas~#2#1#3}{, #2#1#3}{ and~#2#1#3}
\crefmultiformat{corrollary}%
{corrollaries~#2#1#3}{, #2#1#3}{ and~#2#1#3}
+\Crefmultiformat{corrollary}%
+ {Corrollaries~#2#1#3}{, #2#1#3}{ and~#2#1#3}
\crefmultiformat{proposition}%
{propositions~#2#1#3}{, #2#1#3}{ and~#2#1#3}
+\Crefmultiformat{proposition}%
+ {Propositions~#2#1#3}{, #2#1#3}{ and~#2#1#3}
\crefmultiformat{definition}%
{definitions~#2#1#3}{, #2#1#3}{ and~#2#1#3}
+\Crefmultiformat{definition}%
+ {Definitions~#2#1#3}{, #2#1#3}{ and~#2#1#3}
\crefmultiformat{result}%
{results~#2#1#3}{, #2#1#3}{ and~#2#1#3}
+\Crefmultiformat{result}%
+ {Results~#2#1#3}{, #2#1#3}{ and~#2#1#3}
\crefrangemultiformat{lemma}%
{lemmas~#3#1#4--#5#2#6}{, #3#1#4--#5#2#6}%
+ { and~#3#1#4--#5#2#6}%
+\Crefrangemultiformat{lemma}%
+ {Lemmas~#3#1#4--#5#2#6}{, #3#1#4--#5#2#6}%
{ and~#3#1#4--#5#2#6}
\crefrangemultiformat{corrollary}%
{corrollaries~#3#1#4--#5#2#6}{, #3#1#4--#5#2#6}%
{ and~#3#1#4--#5#2#6}
+\Crefrangemultiformat{corrollary}%
+ {Corrollaries~#3#1#4--#5#2#6}{, #3#1#4--#5#2#6}%
+ { and~#3#1#4--#5#2#6}
\crefrangemultiformat{proposition}%
{propositions~#3#1#4--#5#2#6}{, #3#1#4--#5#2#6}%
{ and~#3#1#4--#5#2#6}
+\Crefrangemultiformat{proposition}%
+ {Propositions~#3#1#4--#5#2#6}{, #3#1#4--#5#2#6}%
+ { and~#3#1#4--#5#2#6}
\crefrangemultiformat{definition}%
{definitions~#3#1#4--#5#2#6}{, #3#1#4--#5#2#6}%
{ and~#3#1#4--#5#2#6}
+\Crefrangemultiformat{definition}%
+ {Definitions~#3#1#4--#5#2#6}{, #3#1#4--#5#2#6}%
+ { and~#3#1#4--#5#2#6}
\crefrangemultiformat{result}%
{results~#3#1#4--#5#2#6}{, #3#1#4--#5#2#6}%
{ and~#3#1#4--#5#2#6}
+\Crefrangemultiformat{result}%
+ {Results~#3#1#4--#5#2#6}{, #3#1#4--#5#2#6}%
+ { and~#3#1#4--#5#2#6}
} % end of ntheorem option
% \end{macrocode}
%
%
+% \subsection{Poor Man's \package{cleveref}}
+% \begin{macrocode}
+\DeclareOption{poorman}{%
+\PackageInfo{cleveref}{option `poorman' loaded}
+% \end{macrocode}
+%
+%
+% Define global macro \cmd{\cref@text} to store the text produced by
+% the \cmd{\cref} commands, and open an output stream for writing the
+% script before starting to process to document body.
+% \begin{macrocode}
+\edef\cref@text{}
+\AtBeginDocument{%
+ \newwrite\@crefscript%
+ \immediate\openout\@crefscript=\jobname.sed%
+}
+% \end{macrocode}
+%
+%
+% After processing the document body, we re-read in the temporary
+% script file, and write it out again to the final sed script file,
+% escaping regexp special characters in the process. The escaping is
+% carried out by turning the regexp special characters into active
+% 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
+% 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
+% before they are tokenised. In one way this is convenient: the
+% catcode changes we make don't ``take'' until evaluated, so we can
+% continue to use the standard \TeX characters ($\backslash$, \{, \}
+% etc.) even after the lines containing the catcode commands. But in
+% another, more significant, way, it is very inconvenient: it makes it
+% difficult to define the regexp special characters as active
+% characters, since it's impossible to directly create tokens with the
+% correct char- and catcodes.
+%
+% We get around this by creating the unusual charcode/catcode
+% 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
+% create tokens with the correct char- and catcodes.
+% \begin{macrocode}
+\AtEndDocument{%
+ \immediate\closeout\@crefscript%
+ \newread\@crefscript%
+ \immediate\openin\@crefscript=\jobname.sed%
+ \begingroup%
+ \newif\if@not@eof%
+ \def\@eof{\par }%
+% \end{macrocode}
+% Change catcodes of regexp special characters to make them active
+% characters and define them to expand to their escaped forms. Change
+% those of \TeX special characters to make them normal letters.
+% \begin{macrocode}
+ \catcode`.=13 \catcode`[=13 \catcode`]=13
+ \catcode`^=13 \catcode`$=13 %$
+ \catcode`\=0 \catcode`<=1 \catcode`>=2
+ \catcode`\\=13 \catcode`\{=12 \catcode`\}=12 \catcode`_=12
+ \lccode`/=92
+ \lccode`~=92\lowercase{\def~{\string/\string/}}%
+ \lccode`~=46\lowercase{\def~{\string/\string.}}%
+ \lccode`~=91\lowercase{\def~{\string/\string[}}%
+ \lccode`~=93\lowercase{\def~{\string/\string]}}%
+ \lccode`~=94\lowercase{\def~{\string/\string^}}%
+ \lccode`~=36\lowercase{\def~{\string/\string$}}% $
+ \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}.
+% \begin{macrocode}
+ \def\cref@text{}%
+ \immediate\read\@crefscript to \@tmpa%
+ \edef\@tmpa{\@tmpa}%
+ \ifx\@tmpa\@eof%
+ \@not@eoffalse%
+ \else%
+ \@not@eoftrue%
+ \fi%
+ \@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%
+ \@not@eoffalse%
+ \else%
+ \@not@eoftrue%
+ \fi}%
+ \endgroup%
+ \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
+% $\backslash$, \{ and \} characters. (This could be done in other
+% 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
+ \lowercase{\edef\@tmpa{s/||usepackage|(|[.*|]|)|?<cleveref>//g}}%
+ \expandafter\g@addto@macro\expandafter\cref@text\expandafter{%
+ \@tmpa^^J}
+ \lowercase{\edef\@tmpa{s/||[cC]refformat<.*><.*>//g}}%
+ \expandafter\g@addto@macro\expandafter\cref@text\expandafter{%
+ \@tmpa^^J}
+ \lowercase{\edef\@tmpa{s/||[cC]refrangeformat<.*><.*>//g}}%
+ \expandafter\g@addto@macro\expandafter\cref@text\expandafter{%
+ \@tmpa^^J}
+ \lowercase{\edef\@tmpa{s/||[cC]refmultiformat<.*><.*><.*><.*>//g}}%
+ \expandafter\g@addto@macro\expandafter\cref@text\expandafter{%
+ \@tmpa^^J}
+ \lowercase{\edef\@tmpa{%
+ s/||[cC]refrangemultiformat<.*><.*><.*><.*>//g}}%
+ \expandafter\g@addto@macro\expandafter\cref@text\expandafter{%
+ \@tmpa^^J}
+ \lowercase{\edef\@tmpa{s/||renewcommand<||[cC]ref><.*>//g}}%
+ \expandafter\g@addto@macro\expandafter\cref@text\expandafter{%
+ \@tmpa^^J}
+ \lowercase{\edef\@tmpa{s/||renewcommand<||[cC]refrange><.*>//g}}%
+ \expandafter\g@addto@macro\expandafter\cref@text\%
+ expandafter{\@tmpa}
+ \endgroup
+% \end{macrocode}
+% Overwrite the script file with the new, escaped regexp rules.
+% \begin{macrocode}
+ \newwrite\@crefscript%
+ \immediate\openout\@crefscript=\jobname.sed%
+ \immediate\write\@crefscript{\cref@text}%
+ \immediate\closeout\@crefscript%
+}%
+% \end{macrocode}
+%
+%
+% Redefine the user-level referencing commands so that they write a
+% substitution rule for the reference to the script, as well as
+% typesetting the reference itself.
+% \begin{macrocode}
+\renewcommand{\cref}[1]{%
+ \edef\cref@text{}%
+ \@cref{cref}{#1}%
+ \cref@writescript{\string\cref\string{#1\string}}}
+\renewcommand{\Cref}[1]{%
+ \edef\cref@text{}%
+ \@cref{Cref}{#1}%
+ \cref@writescript{\string\Cref\string{#1\string}}}
+\renewcommand{\crefrange}[2]{%
+ \edef\cref@text{}%
+ \@setcrefrange{#1}{#2}{cref}{}%
+ \cref@writescript{%
+ \string\crefrange\string{#1\string}\string{#2\string}}}
+\renewcommand{\Crefrange}[2]{%
+ \edef\cref@text{}%
+ \@setcrefrange{#1}{#2}{Cref}{}%
+ \cref@writescript{%
+ \string\Crefrange\string{#1\string}\string{#2\string}}}
+% \end{macrocode}
+%
+%
+% The \cmd{\cref@writescript} utility macro does the actual writing of
+% the substitution rule to the script.
+% \begin{macrocode}
+\def\cref@writescript#1{%
+ \edef\@tmpa{\cref@getmeaning{\cref@text}}%
+ \immediate\write\@crefscript{s/#1/\@tmpa/g}%
+}
+% \end{macrocode}
+%
+%
+% Redefine \cmd{\@@setcref}, \cmd{\@@setrangeref},
+% \cmd{\@setcref@middleconjunction} and
+% \cmd{\@setcref@lastconjunction} to append the text they typeset to
+% \cmd{\cref@text}, as well as actually typesetting it.
+% \begin{macrocode}
+\let\old@@setcref\@@setcref
+\let\old@@setcrefrange\@@setcrefrange
+\def\cref@getmeaning#1{\expandafter\@cref@getmeaning\meaning#1\@nil}
+\def\@cref@getmeaning#1->#2\@nil{#2}
+\def\@@setcref#1#2{%
+ \old@@setcref{#1}{#2}%
+ \expandafter\g@addto@macro\expandafter{%
+ \expandafter\cref@text\expandafter}\expandafter{%
+ #1{\ref{#2}}{}{}}}
+\def\@@setcrefrange#1#2#3{%
+ \old@@setcrefrange{#1}{#2}{#3}%
+ \expandafter\g@addto@macro
+ \expandafter{\expandafter\cref@text\expandafter}%
+ \expandafter{#1{\ref{#2}}{\ref{#3}}{}{}{}{}}}
+\def\@setcref@middleconjunction{%
+ \crefmiddleconjunction%
+ \expandafter\g@addto@macro
+ \expandafter{\expandafter\cref@text\expandafter}%
+ \expandafter{\crefmiddleconjunction}}
+\def\@setcref@lastconjunction{%
+ \creflastconjunction%
+ \expandafter\g@addto@macro
+ \expandafter{\expandafter\cref@text\expandafter}%
+ \expandafter{\creflastconjunction}}
+} % end of poorman option
+% \end{macrocode}
+%
+%
% Process options.
% \begin{macrocode}
\ProcessOptions\relax