summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/cleveref
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2007-11-22 19:02:13 +0000
committerKarl Berry <karl@freefriends.org>2007-11-22 19:02:13 +0000
commit10e7ca1dbb544a401baeed19a6d871fae0dd82c7 (patch)
tree99b394b0664ecfe1d769b5d23af156dd06e12868 /Master/texmf-dist/source/latex/cleveref
parent5f24b7cfebd86d4ec19ff264e850d9e14c193fed (diff)
cleveref update (21nov07)
git-svn-id: svn://tug.org/texlive/trunk@5556 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source/latex/cleveref')
-rw-r--r--Master/texmf-dist/source/latex/cleveref/cleveref.dtx1422
1 files changed, 792 insertions, 630 deletions
diff --git a/Master/texmf-dist/source/latex/cleveref/cleveref.dtx b/Master/texmf-dist/source/latex/cleveref/cleveref.dtx
index cbaec876b2e..62ceb705fff 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/30/10 v0.10 Automatic cross-reference formatting]
+%<package> [2007/21/11 v0.11 Automatic cross-reference formatting]
%
%<*driver>
\documentclass{ltxdoc}
@@ -60,7 +60,7 @@
%</driver>
% \fi
%
-% \CheckSum{3165}
+% \CheckSum{3381}
%% \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
@@ -100,12 +100,13 @@
% {Allow optional argument to \\label to override reference
% type. Removed hyperref and ntheorem options; support for these and
% amsmath is enabled automatically if those packages are loaded.}
+% \changes{v0.11}{2007/21/11}{Made referencing aware of appendices.}
%
%
% \GetFileInfo{cleveref.sty}
%
-% \def\fileversion{0.10}
-% \def\filedate{30/10/2007}
+% \def\fileversion{0.11}
+% \def\filedate{21/11/2007}
%
% \title{The \package{cleveref} package\thanks{This document
% corresponds to \textsf{cleveref}~\fileversion, dated
@@ -167,14 +168,14 @@
%
% The \package{cleveref} package allows you to define the format for
% references once-and-for-all in the preamble of your document. If you
-% later decide to change the typesetting of equation references, you
-% only have to change one preamble definition. If you later decide to
-% change a theorem into a lemma, you don't need to change any
-% references at all, because \package{cleveref} will automatically
-% typeset references to it using the appropriate formatting. This
-% makes it far easier to typeset references uniformly across your
-% whole document, as well as saving repetitively typing the same text
-% for each and every reference.
+% later decide to change the format of equation references, you only
+% have to change one preamble definition. If you xchange a theorem
+% into a lemma, you don't need to change any references at all,
+% because \package{cleveref} will automatically typeset references to
+% it using the appropriate formatting. This makes it far easier to
+% typeset references uniformly across your whole document, as well as
+% avoiding repetitively typing the same text for each and every
+% reference.
%
% There are a number of other packages with similar goals, most
% notably \package{varioref}, \package{fancyref}, \package{hyperref}'s
@@ -194,13 +195,13 @@
%
% The enhanced referencing feature provided by the \package{varioref}
% package decides how to format references when the label is
-% \emph{defined}, rather than when it is \emph{referenced}. Most of
-% the time, this isn't a problem. But it makes it impossible to format
-% references differently according the context in which they are
-% referenced, which can sometimes be very useful. For example, if you
-% want references at the beginning of a sentence formatted any other
-% way than by capitalising the first letter of the reference text, it
-% is impossible using \package{varioref}. Perhaps even more
+% \emph{defined}, rather than when it is \emph{referenced}. Often this
+% isn't a problem. But it makes it impossible to format references
+% differently according the context in which they are referenced,
+% which can sometimes be very useful. For example, if you want
+% references at the beginning of a sentence formatted any other way
+% than by capitalising the first letter of the reference text, it is
+% impossible using \package{varioref}. Perhaps even more
% significantly, it makes it impossible to typeset multiple references
% automatically; you are back typesetting
% |Eqs.~(\ref{eq1}) and~(\ref{eq2})| or
@@ -211,13 +212,13 @@
% The \package{hyperref} package's |\autoref| command typesets a name
% before a reference, determined by the reference type. This is less
% flexible than \package{cleveref}'s fully customisable reference
-% formatting, but when combined with \package{varioref}, the two
+% 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.
+% references collapsed automatically, etc.
%
% The \package{ntheorem} package (with the \option{thref} option) does
% things right\ldots except that it only works for theorem-like
@@ -226,9 +227,9 @@
% argument to |\label| commands that specifies the label
% type. \package{cleveref} works equally well when referencing any
% type of object, as well as fully supporting \package{ntheorem}. And
-% \package{cleveref} provides a number additional features, such as
-% multiple references, automatic collapsing of reference ranges,
-% control over the placement of hyper-links, etc.
+% again, \package{cleveref} provides a number additional features,
+% such as multiple references, automatic collapsing of reference
+% ranges, control over the placement of hyper-links, etc.
%
%
%
@@ -246,20 +247,22 @@
%
% If you just want to get going quickly with \package{cleveref}, and
% come back later to read up on all the features it provides in more
-% detail, then here's what you need to do. Wherever you would
-% previously have used |\ref|, use |\cref| instead. (Except that at
-% the beginning of a sentence, you should use |\Cref|.) You no longer
-% need to put the name of the thing you're referencing in front of the
-% |\cref| command, because \package{cleveref} will sort that out for
-% you: i.e.\ use |\cref{eq1}| instead of |Eq.~\ref{eq1}|. If you want
-% to refer to a range of labels, use |\crefrange|:
-% |\crefrange{eq1}{eq5}|. Finally, if you want to refer to multiple
+% detail, here's what you need to do. Wherever you would previously
+% have used |\ref|, use |\cref| instead. (Except at the beginning of a
+% sentence, where you should use |\Cref|.) You no longer need to put
+% the name of the thing you're referencing in front of the |\cref|
+% command, because \package{cleveref} will sort that out for you:
+% i.e.\ use |\cref{eq1}| instead of |eq.~(\ref{eq1})|. If you want to
+% refer to a range of labels, use |\crefrange|: |\crefrange{eq1}{eq5}|
+% gives |eqs.~(1)--(5)|. Finally, if you want to refer to multiple
% things at once, you can now combine them all into one reference and
% leave \package{cleveref} to sort it out: e.g.\
-% |\cref{eq1,eq2,eq4,thm2,def1}|.
+% |\cref{eq1,eq2,eq3,eq5,thm2,def1}| produces
+% |eqs.~(1)--(3) and~(5), theorem~5, and definition~1|.
%
%
% \section{Typesetting References}
+% \label{sec:typesetting}
% \DescribeMacro\cref
% To automatically typeset a cross-reference according to the type of
% object referred to, simply refer to it using
@@ -315,7 +318,7 @@
% \end{quote}
% will be typeset as
% \begin{quote}
-% eqs.~(1)--(3), and Theorems~1 and~2
+% eqs.~(1)--(3), and theorems~1 and~2
% \end{quote}
% whereas
% \begin{quote}
@@ -323,7 +326,7 @@
% \end{quote}
% will be typeset as
% \begin{quote}
-% eqs.~(1) and~(2), Theorems~1 and~2, and Eq.~(3)
+% eqs.~(1) and~(2), theorems~1 and~2, and eq.~(3)
% \end{quote}
% (assuming you haven't customised the reference formats).
%
@@ -365,10 +368,10 @@
% \label{sec:customising}
% The \package{cleveref} package allows you to take full control of
% the typesetting of references. Defaults appropriate for English
-% documents are provided for the standard reference types\footnote{For
-% any pedantic classics scholars out there: ``lemmas'' is recognised
-% as a valid plural form of ``lemma'' in all current versions of the
-% Oxford English Dictionary. ``Lemmata'' was last heard used in a
+% documents are provided for the standard label types\footnote{For any
+% pedantic classics scholars out there: ``lemmas'' is recognised as
+% a valid plural form of ``lemma'' in all current versions of the
+% Oxford English Dictionary. ``Lemmata'' was last heard in a
% mathematical debate that took place in a pub just around the
% corner from Hadrian's wall\dots a few years before the Romans
% pulled out of Britain. \package{cleveref} might have ``clever'' in
@@ -403,7 +406,8 @@
% \subsection{Global Customisation}
% \label{sec:global_customisation}
% \DescribeMacro\crefdefaultlabelformat
-% The label format can be customised globally using
+% The format for the label counter itself can be customised globally
+% using
% \begin{quote}
% |\crefdefaultlabelformat{|\meta{format}|}|
% \end{quote}
@@ -418,7 +422,7 @@
% \emph{must} appear in that order. (Leaving them out completely will
% not cause an error, but in that case no hyper-link will be created
% when \package{hyperref} is used, and there are better ways to
-% achieve this. See \cref{sec:other_packages}.)
+% achieve this. See \cref{sec:typesetting,sec:other_packages}.)
%
% \DescribeMacro\crefrangeconjunction
% The conjunction used in a reference range can be customised by
@@ -432,11 +436,11 @@
% and end references in a reference range, without any additional
% space surrounding it, e.g.\ |\crefrange{eq1}{eq2}| is typeset as
% \begin{quote}
-% |eqs.~\ref{eq1}\crefrangeconjunction\ref{eq2}|
+% |eqs.~(\ref{eq1})\crefrangeconjunction(\ref{eq2})|
% \end{quote}
-% (assuming the default equation name hasn't been customised). So you
-% may or may not want to include surrounding space, depending on the
-% formatting you desire. For example,
+% (assuming the default equation format hasn't been customised). So
+% you may or may not want to include surrounding space, depending on
+% the formatting you desire. For example,
% \begin{quote}
% |\renewcommand{\crefrangeconjunction}{ and~}|
% \end{quote}
@@ -477,10 +481,10 @@
% separate references of the same type\footnote{More accurately,
% redefining $\backslash$crefpairconjunction etc.\ automatically
% redefines $\backslash$crefpairgroupconjunction etc.\ so that they
-% match. If you don't redefine anything, the default definition of
-% $\backslash$creflastgroupconjunction has an additional comma
-% lacking in $\backslash$creflastconjunction.}. You can override
-% this by redefining |\crefpairgroupconjunction|,
+% match. If you \emph{don't} redefine anything, the default
+% definition of $\backslash$creflastgroupconjunction has an
+% additional comma lacking in $\backslash$creflastconjunction.}. You
+% can override this by redefining |\crefpairgroupconjunction|,
% |\crefmiddlegroupconjunction| and |\creflastgroupconjunction|.
%
% For example, if |eq*|, |thm*| and |fig*| are respectively equation,
@@ -492,12 +496,11 @@
% \begin{quote}
% eqs.~(1)|\crefrangeconjunction|(3)|\crefmiddlegroupconjunction|%\\
% theorems~1|\crefpairconjunction|2|\crefmiddlegroupconjunction|%\\
-% fig.~1|\creflastgroupconjunction|Theorem~3
+% fig.~1|\creflastgroupconjunction|theorem~3
% \end{quote}
%
%
% \subsection{Customising Individual Reference Types}
-% \DescribeMacro\creflabelformat
% \DescribeMacro\crefname
% \DescribeMacro\Crefname
% The reference name for a given reference type is customised using
@@ -524,14 +527,16 @@
%
% The reference \meta{type} is usually the name of the counter for the
% environment (equation, chapter, section, etc.). Currently, the only
-% exception is theorem-like environments when the \package{ntheorem}
-% package is loaded, for which \meta{type} should instead be the
-% environment name (lemma, corollary, definition,
-% etc.). \package{ntheorem} provides extra information about the
-% environment when different theorem-like environments use a common
-% counter, which \package{cleveref} makes use of to distinguish
-% between them automatically.
+% exceptions are appendices, for which \meta{type} should be
+% ``appendix'' (instead of chapter or section), and theorem-like
+% environments when the \package{ntheorem} package is loaded, for
+% which \meta{type} should instead be the environment name (lemma,
+% corollary, definition, etc.). \package{ntheorem} provides extra
+% information about the environment when different theorem-like
+% environments use a common counter, which \package{cleveref} makes
+% use of to distinguish between them automatically.
%
+% \DescribeMacro\creflabelformat
% You may want the label format for a particular reference type to
% differ from the global format set by |\crefdefaultlabelformat| (see
% \ref{sec:global_customisation}. You can do this using
@@ -558,11 +563,12 @@
% \end{quote}
% The \meta{format} argument should contain six arguments: |#1|, |#2|,
% |#3|, |#4|, |#5|, |#6|. The first two (|#1| and |#2|) are the
-% formatted versions of the start and end label counters. The next two
-% (|#3| and |#4|) denote the beginning and end of the hyper-link for
-% the first reference, the final two (|#5| and |#6|) the hyper-link
-% for the second reference. The hyper-link arguments must appear in
-% order. For example, the default format for equations is defined as:
+% formatted versions of the two label counters defining the reference
+% range. The next two (|#3| and |#4|) denote the beginning and end of
+% the hyper-link for the first reference, the final two (|#5| and
+% |#6|) the hyper-link for the second reference. The hyper-link
+% arguments must appear in order. For example, the default format for
+% equations is defined as:
% \begin{quote}
% |\crefrangelabelformat{equation}{(#3#1#4)--(#5#2#6)}|
% \end{quote}
@@ -576,7 +582,7 @@
% component-derived format entirely. The formats for single
% references, reference ranges and multi-references are customised
% separately. If you only customise some of these, the other formats
-% will be constructed from components as usual.
+% will still be constructed from components, as usual.
%
% \subsubsection{Single References}
% \label{sec:ref_format}
@@ -593,7 +599,8 @@
% \end{quote}
% The \meta{type} is usually the name of the counter, except for
% theorem-like environments when \package{ntheorem} is loaded, in
-% which case it is the environment name.
+% which case it is the environment name,and appendices, when it is
+% ``appendix''.
%
% As in the case of the |\crefname| and |\Crefname| commands, if the
% corresponding |\Crefformat| is undefined when |\crefformat| is
@@ -601,9 +608,10 @@
% version of |\crefformat|, using |\MakeUppercase|. Conversely, if the
% corresponding |\crefformat| is undefined whe |\Crefformat| is
% called, if will define the |\Crefformat| to produce a lower-case
-% version of |\Crefformat|, using |\MakeLowercase|. This will only
-% work if the format starts with a letter, and the same comments apply
-% as in the case of |\crefname| (see \cref{sec:global_customisation}).
+% version of |\Crefformat|, using |\MakeLowercase|. Obviosly, this
+% will only work properly if the format starts with a letter, and
+% letter constructs (such as accented letter constructs) must be
+% surrounded by braces (see \cref{sec:global_customisation}).
%
% The \meta{format} argument can be any valid \LaTeX{} code, though
% you will need to |\protect| fragile commands. It should contain
@@ -664,7 +672,7 @@
% and |#6|) mark the beginning and end of the second reference's
% hyper-link.
%
-% As an example,
+% As an example, the default
% \begin{quote}
% |\crefrangeformat{equation}{eqs.~(#3#1#4)--(#5#2#6)}|
% \end{quote}
@@ -762,19 +770,21 @@
% the label explicitly each time. An alternative is to use the
% \package{aliascnt} package. This lets you define one counter to be
% an alias for another, so that effectively the same counter has two
-% names. Since \package{cleveref} determines the reference type from
-% the counter name, the two counter aliases can have different
-% reference formats whilst really being the same counter. You have to
-% somehow arrange for the correct counter alias to be used depending
-% on which reference format you want (probably by defining two
-% variants of the environment in question). But the effort involved
-% might be worth the convenience of not having to remember to pass an
-% explicit optional argument to a large number of labels.
+% names. Since \package{cleveref} determines the label type from the
+% counter name, the two counter aliases can have different reference
+% formats whilst really being the same counter. You have to somehow
+% arrange for the correct counter alias to be used depending on which
+% reference format you want (probably by defining two variants of the
+% environment in question). But the effort involved might be worth the
+% convenience of not having to remember to pass an explicit optional
+% argument to a large number of labels.
%
% You can use this trick to get different reference formats for
% different theorem-like environments, \emph{without} using the
-% \package{ntheorem} package\footnote{Thanks to Anand Deopurkar for
-% suggesting this neat trick.}. For example,
+% \package{ntheorem} package\footnote{This trick seems to belong to
+% \LaTeX{} mythology, and certainly isn't my own idea! I haven't
+% been able to definitively track down who originally came up with
+% it.}. For example,
% \begin{quote}
% |\usepackage{aliascnt}|\\
% |\usepackage{cleveref}|\\
@@ -789,31 +799,31 @@
% \section{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.
+% example, many academic journals accept papers in \LaTeX{} format,
+% but only support a small 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!
+% cross-references 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 completely remove the \package{cleveref}
+% the {\tt sed} script to completely remove the \package{cleveref}
% dependency. The recipient won't even realise you used
% \package{cleveref}!
%
-% The {\tt sed} 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:
+% The {\tt sed} script is written to the same directory as the (main)
+% \LaTeX{} source file, and given the same name as that 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} \textgreater \meta{newname}\file{.tex}
@@ -827,6 +837,11 @@
% 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.)
+% If your document is composed of a number of separate \LaTeX{} source
+% files, combined with |\include| commands, only one {\tt sed} script
+% will be generated, but you will need to run \emph {each} source file
+% through that \emph{same} script (and probably modify the |\include|
+% commands to match the new file names).
%
%
%
@@ -894,12 +909,13 @@
% \item The \option{poorman} sed script uses |\ref| when replacing
% \package{cleveref} cross-references, but this loses any custom
% \package{cleveref} hyper-link formatting you might have
-% defined. The philosophy behind the \option{poorman} option
-% is to replace \package{cleveref}'s enhanced cross-referencing with
+% defined. The philosophy behind the \option{poorman} option is to
+% replace \package{cleveref}'s enhanced cross-referencing with
% standard \LaTeX{} cross-reference commands that are guaranteed to
-% work with any \LaTeX{} installation. Although it would be simple
-% to fix this bug, it's not obvious how best to do it without
-% compromising on the underlying philosophy.
+% work with any standard \LaTeX{} installation. Although it would be
+% simple to fix this ``bug'', it's not obvious how to do it without
+% compromising this underlying philosophy, i.e.\ without using
+% \LaTeX{} code that is unlikely to be supported by journals.
% \end{itemize}
%
%
@@ -912,7 +928,7 @@
% \item Add an option to automatically sort references in a
% multi-reference before typesetting them.
% \item Enhance the \option{poorman} option to allow a choice of
-% script language rather than just sed. (E.g.\ awk, perl, \dots?).
+% script language rather than just sed (e.g.\ awk, perl, \dots?).
% \end{itemize}
%
%
@@ -946,24 +962,24 @@
%
% \subsection{Redefinitions of \LaTeX{} kernel macros}
% We store the original \cmd{\refstepcounter} in
-% \cmd{\old@refstepcounter}, then redefine \cmd{\refstepcounter} so
+% \cmd{\cref@old@refstepcounter}, then redefine \cmd{\refstepcounter} so
% that it first calls the old version and then adds the extra
% information to \cmd{\@currentlabel}. The new \cmd{\@refstepcounter}
% can take an optional argument, which overrides using the counter
% name as the ``type'' and instead uses whatever is supplied.
% \begin{macrocode}
-\let\old@refstepcounter\refstepcounter
+\let\cref@old@refstepcounter\refstepcounter
\def\refstepcounter%
{\@ifnextchar[{\refstepcounter@optarg}{\refstepcounter@noarg}}%]
\def\refstepcounter@noarg#1{%
- \old@refstepcounter{#1}%
+ \cref@old@refstepcounter{#1}%
\reset@by{#1}{\@result}%
\ifx\@result\relax\def\@result{}%
\else\edef\@result{\csname the\@result\endcsname}\fi%
\protected@edef\@currentlabel{%
[#1][\arabic{#1}][\@result]\@currentlabel}}
\def\refstepcounter@optarg[#1]#2{%
- \old@refstepcounter{#2}%
+ \cref@old@refstepcounter{#2}%
\reset@by{#2}{\@result}%
\ifx\@result\relax\def\@result{}%
\else\edef\@result{\csname the\@result\endcsname}\fi%
@@ -973,18 +989,18 @@
%
% We redefine the \cmd{\label} command to allow it to take an optional
% argument that overrides the default reference type in
-% \cmd{\@currentlabel}. We have to postpone this redefinition till the
-% beginning of the document because other packages do, and we need to
-% override their redefinitions.
+% \cmd{\@currentlabel}. We have to postpone this redefinition of
+% \cmd{\label} until the beginning of the document because some other
+% packages do too, and we need to override their redefinitions.
% \begin{macrocode}
+\def\cref@override@label@type[#1][#2][#3]#4\@nil#5{[#5][#2][#3]#4}
\AtBeginDocument{%
- \let\old@label\label
- \def\label{\@ifnextchar[\label@optarg\old@label}%]
- \def\override@label@type[#1][#2][#3]#4\@nil#5{[#5][#2][#3]#4}
+ \let\cref@old@label\label
+ \def\label{\@ifnextchar[\label@optarg\cref@old@label}%]
\def\label@optarg[#1]{%
\protected@edef\@currentlabel{%
- \expandafter\override@label@type\@currentlabel\@nil{#1}}%
- \old@label}%
+ \expandafter\cref@override@label@type\@currentlabel\@nil{#1}}%
+ \cref@old@label}%
% \end{macrocode}
%
% The \package{amsmath} package redefines the \cmd{\label} command
@@ -1001,17 +1017,18 @@
% the new \cmd{\label} macro we defined above (since \cmd{\label} will
% be clobbered inside equations). Then we redefine
% \cmd{label@in@display} so that it wraps all its arguments, including
-% any optional argument, in an extra set of \{\}. These are stripped
-% away again by \cmd{\ltx@label} before calling the \cmd{\label} macro
-% we defined above (save in \cmd{\cref@label}.
+% any optional argument, in an extra set of braces \{\}. These are
+% stripped away again by \cmd{\ltx@label} before calling the
+% \cmd{\label} macro we defined above (saved in \cmd{\cref@label}).
% \begin{macrocode}
\@ifpackageloaded{amsmath}{%
\let\cref@label\label%
- \let\old@label@in@display\label@in@display%
+ \let\cref@old@label@in@display\label@in@display%
\def\label@in@display{%
\@ifnextchar[\label@in@display@optarg\label@in@display@noarg}%]
- \def\label@in@display@noarg#1{\old@label@in@display{{#1}}}
- \def\label@in@display@optarg[#1]#2{\old@label@in@display{[#1]{#2}}}
+ \def\label@in@display@noarg#1{\cref@old@label@in@display{{#1}}}
+ \def\label@in@display@optarg[#1]#2{%
+ \cref@old@label@in@display{[#1]{#2}}}
\def\ltx@label#1{\cref@label#1}%
}{}%
}
@@ -1040,6 +1057,53 @@
}
% \end{macrocode}
%
+% The \cmd{\appendix} command causes the top-level sectioning commands
+% (\cmd{\chapter} or \cmd{\section}, depending on the document class)
+% to produce appendices instead. Since we want to be able to format
+% references to appendices separately from references to normal
+% top-level sections, we add to the tasks that \cmd{\appendix} does:
+% it redefines \cmd{\refstepcounter@noarg} to exceptionally override
+% the label type for chapters or sections, as appropriate, setting it
+% to ``appendix'' instead.
+% \begin{macrocode}
+\let\cref@old@appendix\appendix
+\renewcommand\appendix{%
+ \cref@old@appendix%
+ \@ifundefined{chapter}{%
+ \def\refstepcounter@noarg##1{%
+ \cref@old@refstepcounter{##1}%
+ \reset@by{##1}{\@result}%
+ \ifx\@result\relax\def\@result{}%
+ \else\edef\@result{\csname the\@result\endcsname}\fi%
+ \def\@tmpa{##1}
+ \def\@tmpb{section}%
+ \ifx\@tmpa\@tmpb%
+ \protected@edef\@currentlabel{%
+ [appendix][\arabic{##1}][\@result]\@currentlabel}%
+ \else
+ \protected@edef\@currentlabel{%
+ [##1][\arabic{##1}][\@result]\@currentlabel}
+ \fi}
+ }{%
+ \def\refstepcounter@noarg##1{%
+ \cref@old@refstepcounter{##1}%
+ \reset@by{##1}{\@result}%
+ \ifx\@result\relax\def\@result{}%
+ \else\edef\@result{\csname the\@result\endcsname}\fi%
+ \def\@tmpa{##1}
+ \def\@tmpb{chapter}%
+ \ifx\@tmpa\@tmpb%
+ \protected@edef\@currentlabel{%
+ [appendix][\arabic{##1}][\@result]\@currentlabel}%
+ \else
+ \protected@edef\@currentlabel{%
+ [##1][\arabic{##1}][\@result]\@currentlabel}
+ \fi}
+ }%
+}
+% \end{macrocode}
+%
+%
% \subsection{Utility Macros}
% Define some utility macros for extracting label, type, and counter
% information from the contents of \cmd{\@currentlabel}, as written to
@@ -1057,30 +1121,30 @@
% \cmd{\csname}\ldots\cmd{\endcsname}.
% \begin{macrocode}
\def\cref@getlabel#1#2{%
- \expandafter\let\expandafter\@tempa\csname r@#1\endcsname%
- \edef\@tempa{\expandafter\@firstoftwo\@tempa}%
- \expandafter\@cref@getlabel\@tempa\@nil#2}
+ \expandafter\let\expandafter\@tmpa\csname r@#1\endcsname%
+ \edef\@tmpa{\expandafter\@firstoftwo\@tmpa}%
+ \expandafter\@cref@getlabel\@tmpa\@nil#2}
\def\@cref@getlabel{\@ifnextchar[%]
\@@cref@getlabel{\@@cref@getlabel[][][]}}
\def\@@cref@getlabel[#1][#2][#3]#4\@nil#5{\def#5{#4}}
\def\cref@gettype#1#2{%
- \expandafter\let\expandafter\@tempa\csname r@#1\endcsname%
- \edef\@tempa{\expandafter\@firstoftwo\@tempa}%
- \expandafter\@cref@gettype\@tempa\@nil#2}
+ \expandafter\let\expandafter\@tmpa\csname r@#1\endcsname%
+ \edef\@tmpa{\expandafter\@firstoftwo\@tmpa}%
+ \expandafter\@cref@gettype\@tmpa\@nil#2}
\def\@cref@gettype{\@ifnextchar[%]
\@@cref@gettype{\@@cref@gettype[][][]}}
\def\@@cref@gettype[#1][#2][#3]#4\@nil#5{\def#5{#1}}
\def\cref@getcounter#1#2{%
- \expandafter\let\expandafter\@tempa\csname r@#1\endcsname%
- \edef\@tempa{\expandafter\@firstoftwo\@tempa}%
- \expandafter\@cref@getcounter\@tempa\@nil#2}
+ \expandafter\let\expandafter\@tmpa\csname r@#1\endcsname%
+ \edef\@tmpa{\expandafter\@firstoftwo\@tmpa}%
+ \expandafter\@cref@getcounter\@tmpa\@nil#2}
\def\@cref@getcounter{\@ifnextchar[%]
\@@cref@getcounter{\@@cref@getcounter[][][]}}
\def\@@cref@getcounter[#1][#2][#3]#4\@nil#5{\def#5{#2}}
\def\cref@getprefix#1#2{%
- \expandafter\let\expandafter\@tempa\csname r@#1\endcsname%
- \edef\@tempa{\expandafter\@firstoftwo\@tempa}%
- \expandafter\@cref@getprefix\@tempa\@nil#2}
+ \expandafter\let\expandafter\@tmpa\csname r@#1\endcsname%
+ \edef\@tmpa{\expandafter\@firstoftwo\@tmpa}%
+ \expandafter\@cref@getprefix\@tmpa\@nil#2}
\def\@cref@getprefix{\@ifnextchar[%]
\@@cref@getprefix{\@@cref@getprefix[][][]}}
\def\@@cref@getprefix[#1][#2][#3]#4\@nil#5{\def#5{#3}}
@@ -1088,7 +1152,7 @@
%
% A basic utility macro for appending tokens to a token register.
% \begin{macrocode}
-\def\append@toks#1#2{\toks0={#2}%
+\def\cref@append@toks#1#2{\toks0={#2}%
\edef\act{\noexpand#1={\the#1\the\toks0}}%
\act}%
% \end{macrocode}
@@ -1098,25 +1162,26 @@
% utility macros for manipulating stacks (\cmd{\@nil} is used as an
% end-of-stack delimeter).
% \begin{macrocode}
-\def\stack@init#1{\def#1{\@nil}}
-\def\stack@top#1{\expandafter\stack@top@aux#1}
-\def\stack@top@aux#1,#2\@nil{#1}
-\def\stack@pop#1{\expandafter\stack@pop@aux#1#1}
-\def\stack@pop@aux#1,#2\@nil#3{\def#3{#2\@nil}}
-\def\stack@push#1#2{\expandafter\stack@push@aux\expandafter{#2}{#1}{#2}}
-\def\stack@push@aux#1#2#3{\def#3{#2,#1}}
-\def\stack@pull#1#2{\expandafter\stack@pull@aux#2{#1}{#2}}
-\def\stack@pull@aux#1\@nil#2#3{\def#3{#1#2,\@nil}}
-\newif\ifstackempty
-\newif\ifstackfull
-\def\isstackempty#1{%
+\def\cref@stack@init#1{\def#1{\@nil}}
+\def\cref@stack@top#1{\expandafter\cref@stack@top@aux#1}
+\def\cref@stack@top@aux#1,#2\@nil{#1}
+\def\cref@stack@pop#1{\expandafter\cref@stack@pop@aux#1#1}
+\def\cref@stack@pop@aux#1,#2\@nil#3{\def#3{#2\@nil}}
+\def\cref@stack@push#1#2{%
+ \expandafter\cref@stack@push@aux\expandafter{#2}{#1}{#2}}
+\def\cref@stack@push@aux#1#2#3{\def#3{#2,#1}}
+\def\cref@stack@pull#1#2{\expandafter\cref@stack@pull@aux#2{#1}{#2}}
+\def\cref@stack@pull@aux#1\@nil#2#3{\def#3{#1#2,\@nil}}
+\newif\if@cref@stackempty
+\newif\if@cref@stackfull
+\def\cref@isstackempty#1{%
\def\@tmpa{\@nil}%
- \ifx#1\@tmpa\stackemptytrue%
- \else\stackemptyfalse\fi}
-\def\isstackfull#1{%
+ \ifx#1\@tmpa\@cref@stackemptytrue%
+ \else\@cref@stackemptyfalse\fi}
+\def\cref@isstackfull#1{%
\def\@tmpa{\@nil}%
- \ifx#1\@tmpa\stackfullfalse%
- \else\stackfulltrue\fi}
+ \ifx#1\@tmpa\@cref@stackfullfalse%
+ \else\@cref@stackfulltrue\fi}
% \end{macrocode}
%
% We need to be able to determine which counter is used to reset a
@@ -1130,56 +1195,56 @@
% (part), checking whether the given counter is in the list, and
% returns the first sectioning counter whose list it appears in.
% \begin{macrocode}
-\newif\ifinresetlist
-\def\isinresetlist#1#2{%
+\newif\if@cref@inresetlist
+\def\cref@isinresetlist#1#2{%
\def\@counter{#1}%
\begingroup%
\def\@elt##1{##1,}%
\expandafter\ifx\csname cl@#2\endcsname\relax%
- \gdef\@resetstack{,\@nil}%
+ \gdef\cref@resetstack{,\@nil}%
\else%
- \xdef\@resetstack{\csname cl@#2\endcsname\noexpand\@nil}%
+ \xdef\cref@resetstack{\csname cl@#2\endcsname\noexpand\@nil}%
\fi%
\endgroup%
- \isstackfull{\@resetstack}%
- \@whilesw\ifstackfull\fi{%
- \edef\@nextcounter{\stack@top{\@resetstack}}%
+ \cref@isstackfull{\cref@resetstack}%
+ \@whilesw\if@cref@stackfull\fi{%
+ \edef\@nextcounter{\cref@stack@top{\cref@resetstack}}%
\ifx\@nextcounter\@counter%
- \stackfullfalse%
+ \@cref@stackfullfalse%
\else%
\let\@nextcounter\relax%
- \stack@pop{\@resetstack}%
- \isstackfull{\@resetstack}%
+ \cref@stack@pop{\cref@resetstack}%
+ \cref@isstackfull{\cref@resetstack}%
\fi}%
\ifx\@nextcounter\relax%
- \inresetlistfalse%
+ \@cref@inresetlistfalse%
\else%
- \inresetlisttrue%
+ \@cref@inresetlisttrue%
\fi}
%
-\def\reset@by#1#2{%
- \isinresetlist{#1}{subsubsubsection}%
- \ifinresetlist%
+\def\cref@resetby#1#2{%
+ \cref@isinresetlist{#1}{subsubsubsection}%
+ \if@cref@inresetlist%
\def#2{subsubsubsection}%
\else%
- \isinresetlist{#1}{subsubsection}%
- \ifinresetlist%
+ \cref@isinresetlist{#1}{subsubsection}%
+ \if@cref@inresetlist%
\def#2{subsubsection}%
\else%
- \isinresetlist{#1}{subsection}%
- \ifinresetlist%
+ \cref@isinresetlist{#1}{subsection}%
+ \if@cref@inresetlist%
\def#2{subsection}%
\else%
- \isinresetlist{#1}{section}%
- \ifinresetlist%
+ \cref@isinresetlist{#1}{section}%
+ \if@cref@inresetlist%
\def#2{section}%
\else%
- \isinresetlist{#1}{chapter}%
- \ifinresetlist%
+ \cref@isinresetlist{#1}{chapter}%
+ \if@cref@inresetlist%
\def#2{chapter}%
\else%
- \isinresetlist{#1}{part}%
- \ifinresetlist%
+ \cref@isinresetlist{#1}{part}%
+ \if@cref@inresetlist%
\def#2{part}%
\else%
\let#2\relax%
@@ -1220,17 +1285,17 @@
\newif\if@firstgroup%
\newif\if@secondgroup%
\newif\if@secondref%
- \stack@init{\@refstack}%
- \stack@push{#2}{\@refstack}%
+ \cref@stack@init{\@refstack}%
+ \cref@stack@push{#2}{\@refstack}%
\@firstgrouptrue%
\@secondgroupfalse%
- \isstackfull{\@refstack}%
+ \cref@isstackfull{\@refstack}%
% \end{macrocode}
% Loop until the reference stack is empty.
% \begin{macrocode}
- \@whilesw\ifstackfull\fi{%
- \stack@init{\@refsubstack}%
- \edef\@nextref{\stack@top{\@refstack}}%
+ \@whilesw\if@cref@stackfull\fi{%
+ \cref@stack@init{\@refsubstack}%
+ \edef\@nextref{\cref@stack@top{\@refstack}}%
\expandafter\ifx\csname r@\@nextref\endcsname\relax%
\def\@currenttype{\@undefined}%
\else%
@@ -1243,13 +1308,14 @@
% has a different type to those that came before.
% \begin{macrocode}
\@whilesw\ifx\@nexttype\@currenttype\fi{%
- \expandafter\stack@pull\expandafter{\@nextref}{\@refsubstack}%
- \stack@pop{\@refstack}%
- \isstackempty{\@refstack}%
- \ifstackempty%
+ \expandafter\cref@stack@pull\expandafter%
+ {\@nextref}{\@refsubstack}%
+ \cref@stack@pop{\@refstack}%
+ \cref@isstackempty{\@refstack}%
+ \if@cref@stackempty%
\def\@nexttype{\relax}%
\else%
- \edef\@nextref{\stack@top{\@refstack}}%
+ \edef\@nextref{\cref@stack@top{\@refstack}}%
\ifx\@nextref\@empty%
\let\@currenttype\@nexttype%
\else%
@@ -1269,8 +1335,8 @@
\@firstgroupfalse%
\@secondgrouptrue%
\else%
- \isstackfull{\@refstack}%
- \ifstackfull%
+ \cref@isstackfull{\@refstack}%
+ \if@cref@stackfull%
\@setcref@middlegroupconjunction%
\else%
\if@secondgroup%
@@ -1285,13 +1351,13 @@
%
% Process first group of consecutive references from substack.
% \begin{macrocode}
- \edef\@nextref{\stack@top{\@refsubstack}}%
- \stack@pop{\@refsubstack}%
+ \edef\@nextref{\cref@stack@top{\@refsubstack}}%
+ \cref@stack@pop{\@refsubstack}%
% \end{macrocode}
% If the substack only contains one reference, typeset it,
% \begin{macrocode}
- \isstackempty{\@refsubstack}%
- \ifstackempty%
+ \cref@isstackempty{\@refsubstack}%
+ \if@cref@stackempty%
\expandafter\@setcref\expandafter{\@nextref}{#1}{}%
% \end{macrocode}
% otherwise, find end of consecutive references.
@@ -1299,10 +1365,10 @@
\else%
\edef\@beginref{\@nextref}%
\let\@endref\relax%
- \edef\@nextref{\stack@top{\@refsubstack}}%
+ \edef\@nextref{\cref@stack@top{\@refsubstack}}%
\count@consecutive=1%
\expandafter\ifx\csname r@\@beginref\endcsname\relax%
- \refconsecutivefalse%
+ \@cref@refconsecutivefalse%
\else%
% \end{macrocode}
% If next reference in substack is empty, it indicates that no
@@ -1311,14 +1377,14 @@
% references are removed from the substack.
% \begin{macrocode}
\ifx\@nextref\@empty%
- \refconsecutivefalse%
+ \@cref@refconsecutivefalse%
\@whilesw\ifx\@nextref\@empty\fi{%
- \stack@pop{\@refsubstack}%
- \isstackempty{\@refsubstack}%
- \ifstackempty%
+ \cref@stack@pop{\@refsubstack}%
+ \cref@isstackempty{\@refsubstack}%
+ \if@cref@stackempty%
\let\@nextref\relax%
\else%
- \edef\@nextref{\stack@top{\@refsubstack}}%
+ \edef\@nextref{\cref@stack@top{\@refsubstack}}%
\fi%
}%
\ifnum\count@consecutive=2%
@@ -1329,34 +1395,34 @@
% \begin{macrocode}
\else%
\expandafter\ifx\csname r@\@nextref\endcsname\relax%
- \refconsecutivefalse%
+ \@cref@refconsecutivefalse%
\else%
\edef\@tmpa{{\@beginref}{\@nextref}}%
- \expandafter\isrefconsecutive\@tmpa%
+ \expandafter\cref@isrefconsecutive\@tmpa%
\fi%
\fi%
\fi%
- \@whilesw\ifrefconsecutive\fi{%
+ \@whilesw\if@cref@refconsecutive\fi{%
\advance\count@consecutive 1%
\let\@endref\@nextref%
- \stack@pop{\@refsubstack}%
- \isstackempty{\@refsubstack}%
- \ifstackempty%
- \refconsecutivefalse%
+ \cref@stack@pop{\@refsubstack}%
+ \cref@isstackempty{\@refsubstack}%
+ \if@cref@stackempty%
+ \@cref@refconsecutivefalse%
\else%
- \edef\@nextref{\stack@top{\@refsubstack}}%
+ \edef\@nextref{\cref@stack@top{\@refsubstack}}%
% \end{macrocode}
% Test whether next reference is empty;
% \begin{macrocode}
\ifx\@nextref\@empty%
- \refconsecutivefalse%
+ \@cref@refconsecutivefalse%
\@whilesw\ifx\@nextref\@empty\fi{%
- \stack@pop{\@refsubstack}%
- \isstackempty{\@refsubstack}%
- \ifstackempty%
+ \cref@stack@pop{\@refsubstack}%
+ \cref@isstackempty{\@refsubstack}%
+ \if@cref@stackempty%
\let\@nextref\relax%
\else%
- \edef\@nextref{\stack@top{\@refsubstack}}%
+ \edef\@nextref{\cref@stack@top{\@refsubstack}}%
\fi%
}%
\ifnum\count@consecutive=2%
@@ -1367,10 +1433,10 @@
% \begin{macrocode}
\else%
\expandafter\ifx\csname r@\@nextref\endcsname\relax%
- \refconsecutivefalse%
+ \@cref@refconsecutivefalse%
\else%
\edef\@tmpa{{\@endref}{\@nextref}}%
- \expandafter\isrefconsecutive\@tmpa%
+ \expandafter\cref@isrefconsecutive\@tmpa%
\fi%
\fi%
\fi}%
@@ -1387,13 +1453,14 @@
\else%
\ifnum\count@consecutive=2%
\expandafter\@setcref\expandafter{\@beginref}{#1}{@first}%
- \expandafter\stack@push\expandafter{\@endref}{\@refsubstack}%
+ \expandafter\cref@stack@push\expandafter%
+ {\@endref}{\@refsubstack}%
% \end{macrocode}
% otherwise, typeset a reference range.
% \begin{macrocode}
\else%
\edef\@tmpa{{\@beginref}{\@endref}}%
- \ifstackempty%
+ \if@cref@stackempty%
\expandafter\@setcrefrange\@tmpa{#1}{}%
\else%
\expandafter\@setcrefrange\@tmpa{#1}{@first}%
@@ -1406,16 +1473,16 @@
% is empty.
% \begin{macrocode}
\@secondreftrue%
- \isstackfull{\@refsubstack}%
- \@whilesw\ifstackfull\fi{%
- \edef\@beginref{\stack@top{\@refsubstack}}%
- \stack@pop{\@refsubstack}%
+ \cref@isstackfull{\@refsubstack}%
+ \@whilesw\if@cref@stackfull\fi{%
+ \edef\@beginref{\cref@stack@top{\@refsubstack}}%
+ \cref@stack@pop{\@refsubstack}%
\let\@endref\relax%
% \end{macrocode}
% If substack only contains only one reference, typeset it,
% \begin{macrocode}
- \isstackempty{\@refsubstack}%
- \ifstackempty%
+ \cref@isstackempty{\@refsubstack}%
+ \if@cref@stackempty%
\if@secondref%
\expandafter\@setcref\expandafter{\@beginref}{#1}{@second}%
\else%
@@ -1425,20 +1492,20 @@
% otherwise, find end of consecutive references.
% \begin{macrocode}
\else%
- \edef\@nextref{\stack@top{\@refsubstack}}%
+ \edef\@nextref{\cref@stack@top{\@refsubstack}}%
\count@consecutive=1%
% \end{macrocode}
% Test whether next reference is empty;
% \begin{macrocode}
\ifx\@nextref\@empty%
- \refconsecutivefalse%
+ \@cref@refconsecutivefalse%
\@whilesw\ifx\@nextref\@empty\fi{%
- \stack@pop{\@refsubstack}%
- \isstackempty{\@refsubstack}%
- \ifstackempty%
+ \cref@stack@pop{\@refsubstack}%
+ \cref@isstackempty{\@refsubstack}%
+ \if@cref@stackempty%
\let\@nextref\relax%
\else%
- \edef\@nextref{\stack@top{\@refsubstack}}%
+ \edef\@nextref{\cref@stack@top{\@refsubstack}}%
\fi%
}%
\ifnum\count@consecutive=2%
@@ -1449,33 +1516,33 @@
% \begin{macrocode}
\else%
\expandafter\ifx\csname r@\@nextref\endcsname\relax%
- \refconsecutivefalse%
+ \@cref@refconsecutivefalse%
\else%
\edef\@tmpa{{\@beginref}{\@nextref}}%
- \expandafter\isrefconsecutive\@tmpa%
+ \expandafter\cref@isrefconsecutive\@tmpa%
\fi%
\fi%
- \@whilesw\ifrefconsecutive\fi{%
+ \@whilesw\if@cref@refconsecutive\fi{%
\advance\count@consecutive 1%
\let\@endref\@nextref%
- \stack@pop{\@refsubstack}%
- \isstackempty{\@refsubstack}%
- \ifstackempty%
- \refconsecutivefalse%
+ \cref@stack@pop{\@refsubstack}%
+ \cref@isstackempty{\@refsubstack}%
+ \if@cref@stackempty%
+ \@cref@refconsecutivefalse%
\else%
- \edef\@nextref{\stack@top{\@refsubstack}}%
+ \edef\@nextref{\cref@stack@top{\@refsubstack}}%
% \end{macrocode}
% Test whether next reference is empty;
% \begin{macrocode}
\ifx\@nextref\@empty%
- \refconsecutivefalse%
+ \@cref@refconsecutivefalse%
\@whilesw\ifx\@nextref\@empty\fi{%
- \stack@pop{\@refsubstack}%
- \isstackempty{\@refsubstack}%
- \ifstackempty%
+ \cref@stack@pop{\@refsubstack}%
+ \cref@isstackempty{\@refsubstack}%
+ \if@cref@stackempty%
\let\@nextref\relax%
\else%
- \edef\@nextref{\stack@top{\@refsubstack}}%
+ \edef\@nextref{\cref@stack@top{\@refsubstack}}%
\fi%
}%
\ifnum\count@consecutive=2%
@@ -1486,10 +1553,10 @@
% \begin{macrocode}
\else%
\expandafter\ifx\csname r@\@nextref\endcsname\relax%
- \refconsecutivefalse%
+ \@cref@refconsecutivefalse%
\else%
\edef\@tmpa{{\@endref}{\@nextref}}%
- \expandafter\isrefconsecutive\@tmpa%
+ \expandafter\cref@isrefconsecutive\@tmpa%
\fi%
\fi%
\fi}%
@@ -1498,8 +1565,8 @@
% ``end'' reference, otherwise we will need to typeset a
% ``middle'' reference.
% \begin{macrocode}
- \isstackempty{\@refsubstack}%
- \ifstackempty%
+ \cref@isstackempty{\@refsubstack}%
+ \if@cref@stackempty%
\if@secondref%
\def\@pos{@second}%
\else%
@@ -1523,7 +1590,7 @@
\ifnum\count@consecutive=2%
\expandafter\@setcref\expandafter%
{\@beginref}{#1}{@middle}%
- \expandafter\stack@push\expandafter%
+ \expandafter\cref@stack@push\expandafter%
{\@endref}{\@refsubstack}%
% \end{macrocode}
% otherwise, typeset a reference range.
@@ -1535,10 +1602,10 @@
\fi%
\fi%
\@secondreffalse%
- \isstackfull{\@refsubstack}%
+ \cref@isstackfull{\@refsubstack}%
}% end loop over reference substack
\fi%
- \isstackfull{\@refstack}%
+ \cref@isstackfull{\@refstack}%
}% end loop over main reference stack
\endgroup}
% \end{macrocode}
@@ -1583,8 +1650,8 @@
% identical (i.e. the references come from the same chapter, section
% or whatever), and that the label counters differ by 1.
% \begin{macrocode}
-\newif\ifrefconsecutive%
-\def\isrefconsecutive#1#2{%
+\newif\if@cref@refconsecutive%
+\def\cref@isrefconsecutive#1#2{%
\begingroup%
\countdef\refa@counter=1%
\countdef\refb@counter=2%
@@ -1595,10 +1662,10 @@
\refb@counter=\@result%
\cref@getprefix{#1}{\refa@prefix}%
\cref@getprefix{#2}{\refb@prefix}%
- \def\@after{\refconsecutivefalse}%
+ \def\@after{\@cref@refconsecutivefalse}%
\ifx\refa@prefix\refb@prefix%
\ifnum\refa@counter=\refb@counter%
- \def\@after{\refconsecutivetrue}%
+ \def\@after{\@cref@refconsecutivetrue}%
\fi%
\fi%
\expandafter\endgroup\@after}
@@ -1614,45 +1681,48 @@
% these various errors.
% \begin{macrocode}
\def\@setcrefrange#1#2#3#4{%
+ \begingroup%
% \end{macrocode}
% Check if both references are defined.
% \begin{macrocode}
- \expandafter\ifx\csname r@#1\endcsname\relax%
- \protect\G@refundefinedtrue%
- \@latex@warning{Reference `#1' on page \thepage \space undefined}%
- \expandafter\ifx\csname r@#2\endcsname\relax%
- \nfss@text{\reset@font\bfseries ??}--%
- \nfss@text{\reset@font\bfseries ??}%
- \@latex@warning{Reference `#2' on page \thepage \space undefined}%
- \else%
- \cref@getlabel{#2}{\@labelb}%
- \nfss@text{\reset@font\bfseries ??}--\@labelb%
- \fi%
- \else%
- \expandafter\ifx\csname r@#2\endcsname\relax%
+ \expandafter\ifx\csname r@#1\endcsname\relax%
\protect\G@refundefinedtrue%
- \cref@getlabel{#1}{\@labela}%
- \@labela--\nfss@text{\reset@font\bfseries ??}%
- \@latex@warning{Reference `#2' on page \thepage \space undefined}%
+ \@latex@warning{Reference `#1' on page \thepage \space%
+ undefined}%
+ \expandafter\ifx\csname r@#2\endcsname\relax%
+ \nfss@text{\reset@font\bfseries ??}--%
+ \nfss@text{\reset@font\bfseries ??}%
+ \@latex@warning{Reference `#2' on page \thepage \space%
+ undefined}%
+ \else%
+ \cref@getlabel{#2}{\@labelb}%
+ \nfss@text{\reset@font\bfseries ??}--\@labelb%
+ \fi%
+ \else%
+ \expandafter\ifx\csname r@#2\endcsname\relax%
+ \protect\G@refundefinedtrue%
+ \cref@getlabel{#1}{\@labela}%
+ \@labela--\nfss@text{\reset@font\bfseries ??}%
+ \@latex@warning{Reference `#2' on page \thepage \space undefined}%
% \end{macrocode}
% If both references are defined, check that the reference format is
% defined.
% \begin{macrocode}
- \else%
- \cref@gettype{#1}{\@typea}%
- \cref@gettype{#2}{\@typeb}%
- \cref@getlabel{#1}{\@labela}%
- \cref@getlabel{#2}{\@labelb}%
- \edef\@formata{\expandafter\noexpand%
- \csname #3range@\@typea @format#4\endcsname}%
- \edef\@formatb{\expandafter\noexpand%
- \csname #3range@\@typeb @format#4\endcsname}%
- \expandafter\ifx\@formata\relax%
- \protect\G@refundefinedtrue%
- \nfss@text{\reset@font\bfseries ??}~\@labela--\@labelb%
- \@latex@warning{#3\space reference range format for label
- type `\@typea' undefined}%
\else%
+ \cref@gettype{#1}{\@typea}%
+ \cref@gettype{#2}{\@typeb}%
+ \cref@getlabel{#1}{\@labela}%
+ \cref@getlabel{#2}{\@labelb}%
+ \edef\@formata{\expandafter\noexpand%
+ \csname #3range@\@typea @format#4\endcsname}%
+ \edef\@formatb{\expandafter\noexpand%
+ \csname #3range@\@typeb @format#4\endcsname}%
+ \expandafter\ifx\@formata\relax%
+ \protect\G@refundefinedtrue%
+ \nfss@text{\reset@font\bfseries ??}~\@labela--\@labelb%
+ \@latex@warning{#3\space reference range format for label
+ type `\@typea' undefined}%
+ \else%
% \end{macrocode}
% If reference types are identical, typeset reference range,
% otherwise display warning.\\
@@ -1660,17 +1730,18 @@
% type is defined, since if it isn't it will be caught here as a
% non-identical type.)
% \begin{macrocode}
- \ifx\formata\formatb%
- \expandafter\@@setcrefrange\expandafter{\@formata}{#1}{#2}%
- \else%
- \protect\G@refundefinedtrue%
- \nfss@text{\reset@font\bfseries ??}~\@labela--\@labelb%
- \@latex@warning{Types inconsistent in reference range for
- references `#1' and `#2' on page \thepage}%
+ \ifx\formata\formatb%
+ \expandafter\@@setcrefrange\expandafter{\@formata}{#1}{#2}%
+ \else%
+ \protect\G@refundefinedtrue%
+ \nfss@text{\reset@font\bfseries ??}~\@labela--\@labelb%
+ \@latex@warning{Types inconsistent in reference range for
+ references `#1' and `#2' on page \thepage}%
+ \fi%
\fi%
\fi%
\fi%
- \fi}
+ \endgroup}
% \end{macrocode}
%
% We again separate out the very final typesetting step into a
@@ -1736,8 +1807,9 @@
% the other capitalisation.
% \begin{macrocode}
\def\@crefname#1#2#3#4{%
- \expandafter\def\csname #1@#2@name\endcsname{#3}%
- \expandafter\def\csname #1@#2@name@plural\endcsname{#4}%
+ \begingroup%
+ \expandafter\gdef\csname #1@#2@name\endcsname{#3}%
+ \expandafter\gdef\csname #1@#2@name@plural\endcsname{#4}%
% \end{macrocode}
% The following \cmd{\@tmpa} macro makes use of the fact that the
% first character of \#1 is ``c'' for lower-case and ``C'' for
@@ -1745,58 +1817,58 @@
% macros so that the rest of the code can be capitalisation-variant
% agnostic.
% \begin{macrocode}
- \def\@tmpa##1##2\@nil{%
- \if##1c%
- \def\@other{C##2}%
- \def\@changecase{\MakeUppercase}%
- \else%
- \def\@other{c##2}%
- \def\@changecase{\MakeLowercase}%
- \fi}%
- \@tmpa#1\@nil%
+ \def\@tmpa##1##2\@nil{%
+ \if##1c%
+ \def\@other{C##2}%
+ \def\@changecase{\MakeUppercase}%
+ \else%
+ \def\@other{c##2}%
+ \def\@changecase{\MakeLowercase}%
+ \fi}%
+ \@tmpa#1\@nil%
% \end{macrocode}
% If the other capitalisation variant is not already defined...
% \begin{macrocode}
- \@ifundefined{\@other @#2@name}{%
+ \@ifundefined{\@other @#2@name}{%
% \end{macrocode}
% Define \cmd{\@tmpa} and \cmd{@tmpb} to be partial expansions
% (expanded just once) of the macros for the capitalisation variant
% we've just defined above. The \cmd{\@toska} token register just
% makes the code less verbose.
% \begin{macrocode}
- \expandafter\expandafter\expandafter\def%
- \expandafter\expandafter\expandafter\@tmpa%
- \expandafter\expandafter\expandafter{%
- \csname#1@#2@name\endcsname}%
- \expandafter\expandafter\expandafter\def%
- \expandafter\expandafter\expandafter\@tmpb%
- \expandafter\expandafter\expandafter{%
- \csname#1@#2@name@plural\endcsname}%
+ \expandafter\expandafter\expandafter\def%
+ \expandafter\expandafter\expandafter\@tmpa%
+ \expandafter\expandafter\expandafter{%
+ \csname#1@#2@name\endcsname}%
+ \expandafter\expandafter\expandafter\def%
+ \expandafter\expandafter\expandafter\@tmpb%
+ \expandafter\expandafter\expandafter{%
+ \csname#1@#2@name@plural\endcsname}%
% \end{macrocode}
% Add the \cmd{\@changecase} command to the front of the definitions of
-% \cmd{\@tmpa} and \cmd{\}tmpb}.
+% \cmd{\@tmpa} and \cmd{\@tmpb}.
% \begin{macrocode}
- \expandafter\expandafter\expandafter\def%
- \expandafter\expandafter\expandafter\@tmpa%
- \expandafter\expandafter\expandafter{%
- \expandafter\@changecase\@tmpa}%
- \expandafter\expandafter\expandafter\def%
- \expandafter\expandafter\expandafter\@tmpb%
- \expandafter\expandafter\expandafter{%
- \expandafter\@changecase\@tmpb}%
+ \expandafter\expandafter\expandafter\def%
+ \expandafter\expandafter\expandafter\@tmpa%
+ \expandafter\expandafter\expandafter{%
+ \expandafter\@changecase\@tmpa}%
+ \expandafter\expandafter\expandafter\def%
+ \expandafter\expandafter\expandafter\@tmpb%
+ \expandafter\expandafter\expandafter{%
+ \expandafter\@changecase\@tmpb}%
% \end{macrocode}
% Define the other capitalisation variants to be the partial expansions
% (expanded just once) of \cmd{\@tmpa} and \cmd{\@tmpb}.
% \begin{macrocode}
- \newtoks\@toksa%
- \@toksa={%
- \expandafter\def\csname\@other @#2@name\endcsname}%
- \expandafter\the\expandafter\@toksa\expandafter{\@tmpa}%
- \@toksa={%
- \expandafter\def\csname\@other @#2@name@plural\endcsname}%
- \expandafter\the\expandafter\@toksa\expandafter{\@tmpb}%
- }{}%
-}
+ \newtoks\@toksa%
+ \@toksa={%
+ \expandafter\gdef\csname\@other @#2@name\endcsname}%
+ \expandafter\the\expandafter\@toksa\expandafter{\@tmpa}%
+ \@toksa={%
+ \expandafter\gdef\csname\@other @#2@name@plural\endcsname}%
+ \expandafter\the\expandafter\@toksa\expandafter{\@tmpb}%
+ }{}%
+ \endgroup}
% \end{macrocode}
%
%
@@ -1863,174 +1935,190 @@
% macro expansion order.
% \begin{macrocode}
\def\@crefdefineformat#1{%
- \newtoks\@toksa%
- \@crefconstructcomponents{#1}% puts format components into tmp macros
+ \begingroup%
+ \newtoks\@toksa%
+% \end{macrocode}
+% put format components into tmp macros
+% \begin{macrocode}
+ \@crefconstructcomponents{#1}%
% \end{macrocode}
% Assemble the arguments for \cmd{\crefformat} and \cmd{\Crefformat}
% from the components.
% \begin{macrocode}
- \expandafter\expandafter\expandafter\def%
- \expandafter\expandafter\expandafter\@tmpfirst%
- \expandafter\expandafter\expandafter{%
- \expandafter\@tmpname\expandafter~\@tmplabel}%
- \expandafter\expandafter\expandafter\def%
- \expandafter\expandafter\expandafter\@tmpFirst%
- \expandafter\expandafter\expandafter{%
- \expandafter\@tmpName\expandafter~\@tmplabel}%
+ \expandafter\expandafter\expandafter\def%
+ \expandafter\expandafter\expandafter\@tmpfirst%
+ \expandafter\expandafter\expandafter{%
+ \expandafter\@tmpname\expandafter~\@tmplabel}%
+ \expandafter\expandafter\expandafter\def%
+ \expandafter\expandafter\expandafter\@tmpFirst%
+ \expandafter\expandafter\expandafter{%
+ \expandafter\@tmpName\expandafter~\@tmplabel}%
% \end{macrocode}
% Define \cmd{\crefformat} and \cmd{\Crefformat}.
% \begin{macrocode}
- \@toksa={\crefformat{#1}}%
- \expandafter\the\expandafter\@toksa\expandafter{\@tmpfirst}%
- \@toksa={\Crefformat{#1}}%
- \expandafter\the\expandafter\@toksa\expandafter{\@tmpFirst}%
-}
+ \@toksa={\crefformat{#1}}%
+ \expandafter\the\expandafter\@toksa\expandafter{\@tmpfirst}%
+ \@toksa={\Crefformat{#1}}%
+ \expandafter\the\expandafter\@toksa\expandafter{\@tmpFirst}%
+ \endgroup}
%
\def\@crefrangedefineformat#1{%
- \newtoks\@toksa%
- \newtoks\@toksb%
- \@crefconstructcomponents{#1}% puts format components into tmp macros
+ \begingroup%
+ \newtoks\@toksa%
+ \newtoks\@toksb%
+% \end{macrocode}
+% put format components into tmp macros
+% \begin{macrocode}
+ \@crefconstructcomponents{#1}%
% \end{macrocode}
% Assemble the arguments for \cmd{\crefrangeformat} and
% \cmd{\Crefrangeformat} from the components.
% \begin{macrocode}
- \expandafter\expandafter\expandafter\def%
- \expandafter\expandafter\expandafter\@tmpfirst%
- \expandafter\expandafter\expandafter{%
- \expandafter\@tmpnameplural\expandafter~\@tmprangelabel}%
- \expandafter\expandafter\expandafter\def%
- \expandafter\expandafter\expandafter\@tmpFirst%
- \expandafter\expandafter\expandafter{%
- \expandafter\@tmpNameplural\expandafter~\@tmprangelabel}%
+ \expandafter\expandafter\expandafter\def%
+ \expandafter\expandafter\expandafter\@tmpfirst%
+ \expandafter\expandafter\expandafter{%
+ \expandafter\@tmpnameplural\expandafter~\@tmprangelabel}%
+ \expandafter\expandafter\expandafter\def%
+ \expandafter\expandafter\expandafter\@tmpFirst%
+ \expandafter\expandafter\expandafter{%
+ \expandafter\@tmpNameplural\expandafter~\@tmprangelabel}%
% \end{macrocode}
% Define \cmd{\crefrangeformat} and \cmd{\Crefrangeformat}.
% \begin{macrocode}
- \@toksa={\crefrangeformat{#1}}%
- \expandafter\the\expandafter\@toksa\expandafter{\@tmpfirst}%
- \@toksa={\Crefrangeformat{#1}}%
- \expandafter\the\expandafter\@toksa\expandafter{\@tmpFirst}%
-}
+ \@toksa={\crefrangeformat{#1}}%
+ \expandafter\the\expandafter\@toksa\expandafter{\@tmpfirst}%
+ \@toksa={\Crefrangeformat{#1}}%
+ \expandafter\the\expandafter\@toksa\expandafter{\@tmpFirst}%
+ \endgroup}
%
\def\@crefdefinemultiformat#1{%
- \newtoks\@toksa%
- \newtoks\@toksb%
- \@crefconstructcomponents{#1}% puts format components into tmp macros
+ \begingroup%
+ \newtoks\@toksa%
+ \newtoks\@toksb%
+% \end{macrocode}
+% put format components into tmp macros
+% \begin{macrocode}
+ \@crefconstructcomponents{#1}%
% \end{macrocode}
% Assemble the arguments for \cmd{\crefmultiformat} and
% \cmd{\Crefmultiformat} from the components.
% \begin{macrocode}
- \expandafter\expandafter\expandafter\def%
- \expandafter\expandafter\expandafter\@tmpfirst%
- \expandafter\expandafter\expandafter{%
- \expandafter\@tmpnameplural\expandafter~\@tmplabel}%
- \expandafter\expandafter\expandafter\def%
- \expandafter\expandafter\expandafter\@tmpFirst%
- \expandafter\expandafter\expandafter{%
- \expandafter\@tmpNameplural\expandafter~\@tmplabel}%
- \expandafter\expandafter\expandafter\def%
- \expandafter\expandafter\expandafter\@tmpsecond%
- \expandafter\expandafter\expandafter{%
- \expandafter\crefpairconjunction\@tmplabel}%
- \expandafter\expandafter\expandafter\def%
- \expandafter\expandafter\expandafter\@tmpmiddle%
- \expandafter\expandafter\expandafter{%
- \expandafter\crefmiddleconjunction\@tmplabel}%
- \expandafter\expandafter\expandafter\def%
- \expandafter\expandafter\expandafter\@tmplast%
- \expandafter\expandafter\expandafter{%
- \expandafter\creflastconjunction\@tmplabel}%
+ \expandafter\expandafter\expandafter\def%
+ \expandafter\expandafter\expandafter\@tmpfirst%
+ \expandafter\expandafter\expandafter{%
+ \expandafter\@tmpnameplural\expandafter~\@tmplabel}%
+ \expandafter\expandafter\expandafter\def%
+ \expandafter\expandafter\expandafter\@tmpFirst%
+ \expandafter\expandafter\expandafter{%
+ \expandafter\@tmpNameplural\expandafter~\@tmplabel}%
+ \expandafter\expandafter\expandafter\def%
+ \expandafter\expandafter\expandafter\@tmpsecond%
+ \expandafter\expandafter\expandafter{%
+ \expandafter\crefpairconjunction\@tmplabel}%
+ \expandafter\expandafter\expandafter\def%
+ \expandafter\expandafter\expandafter\@tmpmiddle%
+ \expandafter\expandafter\expandafter{%
+ \expandafter\crefmiddleconjunction\@tmplabel}%
+ \expandafter\expandafter\expandafter\def%
+ \expandafter\expandafter\expandafter\@tmplast%
+ \expandafter\expandafter\expandafter{%
+ \expandafter\creflastconjunction\@tmplabel}%
% \end{macrocode}
% Bundle all four arguments for \cmd{\crefmultiformat} in token
% register \cmd{\@toksb}, then call it.
% \begin{macrocode}
- \@toksb={}%
- \expandafter\append@toks\expandafter\@toksb\expandafter{%
- \expandafter{\@tmpfirst}}%
- \expandafter\append@toks\expandafter\@toksb\expandafter{%
- \expandafter{\@tmpsecond}}%
- \expandafter\append@toks\expandafter\@toksb\expandafter{%
- \expandafter{\@tmpmiddle}}%
- \expandafter\append@toks\expandafter\@toksb\expandafter{%
- \expandafter{\@tmplast}}%
- \@toksa={\crefmultiformat{#1}}%
- \expandafter\the\expandafter\@toksa\the\@toksb%
+ \@toksb={}%
+ \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
+ \expandafter{\@tmpfirst}}%
+ \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
+ \expandafter{\@tmpsecond}}%
+ \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
+ \expandafter{\@tmpmiddle}}%
+ \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
+ \expandafter{\@tmplast}}%
+ \@toksa={\crefmultiformat{#1}}%
+ \expandafter\the\expandafter\@toksa\the\@toksb%
% \end{macrocode}
% Bundle all four arguments for \cmd{\Crefmultiformat} in token
% register \cmd{\@toksb}, then call it.
% \begin{macrocode}
- \@toksb={}%
- \expandafter\append@toks\expandafter\@toksb\expandafter{%
- \expandafter{\@tmpFirst}}%
- \expandafter\append@toks\expandafter\@toksb\expandafter{%
- \expandafter{\@tmpsecond}}%
- \expandafter\append@toks\expandafter\@toksb\expandafter{%
- \expandafter{\@tmpmiddle}}%
- \expandafter\append@toks\expandafter\@toksb\expandafter{%
- \expandafter{\@tmplast}}%
- \@toksa={\Crefmultiformat{#1}}%
- \expandafter\the\expandafter\@toksa\the\@toksb%
-}
+ \@toksb={}%
+ \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
+ \expandafter{\@tmpFirst}}%
+ \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
+ \expandafter{\@tmpsecond}}%
+ \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
+ \expandafter{\@tmpmiddle}}%
+ \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
+ \expandafter{\@tmplast}}%
+ \@toksa={\Crefmultiformat{#1}}%
+ \expandafter\the\expandafter\@toksa\the\@toksb%
+ \endgroup}
%
\def\@crefrangedefinemultiformat#1{%
- \newtoks\@toksa%
- \newtoks\@toksb%
- \@crefconstructcomponents{#1}% puts format components into tmp macros
+ \begingroup%
+ \newtoks\@toksa%
+ \newtoks\@toksb%
+% \end{macrocode}
+% put format components into tmp macros
+% \begin{macrocode}
+ \@crefconstructcomponents{#1}%
% \end{macrocode}
% Assemble the arguments that need to be passed to
% \cmd{\crefrangemultiformat} and \cmd{\Crefrangemultiformat} from the
% reference components.
% \begin{macrocode}
- \expandafter\expandafter\expandafter\def%
- \expandafter\expandafter\expandafter\@tmpfirst%
- \expandafter\expandafter\expandafter{%
- \expandafter\@tmpnameplural\expandafter~\@tmprangelabel}%
- \expandafter\expandafter\expandafter\def%
- \expandafter\expandafter\expandafter\@tmpFirst%
- \expandafter\expandafter\expandafter{%
- \expandafter\@tmpNameplural\expandafter~\@tmprangelabel}%
- \expandafter\expandafter\expandafter\def%
- \expandafter\expandafter\expandafter\@tmpsecond%
- \expandafter\expandafter\expandafter{%
- \expandafter\crefpairconjunction\@tmprangelabel}%
- \expandafter\expandafter\expandafter\def%
- \expandafter\expandafter\expandafter\@tmpmiddle%
- \expandafter\expandafter\expandafter{%
- \expandafter\crefmiddleconjunction\@tmprangelabel}%
- \expandafter\expandafter\expandafter\def%
- \expandafter\expandafter\expandafter\@tmplast%
- \expandafter\expandafter\expandafter{%
- \expandafter\creflastconjunction\@tmprangelabel}%
+ \expandafter\expandafter\expandafter\def%
+ \expandafter\expandafter\expandafter\@tmpfirst%
+ \expandafter\expandafter\expandafter{%
+ \expandafter\@tmpnameplural\expandafter~\@tmprangelabel}%
+ \expandafter\expandafter\expandafter\def%
+ \expandafter\expandafter\expandafter\@tmpFirst%
+ \expandafter\expandafter\expandafter{%
+ \expandafter\@tmpNameplural\expandafter~\@tmprangelabel}%
+ \expandafter\expandafter\expandafter\def%
+ \expandafter\expandafter\expandafter\@tmpsecond%
+ \expandafter\expandafter\expandafter{%
+ \expandafter\crefpairconjunction\@tmprangelabel}%
+ \expandafter\expandafter\expandafter\def%
+ \expandafter\expandafter\expandafter\@tmpmiddle%
+ \expandafter\expandafter\expandafter{%
+ \expandafter\crefmiddleconjunction\@tmprangelabel}%
+ \expandafter\expandafter\expandafter\def%
+ \expandafter\expandafter\expandafter\@tmplast%
+ \expandafter\expandafter\expandafter{%
+ \expandafter\creflastconjunction\@tmprangelabel}%
% \end{macrocode}
% Bundle all four arguments for \cmd{\crefrangemultiformat} in token
% register \cmd{\@toksb}, then call it.
% \begin{macrocode}
- \@toksb={}%
- \expandafter\append@toks\expandafter\@toksb\expandafter{%
- \expandafter{\@tmpfirst}}%
- \expandafter\append@toks\expandafter\@toksb\expandafter{%
- \expandafter{\@tmpsecond}}%
- \expandafter\append@toks\expandafter\@toksb\expandafter{%
- \expandafter{\@tmpmiddle}}%
- \expandafter\append@toks\expandafter\@toksb\expandafter{%
- \expandafter{\@tmplast}}%
- \@toksa={\crefrangemultiformat{#1}}%
- \expandafter\the\expandafter\@toksa\the\@toksb%
+ \@toksb={}%
+ \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
+ \expandafter{\@tmpfirst}}%
+ \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
+ \expandafter{\@tmpsecond}}%
+ \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
+ \expandafter{\@tmpmiddle}}%
+ \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
+ \expandafter{\@tmplast}}%
+ \@toksa={\crefrangemultiformat{#1}}%
+ \expandafter\the\expandafter\@toksa\the\@toksb%
% \end{macrocode}
% Bundle all four arguments for \cmd{\Crefrangemultiformat} in token
% register \cmd{\@toksb}, then call it.
% \begin{macrocode}
- \@toksb={}%
- \expandafter\append@toks\expandafter\@toksb\expandafter{%
- \expandafter{\@tmpFirst}}%
- \expandafter\append@toks\expandafter\@toksb\expandafter{%
- \expandafter{\@tmpsecond}}%
- \expandafter\append@toks\expandafter\@toksb\expandafter{%
- \expandafter{\@tmpmiddle}}%
- \expandafter\append@toks\expandafter\@toksb\expandafter{%
- \expandafter{\@tmplast}}%
- \@toksa={\Crefrangemultiformat{#1}}%
- \expandafter\the\expandafter\@toksa\the\@toksb%
-}
+ \@toksb={}%
+ \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
+ \expandafter{\@tmpFirst}}%
+ \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
+ \expandafter{\@tmpsecond}}%
+ \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
+ \expandafter{\@tmpmiddle}}%
+ \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
+ \expandafter{\@tmplast}}%
+ \@toksa={\Crefrangemultiformat{#1}}%
+ \expandafter\the\expandafter\@toksa\the\@toksb%
+ \endgroup}
% \end{macrocode}
%
% \cmd{\@crefdefineallformats} calls each of the above, to define all
@@ -2074,7 +2162,8 @@
% capitalisation.
% \begin{macrocode}
\def\@crefformat#1#2#3{%
- \expandafter\def\csname #1@#2@format\endcsname##1##2##3{#3}%
+ \begingroup%
+ \expandafter\gdef\csname #1@#2@format\endcsname##1##2##3{#3}%
% \end{macrocode}
% The following \cmd{\@tmpa} macro makes use of the fact that the
% first character of \#1 is ``c'' for lower-case and ``C'' for
@@ -2082,52 +2171,53 @@
% macros so that the rest of the code can be capitalisation-variant
% agnostic.
% \begin{macrocode}
- \def\@tmpa##1##2\@nil{%
- \if##1c%
- \def\@other{C##2}%
- \def\@changecase{\MakeUppercase}%
- \else%
- \def\@other{c##2}%
- \def\@changecase{\MakeLowercase}%
- \fi}%
- \@tmpa#1\@nil%
+ \def\@tmpa##1##2\@nil{%
+ \if##1c%
+ \def\@other{C##2}%
+ \def\@changecase{\MakeUppercase}%
+ \else%
+ \def\@other{c##2}%
+ \def\@changecase{\MakeLowercase}%
+ \fi}%
+ \@tmpa#1\@nil%
% \end{macrocode}
% If the other capitalisation variant is not already defined...
% \begin{macrocode}
- \@ifundefined{\@other @#2@format}{%
+ \@ifundefined{\@other @#2@format}{%
% \end{macrocode}
% Define \cmd{\@tmpa} to be a partial expansion (expanded just once)
% of the capitalisation variant we've just defined above. The
% \cmd{\@toska} token register just makes the code less verbose.
% \begin{macrocode}
- \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}}%
+ \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}}%
% \end{macrocode}
% Add the \cmd{\@changecase} command to the front of the definition of
% \cmd{\@tmpa}.
% \begin{macrocode}
- \expandafter\expandafter\expandafter\the%
- \expandafter\expandafter\expandafter\@toksa%
- \expandafter\expandafter\expandafter{%
- \expandafter\@changecase\@tmpa{##1}{##2}{##3}}%
+ \expandafter\expandafter\expandafter\the%
+ \expandafter\expandafter\expandafter\@toksa%
+ \expandafter\expandafter\expandafter{%
+ \expandafter\@changecase\@tmpa{##1}{##2}{##3}}%
% \end{macrocode}
% Define the other capitalisation variant to be the partial expansion
% (expanded just once) of \cmd{\@tmpa}.
% \begin{macrocode}
- \@toksa={%
- \expandafter\def\csname\@other @#2@format\endcsname##1##2##3}%
- \expandafter\the\expandafter\@toksa\expandafter{%
- \@tmpa{##1}{##2}{##3}}%
- }{}%
-}
+ \@toksa={%
+ \expandafter\gdef\csname\@other @#2@format\endcsname##1##2##3}%
+ \expandafter\the\expandafter\@toksa\expandafter{%
+ \@tmpa{##1}{##2}{##3}}%
+ }{}%
+ \endgroup}
%
\def\@crefrangeformat#1#2#3{%
- \expandafter\def\csname #1@#2@format\endcsname%
- ##1##2##3##4##5##6{#3}%
+ \begingroup%
+ \expandafter\gdef\csname #1@#2@format\endcsname%
+ ##1##2##3##4##5##6{#3}%
% \end{macrocode}
% The following \cmd{\@tmpa} macro makes use of the fact that the
% first character of \#1 is ``c'' for lower-case and ``C'' for
@@ -2135,54 +2225,55 @@
% macros so that the rest of the code can be capitalisation-variant
% agnostic.
% \begin{macrocode}
- \def\@tmpa##1##2\@nil{%
- \if##1c%
- \def\@other{C##2}%
- \def\@changecase{\MakeUppercase}%
- \else%
- \def\@other{c##2}%
- \def\@changecase{\MakeLowercase}%
- \fi}%
- \@tmpa#1\@nil%
+ \def\@tmpa##1##2\@nil{%
+ \if##1c%
+ \def\@other{C##2}%
+ \def\@changecase{\MakeUppercase}%
+ \else%
+ \def\@other{c##2}%
+ \def\@changecase{\MakeLowercase}%
+ \fi}%
+ \@tmpa#1\@nil%
% \end{macrocode}
% If the other capitalisation variant is not already defined...
% \begin{macrocode}
- \@ifundefined{\@other @#2@format}{%
+ \@ifundefined{\@other @#2@format}{%
% \end{macrocode}
% Define \cmd{\@tmpa} to be a partial expansion (expanded just once)
% of the capitalisation variant we've just defined above. The
% \cmd{\@toska} token register just makes the code less verbose.
% \begin{macrocode}
- \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}}%
+ \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}}%
% \end{macrocode}
% Add the \cmd{\@changecase} command to the front of the definition of
% \cmd{\@tmpa}.
% \begin{macrocode}
- \expandafter\expandafter\expandafter\the%
- \expandafter\expandafter\expandafter\@toksa%
- \expandafter\expandafter\expandafter{%
- \expandafter\@changecase\@tmpa{##1}{##2}{##3}{##4}{##5}{##6}}%
+ \expandafter\expandafter\expandafter\the%
+ \expandafter\expandafter\expandafter\@toksa%
+ \expandafter\expandafter\expandafter{%
+ \expandafter\@changecase\@tmpa{##1}{##2}{##3}{##4}{##5}{##6}}%
% \end{macrocode}
% Define the other capitalisation variant to be the partial expansion
% (expanded just once) of \cmd{\@tmpa}.
% \begin{macrocode}
- \@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}}%
- }{}%
-}
+ \@toksa={\expandafter\gdef%
+ \csname\@other @#2@format\endcsname##1##2##3##4##5##6}%
+ \expandafter\the\expandafter\@toksa\expandafter{%
+ \@tmpa{##1}{##2}{##3}{##4}{##5}{##6}}%
+ }{}%
+ \endgroup}
%
\def\@crefmultiformat#1#2#3#4#5#6{%
- \expandafter\def\csname #1@#2@format@first\endcsname##1##2##3{#3}%
- \expandafter\def\csname #1@#2@format@second\endcsname##1##2##3{#4}%
- \expandafter\def\csname #1@#2@format@middle\endcsname##1##2##3{#5}%
- \expandafter\def\csname #1@#2@format@last\endcsname##1##2##3{#6}%
+ \begingroup%
+ \expandafter\gdef\csname #1@#2@format@first\endcsname##1##2##3{#3}%
+ \expandafter\gdef\csname #1@#2@format@second\endcsname##1##2##3{#4}%
+ \expandafter\gdef\csname #1@#2@format@middle\endcsname##1##2##3{#5}%
+ \expandafter\gdef\csname #1@#2@format@last\endcsname##1##2##3{#6}%
% \end{macrocode}
% The following \cmd{\@tmpa} macro makes use of the fact that the
% first character of \#1 is ``c'' for lower-case and ``C'' for
@@ -2190,81 +2281,85 @@
% macros so that the rest of the code can be capitalisation-variant
% agnostic.
% \begin{macrocode}
- \def\@tmpa##1##2\@nil{%
- \if##1c%
- \def\@other{C##2}%
- \def\@changecase{\MakeUppercase}%
- \else%
- \def\@other{c##2}%
- \def\@changecase{\MakeLowercase}%
- \fi}%
- \@tmpa#1\@nil%
+ \def\@tmpa##1##2\@nil{%
+ \if##1c%
+ \def\@other{C##2}%
+ \def\@changecase{\MakeUppercase}%
+ \else%
+ \def\@other{c##2}%
+ \def\@changecase{\MakeLowercase}%
+ \fi}%
+ \@tmpa#1\@nil%
% \end{macrocode}
% If the other capitalisation variant of the first part of the
% multi-format definition is not already defined...
% \begin{macrocode}
- \@ifundefined{\@other @#2@format@first}{%
+ \@ifundefined{\@other @#2@format@first}{%
% \end{macrocode}
% Define \cmd{\@tmpa} to be a partial expansion (expanded just once)
% of the capitalisation variant we've just defined above. The
% \cmd{\@toska} token register just makes the code less verbose.
% \begin{macrocode}
- \@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}}%
+ \@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}}%
% \end{macrocode}
% Add the \cmd{\@changecase} command to the front of the definition of
% \cmd{\@tmpa}.
% \begin{macrocode}
- \expandafter\expandafter\expandafter\the%
- \expandafter\expandafter\expandafter\@toksa%
- \expandafter\expandafter\expandafter{%
- \expandafter\@changecase\@tmpa{##1}{##2}{##3}}%
+ \expandafter\expandafter\expandafter\the%
+ \expandafter\expandafter\expandafter\@toksa%
+ \expandafter\expandafter\expandafter{%
+ \expandafter\@changecase\@tmpa{##1}{##2}{##3}}%
% \end{macrocode}
% Define the other capitalisation variant to be the partial expansion
% (expanded just once) of \cmd{\@tmpa}.
% \begin{macrocode}
- \@toksa={%
- \expandafter\def\csname\@other @#2@format@first\endcsname%
- ##1##2##3}%
- \expandafter\the\expandafter\@toksa\expandafter{%
- \@tmpa{##1}{##2}{##3}}%
- }{}%
+ \@toksa={%
+ \expandafter\gdef\csname\@other @#2@format@first\endcsname%
+ ##1##2##3}%
+ \expandafter\the\expandafter\@toksa\expandafter{%
+ \@tmpa{##1}{##2}{##3}}%
+ }{}%
% \end{macrocode}
% The other parts of the multi-format definition are defined to be
% identical for both capitalisation variants.
% \begin{macrocode}
- \@ifundefined{\@other @#2@format@second}{%
- \@toksa={%
- \expandafter\let\csname\@other @#2@format@second\endcsname}%
- \expandafter\the\expandafter\@toksa%
- \csname #1@#2@format@second\endcsname%
- }{}%
- \@ifundefined{\@other @#2@format@middle}{%
- \@toksa={%
- \expandafter\let\csname\@other @#2@format@middle\endcsname}%
- \expandafter\the\expandafter\@toksa%
- \csname #1@#2@format@middle\endcsname%
- }{}%
- \@ifundefined{\@other @#2@format@last}{%
- \@toksa={%
- \expandafter\let\csname\@other @#2@format@last\endcsname}%
- \expandafter\the\expandafter\@toksa%
- \csname #1@#2@format@last\endcsname%
- }{}%
-}
+ \@ifundefined{\@other @#2@format@second}{%
+ \@toksa={%
+ \expandafter\global\expandafter\let%
+ \csname\@other @#2@format@second\endcsname}%
+ \expandafter\the\expandafter\@toksa%
+ \csname #1@#2@format@second\endcsname%
+ }{}%
+ \@ifundefined{\@other @#2@format@middle}{%
+ \@toksa={%
+ \expandafter\global\expandafter\let%
+ \csname\@other @#2@format@middle\endcsname}%
+ \expandafter\the\expandafter\@toksa%
+ \csname #1@#2@format@middle\endcsname%
+ }{}%
+ \@ifundefined{\@other @#2@format@last}{%
+ \@toksa={%
+ \expandafter\global\expandafter\let%
+ \csname\@other @#2@format@last\endcsname}%
+ \expandafter\the\expandafter\@toksa%
+ \csname #1@#2@format@last\endcsname%
+ }{}%
+ \endgroup}
%
\def\@crefrangemultiformat#1#2#3#4#5#6{%
- \expandafter\def\csname #1@#2@format@first\endcsname%
- ##1##2##3##4##5##6{#3}%
- \expandafter\def\csname #1@#2@format@second\endcsname%
- ##1##2##3##4##5##6{#4}%
- \expandafter\def\csname #1@#2@format@middle\endcsname%
- ##1##2##3##4##5##6{#5}%
- \expandafter\def\csname #1@#2@format@last\endcsname%
- ##1##2##3##4##5##6{#6}%
+ \begingroup%
+ \expandafter\gdef\csname #1@#2@format@first\endcsname%
+ ##1##2##3##4##5##6{#3}%
+ \expandafter\gdef\csname #1@#2@format@second\endcsname%
+ ##1##2##3##4##5##6{#4}%
+ \expandafter\gdef\csname #1@#2@format@middle\endcsname%
+ ##1##2##3##4##5##6{#5}%
+ \expandafter\gdef\csname #1@#2@format@last\endcsname%
+ ##1##2##3##4##5##6{#6}%
% \end{macrocode}
% The following \cmd{\@tmpa} macro makes use of the fact that the
% first character of \#1 is ``c'' for lower-case and ``C'' for
@@ -2272,72 +2367,75 @@
% macros so that the rest of the code can be capitalisation-variant
% agnostic.
% \begin{macrocode}
- \def\@tmpa##1##2\@nil{%
- \if##1c%
- \def\@other{C##2}%
- \def\@changecase{\MakeUppercase}%
- \else%
- \def\@other{c##2}%
- \def\@changecase{\MakeLowercase}%
- \fi}%
- \@tmpa#1\@nil%
+ \def\@tmpa##1##2\@nil{%
+ \if##1c%
+ \def\@other{C##2}%
+ \def\@changecase{\MakeUppercase}%
+ \else%
+ \def\@other{c##2}%
+ \def\@changecase{\MakeLowercase}%
+ \fi}%
+ \@tmpa#1\@nil%
% \end{macrocode}
% If the other capitalisation variant of the first part of the
% multi-format definition is not already defined...
% \begin{macrocode}
- \@ifundefined{\@other @#2@format@first}{%
+ \@ifundefined{\@other @#2@format@first}{%
% \end{macrocode}
% Define \cmd{\@tmpa} to be a partial expansion (expanded just once)
% of the capitalisation variant we've just defined above. The
% \cmd{\@toska} token register just makes the code less verbose.
% \begin{macrocode}
- \@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}}%
+ \@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}}%
% \end{macrocode}
% Add the \cmd{\@changecase} command to the front of the definition of
% \cmd{\@tmpa}.
% \begin{macrocode}
- \expandafter\expandafter\expandafter\the%
- \expandafter\expandafter\expandafter\@toksa%
- \expandafter\expandafter\expandafter{%
- \expandafter\@changecase\@tmpa{##1}{##2}{##3}{##4}{##5}{##6}}%
+ \expandafter\expandafter\expandafter\the%
+ \expandafter\expandafter\expandafter\@toksa%
+ \expandafter\expandafter\expandafter{%
+ \expandafter\@changecase\@tmpa{##1}{##2}{##3}{##4}{##5}{##6}}%
% \end{macrocode}
% Define the other capitalisation variant to be the partial expansion
% (expanded just once) of \cmd{\@tmpa}.
% \begin{macrocode}
- \@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}}%
- }{}%
+ \@toksa={%
+ \expandafter\gdef\csname\@other @#2@format@first\endcsname%
+ ##1##2##3##4##5##6}%
+ \expandafter\the\expandafter\@toksa\expandafter{%
+ \@tmpa{##1}{##2}{##3}{##4}{##5}{##6}}%
+ }{}%
% \end{macrocode}
% The other parts of the multi-format definition are defined to be
% identical for both capitalisation variants.
% \begin{macrocode}
- \@ifundefined{\@other @#2@format@second}{%
- \@toksa={%
- \expandafter\let\csname\@other @#2@format@second\endcsname}%
- \expandafter\the\expandafter\@toksa%
- \csname #1@#2@format@second\endcsname%
- }{}%
- \@ifundefined{\@other @#2@format@middle}{%
- \@toksa={%
- \expandafter\let\csname\@other @#2@format@middle\endcsname}%
- \expandafter\the\expandafter\@toksa%
- \csname #1@#2@format@middle\endcsname%
- }{}%
- \@ifundefined{\@other @#2@format@last}{%
- \@toksa={%
- \expandafter\let\csname\@other @#2@format@last\endcsname}%
- \expandafter\the\expandafter\@toksa%
- \csname #1@#2@format@last\endcsname%
- }{}%
-}
+ \@ifundefined{\@other @#2@format@second}{%
+ \@toksa={%
+ \expandafter\global\expandafter\let%
+ \csname\@other @#2@format@second\endcsname}%
+ \expandafter\the\expandafter\@toksa%
+ \csname #1@#2@format@second\endcsname%
+ }{}%
+ \@ifundefined{\@other @#2@format@middle}{%
+ \@toksa={%
+ \expandafter\global\expandafter\let%
+ \csname\@other @#2@format@middle\endcsname}%
+ \expandafter\the\expandafter\@toksa%
+ \csname #1@#2@format@middle\endcsname%
+ }{}%
+ \@ifundefined{\@other @#2@format@last}{%
+ \@toksa={%
+ \expandafter\global\expandafter\let%
+ \csname\@other @#2@format@last\endcsname}%
+ \expandafter\the\expandafter\@toksa%
+ \csname #1@#2@format@last\endcsname%
+ }{}%
+ \endgroup}
% \end{macrocode}
%
%
@@ -2418,6 +2516,9 @@
\@ifundefined{cref@subsubsubsection@name}{%
\@crefname{cref}{subsubsubsection}{section}{sections}%
\@crefname{Cref}{subsubsubsection}{Section}{Sections}}{}%
+ \@ifundefined{cref@appendix@name}{%
+ \@crefname{cref}{appendix}{appendix}{appendices}%
+ \@crefname{Cref}{appendix}{Appendix}{Appendices}}{}%
\@ifundefined{cref@figure@name}{%
\@crefname{cref}{figure}{fig.}{figs.}%
\@crefname{Cref}{figure}{Figure}{Figures}}{}%
@@ -2495,6 +2596,14 @@
\@crefdefinemultiformat{subsubsubsection}}{}%
\@ifundefined{crefrange@subsubsubsection@format@first}{%
\@crefrangedefinemultiformat{subsubsubsection}}{}%
+ \@ifundefined{cref@appendix@format}{%
+ \@crefdefineformat{appendix}}{}%
+ \@ifundefined{crefrange@appendix@format}{%
+ \@crefrangedefineformat{appendix}}{}%
+ \@ifundefined{cref@appendix@format@first}{%
+ \@crefdefinemultiformat{appendix}}{}%
+ \@ifundefined{crefrange@appendix@format@first}{%
+ \@crefrangedefinemultiformat{appendix}}{}%
\@ifundefined{cref@figure@format}{%
\@crefdefineformat{figure}}{}%
\@ifundefined{crefrange@figure@format}{%
@@ -2503,6 +2612,14 @@
\@crefdefinemultiformat{figure}}{}%
\@ifundefined{crefrange@figure@format@first}{%
\@crefrangedefinemultiformat{figure}}{}%
+ \@ifundefined{cref@table@format}{%
+ \@crefdefineformat{table}}{}%
+ \@ifundefined{crefrange@table@format}{%
+ \@crefrangedefineformat{table}}{}%
+ \@ifundefined{cref@table@format@first}{%
+ \@crefdefinemultiformat{table}}{}%
+ \@ifundefined{crefrange@table@format@first}{%
+ \@crefrangedefinemultiformat{table}}{}%
\@ifundefined{cref@theorem@format}{%
\@crefdefineformat{theorem}}{}%
\@ifundefined{crefrange@theorem@format}{%
@@ -2576,21 +2693,21 @@
\def\cref@hyperref#1{\expandafter\expandafter\expandafter%
\@fourthoffive\csname r@#1\endcsname}
\def\cref@getlabel#1#2{%
- \expandafter\let\expandafter\@tempa\csname r@#1\endcsname%
- \edef\@tempa{\expandafter\@firstoffive\@tempa}%
- \expandafter\@cref@getlabel\@tempa\@nil#2}
+ \expandafter\let\expandafter\@tmpa\csname r@#1\endcsname%
+ \edef\@tmpa{\expandafter\@firstoffive\@tmpa}%
+ \expandafter\@cref@getlabel\@tmpa\@nil#2}
\def\cref@gettype#1#2{%
- \expandafter\let\expandafter\@tempa\csname r@#1\endcsname%
- \edef\@tempa{\expandafter\@firstoffive\@tempa}%
- \expandafter\@cref@gettype\@tempa\@nil#2}
+ \expandafter\let\expandafter\@tmpa\csname r@#1\endcsname%
+ \edef\@tmpa{\expandafter\@firstoffive\@tmpa}%
+ \expandafter\@cref@gettype\@tmpa\@nil#2}
\def\cref@getcounter#1#2{%
- \expandafter\let\expandafter\@tempa\csname r@#1\endcsname%
- \edef\@tempa{\expandafter\@firstoffive\@tempa}%
- \expandafter\@cref@getcounter\@tempa\@nil#2}
+ \expandafter\let\expandafter\@tmpa\csname r@#1\endcsname%
+ \edef\@tmpa{\expandafter\@firstoffive\@tmpa}%
+ \expandafter\@cref@getcounter\@tmpa\@nil#2}
\def\cref@getprefix#1#2{%
- \expandafter\let\expandafter\@tempa\csname r@#1\endcsname%
- \edef\@tempa{\expandafter\@firstoffive\@tempa}%
- \expandafter\@cref@getprefix\@tempa\@nil#2}
+ \expandafter\let\expandafter\@tmpa\csname r@#1\endcsname%
+ \edef\@tmpa{\expandafter\@firstoffive\@tmpa}%
+ \expandafter\@cref@getprefix\@tmpa\@nil#2}
% \end{macrocode}
%
% The \package{hyperref} package stores the original
@@ -2600,29 +2717,74 @@
% \begin{macrocode}
\def\H@refstepcounter#1{%
\stepcounter{#1}%
- \reset@by{#1}{\@result}%
+ \cref@resetby{#1}{\@result}%
\ifx\@result\relax\def\@result{}%
\else\edef\@result{\csname the\@result\endcsname}\fi%
- \protected@edef\@currentlabel%
- {[#1][\arabic{#1}][\@result]%
- \csname p@#1\endcsname\csname the#1\endcsname}}
+ \protected@edef\@currentlabel{%
+ [#1][\arabic{#1}][\@result]%
+ \csname p@#1\endcsname\csname the#1\endcsname}}
% \end{macrocode}
%
% The original \cmd{\refstepcounter}, as stored earlier in
-% \cmd{\old@refstepcounter}, already calls \H@refstepcounter if
+% \cmd{\cref@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
% our \cmd{\refstepcounter} if an optional argument was supplied.
% \begin{macrocode}
-\def\refstepcounter@noarg#1{\old@refstepcounter{#1}}
+\def\refstepcounter@noarg#1{\cref@old@refstepcounter{#1}}
\def\refstepcounter@optarg[#1]#2{%
- \old@refstepcounter{#2}%
- \expandafter\@cref@getlabel\@currentlabel\@nil{\@templabel}%
- \reset@by{#2}{\@tempreset}%
- \ifx\@tempreset\relax\def\@tempreset{}%
- \else\edef\@tempreset{\csname the\@tempreset\endcsname}\fi%
+ \cref@old@refstepcounter{#2}%
+ \expandafter\@cref@getlabel\@currentlabel\@nil{\@tmplabel}%
+ \cref@resetby{#2}{\@tmpreset}%
+ \ifx\@tmpreset\relax\def\@tmpreset{}%
+ \else\edef\@tmpreset{\csname the\@tmpreset\endcsname}\fi%
\protected@edef\@currentlabel{%
- [#1][\arabic{#2}][\@tempreset]\@templabel}}
+ [#1][\arabic{#2}][\@tmpreset]\@tmplabel}}
+% \end{macrocode}
+%
+% We again make \cmd{\appendix} redefine things so that the label type
+% for chapters or sections is exceptionally overridden and set to
+% ``appendix'' instead. But this time, it is \cmd{\H@refstepcounter}
+% that needs to be redefined.
+% \begin{macrocode}
+\renewcommand\appendix{%
+ \cref@old@appendix%
+ \@ifundefined{chapter}{%
+ \def\H@refstepcounter##1{%
+ \stepcounter{##1}%
+ \cref@resetby{##1}{\@result}%
+ \ifx\@result\relax\def\@result{}%
+ \else\edef\@result{\csname the\@result\endcsname}\fi%
+ \def\@tmpa{##1}
+ \def\@tmpb{section}%
+ \ifx\@tmpa\@tmpb%
+ \protected@edef\@currentlabel{%
+ [appendix][\arabic{##1}][\@result]%
+ \csname p@##1\endcsname\csname the##1\endcsname}%
+ \else
+ \protected@edef\@currentlabel{%
+ [##1][\arabic{##1}][\@result]%
+ \csname p@##1\endcsname\csname the##1\endcsname}%
+ fi}%
+ }{%
+ \def\H@refstepcounter##1{%
+ \stepcounter{##1}%
+ \cref@resetby{##1}{\@result}%
+ \ifx\@result\relax\def\@result{}%
+ \else\edef\@result{\csname the\@result\endcsname}\fi%
+ \def\@tmpa{##1}
+ \def\@tmpb{chapter}%
+ \ifx\@tmpa\@tmpb%
+ \protected@edef\@currentlabel{%
+ [appendix][\arabic{##1}][\@result]%
+ \csname p@##1\endcsname\csname the##1\endcsname}%
+ \else
+ \protected@edef\@currentlabel{%
+ [##1][\arabic{##1}][\@result]%
+ \csname p@##1\endcsname\csname the##1\endcsname}%
+ fi}%
+ }%
+}
% \end{macrocode}
%
% Redefine \cmd{\cref} and all the others to allow starred variants,
@@ -2653,12 +2815,12 @@
% \package{hyperref}.
% \begin{macrocode}
\def\@@setcref#1#2{%
- \cref@getlabel{#2}{\@templabel}%
+ \cref@getlabel{#2}{\@tmplabel}%
\if@crefstarred%
- #1{\@templabel}{}{}%
+ #1{\@tmplabel}{}{}%
\else%
- \edef\@templink{\cref@hyperref{#2}}%
- #1{\@templabel}{\hyper@linkstart{link}{\@templink}}{\hyper@linkend}%
+ \edef\@tmplink{\cref@hyperref{#2}}%
+ #1{\@tmplabel}{\hyper@linkstart{link}{\@tmplink}}{\hyper@linkend}%
\fi}
\def\@@setcrefrange#1#2#3{%
\cref@getlabel{#2}{\@labela}%
@@ -2690,7 +2852,7 @@
%
% Newer versions of \package{ntheorem} require a call to
% \cmd{\theorem@prework} when typesetting theorems. If an older
-% version of \package{ntheorem} if being used, we just \cmd{\let} it
+% version of \package{ntheorem} is being used, we just \cmd{\let} it
% to \cmd{\relax} to make sure it's defined.
% \begin{macrocode}
\@ifundefined{theorem@prework}{\let\theorem@prework\relax}{}