\def\packagedate{2018/03/27}
\def\packageversion{0.21.4}
% \iffalse meta-comment
%
% Package 'cleveref' to use with LaTeX2e
% Copyright 2006--2018 Toby Cubitt
%
% Written and maintained by Toby Cubitt
%
%% This file may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.2
%% of this license or (at your option) any later version.
%% The latest version of this license is in:
%%
%%    http://www.latex-project.org/lppl.txt
%%
%% and version 1.2 or later is part of all distributions of LaTeX
%% version 1999/12/01 or later.
%
% Please send bug reports and suggestions to toby-cleveref@dr-qubit.org
% \fi
%
% \iffalse
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<package>\ProvidesPackage{cleveref}
%<package> [\packagedate\space v\packageversion\space Intelligent cross-referencing]
%
%<*driver>
\documentclass{ltxdoc}
%\documentclass[draft]{ltxdoc}
\usepackage{url}
\usepackage{pifont} % FIXME: find nicer line-continuation symbol than \ding{229}
\usepackage[colorlinks=true,linktocpage=true]{hyperref}
\usepackage[capitalise]{cleveref}
\DisableCrossrefs
\CodelineIndex
\RecordChanges
\setcounter{IndexColumns}{2}
%%\newcommand\package[1]{\texttt{#1.sty}}
\newcommand\package{\texttt}
\newcommand\file{\texttt}
\newcommand\option{\texttt}
\begin{document}
  \DocInput{cleveref.dtx}
\end{document}
%</driver>
% \fi
%
% \CheckSum{19764}
%% \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
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}
%
% \changes{v0.01}{2006/06/29}{Initial version}
% \changes{v0.02}{2007/04/18}{Complete rewrite}
% \changes{v0.03}{2007/04/26}{Added reference ranges}
% \changes{v0.04}{2007/05/26}{Renamed "cleveref" -- first public release}
% \changes{v0.05}{2007/05/31}{Added \option{poorman} option}
% \changes{v0.06}{2007/06/11}{\option{poorman} no longer writes extra
%   .tmp file}
% \changes{v0.07}{2007/06/21}{Allow prevention of reference range
%   collapsing}
% \changes{v0.08}{2007/07/10}%
%   {Made referencing commands robust, improved default formats, made
%   starred versions of referencing commands for hyperref, allowed
%   multiple consecutive empty references in list to prevent range
%   collapsing, and fixed bugs. Phew.}
% \changes{v0.08.1}{2007/08/08}{Bug fixes.}
% \changes{v0.09}{2007/10/29}%
%   {Added an extra conjunction and format component, used when a list
%   only contains a single pair of references or reference
%   sub-lists. Formats are now constructed from customisable
%   components, unless overridden using the old format definition
%   commands.}
% \changes{v0.10}{2007/10/30}%
%   {Allow optional argument to \textbackslash{}label to override
%   reference type. Removed \option{hyperref} and \option{ntheorem}
%   options; support for these and \package{amsmath} is enabled
%   automatically if those packages are loaded.}
% \changes{v0.11}{2007/11/21}{Made referencing aware of appendices.}
% \changes{v0.11.1}{2007/11/29}{Bug fixes.}
% \changes{v0.12}{2009/02/11}{Restore working \textbackslash{}ref* when
%   hyperref is loaded -- first release mirrored on www.dr-qubit.org}
% \changes{v0.13}{2009/04/17}{Finally implemented \option{sort} and
%   \option{compress} package options. Support \package{amsmath}
%   \textbackslash{}tag command. Added \package{babel} support for
%   English, German and French. Added \package{varioref} support.}
% \changes{v0.13.1}{2009/07/01}{Bug fix to \textbackslash{}cref@get*
%   commands to allow fragile and non-expandable commands in label tags.}
% \changes{v0.13.2}{2009/07/26}{Added\newline
%   \textbackslash{}crefrangepreconjunction and
%   \textbackslash{}crefrangepostconjunction commands, needed by some
%   languages (such as Italian). Added \package{babel} support for
%   Spanish and Italian. Added notes about \package{memoir}
%   (in)compatibility.}
% \changes{v0.14}{2009/08/07}{Fixed bug that caused labels containing
%   components with values of 10 or higher to be sorted
%   incorrectly. Fixed \textbackslash{}Cref to no longer capitalise all
%   cross-reference names in a multi-reference, just the first one. Added
%   \option{capitalise} option to force capitalisation everywhere.}
% \changes{v0.14.1}{2009/08/18}{Added support for \package{amsmath}'s
%   subequations environment}
% \changes{v0.14.2}{2009/09/22}{Fixed subequations sorting bug. Fixed bug
%   in \option{poorman} when used without babel. \option{capitalise}
%   option no longer uses \textbackslash{}Cref variant everywhere; it now
%   redefines the \textbackslash{}cref variants instead.}
% \changes{v0.14.3}{2009/10/17}{Bug-fix in \textbackslash{}appendix
%   code.}
% \changes{v0.15}{2009/11/26}{Added \package{amsthm} support, contributed
%   by Michael Ummels. Added \textbackslash{}leavevmode before
%   \textbackslash{}begingroup in \textbackslash{}@cref to avoid subtle
%   bug that caused page count to be reset if the output routine was
%   triggered within \textbackslash{}@cref.}
% \changes{v0.15.1}{2009/12/02}{Fixed regression introduced in v0.13 in
%   non-\package{hyperref} \option{poorman} code. Fixed bug in
%   \package{varioref} support that caused \textbackslash{}vref to print
%   \textbackslash{}reftextcurrent string for references on the current
%   page, breaking \package{varioref} backwards-compatibility. Added
%   \package{babel} support for Dutch.}
% \changes{v0.15.2}{2009/12/07}{Fixed bug in \textbackslash{}appendix
%   that produced badly formed prefix data for labels that aren't reset
%   by other counters (e.g.\ tables and figures in most document
%   classes). Fixed bug in \package{hyperref} \option{poorman} code that
%   caused all label names to be lower-cased in the sed script. Fixed
%   spacing bugs in the \package{cleveref} versions of the
%   \package{varioref} commands.}
% \changes{v0.15.3}{2009/12/11}{Fixed bug in \package{varioref} support.
%   Changed \option{poorman} \textbackslash{}usepackage sed substitution
%   rule to use POSIX regexp syntax.}
% \changes{v0.16}{2010/04/19}{Major changes to the low-level
%   implementation! \package{cleveref} now stores the extra information
%   it requires in its own \textbackslash{}cref@currentlabel and its own
%   parallel series of labels in the aux file, staying out of the way of
%   the standard cross-reference mechanism and \textbackslash{}ref
%   command. Also added \textbackslash{}namecref and
%   \textbackslash{}nameCref commands, fixed a serious bug in the
%   \package{amsmath} support affecting spacing of multi-line equation
%   environments, added support for footnotes, and made
%   \textbackslash{}newtheorem automatically define the singular form of
%   the cross-reference name for new theorem-like environments.}
% \changes{v0.16.1}{2010/04/30}{Fixed bugs in \package{amsmath} spacing
%   fix and \package{amsthm} support.}
% \changes{v0.16.2}{2010/05/12}{Fixed bugs in \textbackslash{}appendix
%   version used with \package{hyperref}, and in \textbackslash{}footnote
%   support.}
% \changes{v0.16.3}{2010/05/25}{Added missing \textbackslash{}namecrefs
%   and \textbackslash{}nameCrefs commands. Fixed bug in
%   \textbackslash{}AtBeginDocument code used to define
%   \textbackslash{}cref<x>groupconjunction macros. Added missing
%   \textbackslash{}crefname definitions for subsection, subsubsection
%   etc. in terms of those for section, so that \textbackslash{}namecref
%   works for those (and also switching language in the middle of a
%   document). Added \package{babel} support for Russian and Ukrainian.
%   Fixed bug in \textbackslash{}refstepcounter@optarg.}
% \changes{v0.17}{2010/06/07}{Fixed bug in non-\package{hyperref}
%   version of \textbackslash{}refstepcounter. Added
%   \textbackslash{}crefalias command for aliasing a counter to a
%   different cross-reference type. Added support for \package{algorithm}
%   package. Improved support for \package{subfig} package. Added support
%   for \package{listings} package. Fixed bugs in \package{amsmath}
%   \textbackslash{}tag command when used with \option{sort} option, and
%   in the \package{amsmath} multline environment's support for the
%   optional argument to \textbackslash{}label.}
% \changes{v0.17.1}{2010/06/24}{Modified \textbackslash{}@crefname macro
%   so that it no longer makes global definitions, to fix support for
%   \package{babel}'s \textbackslash{}otherlanguage and
%   \textbackslash{}foreignlanguage commands. Fixed typos in
%   \option{poorman} \textbackslash{}foreignlanguage code. Fixed bug in
%   the \package{amsmath} multline environment's support for the optional
%   argument to \textbackslash{}label\dots{} again. Added
%   \textbackslash{}labelcref command.}
% \changes{v0.17.2}{2010/07/24}{Removed unneeded argument from
%   \textbackslash{}@footnotetext redefinition, to improve compatibility
%   with other packages that redefine footnotes.}
% \changes{v0.17.3}{2010/08/30}{Added missing default format definitions
%   for ``part''. Fixed bad active character interaction between
%   \package{cleveref} and some \package{babel} languages (in particular
%   Spanish). Fixed \package{hyperref} support code so
%   that it is only enabled if \package{hyperref} was loaded with the
%   \option{implicit} option set to \option{true} (the default).}
% \changes{v0.17.4}{2010/09/04}{Added automatic support for
%   \package{aliascnt} counters whose parent counter gets reset. Fixed
%   serious bug in the test for \package{hyperref}'s \option{implicit}
%   options.}
% \changes{v0.17.5}{2010/09/15}{Fixed bug that broke compilation of
%   documents that didn't use \package{hyperref}, because
%   \textbackslash{}if@cref@hyperrefloaded was not defined.}
% \changes{v0.17.6}{2011/01/05}{Added \package{babel} support for
%   Norwegian. Replaced ``appendice'' with ``annexe'' in French default
%   cross-reference names, to match \package{babel} names. Replaced
%   ``Linie'' with ``Zeile'' in the German default cross-reference names.
%   Added \textbackslash{}lcnamecref and \textbackslash{}lcnamecrefs
%   commands to force lowercase reference names, useful with the
%   \option{capitalise} option.}
% \changes{v0.17.7}{2011/01/10}{Fixed \textbackslash{}crefname to work
%   with empty reference names.}
% \changes{v0.17.8}{2011/01/19}{Fixed automatic
%   \textbackslash{}newtheorem name definitions to work with empty
%   names.}
% \changes{v0.17.9}{2011/03/22}{Added support for \package{algorithm2e}
%   package. Added missing \textbackslash{}crefname definitions for
%   `listing'. Changed case used in plural forms in Norwegian. Fixed bug
%   in redefinition of \package{amsmath} \textbackslash{}tag command.
%   Added \package{babel} support for Danish. Renamed internal
%   \textbackslash{}@result macro to \textbackslash{}cref@result to avoid
%   conflict with \package{tikz-qtree} package. Also renamed internal
%   \textbackslash{}@temp<x> macros to \textbackslash{}@temp<x>, which
%   seems to be more standard for temporary macros, to mitigate against
%   similar (though less likely) conflicts, and also save a minuscule
%   amount of \TeX{} memory.}
% \changes{v0.17.10}{2011/04/16}{Fixed bug in
%   \textbackslash{}@cref@stack@insert caused by a temporary macro name
%   clash.}
% \changes{v0.18}{2011/10/24}{Implemented clever page referencing via
%   \textbackslash{}cpageref et al.\ commands, which supports
%   multi-references, including sorting and page range collapsing.
%   Improved \package{varioref} support, combining \package{varioref} and
%   (new) \package{cleveref} page-referencing features. Removed
%   \option{legacyvarioref} option. Fixed bug in
%   \textbackslash{}newtheorem support. Documented \package{mathtools}
%   \option{showonlyrefs} incompatibility. Fixed some of the Spanish and
%   German translations. Implemented \option{nameinlink} option, to
%   include cross-reference names in hyperlinks when using
%   \package{hyperref}. Implemented \option{noabbrev} option to disable
%   all use of abbreviations in default cross-reference names. Added
%   support for a \file{cleveref.cfg} file, which is loaded after the
%   rest of \package{cleveref} has loaded. Made cross-references to
%   sections work correctly when using the \package{revtex4} or
%   \package{revtex4-1} docclasses. Fixed \package{subfig} and
%   \package{caption} compatibility with optional argument to
%   \textbackslash{}label.}
% \changes{v0.18.1}{2011/12/24}{Fixed compatibility with newer versions
%   of \package{caption} package.}
% \changes{v0.18.2}{2012/01/17}{Don't try to redefine
%   \textbackslash{}appendix if it's not defined in current document
%   class. Fixed bug in \textbackslash{}@setnamecref. Refactored common
%   code in format-definition macros into separate
%   \textbackslash{}cref@othervariant macro. Added
%   \package{IEEEtrantools} support.}
% \changes{v0.18.3}{2012/01/18}{Fixed bugs with multiple equations and
%   subequations in an \textbackslash{}IEEEeqnarray.}
% \changes{v0.18.4}{2012/01/23}{Set \textbackslash{}cref@currentlabel
%   locally instead of globally, to match how
%   \textbackslash{}@currentlabel is set. Fix \package{xr} compatibility
%   by adding a ``cref'' suffix  to \package{cleveref}'s internal label
%   names, instead of a prefix.}
% \changes{v0.18.5}{2012/03/05}{Fixed \package{listings} and
%   \package{algorithm} package support, broken by change to local rather
%   than global \textbackslash{}cref@currentlabel definitions. Fixed
%   compatibility with \package{memoir}'s internal \package{subfig}
%   re-implementation.}
% \changes{v0.18.6}{2012/09/25}{Sorted out \package{algorithm} and
%   \package{algorithmicx} package support. Note: \package{algorithmic}
%   package is \emph{not} supported. Fixed compatibility with
%   \package{bigfoot} package. Added support for \package{polyglossia}
%   package. Mentioned \package{autonum} as a possible replacement for
%   (incompatible) \option{showonlyrefs} option to \package{mathtools}
%   package.}
% \changes{v0.18.7}{2012/10/04}{Fixed regression in \package{varioref}
%   support that once again (see v0.15.1) caused \textbackslash{}vref to
%   print \textbackslash{}reftextcurrent string for references on the
%   current page. Fixed regression(?) causing spurious whitespace to be
%   produced for empty cross-reference names (see v0.17.7).}
% \changes{v0.18.8}{2013/03/22}{Fixed automatic
%   \textbackslash{}newtheorem definitions in \package{amsthm} support.
%   Add Swedish and Brazilian translations. Fix bug in
%   \package{algorithm2e} + \package{hyperref} support.}
% \changes{v0.18.9}{2013/03/22}{Fixed regression that broke
%   \option{nameinlink} option.}
% \changes{v0.19}{2013/12/28}{Added \package{breqn} package support.
%   Remove unwanted spaces in some macros. Added abbreviation for
%   ``Abbildung'' to German translations. Added \package{xr-hyper}
%   package support. Fixed bug in \package{amsmath} \textbackslash{}tag
%   support. Added \textbackslash{}crefstripprefix utility macro and
%   example usage. Added separate \texttt{subequation} cross-reference
%   type.}
% \changes{v0.19.1}{2014/08/14}{Fixed bug in \textbackslash{}labelcref
%   format customization. Fixed subtle \textbackslash{}varioref bug
%   caused by a stray \%. Fixed typo in Swedish translations. Fix
%   \textbackslash{}setcrefrange to use same test for matching reference
%   types \textbackslash{}cref@processgroup and
%   \textbackslash{}cref@processgroupall.}
% \changes{v0.19.2}{2015/11/18}{Fixed compatibility with REFTeX
%   \textbackslash{}appendix* command. Added catalan language support.
%   Fix \textbackslash{}@bsphack/\textbackslash{}@esphack spacing issues
%   in \textbackslash{}label refefinitions. Fix \textbackslash{}crefalias
%   mechanism in \package{hyperref} support. Fix bugs in \package{breqn}
%   and \package{varioref} support. Ensure any undefined
%   \textbackslash{}labelcref formats for sub-types (subsections,
%   subequations etc.) are copied from parent types. (This fixes missing
%   brackets around \textbackslash{}labelcref subequation references.)}
% \changes{v0.20}{2016/08/10}{Fix erroneous \%'s after
%   \textbackslash{}advance which broke \package{varioref} support.
%   Add \textbackslash{}cref@ifstreq utility macro for
%   catcode-independent string comparison.
%   Fix sorting of enum\meta{x} labels.}
% \changes{v0.21}{2017/07/10}{Add \texttt{cref@} prefix to
%   \textbackslash{}gobble@optarg to avoid conflicts with other packages.
%   Compress away duplicate references in \textbackslash{}cref etc.\ just
%   as we already did for \textbackslash{}cpageref. Fix
%   \textbackslash{}cpageref error on non-arabic page numbers. Fix bug
%   that disabled warning on more than one reference type within a
%   \textbackslash{}labelcref. Refactor \textbackslash{}cpageref to use
%   same machinery as \textbackslash{}cref, treating different page
%   numbering schemes within a document as different page number
%   ``types''. Refactor and simplify main \textbackslash{}@cref macro.
%   Fix compatibility with newer IEEEtrantools versions. Fix subtle
%   bug in \package{amsmath}$+$\package{hyperref} subequations support,
%   which made hyperlinks point to wrong location in \emph{all} equations
%   following the first use of subequations in a document.}
% \changes{v0.21.1}{2018/02/08}{Fix bug in \package{hyperref}
%   \textbackslash{}cpagerefrange support. Disable \package{hyperref}
%   support when \package{hyperref} is loaded with implicit=false option,
%   and generate a warning that this situation is unsupported. Fix bug
%   that broke \texttt{compress} option.}
% \changes{v0.21.2}{2018/02/09}{Fix bug in undefined reference warning
%   message printed by \textbackslash{}namecref etc., and note in the
%   documentation that these commands only accept a single reference.
%   Add support for \textbackslash{}crefalias'ing of appendix reference
%   types.}
% \changes{v0.21.3}{2018/03/03}{Fix bug in \package{hyperref}-support
%   version of \textbackslash{}cpageref. Fix spelling mistakes in Dutch
%   translations. Add additional advanced cross-reference formatting
%   example to manual. Modify \textbackslash{}@crefcopyformats so it
%   copys over format \emph{components}, rather than copying over the
%   low-level format definitions.}
% \changes{v0.21.4}{2018/03/27}{Make subsubsection/subsubappendix formats
%   inherit from subsection/subappendix rather than section/appendix.
%   Modify \textbackslash{}@crefcopyformats to copy over low-level
%   formats again \emph{if} no components have have been customised.
%   Improve explanation of sub-format inheritance in the manual.}
%
% \GetFileInfo{cleveref.sty}
%
%
% \title{The \package{cleveref} package\thanks{This document
%     corresponds to \textsf{cleveref}~\packageversion, dated
%     \packagedate.}}
% \author{Toby Cubitt \\
% \href{mailto:toby-cleveref@dr-qubit.org}{toby-cleveref@dr-qubit.org}}
% \date{\packagedate}
%
% \maketitle
%
% \begin{abstract}
%   The \package{cleveref} package enhances \LaTeX{}'s cross-referencing
%   features,\linebreak[4] allowing the format of cross-references to be
%   determined automatically according to the ``type'' of cross-reference
%   (equation, section, etc.) and the context in which the
%   cross-reference is used. The formatting for each cross-reference type
%   can be fully customised in the preamble of your document. In
%   addition, \package{cleveref} can typeset cross-references to lists
%   of multiple labels, automatically formatting them according to their
%   types, sorting them, and compressing sequences of numerically
%   consecutive labels. Again, the multiple-reference formatting is fully
%   customisable.
%
%   Normally, the latest version of the \package{cleveref} package is
%   available via CTAN.\ Occasionally, slightly newer ``pre-release''
%   versions are available at \url{www.dr-qubit.org/latex.php#cleveref} a
%   little before they make their way onto CTAN.
% \end{abstract}
%
% \clearpage
% \tableofcontents
% \clearpage
%
%
% \section{Introduction}
% When ``clever'' is used in the name of a computer program, it usually
% indicates that the programmer is overly smug about his own
% achievements. But at the heart of the \LaTeX{} philosophy also lies the
% idea that it is clever to delegate as much of the typesetting as
% possible to the computer, in order to achieve a beautiful --- and above
% all consistent --- visual appearance.
%
% All of this probably applies to the \package{cleveref} package. Its
% goals are two-fold: to exploit all the information that \LaTeX{} can
% collect about labels as intelligently as possible (clever processing),
% allowing you to produce an attractive, consistent formatting of
% cross-references throughout your document with the minimum of effort
% (you'd be clever to use it!).
%
% The \package{cleveref} package enhances \LaTeX{}'s cross-referencing
% features by automatically formatting cross-references depending on what
% they refer to (chapter, section, equation, theorem, etc.). It can
% automatically format cross-references to multiple labels, and can sort
% lists of multiple cross-references, compresses consecutive labels into
% a reference range, and all kinds of other clever wizardry. It also does
% similar things with page references.
%
% In standard \LaTeX{}, you have almost certainly found yourself writing
% things like |Eq.~(\ref{eq1})| and |Theorems~\ref{thm1} to~\ref{thm3}|
% over and over again. Tedium isn't the only downside to this. What
% happens if you later decide you want equation references to be typeset
% as |Equation~\ref{eq1}| instead (i.e.\ without the abbreviation and
% without the parentheses)? What happens if you decide to change the
% theorem labelled |thm1| into a lemma?\footnote{Note that to allow
% \package{cleveref} to automatically infer the type of theorem, you need
% to load either the \package{ntheorem} or the \package{amsthm} package.
% See \cref{sec:non-bugs} for more details.} What if you move |thm3| so
% that it appears (and is numbered) before |thm1|, meaning that
% references to the sequence of theorems 1 through 3 should now be
% ordered |Theorems~\ref{thm3} to~\ref{thm1}| (i.e.\ the other way
% around)? What if you decide you prefer references to multiple theorems
% to be written as |Theorems~\ref{thm1}--\ref{thm3}|? Any such change
% requires you to search through the entire \LaTeX{} source of your
% document, modifying all references to equations, updating all
% references to |thm1|, re-ordering all references to |thm1| and |thm3|,
% and changing all the formatting of references to multiple theorems.
%
% The \package{cleveref} package allows you to define the format for the
% different types of cross-references once-and-for-all in the preamble of
% your document. (Of course, sane default formats are provided, so you
% only have to redefine the format if you don't like the default for a
% particular cross-reference type.) If you later decide to change the
% format of equation references, you only have to change one preamble
% definition. If you change a theorem into a lemma, you don't need to
% change any cross-references at all, because \package{cleveref} will
% automatically use the appropriate name when typesetting any
% cross-references to it. This makes it far easier to typeset
% cross-references uniformly across your whole document, as well as
% avoiding repetitively typing similar text for each and every
% cross-reference.
%
%
%
% \section{Usage}
% The \package{cleveref} package is loaded in the usual way, by putting
% the line
% \begin{quote}
%   |\usepackage{cleveref}|
% \end{quote}
% in your document's preamble. However, care must be taken when using
% \package{cleveref} in conjunction with other packages that modify
% \LaTeX{}'s referencing system (see
% \cref{sec:other_packages}). Basically, \package{cleveref} must be
% loaded \emph{last}.
%
% 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,
% 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 the |\crefrange| command: |\crefrange{eq1}{eq5}| produces
% |eqs.~(1) to~(5)|. If you want to refer to multiple things at once, you
% can simply throw them all into one cross-reference and leave
% \package{cleveref} to sort it out: e.g.\
% |\cref{eq2,eq1,eq3,eq5,thm2,def1}| produces%
% |eqs.~(1) to~(3) and~(5),| |theorem~5, and definition~1|. Finally, if
% you want a page reference, use |\cpageref| (and don't write ``page'' in
% front), if you want a page range, use |\cpagerefrange|, and if you want
% to refer to multiple pages, simply throw them all into a single
% |\cpageref|. Just as with |\cref| (above), \package{cleveref} will sort
% it all out for you automaticaly.
%
% \package{Cleveref} supports a number of languages other than English,
% and also supports the \package{babel} and \package{polyglossia}
% packages for those languages. Either pass the desired language as an
% option to \package{cleveref}, or pass it as a global option to
% |\documentclass|. Note that if you're writing in a language in which
% nouns decline, the |\cref| and |\cpageref| commands may be less useful,
% as they always produce the cross-reference name in the nominative
% case.\footnote{Providing separate variants of the \package{cleveref}
% commands for each noun case quickly becomes more cumbersome than just
% typing the cross-reference name by hand. Trying to determine the
% appropriate case automatically would be tantamount to solving the full
% natural-language processing problem in \package{cleveref}. Check back
% in a century or so for this feature.} In such languages, you may
% instead prefer to use the |\labelcref| and |\labelcpageref| commands.
% Unlike |\cref| and |\cpageref|, these don't produce the name in front
% of the cross-reference, so you must supply it (in the appropriate case)
% yourself. But they do still cope with multi-references, so you still
% gain some benefit from using \package{cleveref}.
%
%
%
% \section{Comparison with Other Packages}
% Given how useful automated cross-reference typesetting is, there are
% naturally a number of other \LaTeX{} packages with similar goals to
% \package{cleveref}, most notably \package{varioref},
% \package{fancyref}, \package{hyperref}'s |\autoref| command, and (for
% theorem-like environments) \package{ntheorem} with the \option{thref}
% option. (There are many others, but these come closest to providing
% similar features to \package{cleveref}.) However, all have certain
% deficiencies which \package{cleveref} attempts to overcome.
%
% The \package{fancyref} package doesn't automatically determine the type
% of thing being referred to. Instead, it relies on you adhering to a
% naming convention for labels. This is usually a good idea in any case,
% but it can occasionally be inconvenient. For example, if you change a
% theorem into a lemma, you have to change the label name, and therefore
% also all cross-references to it. So with \package{fancyref}, you will
% at times be back to searching and replacing label names throughout your
% document. Not to mention missing out on all the other
% \package{cleveref} features, such as automatic sorting and compressing
% of consecutive references, \package{ntheorem} and \package{amsthm}
% support, precise control over hyperlinks, etc.
%
% The enhanced referencing feature provided by the \package{varioref}
% package's\linebreak[4] |\labelformat| command decides how to format
% cross-references when the label is \emph{defined}, rather than when it
% is \emph{referenced}. Often this isn't a problem. But it makes it
% impossible to format cross-references according to the context in which
% they are referenced, which can sometimes be very useful. For example,
% you may want cross-references at the beginning of a sentence formatted
% differently to cross-references in the middle of a sentence. E.g.\ you
% may want to use the abbreviation ``eq.'', but revert to ``Equation'' at
% the beginning of sentences (words at the start of sentences shouldn't
% be abbreviated in English). This is not possible with
% \package{varioref}. Perhaps even more significantly,
% \package{varioref}'s |\labelformat| implementation makes it impossible
% to typeset multiple references automatically; if you want to refer to
% equations |eq1| through |eq3|, with \package{varioref} you are back to
% typing |Eqs.~(\ref{eq1}) to~(\ref{eq3})| by hand. Not to mention
% missing out on all the other \package{cleveref} features. In fact,
% \package{cleveref} fully supports \package{varioref}, taking over
% responsibility for typesetting cross-references, whilst retaining (and
% even enhancing) all the \package{varioref} page-referencing magic.
%
% The \package{hyperref} package's |\autoref| command typesets a name
% before a cross-reference, determined by the cross-reference type. This
% is less flexible than \package{cleveref}'s fully customisable
% cross-reference formatting, but, when combined with \package{varioref},
% the two packages working together come pretty close. But surprisingly,
% even with \package{hyperref}, it is impossible to customise precisely
% which part of the cross-reference is made into a hyperlink in PDF
% documents; this is simple with \package{cleveref}. And it still remains
% impossible to typeset multiple references, have consecutive references
% sorted and compressed automatically, etc.
%
% The \package{ntheorem} package (with the \option{thref} option) does
% the right thing when it comes to how and when the format is
% defined\ldots except that it only works for theorem-like environments.
% It is possible to use it for other environments, but only in a
% bastardized form, by manually supplying an optional argument to every
% |\label| command to specify the label type. \package{Cleveref} works
% equally well with any type of cross-reference, as well as fully
% supporting \package{ntheorem}. And again, \package{cleveref} provides a
% number of additional features over \package{ntheorem}, such as
% multi-references, automatic sorting and compressing of consecutive
% cross-references, control over the placement of hyperlinks, etc.
%
%
%
% \section{Typesetting Cross-References}
% \label{sec:typesetting}
% \DescribeMacro\cref
% To automatically typeset a cross-reference according to the type of
% thing referred to, simply refer to it using |\cref|\marg{label}.
% \package{Cleveref} imposes just one extra restriction on the names of
% labels: they are no longer allowed to contain commas ``,''. These are
% instead used to typeset multiple cross-references (see below).
%
% \DescribeMacro\Cref
% As it is very difficult\footnote{Actually, very likely impossible!} for
% \LaTeX{} to determine whether a cross-reference appears at the
% beginning of a sentence or not, a beginning-of-sentence variant exists:
% |\Cref|\marg{label}. By default, this typesets the cross-reference with
% the first letter capitalised, and without using an abbreviation in
% those cases where the standard variant does use one. (However, the
% formatting of the |\cref| and |\Cref| forms can be fully and
% independently customised, see \cref{sec:customising}.)
%
% \DescribeMacro\crefrange
% \DescribeMacro\Crefrange
% To typeset a cross-reference range, e.g.\ |Eqs.~(1.1) to~(1.5)|,
% use\linebreak[4] |\crefrange| or |\Crefrange| (depending on the
% capitalisation you require), which take the beginning and end of the
% range as arguments:
% \begin{quote}
%   |\crefrange|\marg{label1}\marg{label2}
% \end{quote}
%
% \DescribeMacro\cref
% \DescribeMacro\Cref
% To typeset multiple cross-references, simply list the labels inside
% the |\cref| or |\Cref| command, separated by commas (recall that you
% are not allowed to use commas in label names when using
% \package{cleveref}):
% \begin{quote}
%   |\cref{|\meta{label1}|,|\meta{label2}|,|\meta{label3}|,|\dots|}|
% \end{quote}
%
% \DescribeMacro{\cref*}
% \DescribeMacro{\Cref*}
% \DescribeMacro{\crefrange*}
% \DescribeMacro{\Crefrange*}
% When \package{cleveref} is used along with the \package{hyperref}
% package (see \cref{sec:customising,sec:other_packages}), additional
% starred variants of all the referencing commands are available. The
% standard referencing commands will make cross-references into
% hyperlinks; the starred variants prevent this, producing the same
% typeset text but without creating hyperlinks.
%
% \DescribeMacro\cpageref
% \DescribeMacro\Cpageref
% To typeset a page reference, use |\cpageref|\marg{label}, which is
% typeset e.g.\ as ``page~3''. At the beginning of a sentence, use
% |\Cpageref| instead. Since page references are always references to,
% well\dots pages, this doesn't gain you so much over |\pageref|. Where
% |\cpageref| comes into its own is in referring to multiple pages:
% \begin{quote}
%   |\cpageref{|\meta{label1}|,|\meta{label2}|,|\meta{label3}|,|\dots|}|
% \end{quote}
% \DescribeMacro\cpagerefrange
% \DescribeMacro\Cpagerefrange
% Predictably enough, |\cpagerefrange| and |\Cpagerefrange| are used to
% typeset references to page ranges:
% \begin{quote}
%   |\cpagerefrange|\marg{label1}\marg{label2}
% \end{quote}
%
% \DescribeMacro\ref
% \DescribeMacro\pageref
% \package{Cleveref} does \emph{not} modify the standard |\ref| or
% |\pageref| commands, so you can still use them to typeset the
% formatted label counter or page number alone, without any additional
% text or formatting.
%
% \DescribeMacro{\namecref}
% \DescribeMacro{\nameCref}
% \DescribeMacro{\lcnamecref}
% \DescribeMacro{\namecrefs}
% \DescribeMacro{\nameCrefs}
% \DescribeMacro{\lcnamecrefs}
% Occasionally, it's useful to produce just the name of a reference,
% without the label itself. For example, if you want to refer to ``this
% section'', but you're not sure whether you might later change the
% section into a chapter, it might be useful to produce just the name
% ``section'' associated with the section's label. If you later change
% the section into a chapter, the text will then automatically change to
% ``this chapter''. The |\namecref| and |\nameCref| do exactly this:
% \begin{quote}
%   |\namecref{sec1}|
% \end{quote}
% is typeset as ``section'' (assuming |sec1| labels a section). The
% |\namecrefs| and |\nameCrefs| commands produce the plural forms. The
% |\lcnamecref| and |\lcnamecrefs| commands force the reference name to
% lowercase, for use when the \option{capitalise} option is enabled (see
% \cref{sec:capitalise}). (When that option is set, |\namecref| produces
% an uppercase reference name.)
%
% Note that all these commands can only be passed a \emph{single}
% reference name; they do \emph{not} accept multi-references like
% |\cref|. (Passing multiple references to these commands would make
% little sense if the references had different types, and is redundant if
% they have the same type.)
%
% There is a slight pitfall that you should be aware of when using the
% |\namecref| commands. They get the reference name from the names
% defined for the label's reference type using |\crefname| or |\Crefname|
% (see \cref{sec:individual_customisation}). The default reference
% formats provide these definitions. However, it is possible to customise
% reference formats using lower-level commands that do not create
% |\crefname| definitions (see \cref{sec:low-level_customisation}). If
% the |\crefname| definitions are missing for a particular reference
% type, |\namecref| and |\nameCref| will produce errors for labels of
% that type. You can fix the error by adding explicit |\crefname|
% definitions for these types.
%
% \DescribeMacro{\labelcref}
% Conversely, it is occasionally convenient to produce just the label
% part of a reference, without the cross-reference name. For example,
% this can be useful when writing in a language in which nouns decline.
% The |\labelcref| command does exactly this, and can also cope with
% multi-references, processing them just as |\cref| does. However, since
% it typesets a multi-reference without any name, \emph{all} labels in a
% |\labelcref| multi-reference \emph{must} be of the same type.
%
% The |\labelcref| command will typeset cross-reference labels using the
% default label format if no type-specific format is defined using
% |\creflabelformat| (see
% \cref{sec:global_customisation,sec:individual_customisation}). Note
% that, if you customise reference formats using the low-level commands,
% you may want to also explicitly define the |\labelcref| formats to
% match, using the |\labelcrefformat| etc.\ commands (see
% \cref{sec:low-level_customisation}).
%
% \DescribeMacro{\labelcpageref}
% Similarly, |\labelcpageref| typesets the page numbers alone, without
% inserting ``page'' in front. Like |\cpageref|, it also handles
% multi-references. Like |\labelcref|, by default |\labelcpageref|
% typesets the page numbers using the default label format, customised
% using |\crefdefaultlabelformat|. If you want to define a separate
% format for |\labelcpageref|, use |\creflabelformat| to customise the
% label format for the ``page'' cross-reference type. (see
% \cref{sec:low-level_customisation}).
%
%
%
% \section{Sorting and Compressing}
% \label{sec:sort&compress}
% When \package{cleveref} typesets lists of multiple cross-references or
% page-references, the default behaviour is to automatically sort the
% list and compress sequences of consecutive cross-references or page
% numbers into a reference range. You can change this behaviour by
% supplying one of the following package options:
% \begin{description}
% \item[\option{sort}] Sort lists of cross-references, but don't compress
%   consecutive references.
% \item[\option{compress}] Compress sequences of consecutive references
%   into a reference range, but don't sort the list of cross-references.
% \item[\option{nosort}] Neither sort lists of cross-references,
%   \emph{nor} compress consecutive references.
% \item[\option{sort\&compress}] Sort lists of cross-references, and
%   compress sequences of consecutive references into a reference
%   range (this is the default).
% \end{description}
%
% Occasionally, you may want to prevent a particular sequence of
% consecutive cross-references from being compressed to a reference
% range, without disabling this feature globally. To achieve this, you
% can separate the cross-references in the list by one or more empty
% references, at the point at which you want to prevent compression. For
% example,
% \begin{quote}
%   |\cref{eq1,eq2,eq3,,eq4}|
% \end{quote}
% will be typeset as
% \begin{quote}
%   eqs.~(1) to~(3) and (4)
% \end{quote}
% or
% \begin{quote}
%   |\cref{eq1,eq2,,eq3,eq4,eq5,,eq6,eq7,eq8}|
% \end{quote}
% will be typeset as
% \begin{quote}
%   eqs.~(1), (2), (3) to~(5) and (6) to~(8)
% \end{quote}
% You can safely put an empty reference between cross-references that
% would never be compressed anyway; it will simply be ignored.
%
% If lists of cross-references are also being sorted (the default), it
% can be a little confusing to work out where the empty reference should
% go in order to prevent compression of a particular consecutive
% sequence. It's best to think of the empty reference as being
% ``attached'' to the cross-reference preceding it. When the list is
% sorted, the empty reference will still appear after the same preceding
% reference, and will prevent it being compressed with any subsequent
% consecutive cross-references. In other words, an empty reference
% ensures that the preceding reference will appear explicitly in the
% final, typeset cross-reference:
% \begin{quote}
%   |\cref{eq3,,eq2,eq1,eq6,eq4,eq5}|
% \end{quote}
% will be typeset as
% \begin{quote}
%   eqs.~(1) to~(3) and (4) to~(6)
% \end{quote}
%
%
%
% \section{Overriding the Cross-Reference Type}
% \label{sec:label_type}
% \DescribeMacro\label
% A label's ``type'' is usually determined by the name of the counter it
% refers to, or in the case of \package{ntheorem} and \package{amsthm}
% theorem-like environments by the environment name. However, sometimes
% it is useful to override the type. \package{Cleveref} provides two
% different mechanisms for accomplishing this.
%
% You can alias a counter to a different cross-reference type using the
% |\crefalias| command:
% \begin{quote}
%   |\crefalias|\marg{counter}\marg{type}
% \end{quote}
% \meta{counter} will then use the cross-reference formatting of
% \meta{type}. This can be useful if you want multiple counters to use
% the same cross-reference format.
%
% Occasionally, you may want to override the cross-reference type for one
% particular label, one-off. You can do this by supplying the desired
% type as an optional argument to the |\label| command:
% \begin{quote}
%   |\label|\oarg{type}\marg{label}
% \end{quote}
%
% One circumstance in which is useful is when you want to define a
% special cross-reference format for certain labels of a given type. By
% supplying a type that doesn't already exist as the optional argument to
% |\label|, you can then define the cross-reference format for that new
% type in whatever way you like, without affecting other cross-references
% of the same type. For example, if a particular equation contains
% multiple expressions and you want it to always be referred to in the
% plural, you could use:
% \begin{quote}
%   |\crefname{pluralequation}{eqs.}{eqs.}|\\
%   \dots\\
%   |\label[pluralequation]{eq1}|
% \end{quote}
% You can of course reuse this format for other plural equations, too.
%
% If you need to do this frequently, it can become tedious specifying 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 label type from the counter
% name, the two counter aliases can have different cross-reference
% formats whilst really being the same counter. You have to somehow
% arrange for the correct counter alias to be used depending on which
% cross-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 cross-reference formats for
% different theorem-like environments,\footnote{This trick seems to
% belong to \LaTeX{} mythology, and certainly isn't my own idea! But I
% haven't been able to definitively track down who originally came up
% with it.} \emph{without} using the \package{amsthm} or
% \package{ntheorem} package (although using one of those packages is a
% better solution if available). For example,
% \begin{quote}
%   |\usepackage{aliascnt}|\\
%   |\usepackage{cleveref}|\\
%   |\newaliascnt{lemma}{theorem}|\\
%   |\newtheorem{lemma}[lemma]{Lemma}|\\
%   |\aliascntresetthe{lemma}|\\
%   |\crefname{lemma}{lemma}{lemmas}|
% \end{quote}
% Note that \package{aliascnt} must be loaded before \package{cleveref},
% and any \cmd{\newaliascnt} commands \emph{must} come \emph{after}
% \package{cleveref} has been loaded.
%
%
%
% \section{Options that Modify the Cross-Reference Format}
%
% \subsection{Capitalising All Cross-Reference Names}
% \label{sec:capitalise}
% \DescribeMacro{capitalise}
% Many authors prefer to always capitalise cross-reference names,
% regardless of where they appear in the sentence, writing Theorem~1 and
% Equation~3 (as opposed to theorem~1 and equation~3). If you count
% yourself among this group, you can pass the \option{capitalise} option
% to the \package{cleveref} package (\option{capitalize} also works).
%
% All the default cross-reference formats will then have the first letter
% capitalised, as will the automatically generated |\cref| variants (see
% \cref{sec:individual_customisation,sec:low-level_customisation}).
% (However, if you explicitly define a |\cref| variant to \emph{not} be
% capitalised, \package{cleveref} will still honour your definition. In
% other words, you're responsible for defining the capitalisation
% correctly in your own format definitions.)
%
% You should \emph{still} use the |\Cref| variants at the beginning of
% sentences, for one thing, because abbreviations should not be used at
% the beginning of a sentence,\footnote{At least in English; I'm not sure
% about other languages.} and for another, in case you later change your
% mind and remove the \option{capitalise} option.
%
%
% \subsection{Including Names in Hyperlink Targets}
% \label{sec:nameinlink}
% \DescribeMacro{nameinlink}
% When using the \package{hyperref} package, \package{cleveref}
% automatically makes all cross-references into hyperlinks to the
% corresponding reference. By default, only the label itself forms part
% of the hyperlink target (i.e.\ the text you can click on to navigate to
% the cross-reference). The cross-reference name is not part of the
% hyperlink. By contrast, \package{hyperref}'s |\autoref| command
% \emph{does} includes the name as part of the hyperlink. If you prefer
% to include the names in the hyperlinks when using \package{cleveref},
% you can pass the \option{nameinlink} option to the \package{cleveref}
% package. (For even more control over the placement of the hyperlink
% target, use the commands for customising the cross-reference format.
% See \cref{sec:customising}.)
%
% However, use of this option is discouraged on stylistic grounds.
% Firstly, when producing PDF output \package{hyperref} by default
% surrounds hyperlinks with red boxes, which looks particularly ugly when
% the entire cross-reference name is surrounded by a red box (though this
% unfortunate default can be changed using \package{hyperref} package
% options; see the \package{hyperref} documentation for details).
% Secondly, and more significantly, when using multi-references only the
% first reference in a group can include the cross-reference name as part
% of its hyperlink target, for obvious reasons. The hyperlink targets for
% the other references in the group will necessarily be just the labels.
% This makes for somewhat non-uniform typesetting of hyperlinks, with the
% first cross-reference in a multi-reference having a much larger
% hyperlink target than the others.
%
%
% \subsection{Abbreviations in Cross-Reference Names}
% \label{sec:noabbrev}
% \DescribeMacro{noabbrev}
% The default cross-reference names for some languages use common
% abbreviations for some of the names (e.g.\ in the default English
% format, |\cref{eq1}| will be typeset as |eq.~(1)|). Some authors may
% prefer to always use the full name, rather than an abbreviation
% (|equation~(1)| instead of |eq.~(1)|). To disable all use of
% abbreviations in the default cross-reference names, pass the
% \option{noabbrev} option to the \package{cleveref} package.
%
% Note that the default names \emph{never} use abbreviations for the
% start-of-sentence variants (|\Cref| etc.)
% This is because in good written English (and likely other languages
% too), abbreviations should never be used at the beginning of a
% sentence. Many of \TeX{}'s default settings (e.g.\ page margins) are
% specifically chosen to encourage good typesetting style.
% \package{Cleveref} tried to follow the same philosophy. If despite this
% you insist on using abbreviations at the start of sentences, you will
% need to customise the start-of-sentence formats yourself.
%
%
%
%
% \section{Customising the Cross-Reference Formats}
% \label{sec:customising}
% The \package{cleveref} package allows you to take full control of the
% typesetting of cross-references, by allowing the formatting to be
% customised. Defaults appropriate for English 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 its name, but even that doesn't make it pretentious enough to use
% ``lemmata'' for the plural of ``lemma''.} and support for a number of
% languages is provided via package options (see
% \cref{sec:language_babel}). But if you don't like the defaults, or are
% writing in a language that is not supported yet,\footnote{Any
% contributions of translations for missing languages are very welcome!
% See \cref{sec:new-features} for information on how to contribute
% translations.} or you need to refer to something for which no default
% format is defined, then you can take charge and define your own
% formats.
%
% If \package{cleveref} encounters a cross-reference to a type it does
% not know, it will produce a ``reference type undefined'' warning, and
% typeset the cross-reference as
% \begin{quote}
%   {\bf ??}~|\ref|\marg{label}
% \end{quote}
% i.e.\ the label counter preceded by a double question mark. The error
% message indicates the name of the unknown cross-reference type, which
% you will then probably want to define. (References to undefined labels
% still produce a ``reference undefined'' warning and appear as a double
% question mark, as usual.)
%
% The cross-reference formats are usually constructed out of components:
% the cross-reference name (different for each type of cross-reference),
% the format for the label itself, and the conjunctions used in reference
% ranges and lists of multiple cross-references. There are two levels of
% customisation: you can either customise the components, or you can take
% full control and override the component-derived format entirely.
%
% \package{Cleveref} treats page references, as produced e.g.\ by
% |\cpageref|, as cross-references with the type ``page''. Therefore, all
% of the mechanisms for customising cross-references apply equally well
% to page references, simply by using ``page'' as the cross-reference
% type.
%
%
% \subsection{Customising the Cross-Reference Components}
% \label{sec:component_customisation}
%
% \subsubsection{Global Customisation}
% \label{sec:global_customisation}
% The global customisation commands affect all cross-reference formats,
% unless they are overridden by lower-level customisation commands.
%
% \DescribeMacro\crefdefaultlabelformat
% The format for the label counter itself can be customised globally
% using
% \begin{quote}
%   |\crefdefaultlabelformat|\marg{format}
% \end{quote}
% The \meta{format} argument can be any valid \LaTeX{} code, though you
% will need to |\protect| fragile commands. It can (and almost certainly
% should!) contain three arguments, |#1|, |#2| and |#3|. The first
% argument is the formatted version of the label counter (e.g.\
% |\thesection|). The other two are used to mark the beginning and end
% of the part of the cross-reference that should form the hyperlink when
% the \package{hyperref} package is used (see
% \cref{sec:other_packages}). For example, if you wanted to surround all
% labels with square brackets, without the square brackets themselves
% being part of the hyperlink, you would need:
% \begin{quote}
%   |\crefdefaultlabelformat{[#2#1#3]}|
% \end{quote}
% The hyperlink arguments |#2| and |#3| \emph{must} appear in that
% order. (Leaving them out completely will not cause an error, but in
% that case no hyperlink will be created when \package{hyperref} is
% used, and there are better ways to achieve this. See
% \cref{sec:typesetting,sec:other_packages}.)
%
% Note that the default format for equation cross-references already
% overrides |\crefdefaultlabelformat| in order to surround the label with
% parentheses, so the redefining |\crefdefaultlabelformat| will have no
% effect on equations. The label format for equations must be customised
% separately if you want to change it (see
% \cref{sec:individual_customisation}).
%
% \DescribeMacro\crefrangeconjunction
% The conjunction used in a reference range can be customised by
% defining |\crefrangeconjunction|:
% \begin{quote}
%   |\newcommand{\crefrangeconjunction}|\marg{conjunction}
% \end{quote}
% It does not have to be an actual conjunction in the linguistic sense,
% e.g.\ it is perfectly reasonable to define it to be an endash
% ``|--|''. |\crefrangeconjunction| is used directly between the start
% and end references in a reference range, without any additional space
% surrounding it, e.g.\ |\crefrange{thm1}{thm2}| is typeset as
% \begin{quote}
%   |theorems~\ref{thm1}\crefrangeconjunction\ref{thm2}|
% \end{quote}
% so you may or may not want to include surrounding space, depending on
% the formatting you desire. For example,
% \begin{quote}
%   |\newcommand{\crefrangeconjunction}{ and~}|
% \end{quote}
% does require surrounding space, whereas
% \begin{quote}
%   |\newcommand{\crefrangeconjunction}{--}|
% \end{quote}
% does not.
%
% \DescribeMacro\crefrangepreconjunction
% \DescribeMacro\crefrangepostconjunction
% There are two other ``conjunction'' commands available for customizing
% the formatting for reference ranges. These are
% |\crefrangepreconjunction| and |\crefrangepostconjunction|, which
% insert text before the first label defining the range, and after the
% second label, respectively. For example, when these commands are
% defined, |\crefrange{thm1}{thm2}| is typeset as
% \begin{quote}
%   |theorems~\crefrangepreconjunction\ref{thm1}|\\
%   | |\ding{229} |\crefrangeconjunction\ref{thm2}\crefrangepostconjunction|
% \end{quote}
% These commands are not used in the default English format definitions,
% but they are needed in some languages to correctly express a range. For
% example, the Italian format defines |\crefrangepreconjunction| to be
% ``da'', so that |\crefrange{thm1}{thm2}| produces
% \begin{quote}
%   |teorema da~\ref{thm1} a~\ref{thm2}|
% \end{quote}
%
% \DescribeMacro\crefpairconjunction
% \DescribeMacro\crefmiddleconjunction
% \DescribeMacro\creflastconjunction
% The conjunctions used in lists of multiple cross-references can be
% customised by defining the commands |\crefpairconjunction|,
% |\crefmiddleconjunction| and |\creflastconjunction|:
% \begin{quote}
%   |\newcommand{\crefpairconjunction}|\marg{conjunction}\\
%   |\newcommand{\crefmiddleconjunction}|\marg{conjunction}\\
%   |\newcommand{\creflastconjunction}|\marg{conjunction}
% \end{quote}
% |\crefpairconjunction| is used when there are only two cross-references
% in the list, |\creflastconjunction| is used between the penultimate and
% final cross-reference in a list of more than two, and
% |\crefmiddleconjunction| is used between all the others. Again, they do
% not have to be conjunctions in the linguistic sense, and the same
% considerations about surrounding space apply as in the case of
% |\crefrangeconjunction|. For example, the default definition of
% |\crefmiddleconjunction| is:
% \begin{quote}
%   |\newcommand{\crefmiddleconjunction}{, }|
% \end{quote}
%
% \DescribeMacro\crefpairgroupconjunction
% \DescribeMacro\crefmiddlegroupconjunction
% \DescribeMacro\creflastgroupconjunction
% By default, the conjunctions used to separate sub-lists of different
% cross-reference types in a multi-reference are identical to those used
% to separate cross-references of the same type.\footnote{More
%   accurately, if you redefine $\backslash$crefpairconjunction etc.\ in
%   your preamble, $\backslash$crefpairgroupconjunction etc.\ are
%   automatically redefined so that they match. (In some languages, the
%   default definition of $\backslash$creflastgroupconjunction has an
%   additional comma lacking in $\backslash$creflastconjunction.)} You
% can override this by defining the conjunction commands
% |\crefpairgroupconjunction|, |\crefmiddlegroupconjunction| and
% |\creflastgroupconjunction|.
%
% For example,
% \begin{quote}
%   |\cref{eq1,eq2,eq3,thm1,thm2,fig1,thm3}|
% \end{quote}
% is typeset as
% \begin{quote}
%   eqs.~(1)|\crefrangeconjunction|(3)|\crefmiddlegroupconjunction|%\\
%   theorems~1|\crefpairconjunction|2|\crefmiddlegroupconjunction|%\\
%   fig.~1|\creflastgroupconjunction{}|theorem~3
% \end{quote}
%
%
% \subsubsection{Customising Individual Cross-Reference Types}
% \label{sec:individual_customisation}
% \DescribeMacro\crefname
% \DescribeMacro\Crefname
% The cross-reference name for a given cross-reference type is customised
% using the |\crefname| and |\Crefname| commands:
% \begin{quote}
%   |\crefname|\marg{type}\marg{singular}\marg{plural}\\
%   |\Crefname|\marg{type}\marg{singular}\marg{plural}
% \end{quote}
% used by the |\cref| and |\Cref| commands, respectively. You must supply
% both \meta{singular} and \meta{plural} forms of the name. If the
% corresponding |\Crefname| is undefined when |\crefname| is called, it
% will automatically define |\Crefname| to be a capitalised version of
% |\crefname|, using |\MakeUppercase|. Conversely, if the corresponding
% |\crefname| is undefined when |\Crefname| is called, it will
% automatically define |\crefname| to be a lower-case version of
% |\Crefname|, using |\MakeLowercase|. Obviously, this will only work
% properly if the names begin with a letter. If the first letter is a
% special character construct, such as an accented character, you will
% need to surround it by braces. If the first thing in the name is
% \emph{not} a letter at all (e.g.\ if it is a \LaTeX{} command), you
% \emph{must} define both capitalisation variants explicitly. Otherwise
% you will get strange and fatal errors when processing the document.
%
% The cross-reference \meta{type} is usually the name of the counter for
% the environment (equation, chapter, section, etc.). The exceptions are
% appendices, labels whose type has been overridden explicitly by
% supplying an optional argument (see \cref{sec:label_type}), and
% theorem-like environments when the \package{ntheorem} of
% \package{amsthm} packages are loaded, for which \meta{type} should
% instead be the environment name (lemma, corollary, definition, etc.)
% even when different environments are part of the same numbering
% sequence. (\package{ntheorem} and \package{amsthm} provide extra
% information about the environment when different theorem-like
% environments share a common counter, which \package{cleveref} makes use
% of to distinguish between them automatically.) In the case of
% appendices, the \meta{type} is ``appendix'' for the top-level
% sectioning command (|\chapter| or |\section|, depending on the document
% class), ``subappendix'' for the sectioning command one level below
% (|\section| or |\subsection|), ``subsubappendix'' for the next level of
% sectioning command, etc.
%
% For convenience, if they have not been otherwise customised by the end
% of the preamble, the cross-reference name (and label format) for
% |subsection| is by default inherited from that of |section|, and that
% of |subsubsection| is inherited from |subsection| (which might itself
% have been inherited from |section|). Similarly for |subappendix|,
% |subsubappendix| and |subsubsubappendix|. The |enumii|, |enumiii|,
% |enumiv| and |enumv| formats each inherit from the preceding one, with
% |enumii| inheriting from |enumi|. Finally, |subfigure|, |subtable| and
% |subequation| inherit from |figure|, |table| and |equation|,
% respectively.
%
% If some of the format components for one of these reference types have
% been customised using high-level customisation commands, any remaining
% components are inherited from the parent type, and the
% cross-reference formats are then defined in terms of those components.
% (In this case, if the format for the parent type has been customised
% using low-level commands, this low-level customisation will \emph{not}
% be inherited.) If \emph{none} of the format components have been
% customised, the whole format is always inherited from the parent type.
%
% \DescribeMacro\creflabelformat
% You may want the label format for a particular cross-reference type to
% differ from the global format set by |\crefdefaultlabelformat| (see
% \cref{sec:global_customisation}). You can do this using
% \begin{quote}
%   |\creflabelformat|\marg{type}\marg{format}
% \end{quote}
% The \meta{type} argument is the cross-reference type to customise, and
% the \meta{format} argument defines the label format for
% cross-references of that type. As in the case of\linebreak[4]
% |\crefdefaultlabelformat|, the latter should contain the three
% arguments |#1|, |#2| and |#3|, the first being the formatted version of
% the label counter, the others determining the beginning and end of the
% portion that becomes a hyperlink when the \package{hyperref} package
% is loaded (see \cref{sec:other_packages}). |#2| and |#3| \emph{must}
% appear in that order.
%
% \DescribeMacro\crefrangelabelformat
% Normally, the start and end references in a reference range are
% typeset using the usual label format (as defined by
% |\crefdefaultlabelformat| or |\creflabelformat|) separated by
% |\crefrangeconjunction| (\cref{sec:global_customisation}). You can
% override this for a given cross-reference type using
% \begin{quote}
%   |\crefrangelabelformat|\marg{type}\marg{format}
% \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 two label counters defining the reference range. The
% next two (|#3| and |#4|) denote the beginning and end of the hyperlink
% for the first reference, the final two (|#5| and |#6|) the hyperlink
% for the second reference. The hyperlink arguments \emph{must} appear
% in order. For example,
% \begin{quote}
%   |\crefrangelabelformat{equation}{(#3#1#4) to~(#5#2#6)}|
% \end{quote}
%
%
% \subsubsection{Automatic \textbackslash\texttt{newtheorem} Definitions}
% \DescribeMacro\newtheorem
% The standard \LaTeX{} |\newtheorem| command for defining new
% theorem-like environments provides enough information to deduce a
% reasonable cross-reference name for the new environment. So
% \package{cleveref} automatically defines an appropriate cross-reference
% name for new theorem-like environments. This automatic definition is
% only used if no default definition is provided by \package{cleveref}
% itself, and if no |\crefname| or |\Crefname| definition is given
% explicitly (see \cref{sec:individual_customisation}).
%
% The caveat with this automatic definition is that, although
% |\newtheorem| essentially provides the singular form of the
% cross-reference name, it doesn't provide the plural form. And there is
% no reliable way of constructing the plural form from the
% singular.\footnote{If you're a native English-speaker, you might think
% that just adding an `s' would work, though a moment's thought will
% provide examples of words where this will fail. If you're a non-English
% speaker, it probably won't even occur to you to claim that plurals can
% reliably be constructed automatically!} Therefore, if the plural form
% is ever required, \package{cleveref} will produce a ``reference type
% undefined'' warning, and typeset the cross-reference where the plural
% form is required as:
% \begin{quote}
%   {\bf ??}~|\ref|\marg{label} \dots
% \end{quote}
% In this case, you will have to provide an explicit |\crefname| or
% |\Crefname| definition yourself, to define the plural form as well as
% the singular form.
%
% Note that this has \emph{nothing whatsoever} to do with automatically
% determining the type of theorem-like environment in a cross-reference!
% For that, you need to load either the \package{ntheorem} or the
% \package{amsthm} package. See \cref{sec:non-bugs} for more details.
%
%
%
% \subsection{Low-Level Customisation: Taking Full Control}
% \label{sec:low-level_customisation}
% If you need more precise control over the cross-reference format than
% is possible by customising the individual components, then you can take
% full control of the format for any given type, overriding the
% component-derived format entirely. The formats for single
% cross-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.
%
% Note that when deciding which cross-references should be grouped
% together for sorting and/or compressing, \package{cleveref} does
% something slightly more complicated than simply checking whether the
% reference types match. In fact, it checks whether the reference
% \emph{formats} match.\footnote{To be precise, \package{cleveref} checks
% whether the $\backslash$|crefformat| definitions match.} This will
% always be the case for cross-references of the same type. But it could
% also be the case for cross-references that have different types, if the
% cross-reference formats happen to be identical.
%
% The reason for doing this is to allow cross-references to e.g.\
% sections and subsections to be grouped together if they have identical
% formats. The default formats for the sectioning commands, figures and
% subfigures, tables and subtables, and enumerated lists are set up in
% this way. If you change any of them using the low-level customisation
% commands, but still want them to be grouped together, then you must
% ensure that the formats are \emph{identical}. (It is \emph{not}
% sufficient for the formats to produce identical typeset text; the
% format definitions must contain identical \LaTeX{} code.)
%
% Note that if you use the low-level customisation commands, you might
% still want to provide |\crefname| and |\Crefname| definitions too, so
% that the |\namecref| commands will work (see \cref{sec:typesetting}).
%
%
% \subsubsection{Single Cross-References}
% \label{sec:ref_format}
% \DescribeMacro\crefformat
% \DescribeMacro\Crefformat
% Cross-reference formats for \emph{single} cross-references are defined
% or redefined using the |\crefformat| and |\Crefformat| commands, which
% are used by the |\cref| and |\Cref| commands respectively. These take
% two arguments: the cross-reference type, and the formatting code:
% \begin{quote}
%   |\crefformat|\marg{type}\marg{format}\\
%   |\Crefformat|\marg{type}\marg{format}
% \end{quote}
% The \meta{type} is usually the name of the counter, except for labels
% whose type has been overridden explicitly (see \cref{sec:label_type}),
% theorem-like environments \emph{when the \package{ntheorem} or
% \package{amsthm} package is loaded}, in which case it is the
% environment name, and appendices. For the latter, the \meta{type} is
% ``appendix'' for the top-level sectioning command (|\chapter| or
% |\section|, depending on the document class), ``subappendix'' for the
% sectioning command one level below (|\section| or |subsection|),
% ``subsubappendix'' for the next level of sectioning command, etc.
%
% As in the case of the |\crefname| and |\Crefname| commands, if the
% corresponding |\Crefformat| is undefined when |\crefformat| is called,
% it will define the |\Crefformat| to produce a capitalised version of
% |\crefformat|, using |\MakeUppercase|. Conversely, if the corresponding
% |\crefformat| is undefined when |\Crefformat| is called, it will define
% the |\crefformat| to produce a lower-case version of |\Crefformat|,
% using |\MakeLowercase|. Obviously, 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 three
% arguments, |#1|, |#2| and |#3|. The first argument is the formatted
% version of the label counter (e.g.\ |\theequation|). The other two are
% used to mark the beginning and end of the part of the cross-reference
% that forms the hyperlink when the \package{hyperref} package is used,
% and \emph{must} appear in that order (see \cref{sec:other_packages}).
%
% As an example,
% \begin{quote}
%   |\crefformat{equation}{Eq.~(#2#1#3)}|
% \end{quote}
% will typeset equation references as
% \begin{quote}
%   Eq.~(\meta{counter})
% \end{quote}
% with the counter (excluding the parentheses) forming the hyperlink.
%
% Note that the hyperlink arguments are \emph{not} letters, so if |#2|
% appears at the beginning of \meta{format}, \package{cleveref} will not
% be able to automatically define the other capitalisation variant
% automatically using |\MakeUppercase| or |\MakeLowercase|. In this case,
% you will have to define both variants separately. For example, if you
% wanted the ``Eq.''\ to be part of the hyperlink, you would have to
% explicitly define:
% \begin{quote}
%   |\crefformat{equation}{#2eq.~(#1)#3}|\\
%   |\Crefformat{equation}{#2Eq.~(#1)#3}|
% \end{quote}
%
%
% \subsubsection{Reference Ranges}
% \label{sec:ref_range_format}
% \DescribeMacro\crefrangeformat
% \DescribeMacro\Crefrangeformat
% The format for reference ranges is defined by |\crefrangeformat|
% and\linebreak[4] |\Crefrangeformat|. Like |\creformat| and
% |\Crefformat|, the commands take two arguments: the cross-reference
% type, and the formatting code.
% \begin{quote}
%   |\crefrangeformat|\marg{type}\marg{format}\\
%   |\Crefrangeformat|\marg{type}\marg{format}
% \end{quote}
% The same comments apply as in the case of single cross-references: the
% \meta{type} is usually the name of the counter, except for appendices,
% labels with explicitly overridden types, and theorem-like environments
% when \package{ntheorem} or \package{amsthm} are loaded. Again, if the
% other-capitalisation variant is not already defined, it will be defined
% automatically.
%
% The \meta{format} argument can again be any valid \LaTeX{} code, with
% fragile commands |\protect|ed. However, this time it should contain
% \emph{six} arguments, |#1|--|#6|. The first two (|#1| and |#2|) are the
% formatted versions of the label counters, the next two (|#3| and |#4|)
% are used to mark the beginning and end of the hyperlink for the first
% cross-reference, and the final two (|#5| and |#6|) mark the beginning
% and end of the second cross-reference's hyperlink.
%
% As an example,
% \begin{quote}
%   |\crefrangeformat{equation}{eqs.~(#3#1#4) to~(#5#2#6)}|
% \end{quote}
% would typeset equation reference ranges as
% \begin{quote}
%   eqs.~(\meta{counter1}) to~(\meta{counter2})
% \end{quote}
% with the counters (excluding the parentheses) forming the hyperlinks.
%
%
% \subsubsection{Multiple Cross-References}
% \label{sec:multiple_ref_format}
% \DescribeMacro\crefmultiformat
% \DescribeMacro\Crefmultiformat
% \DescribeMacro\crefrangemultiformat
% \DescribeMacro\Crefrangemultiformat
% The format for multiple cross-references is defined by
% |\crefmultiformat| and\linebreak[4] |\Crefmultiformat|, and that of
% reference ranges within multiple cross-references by
% |\crefrangemultiformat| and |\Crefrangemultiformat|. Multi-references
% also require \emph{all} the other cross-reference formats to be defined
% (see \cref{sec:ref_format,sec:ref_range_format}), including the single
% reference range formats, even if you never use the |\crefrange| and
% |\Crefrange| commands.
%
% The commands all take five arguments: the cross-reference type, the
% format for the first cross-reference in a list, the format for the
% second cross-reference in a list of two, the format for the middle
% cross-references in a list of more than two, and the format for the
% last cross-reference in a list of more than two.
% \begin{quote}
%   |\crefmultiformat|\marg{type}\marg{first}\marg{second}\marg{middle}\marg{last}\\
%   |\Crefmultiformat|\marg{type}\marg{first}\marg{second}\marg{middle}\marg{last}\\
%   |\crefrangemultiformat|\marg{type}\marg{first}\marg{second}\marg{middle}\marg{last}\\
%   |\Crefrangemultiformat|\marg{type}\marg{first}\marg{second}\marg{middle}\marg{last}
% \end{quote}
%
% The \meta{type} is, as ever, the counter name (except for appendices,
% explicitly overridden label types, and theorem-like environments when
% the \package{ntheorem} or \package{amsthm} packages are loaded). The
% same considerations apply to the formatting arguments \meta{first},
% \meta{second}, \meta{middle} and \meta{last} as for the \meta{format}
% argument of |\crefformat| or |\crefrangeformat|, including the meaning
% of the arguments that should appear in the formatting code (|#1|, |#2|
% and |#3| for |\crefmultiformat| and |\Crefmultiformat|, |#1|--|#6| for
% |\crefrangemultiformat| and |\Crefrangemultiformat|). However, when the
% corresponding other-capitalisation variant is automatically defined,
% only the first letter of the \meta{first} argument is upper- or
% lower-cased; the other arguments are defined to be identical for both
% variants.
%
% Be careful to get the spaces at the beginning and end of the formatting
% code correct: the \meta{first} and \meta{second}, or \meta{first},
% \meta{middle} and \meta{last}, \LaTeX{} code snippets are typeset one
% after another in a multi-reference, with no space separating them. You
% may or may not want spaces at the beginning or end of the formatting
% code, depending on the formatting you desire. For example, in the
% default equation format:
% \begin{quote}
%   |\crefmultiformat{equation}{eqs.~(#2#1#3)}%|\\
%   |  { and~(#2#1#3)}{, (#2#1#3)}{ and~(#2#1#3)}|
% \end{quote}
% the \meta{middle} argument should \emph{not} have a space at the
% beginning, whereas the \meta{second} and \meta{last} arguments
% \emph{should} have a space.
%
%
% \subsubsection{Label Cross-References}
% If you define the format for a particular cross-reference type using
% the low-level customisation commands, and still want to use the
% |\labelcref| command to produce just the label part of the
% cross-reference, then you must also define the appropriate |\labelcref|
% formats for that type. This is done using the |\labelcrefformat|,
% |\labelcrefrangeformat|, |\labelcrefmultiformat| and
% |\labelcrefrangemultiformat| commands. Their syntax is identical to
% that of the corresponding |\crefformat|, |\crefrangmeformat|,
% |\crefmultiformat| or |\crefrangemultiformat| command. Typically, the
% |\labelcref| formats should be defined identically to the standard
% |\cref| formats, except for the \meta{first} part, which should leave
% off the cross-reference name. This is not enforced, however.
%
%
%
% \section{Advanced Cross-Reference Formating}
% When you define a custom cross-reference format using
% |\creflabelformat|, |\creformat| et al.\ (see \cref{sec:customising}),
% you're not merely defining a pattern with placeholders to be filled in.
% You're really defining the body of a LaTeX macro, with the formatted
% labels as arguments. This is a very powerful tool. It means that the
% only limit on how you can process the labels is your ability to code it
% in \TeX{}.\footnote{Since \TeX{} is Turing-complete, that means you
% can do anything you like short of solving the Halting Problem.} Which
% potentially allows for very sophisticated cross-reference formatting.
%
% One example of this is removing common prefixes from reference ranges.
% E.g.\ if you're numbering equations within sections, and |eq1|, |eq2|
% and |eq3| are all in the section 1.2, then you might want to typeset
% |\cref{eq1,eq2,eq3}| as ``eqs.~(1.2.1--3)'' instead of ``eqs.~(1.2.1)
% to~(1.2.3)''. Similarly, if |eq1a|, |eq1b| and |eq1c| are
% \package{amsmath} subequations, you might want to typeset
% |\cref{eq1a,eq1b,eq1c}| as ``eqs.~(1a--c)'' instead of ``eqs.~(1a)
% to~(1c)''.
%
% \package{Cleveref} provides a useful utility macro for this:
% |\crefstripprefix|, which takes two strings as arguments, and returns
% the second one with any common prefix stripped off. (However, the very
% last run of digits or letters in the string is retained in its
% entirety, even if it has a part in common.) With the help of this
% macro, you can produce the desired reference-range formatting with:
% \begin{quote}
%   |\crefrangelabelformat{equation}%|\\
%   |  {(#3#1#4--#5\crefstripprefix{#1}{#2}#6)}|\\
%   |\crefrangelabelformat{subequation}%|\\
%   | {(#3#1#4--#5\crefstripprefix{#1}{#2}#6)}|
% \end{quote}
%
% Similarly, stripping prefixes from multi-references so that e.g.\linebreak
% |\cref{fig1a,fig1b,fig1d}| is typeset as ``figs.~1a, b and d'' instead
% of ``figs.~1a, 1b and 1d'' can be achieved by passing the prefix from
% the first component to the others in an auxiliary macro (called
% |\crefstripprefixinfo| here):
% \begin{quote}
%   |\crefmultiformat{figure}%|\\
%   |  {\edef\crefstripprefixinfo{#1}figs.~#2#1#3}%|\\
%   |  { and~#2\crefstripprefix{\crefstripprefixinfo}{#1}#3}%|\\
%   |  {, #2\crefstripprefix{\crefstripprefixinfo}{#1}#3}%|\\
%   |  {, and~#2\crefstripprefix{\crefstripprefixinfo}{#1}#3}|
% \end{quote}
%
%
% \section{Language, \package{babel} and \package{polyglossia}
%             support}
% \label{sec:language_babel}
% \package{Cleveref} supports different languages via package options, in
% the usual way, though not all languages are supported
% yet.\footnote{Contributions of translations for missing languages are
% very welcome! See \cref{sec:new-features} for information on how to
% contribute translations.} Basic \package{cleveref} language support
% will work even if \package{babel} or \package{polyglossia} are not
% loaded. The only exception currently is Catalan (which requires the
% |\lgem| command provided by these packages).
%
% The \package{babel} package is fully supported if it is loaded,
% allowing you to change the language used in cross-references using the
% \package{babel} language switching commands, such as |\selectlanguage|
% and |\foreignlanguage|. Similar support is provided for the
% \package{polyglossia} babel replacement package.
%
% Note that when using \package{babel}, you still need to tell
% \package{cleveref} which language it should use for the default
% cross-reference formats. It is \emph{not} sufficient to pass the
% language option to \package{babel} alone. You \emph{must} also
% \emph{either} pass the language options to \package{cleveref} package
% directly when loading it:
% \begin{quote}
%   |\usepackage|\oarg{language}|{cleveref}|
% \end{quote}
% \emph{or} (better) specify the desired language globally as a document class
% option:
% \begin{quote}
%   |\documentclass|\oarg{language}\marg{class}\\
%   |\usepackage{babel}|\\
%   |\usepackage{cleveref}|\\
% \end{quote}
% The latter method is strongly recommended. \LaTeX{} automatically
% passes document class options to \emph{every} loaded package. So
% specifying the language as a global option causes the appropriate
% language support to be enabled automatically in every package that
% supports it.
%
% When writing multi-language documents, you may need to specify multiple
% language options in order to load \package{babel} support for all of
% them. In this case, \package{babel} sets the initial document language
% to the \emph{last} language option. (See the \package{babel}
% documentation for more details.) \package{Cleveref} does the same: the
% last language in the option list determines the language for the
% initial cross-reference format definitions; additional language options
% load \package{cleveref} support for switching between those languages.
%
% \package{Polyglossia} uses a different mechanism for selecting and
% loading languages, and ignores package language options entirely. The
% default language must be set using \cmd{\setdefaultlanguage}, and
% additional languages are loaded using \cmd{\setotherlanguage}.
% \package{Cleveref} recognises these commands, so you should \emph{not}
% pass language options to \package{cleveref} when using
% \package{polyglossia}. (Passing language options to \package{cleveref},
% either as package options or global options, will override the default
% language set by \package{polyglossia}'s \cmd{\setdefaultlanguage}.)
% Note that the |\setdefaultlanguage| option \emph{must} come before
% \package{cleveref} is loaded, so that \package{cleveref} knows what
% default language you want. (If you don't do this, \package{cleveref}
% will generate a warning message in the log.)
%
% The \package{babel} and \package{polyglossia} support works by
% redefining the cross-reference names and conjunctions for the default
% cross-reference types. Any customisations you make to the default
% cross-reference names and conjunctions \emph{in the preamble} apply to
% the main language (i.e.\ the last language listed in the options). A
% |\selectlanguage| \package{babel} command (or similar) in the document
% body will override these customisations, replacing them with the
% defaults for the newly selected language. If you later use
% |\selectlanguage| to switch back to the main language, any
% customisations from the preamble will be restored. If you want to
% customise cross-reference names or conjunctions for any language other
% than the main one, you either have to explicitly redefine them after
% every language switching command, or hook the redefinitions into
% \package{babel} or \package{polyglossia}'s language switching
% mechanism. (See section ``Language and \package{babel} Support'' in the
% full implementation documentation, and the \package{babel} or
% \package{polyglossia} package documentation.)
%
% If you have defined formats for new cross-reference types for which no
% defaults are provided, then you're on your own. \package{Cleveref} will
% not know how to redefine them for other languages, and again you will
% have to take care of it yourself, either by explicitly redefining them
% in your document after each language switch, or by hooking the
% redefinitions into \package{babel} or \package{polyglossia}'s language
% switching mechanisms.
%
% On the other hand, since the language switching commands only modify
% the cross-reference components, if you use the low-level customisation
% commands to take full control of the format for a particular
% cross-reference type, then (unless you're careful) you take it out of
% the control of \package{babel} or \package{polyglossia} entirely. If
% you want to use the low-level customisation commands, but \emph{do}
% still want the language switching commands to work, then you have to
% use the component macros in your customised formats. The
% cross-reference names are stored in macros called
% |\cref@|\meta{type}|@name|, |\Cref@|\meta{type}|@name|,
% |\cref@|\meta{type}|@name@plural|, and
% |\Cref@|\meta{type}|@name@plural|. (Note that since these
% macro names contain the ``@'' character, you must use |\makeatletter|
% and |\makeatother| to access them.)
%
% For example, if you wanted to redefine the equation format so that the
% cross-reference name (``equation'') was also part of the
% hyperlink,\footnote{This is merely as an example. Including names in
% hyperlinks is more easily accomplished by setting the
% \option{nameinlink} package option.} but you still want to be able to
% switch language using \package{babel} or \package{polyglossia}, you
% would need something like:
% \begin{quote}
%   |\makeatletter|\\
%   |\crefformat{equation}{#2\cref@equation@name~(#1)#3}|\\
%   \dots\\
%   |\makeatother|
% \end{quote}
% and similarly for |\crefrangeformat|, |\crefmultiformat|,
% |\Crefformat|, etc.
%
% Note that if you define an empty cross-reference name for some type
% using an empty |\crefname|, e.g.\ for equations
% \begin{quote}
%   |\crefname{equation}{}{}|
% \end{quote}
% then the empty cross-reference name will be retained when switching
% languages. This is probably what you want anyway.
%
%
%
% \section{The \file{cleveref.cfg} File}
% If \package{cleveref} finds a \file{cleveref.cfg} file somewhere in the
% \LaTeX{} search path, it automatically loads any definitions found in
% that file. (For details of which directories \LaTeX{} searches, consult
% the documentation for your site's \TeX{} installation.) The main use of
% \file{cleveref.cfg} is to store any cross-reference format
% customisations that you want to use in every document you write, so
% that you don't have to include them explicitly in every document's
% preamble.
%
%
%
% \section{Poor Man's \package{cleveref}}
% Sometimes you may need to send your \LaTeX{} source to someone who
% can't or won't install the \package{cleveref} package themselves. For
% 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 |sed| script will automatically
% be written, containing rules for replacing all the \package{cleveref}
% commands with the \LaTeX{} code that they would produce, and using the
% standard |\ref| command to produce the 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 elsewhere, you can process it through the |sed| script to
% completely remove the \package{cleveref} dependency. The recipient
% won't even realise you used \package{cleveref}!
%
% The |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}
% \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 won't work. (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 in the same way as 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 |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). However, using \package{babel}'s language
% switching commands in a document split across multiple separate source
% files is beyond the capabilities of the \package{poorman} option. You
% will almost certainly need to manually tweak the |sed| script in that
% case.
%
% Note that the \option{poorman} script cannot fully reproduce the
% typesetting of the original \package{cleveref} cross-references in all
% cases.\footnote{At least, not without resorting to inserting low-level
% \LaTeX{} code in your document, which would somewhat defeat the purpose
% of the \option{poorman} option.} In particular, if you're using the
% \package{hyperref} package (see \cref{sec:other_packages}) to turn
% cross-references into hyperlinks, any customisation of hyperlinks will
% be lost. And if you're using the \package{varioref} package (see
% \cref{sec:other_packages}), you may need to manually tweak the spacing
% in front of some of the \package{varioref} commands in the document
% produced by the |sed| script.
%
%
%
% \section{Interaction with Other Packages}
% \label{sec:other_packages}
% The \package{cleveref} package \emph{must} be loaded \emph{after} all
% other packages that don't specifically support it,\footnote{At the time
% of writing, the only packages I'm aware of that should be loaded after
% \package{cleveref} are the \package{hypdvips} and \package{autonum}
% packages.} i.e.\ the
% \begin{quote}
%   |\usepackage{cleveref}|
% \end{quote}
% line should usually be the last |\usepackage| command in your
% document's preamble.
%
% \package{Cleveref} tries as far as possible to minimise its impact on
% the standard \LaTeX{} cross-referencing machinery, allowing it to work
% alongside many of the other packages that also enhance \LaTeX{}'s
% cross-referencing features, though it can occasionally interact badly
% with packages that redefine the same core \LaTeX{} commands. Beyond
% peacefully co-existing with many packages, \package{cleveref} includes
% specific support for a number other packages, allowing it to integrate
% its clever cross-referencing features with the features provided by
% these packages: \package{babel}, \package{polyglossia},
% \package{hyperref}, \package{varioref}, \package{ntheorem},
% \package{amsthm}, \package{aliascnt}, \package{subfig},
% \package{algorithmicx}\footnote{The \package{algorithmic} package is
% \emph{not} supported.}, \package{algorithm2e}, \package{listings}.
%
% \package{Cleveref} implements a significantly enhanced version of the
% features found in the \package{fancyref} package, \package{ntheorem}'s
% \option{thref} option, and \package{varioref}'s |\labelformat| command.
% Although these features may (or may not) work correctly alongside
% \package{cleveref}, there is no good reason to use them when using
% \package{cleveref}, and their use is unsupported. (Note that
% \package{varioref} \emph{is} fully supported by \package{cleveref},
% just that \package{cleveref}'s features supersede \package{varioref}'s
% |\labelformat| feature. Similarly, \package{ntheorem} is fully supported
% and even recommended, only the \option{thref} option is superseded by
% \package{cleveref}.)
%
% \DescribeMacro{\thref}
% \DescribeMacro{\vref}
% \DescribeMacro{\Vref}
% \DescribeMacro{\vrefrange}
% \DescribeMacro{\Vrefrange}
% \DescribeMacro{\fullref}
% \DescribeMacro{\Fullref}
% In fact, if \package{ntheorem} is loaded with the \option{thref}
% option, \package{cleveref} redefines \package{ntheorem}'s |\thref|
% command for you, to be an alias for |\cref|. Similarly, if
% \package{varioref} is loaded, \package{cleveref} redefines the |\vref|,
% |\vrefrange|, |\fullref| commands and variants to instead use the
% \package{cleveref} features for cross-reference formatting, whilst
% retaining all the \package{varioref} page-referencing magic. You can
% continue to use the other \package{varioref} and \package{ntheorem}
% commands (other than |\labelformat| and the \option{thref} option)
% whilst using \package{cleveref}, as long as \package{cleveref} is
% loaded \emph{last}.
%
% \DescribeMacro{\vref*}
% \DescribeMacro{\Vref*}
% \DescribeMacro{\vrefrange*}
% \DescribeMacro{\Vrefrange*}
% \DescribeMacro{\fullref*}
% \DescribeMacro{\Fullref*}
% Note that, whilst in the business of redefining the \package{varioref}
% commands, \package{cleveref} seizes the opportunity to get rid of the
% irritating spacing behaviour of the |\vref| and |\Vref| commands,
% instead making it consistent with the other \package{cleveref}
% cross-referencing commands. This also frees up the starred variants of
% the \package{varioref} commands to be used for suppressing hyperlinks
% when the \package{hyperref} package is loaded, as usual.
% (Unfortunately, due to lack of support for this in \package{varioref},
% the page references will still sometimes be hyperlinks, even when using
% the starred variants. Go bug the \package{varioref} maintainer about
% this if you don't like it.)
%
% \package{Cleveref} is currently incompatible with the
% \package{mathtools} package's\linebreak[4] \option{showonlyrefs}
% option, which automatically labels only those equations that are
% cross-referenced. The \package{autonum} package provides a possible
% alternative, which implements similar features in a
% \package{cleveref}-compatible manner.
%
%
%
% \section{Known Bugs, Non-Bugs, and Possible Improvements}
% \label{sec:known_bugs}
%
% \subsection{Non-Bugs}\label{sec:non-bugs}
% The following are \emph{not} bugs. They are either intentional
% behaviour, unavoidable behaviour, or are caused by \LaTeX{}
% misunderstandings:
% \begin{itemize}
% \item If you are using both \package{varioref} and \package{hyperref},
%   \emph{make sure you are loading them in the correct order}, otherwise
%   cross-references will reference completely the wrong thing
%   \emph{without any warning in the \LaTeX{} output or log!} The
%   packages \emph{must} be loaded in the following order:
%   \package{varioref}, \package{hyperref}, \package{cleveref}.
% \item \package{Cleveref} on its own won't automatically infer the type
%   of theorem-like environment you're referring to in a cross-reference.
%   Cross-references to all theorem-like environments will use the same
%   name, ``theorem''. To allow the theorem type to be determined
%   automatically, you need to load either the \package{ntheorem} or the
%   \package{amsthm} package. Also note that all |\newtheorem|
%   definitions must be placed \emph{after} the \package{cleveref}
%   package is loaded.
% \item Due to the way \TeX{} parses arguments, you have to be a little
%   careful when using |\label| inside an optional argument to another
%   command. |\label|\marg{label} will work, but trying to pass an
%   optional argument |\label|\oarg{type}\marg{label} will fail. If you
%   want to pass an optional argument to |\label| whilst already within
%   an optional argument to some other command, you must surround the
%   entire label command with braces:
%   |{\label|\oarg{type}\marg{label}|}|. This crops up e.g.\ when adding
%   labels to subfigure subcaptions in the \package{memoir} document
%   class. A simpler solution in this particular case is to define the
%   label in the subfigure body, instead of in the subcaption.
% \item \package{Cleveref} will not work properly with the standard
%   \LaTeX{} |eqnarray| environment. There is no intention to fix this.
%   The |eqnarray| environment is poorly implemented, making it difficult
%   to get it to work properly with \package{cleveref}, and it's broken
%   any way. You're \emph{far} better off using the \package{amsmath}
%   replacements, such as |gather|, |align|, |multline| and |split|,
%   which \emph{do} work properly with \package{cleveref}. (See
%   \url{http://www.tug.org/pracjourn/2006-4/madsen/}).
% \item If you are using \package{babel}, you \emph{must still} pass the
%   appropriate language option to \package{cleveref}, as well as to
%   \package{babel}. Passing it to \package{babel} alone is \emph{not}
%   sufficient (you will get the default English cross-reference
%   formats). The best way to set the document language is as a global
%   option in the |\documentclass| line. (This is standard \LaTeX{} and
%   \package{babel} practice -- read up on \LaTeX{}'s option handling for
%   more detail.)
% \item \package{Cleveref} can't cope with active characters being
%   present in cross-reference label names. For example, if French
%   \package{babel} support is loaded, the commonly used ``:'' in label
%   names will often fail, spewing the usual random selection of
%   mysterious \TeX{} errors that accompany such deep-seated errors. The
%   solution is to avoid using active characters in label names. (You may
%   need to consult the \package{babel} documentation to discover which
%   active characters are defined in your language.)
% \item The \option{poorman} |sed| script loses any custom
%   \package{cleveref} hyperlink formatting you might have defined, and
%   does not always reproduce the original spacing around the
%   \package{varioref} commands when \package{varioref} is used. This is
%   not a bug; it is a side-effect of the intended purpose of the
%   \option{poorman} option. The philosophy behind \option{poorman} is to
%   replace \package{cleveref}'s enhanced cross-referencing with standard
%   \LaTeX{} cross-reference commands that are guaranteed to work with
%   any standard \LaTeX{} installation. Although it would be simple to
%   fix these ``bugs'', it's almost certainly impossible without using
%   low-level \LaTeX{} code that is unlikely to be supported by e.g.\
%   academic journals, thereby defeating the whole purpose of the
%   \option{poorman} option.
% \end{itemize}
%
%
% \subsection{Known Bugs and Work-Arounds}
% In rough order of significance:
% \begin{itemize}
% \item When both the \package{amsmath} \emph{and} \package{hyperref}
%   packages are loaded at the same time, the \package{cleveref}
%   cross-referencing commands do not work when used within section
%   titles. If anyone can figure out why, let me know! As a work-around,
%   use |\ref| within section titles when your document uses both
%   \package{amsmath} and \package{hyperref}.
% \item When using \package{varioref} and \package{hyperref} with
%   \package{cleveref}, the \package{cleveref}\linebreak[4]
%   \option{nameinlink} option will not cause the word ``page'' in the
%   page-reference part of a |\vref| (or other \package{varioref})
%   command to be included in the hyperlink, nor will the ``on the
%   previous page'' (or similar) text produced by |\vref| be hyperlinked.
%   This is not strictly speaking a \package{cleveref} issue. It is the
%   normal behaviour of the \package{hyperref}-enhanced version of
%   \package{varioref}'s |\vpageref| command, which \package{cleveref}
%   uses to produce the page references in its enhanced |\vref| command.
%   (This \emph{might} be improved in a future version by partially
%   overriding \package{hyperref}.)
% \item \package{Cleveref} doesn't know about the \package{subfloat}
%   package, so you have to revert to using |\ref| for cross-references
%   to sub-figures. (Might be fixed in a future version.)
% \item The \package{beamer} document class redefines the |\label|
%   command in a particularly devious way that breaks
%   \package{cleveref}'s optional argument to that command. (Might be
%   fixed in a future version.)
% \item \package{Cleveref} is incompatible with the \option{showonlyrefs}
%   option of the \package{mathtools} package, though it should be
%   compatible with the rest of \package{mathtools}. (Might be fixed in a
%   future version.) The \package{autonum} package, which provides
%   similar functionality and \emph{is} designed to be
%   \package{cleveref}-compatible, is a possible alternative.
% \item \package{Cleveref} assumes that counters are only ever reset by
%   the standard sectioning commands (|\chapter|, |\section|, etc.). If
%   this is not the case, the automatic compression of consecutive
%   cross-references into a reference range may be incorrect. Making this
%   more flexible would be a simple task, but so far there doesn't seem
%   to be much need for it.
% \end{itemize}
%
%
% \subsection{Possible New Features and Improvements}
% \label{sec:new-features}
% In no particular order:
% \begin{itemize}
% \item The \option{poorman} option could be enhanced to allow a choice
%   of scripting language rather than just |sed| (e.g.\ |awk|, |perl|,
%   \dots?), but these are unlikely to be much better for those apt to
%   complain about the use of |sed|. The portable option would be to
%   output a \TeX{} ``script'', but this would be \emph{much} more
%   work\footnote{\LaTeX{} \emph{really} isn't suited to that kind of
%   pattern matching task -- just take a look at the code for escaping
%   regexp special characters in this package!} than I'm prepared to
%   invest.
% \item \package{Cleveref} doesn't include support for all languages yet.
%   Any contributions of translations for missing languages are most
%   welcome! If you can contribute definitions for a missing language,
%   ideally you should add them below the existing ones in the
%   implementation (using those as a model), generate a patch against the
%   original \package{cleveref.dtx} file, and send the patch by email to
%   the package author. However, if you don't know how to produce a
%   patch, you can instead just send the translations as a plain text
%   file.
% \end{itemize}
%
%
%
% \section{Thanks}
% A number of people have helped improve \package{cleveref} by
% contributing code and translations. Thanks to Michael Ummels for
% contributing the \package{amsthm} support code, and to Stefan Pinnow,
% Gonzalo Medina, Massimo Redaelli, Philip H\"olzenspies, Aleksander
% Gorohovski, Benjamin H{\o}yer, Johannes Mueller, Paulo Roberto Massa
% Cereda, Simon Sigurdhsson, Rafel Jaume Dey\`a and Eva Bosch Roura for
% contributing translations. Thanks also to Susanna Goldschmidt for
% additional help with the translations.
%
% Many people have suggested improvements or reported bugs -- indeed,
% many have put significant effort into helping investigate and fix them.
% So thanks (in alphabetical order) to: Adrian Knoth, Akim Demaille, Alan
% Munn, Aleksander Gorohovski, Amar Ghaisas, Anand Deopurkar, Andreas
% Haselbacher, Arne Meier, Bas Ploeger, Christian Tuma, Dan Luecking,
% David Gleich, Davide Liessi, Denis Bitouz\'e, Domenic Denicola, Donald
% Ars\-en\-eau, Eric Ahlberg, Frank Mittlebach, Hendrik Maryns, Iain
% Cunningham, Ingolf Becker, James Sharam, Jens Mueller, Joel C.\
% Salomon, Jonas Nyrup, Joris Pinkse, Kristian Debrabant, Leo Shidai Liu,
% Lev Bishop, Mak Trifkovic, Mark Cipolone, Matej Batic, Matt Gately,
% Matthew Skala, Michael Barber, Michael Gorven, Michal Kaut, Mico
% Loretan, Milania, Nicolas Dudebout, Olivier Roy, Patrick H\"acker, Paul
% Gomme, Ricardo de Aldama S\'anchez, Robert Fischer, Sebastian
% \O{}rsted, Simon Spiegel, Stefan Pinnow, Steve Dower, Ted Pavlic,
% Thomas Arildsen, Tobias Jores, Uwe L\"uck and Vadim Makarov for their
% help.
% (If I've inadvertently missed you out, please let me know!)
%
%
% \StopEventually{\clearpage\PrintChanges\clearpage\PrintIndex}
%
%
% \clearpage
% \section{Implementation}
% Essentially, the core of the implementation consists of writing an
% extra piece of information --- the label ``type'' --- to the \file{aux}
% file, and defining \cmd{\cref} commands which use this extra
% information to typeset the cross-reference.
%
% The least invasive previous implementation of this kind of thing seems
% to be that used by the \package{varioref} package. Namely, to redefine
% the \cmd{\refstepcounter} command so that the \cmd{\@currentlabel}
% macro, which usually just contains the typeset version of the counter,
% now contains the additional type information.
%
% However, even less invasive than \package{varioref}'s implementation is
% to leave \cmd{\@currentlabel} alone, and define a new
% \cmd{\cref@currentlabel} macro to hold the extra information. (In fact,
% we store three extra pieces of information: the type, the counter value
% itself, and the value of the counter that causes the label's counter to
% be reset, which we call the ``prefix'' from now on.) The standard
% \cmd{\@currentlabel} contents eventually get written to the \file{aux}
% file as an argument to \cmd{\newlabel} by the usual \LaTeX{} label
% mechanisms. In order to also get the information in
% \cmd{\cref@currentlabel} into the \file{aux} file, we have to redefine
% the \cmd{\label} macro so that it writes \emph{two} \cmd{\newlabel}
% lines to the \file{aux} file for \emph{each} label: the standard one,
% plus an additional one which contains the extra information in
% \cmd{\cref@currentlabel}. The additional \cmd{\newlabel} line has the
% suffix |@cref| added to the label name. Thus the extra information in
% \cmd{\cref@currentlabel} will end up in \cmd{\r@\meta{label}@cref} when
% the \file{aux} file is re-read on the next pass.
%
% Doing things this way involves less hacking to get everything else
% working again, since the standard cross-reference mechanism and
% \cmd{\ref} command are left entirely intact. \package{Cleveref} can
% then do what it likes with its own parallel set of labels, without
% getting in the way of other packages that play around with the
% cross-reference mechanism. The only downside is the additional memory
% resources this uses, but on modern \TeX{} implementations this is
% unlikely to be a problem.
%
%
% \subsection{Redefinitions of \LaTeX{} Kernel Macros}
% \begin{macro}{\refstepcounter}
% \begin{macro}{\cref@currentlabel}
% \begin{macro}{\cref@old@refstepcounter}
%   We store the original \cmd{\refstepcounter} in
%   \cmd{\cref@old@refstepcounter}, then redefine \cmd{\refstepcounter}
%   so that it first calls the old version to define the standard
%   \cmd{\@currentlabel} macro, before defining \package{cleveref}'s
%   \cmd{\cref@currentlabel}, which contains the extra information. The
%   cross-reference ``type'' stored in \cmd{\cref@currentlabel} is usually
%   inferred from the counter. This can be overridden by aliasing the
%   counter name to a different type using \cmd{\crefalias}. The new
%   \cmd{\refstepcounter} can also take an optional argument, which
%   always overrides the type.
%    \begin{macrocode}
\def\cref@currentlabel{}%
\let\cref@old@refstepcounter\refstepcounter%
\def\refstepcounter{%
  \@ifnextchar[{\refstepcounter@optarg}{\refstepcounter@noarg}%]
}%
\def\refstepcounter@noarg#1{%
  \cref@old@refstepcounter{#1}%
  \cref@constructprefix{#1}{\cref@result}%
  \@ifundefined{cref@#1@alias}%
    {\def\@tempa{#1}}%
    {\def\@tempa{\csname cref@#1@alias\endcsname}}%
  \protected@edef\cref@currentlabel{%
    [\@tempa][\arabic{#1}][\cref@result]%
    \csname p@#1\endcsname\csname the#1\endcsname}}%
\def\refstepcounter@optarg[#1]#2{%
  \cref@old@refstepcounter{#2}%
  \cref@constructprefix{#2}{\cref@result}%
  \@ifundefined{cref@#1@alias}%
    {\def\@tempa{#1}}%
    {\def\@tempa{\csname cref@#1@alias\endcsname}}%
  \protected@edef\cref@currentlabel{%
    [\@tempa][\arabic{#2}][\cref@result]%
    \csname p@#2\endcsname\csname the#2\endcsname}}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
% \begin{macro}{\label}
% \begin{macro}{\cref@label}
% \begin{macro}{\label@optarg}
% \begin{macro}{\label@noarg}
%   We redefine the \cmd{\label} command to make it define \emph{two}
%   labels each time it's called: the standard one, and an additional
%   \package{cleveref}-specific one with the suffix |@cref| added to the
%   label name, which contains the extra information from
%   \cmd{\cref@currentlabel}. We call the original \cmd{\label} command,
%   stored in \cmd{\cref@old@label}, to write the standard label to the
%   \file{aux} file. However, to avoid other packages messing around with
%   the content of the parallel set of \package{cleveref}-specific
%   labels, we write those directly to the \file{aux} file ourselves. We
%   also allow \cmd{\label} to take an optional argument which overrides
%   the default reference type in \cmd{\cref@currentlabel}.
%
%   The redefinition of \cmd{\label} has to be postponed until the
%   beginning of the document because some other packages postpone their
%   own \cmd{\label} redefinitions too, and we need to override their
%   redefinitions.
%    \begin{macrocode}
\AtBeginDocument{%
  \let\cref@old@label\label%
  \def\label{\@ifnextchar[\label@optarg\label@noarg}%]
  \let\cref@label\label%
  \def\label@noarg#1{%
    \cref@old@label{#1}%
    \@bsphack%
    \edef\@tempa{{page}{\the\c@page}}%
    \setcounter{page}{1}%
    \edef\@tempb{\thepage}%
    \expandafter\setcounter\@tempa%
    \cref@constructprefix{page}{\cref@result}%
    \protected@write\@auxout{}%
      {\string\newlabel{#1@cref}{{\cref@currentlabel}%
      {[\@tempb][\arabic{page}][\cref@result]\thepage}}}%
    \@esphack}%
  \def\label@optarg[#1]#2{%
    \cref@old@label{#2}%
    \@bsphack%
    \edef\@tempa{{page}{\the\c@page}}%
    \setcounter{page}{1}%
    \edef\@tempb{\thepage}%
    \expandafter\setcounter\@tempa%
    \cref@constructprefix{page}{\cref@result}%
    \protected@edef\cref@currentlabel{%
      \expandafter\cref@override@label@type%
        \cref@currentlabel\@nil{#1}}%
    \protected@write\@auxout{}%
      {\string\newlabel{#2@cref}{{\cref@currentlabel}%
      {[\@tempb][\arabic{page}][\cref@result]\thepage}}}%
    \@esphack}%
}% end of AtBeginDocument
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
% \begin{macro}{\@makefntext}
%   Footnotes don't use the \cmd{\refstepcounter} mechanism, but instead
%   set\linebreak[4] \cmd{\@currentlabel} directly inside the footnote
%   insertion item. Thus we need to explicitly set
%   \cmd{\cref@currentlabel} in footnotes. To avoid the definition
%   spilling out of the footnote, we need to set it inside
%   \cmd{\insert}'s implicit insertion item grouping level. To this end,
%   we add the explicit \cmd{\cref@currentlabel} redefinition to
%   \cmd{\@makefntext}, which gets called from within \cmd{\insert} by
%   both \cmd{\@footnotetext} and \cmd{\@mpfootnotentext}.
%    \begin{macrocode}
\let\cref@old@makefntext\@makefntext%
\long\def\@makefntext{%
  \cref@constructprefix{footnote}{\cref@result}%
  \protected@edef\cref@currentlabel{%
    [footnote][\arabic{footnote}][\cref@result]%
    \p@footnote\@thefnmark}%
  \cref@old@makefntext}%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\newtheorem}
%   A \cmd{\newtheorem} command provides sufficient information to
%   automatically define a reasonable cross-reference name for
%   theorem-like environments (\package{ntheorem}'s \option{thref} does
%   essentially this). So we modify \cmd{\newtheorem} (actually, the
%   lower-level \cmd{\@othm}, \cmd{\@xnthm} and \cmd{\@ynthm} macros) so
%   that it does so. We do this in such a way that default definitions or
%   explicit \cmd{\crefname} definitions for theorem-like environments
%   override those produced automatically by our modified
%   \cmd{\newtheorem}.
%
%   The catch is that, although the \cmd{\newtheorem} command provides
%   the singular form, there's no way of reliably deducing the correct
%   plural form. Rather than implement some half-baked attempt at this
%   which will be wrong more often than it's right (especially in
%   languages other than English) and generally cause more trouble than
%   it's worth, we simply define the singular form but leave the plural
%   form undefined. If the latter is ever needed, it will produce a
%   ``undefined cross-reference type'' warning, prompting the author to
%   provide an appropriate \cmd{\crefname} definition themselves.
%
% \begin{macro}{\@othm}
% \begin{macro}{\@xnthm}
% \begin{macro}{\@ynthm}
%   After sorting out its arguments, \cmd{\newtheorem} calls one of
%   \cmd{\@othm}, \cmd{\@xthm} or \cmd{\@ythm}. We add automatic
%   definitions of \cmd{\cref@\meta{type}@name} and\linebreak[4]
%   \cmd{\Cref@\meta{type}@name} to all three of these, and add the
%   theorem-like environment to the list of cross-reference types that
%   need to be defined from components at |\||begin{document}|. Since we
%   want explicit \cmd{\crefname}'s to override these automatic
%   definitions, we store the definitions in
%   \cmd{\cref@\meta{type}@name@preamble}, which are processed at
%   |\||begin{document}|) if they haven't been overridden. The default
%   definitions also get stored in \cmd{\cref@\meta{type}@name@preamble}
%   later on, so they too will override these automatic definitions,
%   which is what we want.
%
%   All this means that these automatic \cmd{\newtheorem} definitions
%   will only work when \cmd{\newtheorem} is used in the preamble.
%   However, this is also true of (new) cross-reference types defined
%   using \cmd{\crefname}, so it doesn't seem worth the significant
%   effort of getting the automatic definitions to work within the
%   document body.
%    \begin{macrocode}
\let\cref@old@othm\@othm%
\def\@othm#1[#2]#3{%
  \edef\@tempa{\expandafter\noexpand%
    \csname cref@#1@name@preamble\endcsname}%
  \edef\@tempb{\expandafter\noexpand%
    \csname Cref@#1@name@preamble\endcsname}%
  \def\@tempc{#3}%
  \ifx\@tempc\@empty\relax%
    \expandafter\gdef\@tempa{}%
    \expandafter\gdef\@tempb{}%
  \else%
    \if@cref@capitalise%
      \expandafter\expandafter\expandafter\gdef\expandafter%
        \@tempa\expandafter{\MakeUppercase #3}%
    \else%
      \expandafter\expandafter\expandafter\gdef\expandafter%
        \@tempa\expandafter{\MakeLowercase #3}%
    \fi%
    \expandafter\expandafter\expandafter\gdef\expandafter%
      \@tempb\expandafter{\MakeUppercase #3}%
  \fi%
  \cref@stack@add{#1}{\cref@label@types}%
  \cref@old@othm{#1}[#2]{#3}}%
\let\cref@old@xnthm\@xnthm%
\def\@xnthm#1#2[#3]{%
  \edef\@tempa{\expandafter\noexpand%
    \csname cref@#1@name@preamble\endcsname}%
  \edef\@tempb{\expandafter\noexpand%
      \csname Cref@#1@name@preamble\endcsname}%
  \def\@tempc{#2}%
  \ifx\@tempc\@empty\relax%
    \expandafter\gdef\@tempa{}%
    \expandafter\gdef\@tempb{}%
  \else%
    \if@cref@capitalise%
      \expandafter\expandafter\expandafter\gdef\expandafter%
        \@tempa\expandafter{\MakeUppercase #2}%
    \else%
      \expandafter\expandafter\expandafter\gdef\expandafter%
        \@tempa\expandafter{\MakeLowercase #2}%
    \fi%
    \expandafter\expandafter\expandafter\gdef\expandafter%
      \@tempb\expandafter{\MakeUppercase #2}%
  \fi%
  \cref@stack@add{#1}{\cref@label@types}%
  \cref@old@xnthm{#1}{#2}[#3]}%
\let\cref@old@ynthm\@ynthm%
\def\@ynthm#1#2{%
  \edef\@tempa{\expandafter\noexpand%
    \csname cref@#1@name@preamble\endcsname}%
  \edef\@tempb{\expandafter\noexpand%
      \csname Cref@#1@name@preamble\endcsname}%
  \def\@tempc{#2}%
  \ifx\@tempc\@empty\relax%
    \expandafter\gdef\@tempa{}%
    \expandafter\gdef\@tempb{}%
  \else%
    \if@cref@capitalise%
      \expandafter\expandafter\expandafter\gdef\expandafter%
        \@tempa\expandafter{\MakeUppercase #2}%
    \else%
      \expandafter\expandafter\expandafter\gdef\expandafter%
        \@tempa\expandafter{\MakeLowercase #2}%
    \fi%
    \expandafter\expandafter\expandafter\gdef\expandafter%
      \@tempb\expandafter{\MakeUppercase #2}%
  \fi%
  \cref@stack@add{#1}{\cref@label@types}%
  \cref@old@ynthm{#1}{#2}}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
% \begin{macro}{\appendix}
%   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. There are two alternative definitions: one if
%   ``section'' is the top-level sectioning command, and one if
%   ``chapter'' fulfils that role.
%    \begin{macrocode}
\@ifundefined{appendix}{}{%
  \let\cref@old@appendix\appendix%
  \def\appendix{%
    \@ifundefined{chapter}{%
      \gdef\refstepcounter@noarg##1{%
        \cref@old@refstepcounter{##1}%
        \cref@constructprefix{##1}{\cref@result}%
%    \end{macrocode}
%     We add a large value to the front of the counter data, to force
%     references to anything in appendices to be sorted after everything
%     else.
%    \begin{macrocode}
        \ifx\cref@result\@empty%
          \def\cref@result{2147483647}%
        \else%
          \edef\cref@result{2147483647,\cref@result}%
        \fi%
%    \end{macrocode}
%       Override the cross-reference type of sectioning commands.
%    \begin{macrocode}
        \def\@tempa{##1}%
        \def\@tempb{section}%
        \ifx\@tempa\@tempb%
          \@ifundefined{cref@appendix@alias}%
            {\def\@tempa{appendix}}%
            {\def\@tempa{\cref@appendix@alias}}%
          \protected@edef\cref@currentlabel{%
            [\@tempa][\arabic{##1}][\cref@result]%
            \csname p@##1\endcsname\csname the##1\endcsname}%
        \else%
          \def\@tempa{##1}%
          \def\@tempb{subsection}%
          \ifx\@tempa\@tempb%
            \@ifundefined{cref@subappendix@alias}%
              {\def\@tempa{subappendix}}%
              {\def\@tempa{\cref@subappendix@alias}}%
            \protected@edef\cref@currentlabel{%
              [\@tempa][\arabic{##1}][\cref@result]%
              \csname p@##1\endcsname\csname the##1\endcsname}%
          \else%
            \def\@tempa{##1}%
            \def\@tempb{subsubsection}%
            \ifx\@tempa\@tempb%
              \@ifundefined{cref@subsubappendix@alias}%
                {\def\@tempa{subsubappendix}}%
                {\def\@tempa{\cref@subsubappendix@alias}}%
              \protected@edef\cref@currentlabel{%
                [\@tempa][\arabic{##1}][\cref@result]%
                \csname p@##1\endcsname\csname the##1\endcsname}%
            \else%
              \@ifundefined{cref@##1@alias}%
                {\def\@tempa{##1}}%
                {\def\@tempa{\csname cref@##1@alias\endcsname}}%
              \protected@edef\cref@currentlabel{%
                [\@tempa][\arabic{##1}][\cref@result]%
                \csname p@##1\endcsname\csname the##1\endcsname}%
            \fi%
          \fi%
        \fi}%
      \cref@old@appendix%
    }{%
      \def\refstepcounter@noarg##1{%
        \cref@old@refstepcounter{##1}%
        \cref@constructprefix{##1}{\cref@result}%
%    \end{macrocode}
%     Again, the large value added to the front of the counter data forces
%     references to appendix items to be sorted last.
%    \begin{macrocode}
        \ifx\cref@result\@empty%
          \def\cref@result{2147483647}%
        \else%
          \edef\cref@result{2147483647,\cref@result}%
        \fi%
%    \end{macrocode}
%       Override the cross-reference type of sectioning commands.
%    \begin{macrocode}
        \def\@tempa{##1}%
        \def\@tempb{chapter}%
        \ifx\@tempa\@tempb%
          \@ifundefined{cref@appendix@alias}%
            {\def\@tempa{appendix}}%
            {\def\@tempa{\cref@appendix@alias}}%
          \protected@edef\cref@currentlabel{%
            [\@tempa][\arabic{##1}][\cref@result]%
            \csname p@##1\endcsname\csname the##1\endcsname}%
        \else%
          \def\@tempa{##1}%
          \def\@tempb{section}%
          \ifx\@tempa\@tempb%
            \@ifundefined{cref@subappendix@alias}%
              {\def\@tempa{subappendix}}%
              {\def\@tempa{\cref@subappendix@alias}}%
            \protected@edef\cref@currentlabel{%
              [\@tempa][\arabic{##1}][\cref@result]%
              \csname p@##1\endcsname\csname the##1\endcsname}%
          \else%
            \def\@tempa{##1}%
            \def\@tempb{subsection}%
            \ifx\@tempa\@tempb%
              \@ifundefined{cref@subsubappendix@alias}%
                {\def\@tempa{subsubappendix}}%
                {\def\@tempa{\cref@subsubappendix@alias}}%
              \protected@edef\cref@currentlabel{%
                [\@tempa][\arabic{##1}][\cref@result]%
                \csname p@##1\endcsname\csname the##1\endcsname}%
            \else%
              \def\@tempa{##1}%
              \def\@tempb{subsubsection}%
              \ifx\@tempa\@tempb%
                \@ifundefined{cref@subsubappendix@alias}%
                  {\def\@tempa{subsubsubappendix}}%
                  {\def\@tempa{\cref@subsubsubappendix@alias}}%
                \protected@edef\cref@currentlabel{%
                  [\@tempa][\arabic{##1}][\cref@result]%
                  \csname p@##1\endcsname\csname the##1\endcsname}%
              \else%
                \@ifundefined{cref@##1@alias}%
                  {\def\@tempa{##1}}%
                  {\def\@tempa{\csname cref@##1@alias\endcsname}}%
                \protected@edef\cref@currentlabel{%
                  [\@tempa][\arabic{##1}][\cref@result]%
                  \csname p@##1\endcsname\csname the##1\endcsname}%
              \fi%
            \fi%
          \fi%
        \fi}%
    \cref@old@appendix}%
  }%
}% end of \@ifundefined{appendix}
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsection{Utility Macros}
%
% \subsubsection{miscellaneous}
% \begin{macro}{\cref@gobble@optarg}
%   A basic macro that gobbles one argument plus, if present, one
%   optional argument.
%    \begin{macrocode}
\def\cref@gobble@optarg{\@ifnextchar[\@cref@gobble@optarg\cref@gobble}%]
\def\cref@gobble#1{}%
\def\@cref@gobble@optarg[#1]#2{}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cref@append@toks}
%   A basic utility macro for appending tokens to a token register.
%    \begin{macrocode}
\def\cref@append@toks#1#2{\toks0={#2}%
  \edef\act{\noexpand#1={\the#1\the\toks0}}%
  \act}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cref@ifstreq}
%   A utility macro to test string equality in a catcode-independent
%   fashion. Assumes both arguments are fully expandable. Note: using the
%   |\pdfstrcmp| primitive from |pdftex| would be more robust, but we don't
%   want to depend on |pdftex|. This macro suffices for our purposes.
%    \begin{macrocode}
\def\cref@ifstreq#1#2#3#4{%
  \begingroup%
    \edef\@tempa{#1}%
    \edef\@tempb{#2}%
    \expandafter\def\expandafter\@tempa\expandafter{\csname\@tempa\endcsname}%
    \expandafter\def\expandafter\@tempb\expandafter{\csname\@tempb\endcsname}%
    \ifx\@tempa\@tempb%
      \let\@tempc\@firstoftwo%
    \else%
      \let\@tempc\@secondoftwo%
    \fi%
    \expandafter%
  \endgroup%
  \@tempc{#3}{#4}}%
%    \end{macrocode}
% \end{macro}
%
%
% \subsubsection{\file{aux} file information}
% \begin{macro}{\cref@getlabel}
% \begin{macro}{\cref@gettype}
% \begin{macro}{\cref@getcounter}
% \begin{macro}{\cref@getprefix}
%   Define some utility macros for extracting label, type, and counter
%   information from the contents of \cmd{\cref@currentlabel}, as written
%   to the \file{aux} file and stored in \cmd{\r@\meta{label}@cref} when
%   this is re-read on the next pass. Some other packages commandeer the
%   referencing system to write label information to the \file{aux} file
%   for other purposes, and probably use \cmd{\ref} to recover it later.
%   We still want them to work, so our utility macros must cope with the
%   type information being absent. However, since we need them to be
%   fully expandable in various places, and \cmd{\@ifnextchar} is
%   definitely \emph{not} fully expandable, we use the work-around of
%   having the macros store their result in another macro, whose name is
%   passed as the second argument. This other macro \emph{will} then be
%   fully expandable, and can be used e.g.\ inside an \cmd{\edef} or
%   \cmd{\csname}\ldots\cmd{\endcsname}.
%    \begin{macrocode}
\def\cref@getref#1#2{%
  \expandafter\let\expandafter#2\csname r@#1@cref\endcsname%
  \expandafter\expandafter\expandafter\def%
    \expandafter\expandafter\expandafter#2%
    \expandafter\expandafter\expandafter{%
      \expandafter\@firstoftwo#2}}%
\def\cref@getlabel#1#2{%
  \cref@getref{#1}{\@tempa}%
  \expandafter\@cref@getlabel\@tempa\@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{%
  \cref@getref{#1}{\@tempa}%
  \expandafter\@cref@gettype\@tempa\@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{%
  \cref@getref{#1}{\@tempa}%
  \expandafter\@cref@getcounter\@tempa\@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{%
  \cref@getref{#1}{\@tempa}%
  \expandafter\@cref@getprefix\@tempa\@nil#2}%
\def\@cref@getprefix{\@ifnextchar[%]
  \@@cref@getprefix{\@@cref@getprefix[][][]}}%
\def\@@cref@getprefix[#1][#2][#3]#4\@nil#5{\def#5{#3}}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \begin{macro}{\cpageref@getlabel}
% \begin{macro}{\cpageref@gettype}
% \begin{macro}{\cpageref@getcounter}
%   Similarly for the page number information. Here, the information we
%   store in addition to the page label is the page label ``type'' (used
%   to distinguish different page numbering sequences, e.g.\ roman in the
%   front-matter and arabic in the main text), and the numerical value of
%   the page counter.
%    \begin{macrocode}
\def\cpageref@getref#1#2{%
  \expandafter\let\expandafter#2\csname r@#1@cref\endcsname%
  \expandafter\expandafter\expandafter\def%
    \expandafter\expandafter\expandafter#2%
    \expandafter\expandafter\expandafter{%
      \expandafter\@secondoftwo#2}}%
\def\cpageref@getlabel#1#2{%
  \cpageref@getref{#1}{\@tempa}%
  \expandafter\@cpageref@getlabel\@tempa\@nil#2}%
\def\@cpageref@getlabel{\@ifnextchar[%]
  \@@cpageref@getlabel{\@@cpageref@getlabel[][][]}}%
\def\@@cpageref@getlabel[#1][#2][#3]#4\@nil#5{\def#5{#4}}%
\def\cpageref@gettype#1#2{%
  \cpageref@getref{#1}{\@tempa}%
  \expandafter\@cpageref@gettype\@tempa\@nil#2}%
\def\@cpageref@gettype{\@ifnextchar[%]
  \@@cpageref@gettype{\@@cpageref@gettype[][][]}}%
\def\@@cpageref@gettype[#1][#2][#3]#4\@nil#5{\def#5{#1}}%
\def\cpageref@getcounter#1#2{%
  \cpageref@getref{#1}{\@tempa}%
  \expandafter\@cpageref@getcounter\@tempa\@nil#2}%
\def\@cpageref@getcounter{\@ifnextchar[%]
  \@@cpageref@getcounter{\@@cpageref@getcounter[][][]}}%
\def\@@cpageref@getcounter[#1][#2][#3]#4\@nil#5{\def#5{#2}}%
\def\cpageref@getprefix#1#2{%
  \cpageref@getref{#1}{\@tempa}%
  \expandafter\@cpageref@getprefix\@tempa\@nil#2}%
\def\@cpageref@getprefix{\@ifnextchar[%]
  \@@cpageref@getprefix{\@@cpageref@getprefix[][][]}}%
\def\@@cpageref@getprefix[#1][#2][#3]#4\@nil#5{\def#5{#3}}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \cmd{\cref@override@label@type} is a convenience macro for overriding
% the label type stored in \cmd{\cref@currentlabel}.
% \begin{macro}{\cref@override@label@type}
%    \begin{macrocode}
\def\cref@override@label@type[#1][#2][#3]#4\@nil#5{[#5][#2][#3]#4}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cref@constructprefix}
%   The \cmd{\cref@constructprefix} macro constructs the prefix
%   information stored in \cmd{\cref@currentlabel} (retrieved using
%   \cmd{\cref@getprefix}). This information consists of the numerical
%   value of each counter that's involved in resetting the label's
%   counter, i.e.\ it contains the numerical values of the chapter,
%   section, subsection\dots{} numbers that (ought to) make up the
%   formatted label produced by \cmd{\the\meta{counter}}. E.g.\ if
%   \cmd{\theequation} produces ``B.1.3'', this utility macro will return
%   ``2,1'' (the ``3'' corresponds to the equation number itself, which
%   is stored separately in \cmd{\cref@currentlabel}). The first argument
%   is the counter in question; the return value is stored in the second
%   argument, which should be a macro name.
%
%   The real work is done by the recursive \cmd{\@cref@constructprefix}
%   macro, which works its way upwards through the counters' reset lists
%   until it reaches a counter that isn't reset by any other.
%    \begin{macrocode}
\def\cref@constructprefix#1#2{%
  \cref@stack@init{\@tempstack}%
%    \end{macrocode}
% We fully expand the first argument (the counter name) because sometimes
% we get passed a counter name containing a macro.
%    \begin{macrocode}
  \edef\@tempa{\noexpand{#1\noexpand}}%
  \expandafter\def\expandafter\@tempa\expandafter{\@tempa{#2}}%
  \expandafter\@cref@constructprefix\@tempa%
  \cref@stack@to@list{\@tempstack}{\@tempa}%
  \expandafter\def\expandafter#2\expandafter{\@tempa}}%
\def\@cref@constructprefix#1#2{%
  \cref@resetby{#1}{#2}%
  \ifx#2\relax%
  \else%
    \edef\@tempa{\the\csname c@#2\endcsname}%
    \expandafter\cref@stack@push\expandafter{\@tempa}{\@tempstack}%
    \edef\@tempa{{#2}}%
    \expandafter\expandafter\expandafter\@cref@constructprefix%
      \expandafter\@tempa\expandafter{\expandafter#2\expandafter}%
  \fi}%
%    \end{macrocode}
% \end{macro}
%
%
% \subsubsection{Stack data structures}
% \begin{macro}{\cref@stack@init}
% \begin{macro}{\cref@stack@top}
% \begin{macro}{\cref@stack@pop}
% \begin{macro}{\cref@stack@push}
% \begin{macro}{\cref@stack@topandbottom}
% \begin{macro}{\cref@stack@add}
% \begin{macro}{\cref@stack@to@list}
%   We treat multiple references, supplied as a comma-separated list to
%   \cmd{\cref} or \cmd{\Cref}, as a stack structure. So we define some
%   utility macros for manipulating stacks (\cmd{\@nil} is used as an
%   end-of-stack delimiter).
%    \begin{macrocode}
\def\cref@stack@init#1{\def#1{\@nil}}%
\def\cref@stack@top#1{\expandafter\@cref@stack@top#1}%
\def\@cref@stack@top#1,#2\@nil{#1}%
\def\cref@stack@pop#1{\expandafter\@cref@stack@pop#1#1}%
\def\@cref@stack@pop#1,#2\@nil#3{\def#3{#2\@nil}}%
\def\cref@stack@push#1#2{%
  \expandafter\@cref@stack@push\expandafter{#2}{#1}{#2}}%
\def\@cref@stack@push#1#2#3{\def#3{#2,#1}}%
\def\cref@stack@pull#1#2{\expandafter\@cref@stack@pull#2{#1}{#2}}%
\def\@cref@stack@pull#1\@nil#2#3{\def#3{#1#2,\@nil}}%
\def\cref@stack@to@list#1#2{%
  \cref@isstackfull{#1}%
  \if@cref@stackfull%
    \expandafter\expandafter\expandafter\def%
    \expandafter\expandafter\expandafter#2%
    \expandafter\expandafter\expandafter{%
      \expandafter\@cref@stack@to@list#1}%
  \else%
    \def#2{}%
  \fi}%
\def\@cref@stack@to@list#1,\@nil{#1}%
\def\cref@stack@topandbottom#1#2#3{%
  \def#2{}%
  \def#3{}%
  \cref@isstackfull{#1}%
  \if@cref@stackfull%
    \edef#2{\cref@stack@top{#1}}%
    \cref@stack@pop{#1}%
    \cref@isstackfull{#1}%
    \@whilesw\if@cref@stackfull\fi{%
      \edef#3{\cref@stack@top{#1}}%
      \cref@stack@pop{#1}%
      \cref@isstackfull{#1}}%
  \fi}%
\def\cref@stack@add#1#2{%
  \begingroup%
    \def\@arg1{#1}%
    \let\@tempstack#2%
    \newif\if@notthere%
    \@nottheretrue%
    \cref@isstackfull{\@tempstack}%
    \@whilesw\if@cref@stackfull\fi{%
      \edef\@tempb{\cref@stack@top{\@tempstack}}%
      \def\@tempa{#1}%
      \ifx\@tempa\@tempb%
        \@cref@stackfullfalse%
        \@nottherefalse%
      \else%
        \cref@stack@pop{\@tempstack}%
        \cref@isstackfull{\@tempstack}%
      \fi}%
  \expandafter\endgroup%
  \if@notthere\cref@stack@push{#1}{#2}\fi}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\if@cref@stackempty}
% \begin{macro}{\if@cref@stackfull}
% \begin{macro}{\cref@isstackempty}
% \begin{macro}{\cref@isstackfull}
%   The \cmd{\cref@isstackempty} and \cmd{\cref@isstackfull} macros test
%   whether a stack is empty or full, respectively, and set the
%   corresponding conditionals\linebreak[4] |\if@cref@stackempty| and
%   |\if@cref@stackfull|.
%    \begin{macrocode}
\newif\if@cref@stackempty%
\newif\if@cref@stackfull%
\def\cref@isstackempty#1{%
  \def\@tempa{\@nil}%
  \ifx#1\@tempa\@cref@stackemptytrue%
  \else\@cref@stackemptyfalse\fi}%
\def\cref@isstackfull#1{%
  \def\@tempa{\@nil}%
  \ifx#1\@tempa\@cref@stackfullfalse%
  \else\@cref@stackfulltrue\fi}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\cref@stack@dropempty}
%   Drop any empty references from head of a stack.
%    \begin{macrocode}
\def\cref@stack@dropempty#1{%
  \edef\@tempa{\cref@stack@top{#1}}%
  \@whilesw\ifx\@tempa\@empty\fi{%
    \cref@stack@pop{#1}%
    \cref@isstackempty{#1}%
    \if@cref@stackempty%
      \let\@tempa\relax%
    \else%
      \edef\@tempa{\cref@stack@top{#1}}%
    \fi}}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cref@stack@sort}
%   The \cmd{\cref@stack@sort} macro sorts a stack passed in |#2|, using
%   the comparison macro passed in |#1|, which we use later to sort lists
%   of references. We use insertion sort despite its $O(n^2)$ scaling
%   because it's simpler to code, and because we're very unlikely to
%   encounter lists of more than ten or so references, so in practice a
%   more complicated $O(n\log n)$ sorting algorithm will very likely be
%   slower anyway.
%    \begin{macrocode}
\def\cref@stack@sort#1#2{%
  \begingroup%
  \cref@stack@init{\@sortstack}%
%    \end{macrocode}
% Push first element into sorted stack.
%    \begin{macrocode}
  \edef\@element{\cref@stack@top{#2}}%
  \expandafter\cref@stack@push\expandafter{\@element}{\@sortstack}%
  \cref@stack@pop{#2}%
%    \end{macrocode}
% If empty elements follow first one, need to add them after it in sorted
% stack.
%    \begin{macrocode}
  \cref@isstackfull{#2}%
  \if@cref@stackfull%
    \edef\@tempa{\cref@stack@top{#2}}%
    \@whilesw\ifx\@tempa\@empty\fi{%
      \cref@stack@pull{}{\@sortstack}%
      \cref@stack@pop{#2}%
      \cref@isstackempty{#2}%
      \if@cref@stackempty%
        \let\@tempa\relax%
      \else%
        \edef\@tempa{\cref@stack@top{#2}}%
      \fi}%
  \fi%
%    \end{macrocode}
% Process elements from stack.
%    \begin{macrocode}
  \cref@isstackfull{#2}%
  \@whilesw\if@cref@stackfull\fi{%
    \edef\@element{\cref@stack@top{#2}}%
    \cref@stack@pop{#2}%
%    \end{macrocode}
% If empty elements follow current one, need to add them to sorted stack,
% right after element we're currently dealing with.
%    \begin{macrocode}
    \def\@empties{}%
    \cref@isstackfull{#2}%
    \if@cref@stackfull%
      \edef\@tempa{\cref@stack@top{#2}}%
      \@whilesw\ifx\@tempa\@empty\fi{%
        \edef\@empties{\@empties,}%
        \cref@stack@pop{#2}%
        \cref@isstackempty{#2}%
        \if@cref@stackempty%
          \let\@tempa\relax%
        \else%
          \edef\@tempa{\cref@stack@top{#2}}%
        \fi}%
    \fi%
%    \end{macrocode}
% Insert current element into sorted stack, appending any following empty
% elements.
%    \begin{macrocode}
    \edef\@tempa{{\expandafter\noexpand\@element}%
      {\expandafter\noexpand\@empties}%
      {\noexpand\@sortstack}{\noexpand#1}}%
    \expandafter\cref@stack@insert\@tempa%
    \cref@isstackfull{#2}}%
  \expandafter\endgroup\expandafter%
  \def\expandafter#2\expandafter{\@sortstack}}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cref@stack@insert}
%   \cmd{\cref@stack@insert}|{#1}{#2}{#3}{#4}| inserts |#1| into the
%   appropriate location in the sorted stack |#3| (appending |#2| onto
%   the end of |#1| when it's inserted), using the comparison macro |#4|.
%    \begin{macrocode}
\def\cref@stack@insert#1#2#3#4{%
  \let\@cmp#4%
  \@cref@stack@insert{}{#1}{#2}{#3}%
  \cref@stack@pop{#3}}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\@cref@stack@insert}
%   \cmd{\@cref@stack@insert}|{#1}{#2}{#3}{#4}| prepends |#1| to the
%   stack resulting from inserting |#2| (with |#3| appended to it) into
%   the sorted stack |#4|.
%    \begin{macrocode}
\def\@cref@stack@insert#1#2#3#4{%
  \let\cref@iterate\relax%
  \cref@isstackempty{#4}%
  \if@cref@stackempty%
    \cref@stack@push{#1,#2#3}{#4}%
  \else%
    \edef\cref@elem{\cref@stack@top{#4}}%
    \expandafter\@cmp\expandafter{\cref@elem}{#2}{\cref@result}%
    \ifnum\cref@result=2\relax%
      \cref@stack@push{#1,#2#3}{#4}%
    \else%
      \cref@stack@pop{#4}%
      \edef\cref@elem{{\noexpand#1,\cref@elem}{\noexpand#2}%
        {\noexpand#3}{\noexpand#4}}%
      \expandafter\def\expandafter\cref@iterate\expandafter%
        {\expandafter\@cref@stack@insert\cref@elem}%
    \fi%
  \fi%
  \cref@iterate}%
%    \end{macrocode}
% \end{macro}
%
%
% \subsubsection{Reference comparison and sorting}
% \begin{macro}{\cref@isrefsametype}
% \begin{macro}{\if@cref@sametype}
%   Test if two references have same type, and set |\if@cref@sametype|
%   conditional accordingly.
%    \begin{macrocode}
\newif\if@cref@sametype%
\def\cref@isrefsametype#1#2{%
  \begingroup%
%    \end{macrocode}
% Undefined references are treated as different from any other type, but
% the same type as each other.
%    \begin{macrocode}
  \expandafter\ifx\csname r@#1@cref\endcsname\relax%
    \expandafter\ifx\csname r@#2@cref\endcsname\relax%
      \def\@after{\@cref@sametypetrue}%
    \else%
      \def\@after{\@cref@sametypefalse}%
    \fi%
  \else%
    \expandafter\ifx\csname r@#2@cref\endcsname\relax%
      \def\@after{\@cref@sametypefalse}%
%    \end{macrocode}
% To test if two references have the same type, we actually compare the
% expansion of |\cref@|\meta{type}|@format| rather than the \meta{type}
% per se. This allows references with different counters but identical
% formatting (e.g.\ equations and subequations with the default
% formatting) to be typeset as part of the same reference group, which is
% almost always what we want.
%    \begin{macrocode}
    \else%
      \cref@gettype{#1}{\@type}%
      \expandafter\expandafter\expandafter\def%
        \expandafter\expandafter\expandafter\@formata%
        \expandafter\expandafter\expandafter{%
          \csname cref@\@type @format\endcsname%
          {\@dummya}{\@dummyb}{\@dummyc}}%
      \cref@gettype{#2}{\@type}%
      \expandafter\expandafter\expandafter\def%
        \expandafter\expandafter\expandafter\@formatb%
        \expandafter\expandafter\expandafter{%
          \csname cref@\@type @format\endcsname%
          {\@dummya}{\@dummyb}{\@dummyc}}%
      \ifx\@formata\@formatb%
        \def\@after{\@cref@sametypetrue}%
      \else%
        \def\@after{\@cref@sametypefalse}%
      \fi%
    \fi%
  \fi%
  \expandafter\endgroup\@after}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\cpageref@isrefsametype}
%   Test if two page references have same ``type'', and set
%   |\if@cref@sametype| conditional accordingly.
%    \begin{macrocode}
\def\cpageref@isrefsametype#1#2{%
  \begingroup%
%    \end{macrocode}
% Undefined references are treated as different from any other type, but
% the same type as each other.
%    \begin{macrocode}
  \expandafter\ifx\csname r@#1@cref\endcsname\relax%
    \expandafter\ifx\csname r@#2@cref\endcsname\relax%
      \def\@after{\@cref@sametypetrue}%
    \else%
      \def\@after{\@cref@sametypefalse}%
    \fi%
  \else%
    \expandafter\ifx\csname r@#2@cref\endcsname\relax%
      \def\@after{\@cref@sametypefalse}%
    \else%
      \cpageref@gettype{#1}{\@typea}%
      \cpageref@gettype{#2}{\@typeb}%
      \ifx\@typea\@typeb%
        \def\@after{\@cref@sametypetrue}%
      \else%
        \def\@after{\@cref@sametypefalse}%
      \fi%
    \fi%
  \fi%
  \expandafter\endgroup\@after}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cref@countercmp}
%   The \cmd{\cref@countercmp} macro compares references |#1| and |#2|
%   according to their respective sets of counter data (stored in the
%   \file{aux} file). It \cmd{\chardef}'s |#3| to 0 if they're equal, 1
%   if the first comes earlier than the second, or 2 if the first
%   reference comes later than the second. This is used later for sorting
%   references. \cmd{\cref@countercmp} compares the references
%   themselves, \cmd{\cpageref@countercmp} compares their page numbers.
%    \begin{macrocode}
\def\cref@counter@first#1#2\@nil{#1}%
\def\cref@counter@rest#1#2\@nil{#2}%
\def\cref@countercmp{\@cref@countercmp{cref}}%
\def\cpageref@countercmp{\@cref@countercmp{cpageref}}%
\def\@cref@countercmp#1#2#3#4{%
  \begingroup%
  \def\@tempa{#2}%
%    \end{macrocode}
% In order to ensure empty references end up in the right place when
% sorting lists of multiple references, we make the comparison macro
% sort them before a non-empty reference.
%    \begin{macrocode}
  \ifx\@tempa\@empty%
    \def\cref@result{1}%
  \else%
    \def\@tempa{#3}%
    \ifx\@tempa\@empty%
      \def\cref@result{2}%
    \else%
%    \end{macrocode}
% Conversely, undefined references come after everything else.
%    \begin{macrocode}
      \expandafter\ifx\csname r@#2@cref\endcsname\relax%
        \def\cref@result{2}%
      \else%
        \expandafter\ifx\csname r@#3@cref\endcsname\relax%
          \def\cref@result{1}%
        \else%
%    \end{macrocode}
% The real work of comparing two references is done by
% \cmd{\@@cref@countercmp}.
%    \begin{macrocode}
          \csname #1@getcounter\endcsname{#2}{\@countera}%
          \csname #1@getprefix\endcsname{#2}{\@prefixa}%
          \csname #1@getcounter\endcsname{#3}{\@counterb}%
          \csname #1@getprefix\endcsname{#3}{\@prefixb}%
          \cref@stack@init{\@countstacka}%
          \expandafter\cref@stack@push\expandafter%
            {\@countera}{\@countstacka}%
          \ifx\@prefixa\@empty\else%
            \expandafter\cref@stack@push\expandafter%
              {\@prefixa}{\@countstacka}%
          \fi%
          \cref@stack@init{\@countstackb}%
          \expandafter\cref@stack@push\expandafter%
            {\@counterb}{\@countstackb}%
          \ifx\@prefixb\@empty\else%
            \expandafter\cref@stack@push\expandafter%
              {\@prefixb}{\@countstackb}%
          \fi%
          \@@cref@countercmp%
        \fi%
      \fi%
    \fi%
  \fi%
  \expandafter\endgroup\expandafter%
  \chardef\expandafter#4\expandafter=\cref@result\relax}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\@@cref@countercmp}
%   The \cmd{\@@cref@countercmp} macro recursively compares counter
%   components until it runs out of components for one of the references,
%   or finds two corresponding components that are unequal.
%    \begin{macrocode}
\def\@@cref@countercmp{%
  \let\@iterate\relax%
  \cref@isstackempty{\@countstacka}%
  \if@cref@stackempty%
    \cref@isstackempty{\@countstackb}%
    \if@cref@stackempty%
      \def\cref@result{0}%
    \else%
      \def\cref@result{1}%
    \fi%
  \else%
    \cref@isstackempty{\@countstackb}%
    \if@cref@stackempty%
      \def\cref@result{2}%
    \else%
      \edef\@tempa{\cref@stack@top{\@countstacka}}%
      \cref@stack@pop{\@countstacka}%
      \edef\@tempb{\cref@stack@top{\@countstackb}}%
      \cref@stack@pop{\@countstackb}%
      \ifnum\@tempa<\@tempb\relax%
        \def\cref@result{1}%
      \else%
        \ifnum\@tempa>\@tempb\relax%
          \def\cref@result{2}%
        \else%
          \def\@iterate{\@@cref@countercmp}%
        \fi%
      \fi%
    \fi%
  \fi%
  \@iterate}%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\if@cref@inresetlist}
% \begin{macro}{\cref@isinresetlist}
% \begin{macro}{\cref@resetby}
%   We need to be able to determine which counter is used to reset a
%   given counter. Usually, resets are done by sectioning counters, and
%   we assume that to be the case here. \cmd{\cref@isinresetlist}
%   searches through one counter's reset list, stored in
%   \cmd{\cl@\meta{counter}}, to determine whether another counter
%   appears there, and sets the new conditional
%   appropriately. \cmd{\cref@reset@by} searches through all the
%   sectioning counters' reset lists, from lowest-level (subsubsection)
%   to highest (part), checking whether the given counter is in the list,
%   and returns the first sectioning counter in whose list it appears.
%   (The value is returned by defining its second argument, which should
%   be a macro name.)
%    \begin{macrocode}
\newif\if@cref@inresetlist%
\def\cref@isinresetlist#1#2{%
  \begingroup%
    \def\@counter{#1}%
%    \end{macrocode}
%   We locally redefine \cmd{\@elt}, which appears at the head of the
%   expansion of |\cl@|\meta{counter}, so that entries in the reset list
%   end up separated by commas, thus can be treated as a stack.
%    \begin{macrocode}
    \def\@elt##1{##1,}%
    \expandafter\ifx\csname cl@#2\endcsname\relax%
      \def\cref@resetstack{,\@nil}%
    \else%
      \edef\cref@resetstack{\csname cl@#2\endcsname\noexpand\@nil}%
    \fi%
    \let\@nextcounter\relax%
    \cref@isstackfull{\cref@resetstack}%
    \@whilesw\if@cref@stackfull\fi{%
      \edef\@nextcounter{\cref@stack@top{\cref@resetstack}}%
      \ifx\@nextcounter\@counter%
        \@cref@stackfullfalse%
      \else%
        \let\@nextcounter\relax%
        \cref@stack@pop{\cref@resetstack}%
        \cref@isstackfull{\cref@resetstack}%
      \fi}%
    \ifx\@nextcounter\relax%
      \def\@next{\@cref@inresetlistfalse}%
    \else%
      \def\@next{\@cref@inresetlisttrue}%
    \fi%
  \expandafter%
  \endgroup%
  \@next}%
%    \end{macrocode}
%
% FIXME: We could easily remove the hard-coded search order in
% \cmd{\cref@resetby} and, say, replace it with a customisable list of
% counters to search in order. But, so far, I've yet to encounter a need
% for anything other than the hard-coded default.
%    \begin{macrocode}
\def\cref@resetby#1#2{%
  \let#2\relax%
%    \end{macrocode}
% If counter in question is |subfigure| or |subtable|, check if it's
% reset by |figure| or |table|, respectively.
%    \begin{macrocode}
  \cref@ifstreq{#1}{subfigure}{%
    \cref@isinresetlist{#1}{figure}%
    \if@cref@inresetlist%
      \def#2{figure}%
    \fi%
  }{}%
  \cref@ifstreq{#1}{subtable}{%
    \cref@isinresetlist{#1}{table}%
    \if@cref@inresetlist%
      \def#2{table}%
    \fi%
  }{}%
%    \end{macrocode}
% If counter in question is |equation|, and the counter |parentequation|
% is defined, check if it's reset by that. The |parentequation| counter
% is used by \package{amsmath}'s |subequations| environment. Although
% \package{amsmath} doesn't implement |subequations| using counter reset
% lists, \package{cleveref}'s \package{amsmath} support tweaks the reset
% lists inside |subequations| environments to hook into this mechanism.
% We should really only check this when \package{amsmath} is loaded, but
% checking it anyway might catch other packages that independently
% implement amsmath's |subequations| environment (are there any?).
%    \begin{macrocode}
  \@ifundefined{cl@parentequation}{}{%
    \cref@ifstreq{#1}{equation}{%
      \cref@isinresetlist{#1}{parentequation}%
      \if@cref@inresetlist%
        \expandafter\ifnum\c@parentequation=0\else%
          \def#2{parentequation}%
        \fi%
      \fi%
    }{}}%
%    \end{macrocode}
% \LaTeX{} hard-codes resetting of |enum|\meta{x} counters by
% higher-level |enum|\meta{x} counters, so we hard-code the results for
% these cases.
%    \begin{macrocode}
  \cref@ifstreq{#1}{enumii}{%
    \def#2{enumi}%
  }{%
    \cref@ifstreq{#1}{enumiii}{%
      \def#2{enumii}%
    }{%
      \cref@ifstreq{#1}{enumiv}{%
        \def#2{enumiii}%
      }{}%
    }%
  }%
%    \end{macrocode}
% If we haven't found anything so far, check if it's reset by a
% sectioning command.
%    \begin{macrocode}
  \ifx#2\relax%
    \cref@isinresetlist{#1}{table}%
    \if@cref@inresetlist%
      \def#2{table}%
    \else%
      \cref@isinresetlist{#1}{subsubsection}%
      \if@cref@inresetlist%
        \def#2{subsubsection}%
      \else%
        \cref@isinresetlist{#1}{subsection}%
        \if@cref@inresetlist%
          \def#2{subsection}%
        \else%
          \cref@isinresetlist{#1}{section}%
          \if@cref@inresetlist%
            \def#2{section}%
          \else%
            \cref@isinresetlist{#1}{chapter}%
            \if@cref@inresetlist%
              \def#2{chapter}%
            \else%
             \cref@isinresetlist{#1}{part}%
              \if@cref@inresetlist%
                \def#2{part}%
              \else%
                \let#2\relax%
              \fi%
            \fi%
          \fi%
        \fi%
      \fi%
    \fi%
  \fi}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\if@cref@refconsecutive}
% \begin{macro}{\cref@isrefconsecutive}
% \begin{macro}{\cpageref@isrefconsecutive}
%   Define a new conditional to test whether two references are
%   consecutive (needed when compressing references and typesetting
%   reference ranges). This uses the counter and prefix (i.e.\ chain of
%   counters that reset the reference's counter) information provided by
%   \cmd{\r@\meta{label}@cref} (via the \file{aux} file) to check if the
%   prefixes are identical (i.e.\ the references come from the same
%   chapter, section or whatever), and that the label counters differ
%   by~0 or~1. \cmd{\cref@isrefconsecutive} tests the references
%   themselves, \cmd{\cpageref@isrefconsecutve} tests their page numbers.
%    \begin{macrocode}
\newif\if@cref@refconsecutive%
\def\cref@isrefconsecutive{\@cref@isrefconsecutive{cref}}%
\def\cpageref@isrefconsecutive{\@cref@isrefconsecutive{cpageref}}%
\def\@cref@isrefconsecutive#1#2#3{%
  \begingroup%
  \def\@after{\@cref@refconsecutivefalse}%
  \expandafter\ifx\csname r@#2@cref\endcsname\relax\else%
    \expandafter\ifx\csname r@#3@cref\endcsname\relax\else%
      \countdef\refa@counter=0%
      \countdef\refb@counter=1%
      \csname #1@getcounter\endcsname{#2}{\cref@result}%
      \refa@counter=\cref@result%
      \csname #1@getcounter\endcsname{#3}{\cref@result}%
      \refb@counter=\cref@result%
      \csname #1@getprefix\endcsname{#2}{\refa@prefix}%
      \csname #1@getprefix\endcsname{#3}{\refb@prefix}%
      \ifx\refa@prefix\refb@prefix%
        \ifnum\refa@counter=\refb@counter\relax%
          \def\@after{\@cref@refconsecutivetrue}%
        \else%
          \advance\refa@counter 1\relax%
          \ifnum\refa@counter=\refb@counter\relax%
            \def\@after{\@cref@refconsecutivetrue}%
          \fi%
        \fi%
      \fi%
    \fi%
  \fi%
  \expandafter\endgroup\@after}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
% \subsubsection{Reference stack processing}
% \begin{macro}{\cref@processgroup}
%   \cmd{\cref@processgroup} processes the first group of references from
%   the stack passed in argument |#2|, by moving references to the stack
%   passed in argument |#3| until it encounters a reference that has a
%   different type to those that came before. Note that empty references
%   are treated as having the same type as the preceding one. If argument
%   |#1| is |cref| it processes references, it it's |cpageref| it
%   processes page references.
%    \begin{macrocode}
\def\cref@processgroup#1#2#3{%
  \cref@stack@dropempty{#2}%
  \edef\@firstref{\cref@stack@top{#2}}%
  \let\@nextref\@firstref%
  \@cref@sametypetrue%
  \@whilesw\if@cref@sametype\fi{%
    \expandafter\cref@stack@pull\expandafter{\@nextref}{#3}%
    \cref@stack@pop{#2}%
    \cref@isstackempty{#2}%
    \if@cref@stackempty%
      \@cref@sametypefalse%
    \else%
      \edef\@nextref{\cref@stack@top{#2}}%
      \ifx\@nextref\@empty%
        \@cref@sametypetrue%
      \else%
        \csname #1@isrefsametype\endcsname{\@firstref}{\@nextref}%
      \fi%
    \fi}}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cref@processgroupall}
%   \cmd{\cref@processgroupall} processes the first group of references
%   from the stack passed in argument |#2|, by moving all references with
%   the same type as the first one into the stack passed in argument
%   |#3|. If argument |#1| is |cref| it processes references, if it's
%   |cpageref| it processes page references.
%    \begin{macrocode}
\def\cref@processgroupall#1#2#3{%
  \cref@stack@init{\@tempstack}%
  \cref@stack@dropempty{#2}%
  \edef\@firstref{\cref@stack@top{#2}}%
  \cref@isstackfull{#2}%
  \@whilesw\if@cref@stackfull\fi{%
    \edef\@nextref{\cref@stack@top{#2}}%
    \ifx\@nextref\@empty%
      \expandafter\cref@stack@pull\expandafter{\@nextref}{#3}%
    \else%
      \edef\@tempa{{\@firstref}{\@nextref}}%
      \csname #1@isrefsametype\expandafter\endcsname\@tempa%
      \if@cref@sametype%
        \expandafter\cref@stack@pull\expandafter{\@nextref}{#3}%
      \else%
        \expandafter\cref@stack@pull\expandafter{\@nextref}{\@tempstack}%
      \fi%
    \fi%
    \cref@stack@pop{#2}%
    \cref@isstackfull{#2}}%
  \let#2\@tempstack}%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\cref@processconsecutive}
%   \cmd{\cref@processconsecutive} processes the first sequence of
%   consecutive references from the stack passed in |#2|, sets the macro
%   passed as |#3| to the first reference in the sequence, sets |#4| to
%   the last reference, and sets the counter passed in |#5| to the number
%   of consecutive references in the sequence. If argument |#1| is |cref|
%   it processes references, if it's |cpageref| it processes page
%   references.
%    \begin{macrocode}
\def\cref@processconsecutive#1#2#3#4#5{%
%    \end{macrocode}
% Initialise return values to those appropriate for a single reference.
%    \begin{macrocode}
  \let#4\relax%
  #5=1\relax%
  \edef\@nextref{\cref@stack@top{#2}}%
  \edef#3{\@nextref}%
  \cref@stack@pop{#2}%
  \cref@isstackfull{#2}%
%    \end{macrocode}
% If stack contains multiple references, find end of consecutive references.
%    \begin{macrocode}
  \if@cref@stackfull%
    \edef\@nextref{\cref@stack@top{#2}}%
    \expandafter\ifx\csname r@#3@cref\endcsname\relax%
      \@cref@refconsecutivefalse%
    \else%
%    \end{macrocode}
%     If next reference in stack is empty, it indicates that no
%     further compression should take place. Having served its purpose,
%     the empty reference and any consecutive empty references are
%     removed from the stack.
%    \begin{macrocode}
      \ifx\@nextref\@empty%
        \@cref@refconsecutivefalse%
        \cref@stack@dropempty{#2}%
%    \end{macrocode}
%     Otherwise, test whether next reference is consecutive or not.
%    \begin{macrocode}
      \else%
        \edef\@tempa{{#3}{\@nextref}}%
        \csname #1@isrefconsecutive\expandafter\endcsname\@tempa%
      \fi%
    \fi%
%    \end{macrocode}
%   Remove references from the stack until we find end of consecutive
%   sequence.
%    \begin{macrocode}
    \@whilesw\if@cref@refconsecutive\fi{%
      \advance#5 1\relax%
      \let#4\@nextref%
      \cref@stack@pop{#2}%
      \cref@isstackempty{#2}%
      \if@cref@stackempty%
        \@cref@refconsecutivefalse%
      \else%
        \edef\@nextref{\cref@stack@top{#2}}%
%    \end{macrocode}
%       If next reference is empty, remove any consecutive empty
%       references and we're done.
%    \begin{macrocode}
        \ifx\@nextref\@empty%
          \@cref@refconsecutivefalse%
          \@whilesw\ifx\@nextref\@empty\fi{%
            \cref@stack@pop{#2}%
            \cref@isstackempty{#2}%
            \if@cref@stackempty%
              \let\@nextref\relax%
            \else%
              \edef\@nextref{\cref@stack@top{#2}}%
            \fi}%
%    \end{macrocode}
%         Otherwise, test whether next reference is consecutive or not.
%    \begin{macrocode}
        \else%
          \edef\@tempa{{#4}{\@nextref}}%
          \csname #1@isrefconsecutive\expandafter\endcsname\@tempa%
        \fi%
      \fi}%
  \fi}%
%    \end{macrocode}
% \end{macro}
%
%
% \subsubsection{Prefix-stripping}
% \begin{macro}{\crefstripprefix}
%   The \cmd{\crefstripprefix} utility command is intended for use in
%   cross-reference format definitions. It takes two strings of
%   characters as arguments, and strips any common prefix from the second
%   argument. The common prefix is only stripped up to the last sequence
%   of digits or letters in the second argument.
%    \begin{macrocode}
\newcommand\crefstripprefix[2]{%
  \begingroup%
    \edef\@toksa{#1}%
    \edef\@toksb{#2}%
    \let\cref@acc\@empty%
    \@crefstripprefix%
    \cref@result%
  \endgroup}%
%    \end{macrocode}
% \end{macro}
%
% The real work is done by the recursive \cmd{\@crefstripprefix} macro,
% which compares characters one-by-one (accumulating runs of the same
% type of character -- digit or letter as it goes). It removes matching
% characters from the strings, and outputs the remaining characters
% from the second string (plus any accumulated characters of the same
% type) when it encounters the first non-matching character;
%    \begin{macrocode}
\def\@crefstripprefix{%
  \let\@iterate\relax%
  \def\accum@flag{0}%
%    \end{macrocode}
% Pop next characters from |\@toksa| and |\@toksb| string into |\@tempa|
% and |\@tempb|, storing previous b-string character in |\@tempc|.
%    \begin{macrocode}
  \let\@tempc\@tempb%
  \cref@poptok{\@toksa}{\@tempa}%
  \cref@poptok{\@toksb}{\@tempb}%
%    \end{macrocode}
% If characters match, drop character and proceed to next.
%    \begin{macrocode}
  \ifx\@tempa\@tempb\relax%
    \def\@iterate{\@crefstripprefix}%
%    \end{macrocode}
%   Accumulate popped character if accumulated string is empty\dots
%    \begin{macrocode}
    \ifx\cref@acc\@empty\relax%
      \let\cref@acc\@tempb%
    \else%
%    \end{macrocode}
%     or if it has same catcode as previous character, and is either a
%     letter\dots
%    \begin{macrocode}
      \ifcat\@tempb\@tempc\relax%
        \ifcat\@tempb a\relax%
          \def\accum@flag{1}%
        \else%
%    \end{macrocode}
%    or a digit.
%    \begin{macrocode}
          \expandafter\chardef\expandafter\@tempa%
            \expandafter=\expandafter`\@tempb\relax%
          \ifnum\@tempa>`/\relax%
            \expandafter\ifnum\@tempb<`:\relax%
              \def\accum@flag{1}%
            \fi%
          \fi%
        \fi%
      \fi%
      \def\@tempa{1}%
      \ifx\accum@flag\@tempa%
        \edef\cref@acc{\cref@acc\@tempb}%
      \else%
        \let\cref@acc\@empty%
      \fi%
    \fi%
%    \end{macrocode}
% If characters don't match, return remaining characters from b-string,
% prepending any accumulated characters.
%    \begin{macrocode}
  \else%
    \ifcat\@tempb\@tempc\relax\else%
      \let\cref@acc\@empty%
    \fi%
    \edef\cref@result{\cref@acc\@tempb\@toksb}%
  \fi%
  \@iterate}%
%    \end{macrocode}
%
% \begin{macro}{\cref@poptok}
%   The \cmd{\cref@poptok} macro takes two arguments, both macros. It
%   defines |#2| to be the first token in |#1|'s expansion, and removes
%   that token from |#1|'s definition.
%    \begin{macrocode}
\def\cref@poptok#1#2{%
  \expandafter\expandafter\expandafter\def%
    \expandafter\expandafter\expandafter#2%
    \expandafter\expandafter\expandafter{%
      \expandafter\@cref@firsttok#1\@nil}%
  \expandafter\expandafter\expandafter\def%
    \expandafter\expandafter\expandafter#1%
    \expandafter\expandafter\expandafter{%
      \expandafter\@cref@poptok#1\@nil}}%
\def\@cref@firsttok#1#2\@nil{#1}%
\def\@cref@poptok#1#2\@nil{#2}%
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsection{Cross-Referencing Commands}
% \begin{macro}{\cref}
% \begin{macro}{\Cref}
% \begin{macro}{\crefrange}
% \begin{macro}{\Crefrange}
%   Define the main referencing command \cmd{\cref} and the
%   start-of-sentence variant \cmd{\Cref}, along with the reference range
%   commands \cmd{\crefrange} and \cmd{\Crefrange}.
%    \begin{macrocode}
\DeclareRobustCommand{\cref}[1]{\@cref{cref}{#1}}%
\DeclareRobustCommand{\Cref}[1]{\@cref{Cref}{#1}}%
\DeclareRobustCommand{\crefrange}[2]{\@setcrefrange{#1}{#2}{}}%
\DeclareRobustCommand{\Crefrange}[2]{\@setCrefrange{#1}{#2}{}}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\if@crefstarred}
%   The |\if@crefstarred| flag is set within starred variants of
%   \package{cleveref} commands. Starred variants are only defined if
%   either the \package{hyperref} or \package{varioref} package is
%   loaded, so we only define it in those cases. We need to |\let|
%   |\if@crefstarred| to something even when not using it, otherwise
%   \TeX{} gets confused when parsing code that contains
%   |\if@crefstarred| inside a nested if.
%    \begin{macrocode}
\@ifpackageloaded{hyperref}{\newif\if@crefstarred}{%
  \@ifpackageloaded{varioref}{\newif\if@crefstarred}{}}%
\let\if@crefstarred\iffalse%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@cref}
%   To save duplicating code, the referencing macros pass an argument
%   determining the variant to an auxiliary macro \cmd{\@cref}, which
%   does the real work. The \cmd{\@cref} macro is the behemoth at the
%   heart of all the clever referencing features. It deals with grouping
%   references by type, typesetting the conjunctions between groups,
%   choosing the right formatting macro to use for each reference, and
%   compressing consecutive references into ranges.
%    \begin{macrocode}
\def\@cref#1#2{%
  \leavevmode%
  \begingroup%
  \def\cref@variant{#1}%
  \def\@tempa{\in@{page}}%
  \expandafter\@tempa\expandafter{\cref@variant}%
  \ifin@%
    \def\cref@variant@get{cpageref}%
  \else%
    \def\cref@variant@get{cref}%
  \fi%
%    \end{macrocode}
% Initialise some things, and put all the references into a stack called
% \cmd{\@refstack}. Note that we fully expand the second argument, in
% case it contains commands that \emph{expand to} label names, rather
% than label names per se.
%    \begin{macrocode}
  \countdef\count@consecutive=0%
  \countdef\count@group=1%
  \count@group=1%
  \countdef\count@subgroup=2%
  \cref@stack@init{\@refstack}%
  \edef\@tempa{#2}%
  \expandafter\cref@stack@push\expandafter{\@tempa}{\@refstack}%
  \cref@isstackfull{\@refstack}%
%    \end{macrocode}
%
% Loop until the reference stack is empty.
%    \begin{macrocode}
  \@whilesw\if@cref@stackfull\fi{%
%    \end{macrocode}
% Move next group of references with same type into \cmd{\@refsubstack}.
%    \begin{macrocode}
    \cref@stack@init{\@refsubstack}%
    \if@cref@sort%
      \expandafter\cref@processgroupall\expandafter%
        {\cref@variant@get}{\@refstack}{\@refsubstack}%
      \expandafter\cref@stack@sort\expandafter%
        {\csname\cref@variant@get @countercmp\endcsname}{\@refsubstack}%
    \else%
      \expandafter\cref@processgroup\expandafter%
        {\cref@variant@get}{\@refstack}{\@refsubstack}%
    \fi%
%    \end{macrocode}
%
% Typeset appropriate conjunction between groups of reference types.
%    \begin{macrocode}
    \ifnum\count@group=1\relax%
      \advance\count@group 1\relax%
    \else%
      \cref@isstackfull{\@refstack}%
      \if@cref@stackfull%
        \@setcref@middlegroupconjunction%
      \else%
        \ifnum\count@group=2\relax%
          \@setcref@pairgroupconjunction%
        \else%
          \@setcref@lastgroupconjunction%
        \fi%
      \fi%
      \advance\count@group 1\relax%
      \lowercase{\def\cref@variant{#1}}%
    \fi%
%    \end{macrocode}
%
% Process groups of consecutive references until substack is empty.
%    \begin{macrocode}
    \count@subgroup=1%
    \cref@isstackfull{\@refsubstack}%
    \@whilesw\if@cref@stackfull\fi{%
      \if@cref@compress%
        \expandafter\cref@processconsecutive\expandafter{\cref@variant@get}%
          {\@refsubstack}{\@beginref}{\@endref}{\count@consecutive}%
%    \end{macrocode}
% Empty references serve no purpose when we're not compressing, so we
% simply remove them and process the first non-empty reference..
%    \begin{macrocode}
      \else%
        \cref@stack@dropempty{\@refsubstack}%
        \edef\@beginref{\cref@stack@top{\@refsubstack}}%
        \cref@stack@pop{\@refsubstack}%
        \let\@endref\relax%
        \count@consecutive=1\relax%
      \fi%
%    \end{macrocode}
% If the start and end labels are identical, treat it as a single
% reference instead of a range
%    \begin{macrocode}
      \ifnum\count@consecutive>1\relax%
        \csname\cref@variant@get @getlabel\endcsname{\@beginref}{\@labela}%
        \csname\cref@variant@get @getlabel\endcsname{\@endref}{\@labelb}%
        \ifx\@labela\@labelb%
          \let\@endref\relax%
          \count@consecutive=1\relax%
        \fi%
      \fi%
%    \end{macrocode}
% If there were only two consecutive references, keep the first one and
% return the second one to the substack. (We add an empty reference after
% it just to make sure there's no further compression.)
%    \begin{macrocode}
      \ifnum\count@consecutive=2\relax%
        \expandafter\cref@stack@push\expandafter{\@endref,}{\@refsubstack}%
        \let\@endref\relax%
        \count@consecutive=1\relax%
      \fi%
%    \end{macrocode}
% Work out which type of reference we need to typeset.
%    \begin{macrocode}
      \cref@isstackfull{\@refsubstack}%
      \if@cref@stackfull%
        \ifnum\count@subgroup=1\relax%
          \def\@pos{@first}%
        \else%
          \def\@pos{@middle}%
        \fi%
      \else%
        \ifnum\count@subgroup=1\relax%
          \def\@pos{}%
        \else%
          \ifnum\count@subgroup=2\relax%
            \def\@pos{@second}%
          \else%
            \def\@pos{@last}%
          \fi%
        \fi%
      \fi%
%    \end{macrocode}
% If there were no consecutive references, just typeset the next
% reference;
%    \begin{macrocode}
      \ifnum\count@consecutive=1\relax%
        \edef\@tempa{{\@beginref}{\@pos}}%
        \csname @set\cref@variant\expandafter\endcsname\@tempa%
%    \end{macrocode}
% otherwise, typeset a reference range.
%    \begin{macrocode}
      \else%
        \edef\@tempa{{\@beginref}{\@endref}{\@pos}}%
        \csname @set\cref@variant range\expandafter\endcsname\@tempa%
      \fi%
      \advance\count@subgroup 1\relax%
      \cref@isstackfull{\@refsubstack}%
    }% end loop over reference substack
    \cref@isstackfull{\@refstack}%
%    \end{macrocode}
%
% If we're typesetting a \cmd{\labelcref} reference and references in
% stack have different types, throw a warning and stop processing.
%    \begin{macrocode}
    \if@cref@stackfull%
      \def\@tempa{labelcref}%
      \ifx\cref@variant\@tempa%
        \protect\G@refundefinedtrue%
        \nfss@text{\reset@font\bfseries\space ??}%
        \@latex@warning{References in label reference on page \thepage
          \space have different types}%
        \@cref@stackfullfalse%
      \fi%
    \fi%
  }% end loop over main reference stack
  \endgroup}%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@setcref}
% \begin{macro}{\@setCref}
% \begin{macro}{\@setlavelcref}
% \begin{macro}{\@@setcref}
%   The \cmd{\@setcref}, \cmd{\@setCref} and \cmd{\@setlabelcref} macros
%   are called as appropriate by \cmd{\@cref} to typeset a reference.
%   These macros just turn the |cref|, |Cref| or |labelcref| variant into
%   a macro argument and pass it along to \cmd{\@@setcref}, which deals
%   with actually typesetting the reference by calling the appropriate
%   type-dependent formatting macro defined by \cmd{\crefformat} etc.
%   \cmd{\@@setcref} takes three arguments. |#1| is the variant passed
%   along by |\@set|\meta{x}|ref|. |#2| contains the reference itself.
%   |#3| is either empty or one of ``@second'', ``@middle'' or ``@last'',
%   determining the type of reference group to typeset.
%    \begin{macrocode}
\def\@setcref{\@@setcref{cref}}%
\def\@setCref{\@@setcref{Cref}}%
\def\@setlabelcref{\@@setcref{labelcref}}%
\def\@@setcref#1#2#3{%
  \expandafter\ifx\csname r@#2@cref\endcsname\relax%
    \protect\G@refundefinedtrue%
    \nfss@text{\reset@font\bfseries ??}%
    \@latex@warning{Reference `#2' on page \thepage \space undefined}%
  \else%
    \cref@gettype{#2}{\@temptype}%  puts label type in \@temptype
    \cref@getlabel{#2}{\@templabel}%  puts label in \@templabel
    \expandafter\ifx\csname #1@\@temptype @format#3\endcsname\relax%
%    \end{macrocode}
%     If reference format is undefined, but we're typesetting a
%     \cmd{\labelcref}, fall back to default \cmd{\labelcref} format.
%    \begin{macrocode}
      \edef\@tempa{#1}\def\@tempb{labelcref}%
      \ifx\@tempa\@tempb\relax%
        \expandafter\@@@setcref\expandafter%
          {\csname #1@default@format#3\endcsname}{#2}%
      \else%
        \protect\G@refundefinedtrue%
        \nfss@text{\reset@font\bfseries ??}~\@templabel%
        \@latex@warning{#1\space reference format for label type
          `\@temptype' undefined}%
      \fi%
    \else%
      \expandafter\@@@setcref\expandafter%
        {\csname #1@\@temptype @format#3\endcsname}{#2}%
    \fi%
  \fi}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@@@setcref}
%   We separate out the very final typesetting step into a separate
%   macro, in order to make it easier to redefine things later to make
%   them work with the \package{hyperref} package.
%    \begin{macrocode}
\def\@@@setcref#1#2{\cref@getlabel{#2}{\@templabel}#1{\@templabel}{}{}}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@setcrefrange}
% \begin{macro}{\@setCrefrange}
% \begin{macro}{\@setlabelcrefrange}
% \begin{macro}{\@@setcrefrange}
%   The \cmd{\@setcrefrange}, \cmd{\@setCrefrange} and
%   \cmd{\@setlabelrefrange} macros are called as appropriate by
%   \cmd{\@cref} to typeset a reference. The internal
%   \cmd{\@@setcrefrange} macro deals with actually typesetting reference
%   ranges, and takes four arguments. |#1| is the variant passed along by
%   |\@set|\meta{x}|ref|. |#2| and |#3| contains the references
%   themselves. |#4| is either empty or one of ``@second'', ``@middle''
%   or ``@last'', determining the type of reference group to typeset.
%
%   The actual typesetting is no more complicated than in the
%   \cmd{\@@setcref} case; it's the error checking that makes the code
%   longer. We now have to check whether \emph{two} references are
%   undefined, whether \emph{two} reference formats are undefined,
%   whether the reference types are consistent, and also combinations of
%   these various errors.
%    \begin{macrocode}
\def\@setcrefrange{\@@setcrefrange{cref}}%
\def\@setCrefrange{\@@setcrefrange{Cref}}%
\def\@setlabelcrefrange{\@@setcrefrange{labelcref}}%
\def\@@setcrefrange#1#2#3#4{%
  \begingroup%
%    \end{macrocode}
% Check if both references are defined.
%    \begin{macrocode}
    \expandafter\ifx\csname r@#2@cref\endcsname\relax%
      \protect\G@refundefinedtrue%
      \@latex@warning{Reference `#2' on page \thepage \space%
        undefined}%
      \expandafter\ifx\csname r@#3@cref\endcsname\relax%
        \nfss@text{\reset@font\bfseries ??}--%
        \nfss@text{\reset@font\bfseries ??}%
        \@latex@warning{Reference `#3' on page \thepage \space%
          undefined}%
      \else%
        \cref@getlabel{#3}{\@labelb}%
        \nfss@text{\reset@font\bfseries ??}--\@labelb%
      \fi%
    \else%
      \expandafter\ifx\csname r@#3@cref\endcsname\relax%
        \protect\G@refundefinedtrue%
        \cref@getlabel{#2}{\@labela}%
        \@labela--\nfss@text{\reset@font\bfseries ??}%
        \@latex@warning{Reference `#3' on page \thepage %
          \space undefined}%
%    \end{macrocode}
%   If both references are defined, check that the reference format is
%   defined.
%    \begin{macrocode}
      \else%
        \cref@gettype{#2}{\@typea}%
        \cref@gettype{#3}{\@typeb}%
        \cref@getlabel{#2}{\@labela}%
        \cref@getlabel{#3}{\@labelb}%
        \edef\@format{\expandafter\noexpand%
          \csname #1range@\@typea @format#4\endcsname}%
        \expandafter\ifx\@format\relax%
%    \end{macrocode}
%         If reference format is undefined, but we're typesetting a
%         \cmd{\labelcref}, fall back to default \cmd{\labelcref}
%         formats.
%    \begin{macrocode}
          \edef\@tempa{#1}\def\@tempb{labelcref}%
          \ifx\@tempa\@tempb\relax%
            \expandafter\@@@setcrefrange\expandafter%
              {\csname #1range@default@format#4\endcsname}{#2}{#3}%
          \else%
            \protect\G@refundefinedtrue%
            \nfss@text{\reset@font\bfseries ??}~\@labela--\@labelb%
            \@latex@warning{#1 reference range format for label
              type `\@typea' undefined}%
          \fi%
        \else%
%    \end{macrocode}
%     If reference types are identical, typeset reference range,
%     otherwise display warning.\\
%     (Note: there's no need to check if reference format for second type
%     is defined, since if it isn't it will be caught here as a
%     non-identical type.)
%    \begin{macrocode}
          \expandafter\expandafter\expandafter\def%
            \expandafter\expandafter\expandafter\@formata%
            \expandafter\expandafter\expandafter{%
              \csname #1range@\@typea @format#4\endcsname%
              {\@dummya}{\@dummyb}{\@dummyc}{\@dummyd}{\@dummye}{\@dummyf}}%
          \expandafter\expandafter\expandafter\def%
            \expandafter\expandafter\expandafter\@formatb%
            \expandafter\expandafter\expandafter{%
              \csname #1range@\@typeb @format#4\endcsname%
              {\@dummya}{\@dummyb}{\@dummyc}{\@dummyd}{\@dummye}{\@dummyf}}%
          \ifx\@formata\@formatb%
            \expandafter\@@@setcrefrange\expandafter{\@format}{#2}{#3}%
          \else%
            \protect\G@refundefinedtrue%
            \nfss@text{\reset@font\bfseries ??}~\@labela--\@labelb%
            \@latex@warning{References `#2' and `#3' in reference range
              on page \thepage \space have different types
              `\@typea' and `\@typeb'}%
          \fi%
        \fi%
      \fi%
    \fi%
  \endgroup}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@@@setcrefrange}
%   We again separate out the very final typesetting step into a
%   separate macro, in order to make it easier to redefine things later
%   to make them work with the \package{hyperref} package.
%    \begin{macrocode}
\def\@@@setcrefrange#1#2#3{%
  \cref@getlabel{#2}{\@labela}%
  \cref@getlabel{#3}{\@labelb}%
  #1{\@labela}{\@labelb}{}{}{}{}}%
%    \end{macrocode}
% \end{macro}
%
%
% The typesetting of conjunctions is also separated out into separate
% macros, for the same reason.
%    \begin{macrocode}
\def\@setcref@pairgroupconjunction{\crefpairgroupconjunction}%
\def\@setcref@middlegroupconjunction{\crefmiddlegroupconjunction}%
\def\@setcref@lastgroupconjunction{\creflastgroupconjunction}%
%    \end{macrocode}
%
% \begin{macro}{\labelcref}
% \begin{macro}{\namecref}
% \begin{macro}{\nameCref}
% \begin{macro}{\lcnamecref}
% \begin{macro}{\namecrefs}
% \begin{macro}{\nameCrefs}
% \begin{macro}{\lcnamecrefs}
%   Finally, we define a \cmd{\labelcref} command that returns just the
%   typeset label part of a (multi-)reference, without the reference
%   name, and conversely \cmd{\namecref}, \cmd{\nameCref},
%   \cmd{\namecrefs} and \cmd{\nameCrefs} commands that return just the
%   typeset name of a reference, without the reference label. The latter
%   four retrieve the reference name from the corresponding
%   \cmd{\crefname} or \cmd{\Crefname} definition, so they only work when
%   this has been defined. We also define \cmd{\lcnamecref} and
%   \cmd{\lcnamecrefs} commands which force the reference name to
%   lowercase, for use when the \option{capitalise} option is enabled.
%    \begin{macrocode}
\DeclareRobustCommand{\labelcref}[1]{\@cref{labelcref}{#1}}%
\DeclareRobustCommand{\namecref}[1]{%
  \@setnamecref{cref}{#1}{}{}}%
\DeclareRobustCommand{\nameCref}[1]{%
  \@setnamecref{Cref}{#1}{}{}}%
\DeclareRobustCommand{\lcnamecref}[1]{%
  \@setnamecref{Cref}{#1}{}{\MakeLowercase}}%
\DeclareRobustCommand{\namecrefs}[1]{%
  \@setnamecref{cref}{#1}{@plural}{}}%
\DeclareRobustCommand{\nameCrefs}[1]{%
  \@setnamecref{Cref}{#1}{@plural}{}}%
\DeclareRobustCommand{\lcnamecrefs}[1]{%
  \@setnamecref{Cref}{#1}{@plural}{\MakeLowercase}}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@setnamecref}
%   \cmd{\@setnamecref} is the real macro underlying all the
%   \cmd{\namecref} commands. |#1| is the capitalisation variant, |#2|
%   the reference, |#3| is either empty or |@plural| if the plural name
%   should be generated, and |#4| is either empty or contains
%   \cmd{\MakeLowercase} if a lower-cased name should be generated.
%    \begin{macrocode}
\def\@setnamecref#1#2#3#4{%
  \expandafter\ifx\csname r@#2@cref\endcsname\relax%
    \protect\G@refundefinedtrue%
    \nfss@text{\reset@font\bfseries ??}%
    \@latex@warning{Reference `#2' on page \thepage \space undefined}%
  \else%
    \cref@gettype{#2}{\@tempa}%
    \@ifundefined{#1@\@tempa @name#3}{%
      \protect\G@refundefinedtrue%
      \nfss@text{\reset@font\bfseries ??}%
      \@latex@warning{Reference name for label type `\@tempa' undefined}%
    }{%
      \edef\@tempa{%
        \expandafter\noexpand\csname #1@\@tempa @name#3\endcsname}%
      \expandafter\@@@setnamecref\expandafter{\@tempa}{#4}%
    }%
  \fi}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@@setnamecref}
%   We again separate out the final typesetting step of the
%   \cmd{\namecref} commands.
%    \begin{macrocode}
\def\@@@setnamecref#1#2{%
  \expandafter\def\expandafter\@tempa\expandafter{#1}%
  \expandafter#2\@tempa}%
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsection{Page-Referencing Commands}
% \begin{macro}{\cpageref}
% \begin{macro}{\Cpageref}
% \begin{macro}{\cpagerefrange}
% \begin{macro}{\Cpagerefrange}
%   Define the main page referencing command \cmd{\cpageref} and the
%   start-of-sentence variant \cmd{\Cpageref}, along with the
%   \cmd{\cpagerefrange} and \cmd{\Cpagerefrange} page range referencing
%   commands, and \cmd{\labelcpageref} (the counterpart to
%   \cmd{\labelcref}).
%    \begin{macrocode}
\DeclareRobustCommand{\cpageref}[1]{\@cref{cpageref}{#1}}%
\DeclareRobustCommand{\Cpageref}[1]{\@cref{Cpageref}{#1}}%
\DeclareRobustCommand{\cpagerefrange}[2]{%
  \@@setcpagerefrange{#1}{#2}{cref}{}}%
\DeclareRobustCommand{\Cpagerefrange}[2]{%
  \@@setcpagerefrange{#1}{#2}{Cref}{}}%
\DeclareRobustCommand{\labelcpageref}[1]{%
  \@cref{labelcpageref}{#1}}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@setcpageref}
% \begin{macro}{\@setCpageref}
% \begin{macro}{\@setlabelcpageref}
% \begin{macro}{\@@setcpageref}
%   The \cmd{\@setcpageref}, \cmd{\@setCpageref} and
%   \cmd{\@setlabelcpageref} macros are called as appropriate by
%   \cmd{\@cref} to typeset a page reference. These macros just turn the
%   |cref|, |Cref| or |labelcref| variant into a macro argument and pass
%   it along to \cmd{\@@setcpageref}, which deals with actually
%   typesetting the page reference by calling the appropriate page
%   reference formatting macro defined by \cmd{\crefformat}|{page}| etc.
%   \cmd{\@@setcpageref} takes four arguments. |#1| is the variant passed
%   along by |\@set|\meta{x}|pageref|. |#2| contains the reference
%   itself. |#3| is either empty or one of ``@second'', ``@middle'' or
%   ``@last'', determining the type of page reference group to typeset.
%    \begin{macrocode}
\def\@setcpageref{\@@setcpageref{cref}}
\def\@setCpageref{\@@setcpageref{Cref}}
\def\@setlabelcpageref{\@@setcpageref{labelcref}}
\def\@@setcpageref#1#2#3{%
  \expandafter\ifx\csname r@#2@cref\endcsname\relax%
    \protect\G@refundefinedtrue%
    \nfss@text{\reset@font\bfseries ??}%
    \@latex@warning{Reference `#2' on page \thepage \space undefined}%
  \else%
    \cpageref@getlabel{#2}{\@temppage}%
    \expandafter\ifx\csname #1@page@format#3\endcsname\relax%
%    \end{macrocode}
%     If reference format is undefined, but we're typesetting a
%     \cmd{\labelcpageref}, fall back to default \cmd{\labelcref} format.
%    \begin{macrocode}
      \edef\@tempa{#1}\def\@tempb{labelcref}%
      \ifx\@tempa\@tempb\relax%
        \expandafter\@@@setcpageref\expandafter%
          {\csname #1@default@format#3\endcsname}{#2}%
      \else%
        \protect\G@refundefinedtrue%
        \nfss@text{\reset@font\bfseries ??}~\@temppage%
        \@latex@warning{ #1 reference format for
          page references undefined}%
      \fi%
    \else%
      \expandafter\@@@setcpageref\expandafter%
        {\csname #1@page@format#3\endcsname}{#2}%
    \fi%
  \fi}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@@setcpageref}
%   We separate out the very final typesetting step into a separate
%   macro, in order to make it easier to redefine things later to make
%   them work with the \package{hyperref} package.
%    \begin{macrocode}
\def\@@@setcpageref#1#2{%
  \cpageref@getlabel{#2}{\@temppage}#1{\@temppage}{}{}}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@@setcpagerefrange}
%   The \cmd{\@@setcpagerefrange} macro deals with typesetting page range
%   references, just as \cmd{\@@setcpageref} does for normal page
%   references.
%    \begin{macrocode}
\def\@@setcpagerefrange#1#2#3#4{%
  \begingroup%
%    \end{macrocode}
% Check if both references are defined.
%    \begin{macrocode}
    \expandafter\ifx\csname r@#1@cref\endcsname\relax%
      \protect\G@refundefinedtrue%
      \@latex@warning{Reference `#1' on page \thepage \space%
        undefined}%
      \expandafter\ifx\csname r@#2@cref\endcsname\relax%
        \nfss@text{\reset@font\bfseries ??}--%
        \nfss@text{\reset@font\bfseries ??}%
        \@latex@warning{Reference `#2' on page \thepage \space%
          undefined}%
      \else%
        \cpageref@getlabel{#2}{\@pageb}%
        \nfss@text{\reset@font\bfseries ??}--\@pageb%
      \fi%
    \else%
      \expandafter\ifx\csname r@#2@cref\endcsname\relax%
        \protect\G@refundefinedtrue%
        \cpageref@getlabel{#1}{\@pagea}%
        \@pagea--\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%
        \cpageref@getlabel{#1}{\@pagea}%
        \cpageref@getlabel{#2}{\@pageb}%
        \edef\@format{\expandafter\noexpand%
          \csname#3range@page@format#4\endcsname}%
        \expandafter\ifx\@format\relax%
%    \end{macrocode}
%         If page reference format is undefined, but we're typesetting a
%         \cmd{\labelcpageref}, fall back to default \cmd{\labelcref}
%         formats.
%    \begin{macrocode}
          \edef\@tempa{#3}\def\@tempb{labelcref}%
          \ifx\@tempa\@tempb\relax%
            \expandafter\@@@setcpagerefrange\expandafter%
              {\csname#3range@default@format#4\endcsname}{#1}{#2}%
          \else%
            \protect\G@refundefinedtrue%
            \nfss@text{\reset@font\bfseries ??}~\@pagea--\@pageb%
            \@latex@warning{#3 reference range format for page
              references undefined}%
          \fi%
        \else%
%    \end{macrocode}
%     typeset page reference range,
%    \begin{macrocode}
          \expandafter\@@@setcpagerefrange\expandafter{\@format}{#1}{#2}%
        \fi%
      \fi%
    \fi%
  \endgroup}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@@setcpagerefrange}
%   We again separate out the very final typesetting step into a
%   separate macro, in order to make it easier to redefine things later
%   to make them work with the \package{hyperref} package.
%    \begin{macrocode}
\def\@@@setcpagerefrange#1#2#3{%
  \cpageref@getlabel{#2}{\@pagea}%
  \cpageref@getlabel{#3}{\@pageb}%
  #1{\@pagea}{\@pageb}{}{}{}{}}%
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsection{Reference Format Customisation Commands}
%
% \subsubsection{Format component commands}
% \begin{macro}{\cref@label@types}
%   The reference formats are usually constructed out of components
%   defined by the user-level \cmd{\crefname}, \cmd{\Crefname},
%   \cmd{\creflabel} and \cmd{\crefrangelabel} commands.
%   \cmd{\cref@label@types} keeps track of label types for which
%   components have been defined, and therefore need constructing at
%   \cmd{\begindocument} (see below).
%
%   FIXME: We don't check if the label type is already in the list, so
%   some formats may needlessly be redefined identically, multiple times.
%
%    \begin{macrocode}
\cref@stack@init{\cref@label@types}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\crefdefaultlabelformat}
% \begin{macro}{\crefname}
% \begin{macro}{\Crefname}
% \begin{macro}{\creflabelformat}
% \begin{macro}{\crefrangelabelformat}
%   The component customisation commands simply use the supplied
%   arguments to define appropriately named macros containing the
%   formatting components. If the corresponding \cmd{\Crefname} or
%   \cmd{\crefname} variant is not already defined, \cmd{\crefname} and
%   \cmd{\Crefname} define it to be a version with the first letter
%   capitalised or lower-cased, respectively.
%    \begin{macrocode}
\newcommand\crefdefaultlabelformat[1]{%
  \def\cref@default@label##1##2##3{#1}}%
\newcommand\crefname[3]{%
  \@crefname{cref}{#1}{#2}{#3}{}}%
\newcommand\Crefname[3]{%
  \@crefname{Cref}{#1}{#2}{#3}{}}%
\newcommand\creflabelformat[2]{%
  \expandafter\def\csname cref@#1@label\endcsname##1##2##3{#2}%
  \cref@stack@add{#1}{\cref@label@types}}%
\newcommand\crefrangelabelformat[2]{%
  \expandafter\def\csname cref@#1@rangelabel\endcsname%
    ##1##2##3##4##5##6{#2}%
  \cref@stack@add{#1}{\cref@label@types}}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\crefalias}
%   The \cmd{\crefalias} command aliases a counter name to another
%   cross-reference type, so can be used to make the same cross-reference
%   format apply to multiple different counters.
%\begin{macrocode}
\newcommand\crefalias[2]{%
  \expandafter\def\csname cref@#1@alias\endcsname{#2}}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\crefname@preamble}
% \begin{macro}{\Crefname@preamble}
%   The \cmd{\crefname@preamble} and \cmd{\Crefname@preamble} commands
%   are very like the \cmd{\crefname} and \cmd{\Crefname} commands, but
%   they tag ``|@preamble|'' onto the end of the generated macro names.
%   They are used when defining the default formats for different
%   languages (see \cref{sec:code:babel}).
%\begin{macrocode}
\newcommand\crefname@preamble[3]{%
  \@crefname{cref}{#1}{#2}{#3}{@preamble}}%
\newcommand\Crefname@preamble[3]{%
  \@crefname{Cref}{#1}{#2}{#3}{@preamble}}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
%
% \begin{macro}{cref@othervariant}
%   The following utility macro sets up the appropriate definitions for
%   the other capitalisation variant. It defines the macro passed in |#2|
%   to be the other variant (``cref'' or ``Cref'') to the one specified
%   in |#1|, and defines |#3| to be the appropriate
%   capitalisation-changing command. It makes use of the fact that the
%   first character of \#1 is ``c'' for the lower-case variant and ``C''
%   for the upper-case one.
%    \begin{macrocode}
\def\cref@othervariant#1#2#3{\cref@@othervariant#1\@nil#2#3}%
\def\cref@@othervariant#1#2\@nil#3#4{%
  \if#1c%
    \def#3{C#2}%
    \def#4{\MakeUppercase}%
  \else%
    \def#3{c#2}%
    \if@cref@capitalise%
      \def#4{}%
    \else%
      \def#4{\MakeLowercase}%
    \fi%
  \fi}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@crefname}
%   The \cmd{\@crefname} utility macro does the real work of defining
%   format names, by defining an appropriately named command to contain
%   the format component, and using the additional first argument
%   (``cref'' or ``Cref'') to determine how to define the corresponding
%   command with the other capitalisation. The extra fifth argument gets
%   tagged onto the end of the generated macro names. Note that
%   \cmd{\@crefname} \emph{must not} create global definitions, or else
%   it will break \package{babel}'s \cmd{\otherlanguage},
%   \cmd{\otherlanguage*} and \cmd{\foreignlanguage} commands.
%    \begin{macrocode}
\def\@crefname#1#2#3#4#5{%
  \expandafter\def\csname #1@#2@name#5\endcsname{#3}%
  \expandafter\def\csname #1@#2@name@plural#5\endcsname{#4}%
%    \end{macrocode}
% If the other capitalisation variant is not already defined\dots
%    \begin{macrocode}
  \cref@othervariant{#1}{\@tempc}{\@tempd}%
  \@ifundefined{\@tempc @#2@name#5}{%
%    \end{macrocode}
% Define \cmd{\@tempa} and \cmd{\@tempb} to be partial expansions (expanded
% just once) of the macros for the capitalisation variant we've just
% defined above.
%    \begin{macrocode}
    \expandafter\expandafter\expandafter\def%
    \expandafter\expandafter\expandafter\@tempa%
    \expandafter\expandafter\expandafter{%
      \csname#1@#2@name\endcsname}%
    \expandafter\expandafter\expandafter\def%
    \expandafter\expandafter\expandafter\@tempb%
    \expandafter\expandafter\expandafter{%
      \csname#1@#2@name@plural\endcsname}%
%    \end{macrocode}
% Add the case-change command stored in \cmd{\@tempd} to the front of the
% definitions of \cmd{\@tempa} and \cmd{\@tempb}.
%    \begin{macrocode}
    \expandafter\ifx\@tempa\@empty\else%
      \expandafter\expandafter\expandafter\def%
      \expandafter\expandafter\expandafter\@tempa%
      \expandafter\expandafter\expandafter{%
        \expandafter\@tempd\@tempa}%
      \expandafter\expandafter\expandafter\def%
      \expandafter\expandafter\expandafter\@tempb%
      \expandafter\expandafter\expandafter{%
        \expandafter\@tempd\@tempb}%
    \fi%
%    \end{macrocode}
% Define the other capitalisation variants to be the partial expansions
% (expanded just once) of \cmd{\@tempa} and \cmd{\@tempb}. The
% \cmd{\@toksa} token register just makes the code less verbose.
%    \begin{macrocode}
    \toksdef\@toksa=0%
    \@toksa={%
      \expandafter\def\csname\@tempc @#2@name#5\endcsname}%
    \expandafter\the\expandafter\@toksa\expandafter{\@tempa}%
    \@toksa={%
      \expandafter\def\csname\@tempc @#2@name@plural#5\endcsname}%
    \expandafter\the\expandafter\@toksa\expandafter{\@tempb}%
  }{}%
%    \end{macrocode}
% Add label type to list of types that need defining from components.
%    \begin{macrocode}
  \cref@stack@add{#2}{\cref@label@types}}%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@crefconstructcomponents}
%   The \cmd{\@crefconstructcomponents} utility macro puts the reference
%   format components for the specified reference type into temporary
%   macros, for use by later macros. The ridiculous number of ``\#''
%   characters ensure that the correct number remain when they come to be
%   used later (recall that pairs ``\#\#'' are collapsed to a single
%   ``\#'' each time the code is expanded).
%    \begin{macrocode}
\def\@crefconstructcomponents#1{%
%    \end{macrocode}
% Single cross-reference label format.
%    \begin{macrocode}
  \@ifundefined{cref@#1@label}{%
    \let\@templabel\cref@default@label%
  }{%
    \expandafter\let\expandafter\@templabel%
    \csname cref@#1@label\endcsname%
  }%
%    \end{macrocode}
% Reference range label format.
%    \begin{macrocode}
  \@ifundefined{cref@#1@rangelabel}{%
    \expandafter\def\expandafter\@tempa\expandafter{%
      \@templabel{####1}{####3}{####4}}%
    \expandafter\def\expandafter\@tempb\expandafter{%
      \@templabel{####2}{####5}{####6}}%
    \toksdef\@toksa=0%
    \@toksa={\def\@temprangelabel##1##2##3##4##5##6}%
    \expandafter\expandafter\expandafter\the%
    \expandafter\expandafter\expandafter\@toksa%
    \expandafter\expandafter\expandafter{%
      \expandafter\expandafter\expandafter\crefrangepreconjunction%
      \expandafter\@tempa\expandafter\crefrangeconjunction\@tempb%
      \crefrangepostconjunction}%
  }{%
    \expandafter\let\expandafter\@temprangelabel%
    \csname cref@#1@rangelabel\endcsname%
  }%
%    \end{macrocode}
% If we're including names in hyperlinks, define variants of temporary
% label macros which lack the hyperlink start argument (it will instead
% be included in the temporary name macros).
%    \begin{macrocode}
  \if@cref@nameinlink%
    \expandafter\def\expandafter\@templabel@first\expandafter{%
      \@templabel{########1}{}{########3}}%
    \expandafter\def\expandafter\@temprangelabel@first\expandafter{%
      \@temprangelabel{########1}{########2}%
        {}{########4}{########5}{########6}}%
  \fi%
%    \end{macrocode}
% Get the correct number of ``\#'''s into the label format definitions.
%    \begin{macrocode}
  \expandafter\def\expandafter\@templabel\expandafter{%
    \@templabel{########1}{########2}{########3}}%
  \expandafter\def\expandafter\@temprangelabel\expandafter{%
    \@temprangelabel{########1}{########2}{########3}%
    {########4}{########5}{########6}}%
%    \end{macrocode}
% If we're not including names in hyperlinks, define all variants to be
% the same as standard temporary name macros.
%    \begin{macrocode}
  \if@cref@nameinlink\else%
    \let\@templabel@first\@templabel%
    \let\@temprangelabel@first\@temprangelabel%
  \fi%
%    \end{macrocode}
%
% If including names in hyperlinks, define temporary name macros to
% include hyperlink start argument.
%    \begin{macrocode}
  \if@cref@nameinlink%
    \def\@tempa##1##2{##2##1}%
%    \end{macrocode}
% Lower-case singular cross-reference name.
%    \begin{macrocode}
    \expandafter\expandafter\expandafter\def%
    \expandafter\expandafter\expandafter\@tempname%
    \expandafter\expandafter\expandafter{%
      \expandafter\@tempa\expandafter%
        {\csname cref@#1@name\endcsname}{########2}}%
%    \end{macrocode}
% Upper-case singular cross-reference name.
%    \begin{macrocode}
    \expandafter\expandafter\expandafter\def%
    \expandafter\expandafter\expandafter\@tempName%
    \expandafter\expandafter\expandafter{%
      \expandafter\@tempa\expandafter%
        {\csname Cref@#1@name\endcsname}{########2}}%
%    \end{macrocode}
% Lower-case plural cross-reference name.
%    \begin{macrocode}
    \expandafter\expandafter\expandafter\def%
    \expandafter\expandafter\expandafter\@tempnameplural%
    \expandafter\expandafter\expandafter{%
      \expandafter\@tempa\expandafter%
        {\csname cref@#1@name@plural\endcsname}{########2}}%
%    \end{macrocode}
% Upper-case plural cross-reference name.
%    \begin{macrocode}
    \expandafter\expandafter\expandafter\def%
    \expandafter\expandafter\expandafter\@tempNameplural%
    \expandafter\expandafter\expandafter{%
      \expandafter\@tempa\expandafter%
        {\csname Cref@#1@name@plural\endcsname}{########2}}%
%    \end{macrocode}
% For cross-reference ranges, the hyperlink start argument is \#3 instead
% of \#2, so we need a different variant of the temporary plural name
% macros.
%    \begin{macrocode}
    \expandafter\expandafter\expandafter\def%
    \expandafter\expandafter\expandafter\@tempnameplural@range%
    \expandafter\expandafter\expandafter{%
      \expandafter\@tempa\expandafter%
        {\csname cref@#1@name@plural\endcsname}{########3}}%
    \expandafter\expandafter\expandafter\def%
    \expandafter\expandafter\expandafter\@tempNameplural@range%
    \expandafter\expandafter\expandafter{%
      \expandafter\@tempa\expandafter%
        {\csname Cref@#1@name@plural\endcsname}{########3}}%
%    \end{macrocode}
%
% If we're not including names in hyperlinks, temporary name macros don't
% include the hyperlink start argument.
%    \begin{macrocode}
  \else%
%    \end{macrocode}
% Lower-case singular cross-reference name.
%    \begin{macrocode}
    \expandafter\def\expandafter\@tempname\expandafter{%
      \csname cref@#1@name\endcsname}%
%    \end{macrocode}
% Upper-case singular cross-reference name.
%    \begin{macrocode}
    \expandafter\def\expandafter\@tempName\expandafter{%
      \csname Cref@#1@name\endcsname}%
%    \end{macrocode}
% Lower-case plural cross-reference name.
%    \begin{macrocode}
    \expandafter\def\expandafter\@tempnameplural\expandafter{%
      \csname cref@#1@name@plural\endcsname}%
%    \end{macrocode}
% Upper-case plural cross-reference name.
%    \begin{macrocode}
    \expandafter\def\expandafter\@tempNameplural\expandafter{%
      \csname Cref@#1@name@plural\endcsname}%
%    \end{macrocode}
% Define reference range variants to be identical to normal variants.
%    \begin{macrocode}
    \let\@tempnameplural@range\@tempnameplural%
    \let\@tempNameplural@range\@tempNameplural%
  \fi%
}%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@crefdefineformat}
%   The \cmd{\@crefdefineformat} et al.\ macros construct calls to
%   \cmd{\crefformat} et al.\ for the supplied reference type, which
%   define the corresponding formats in terms of the format components.
%   This is mostly just an arduous exercise in controlling macro
%   expansion order.
%    \begin{macrocode}
\def\@crefdefineformat#1{%
  \begingroup%
%    \end{macrocode}
% Put format components into tmp macros.
%    \begin{macrocode}
    \@crefconstructcomponents{#1}%
%    \end{macrocode}
% Assemble the arguments for \cmd{\crefformat}, \cmd{\Crefformat} and
% \cmd{\labelcrefformat} from the components.
%    \begin{macrocode}
    \expandafter\ifx\csname cref@#1@name\endcsname\@empty\relax%
      \expandafter\def\expandafter\@tempfirst\expandafter{\@templabel}%
    \else%
      \expandafter\expandafter\expandafter\def%
      \expandafter\expandafter\expandafter\@tempfirst%
      \expandafter\expandafter\expandafter{%
        \expandafter\@tempname\expandafter\nobreakspace\@templabel@first}%
    \fi%
    \expandafter\ifx\csname Cref@#1@name\endcsname\@empty\relax%
      \expandafter\def\expandafter\@tempFirst\expandafter{\@templabel}%
    \else%
      \expandafter\expandafter\expandafter\def%
      \expandafter\expandafter\expandafter\@tempFirst%
      \expandafter\expandafter\expandafter{%
        \expandafter\@tempName\expandafter\nobreakspace\@templabel@first}%
    \fi%
    \expandafter\def\expandafter\@templabel\expandafter{\@templabel}%
%    \end{macrocode}
% Define \cmd{\crefformat} and \cmd{\Crefformat}.
%    \begin{macrocode}
    \toksdef\@toksa=0%
    \@toksa={\crefformat{#1}}%
    \expandafter\the\expandafter\@toksa\expandafter{\@tempfirst}%
    \@toksa={\Crefformat{#1}}%
    \expandafter\the\expandafter\@toksa\expandafter{\@tempFirst}%
%    \end{macrocode}
% Define \cmd{\labelcrefformat} if type has custom label format.
%    \begin{macrocode}
    \@ifundefined{cref@#1@label}{}{%
      \@toksa={\labelcrefformat{#1}}%
      \expandafter\the\expandafter\@toksa\expandafter{\@templabel}}%
  \endgroup}%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@crefrangedefineformat}
%   Construct call to \cmd{\crefrangeformat}.
%    \begin{macrocode}
\def\@crefrangedefineformat#1{%
  \begingroup%
%    \end{macrocode}
% Put format components into tmp macros.
%    \begin{macrocode}
    \@crefconstructcomponents{#1}%
%    \end{macrocode}
% Assemble the arguments for \cmd{\crefrangeformat},
% \cmd{\Crefrangeformat} and\linebreak[4] \cmd{\labelcrefrangeformat}
% from the components.
%    \begin{macrocode}
    \expandafter\ifx\csname cref@#1@name\endcsname\@empty\relax%
      \expandafter\def\expandafter\@tempfirst%
        \expandafter{\@temprangelabel}%
    \else%
      \expandafter\expandafter\expandafter\def%
      \expandafter\expandafter\expandafter\@tempfirst%
      \expandafter\expandafter\expandafter{%
        \expandafter\@tempnameplural@range%
        \expandafter\nobreakspace\@temprangelabel@first}%
    \fi%
    \expandafter\ifx\csname Cref@#1@name\endcsname\@empty\relax%
      \expandafter\def\expandafter\@tempFirst%
        \expandafter{\@temprangelabel}%
    \else%
      \expandafter\expandafter\expandafter\def%
      \expandafter\expandafter\expandafter\@tempFirst%
      \expandafter\expandafter\expandafter{%
        \expandafter\@tempNameplural@range%
        \expandafter\nobreakspace\@temprangelabel@first}%
    \fi%
    \expandafter\def\expandafter\@temprangelabel%
      \expandafter{\@temprangelabel}%
%    \end{macrocode}
% Define \cmd{\crefrangeformat} and \cmd{\Crefrangeformat}.
%    \begin{macrocode}
    \toksdef\@toksa=0%
    \@toksa={\crefrangeformat{#1}}%
    \expandafter\the\expandafter\@toksa\expandafter{\@tempfirst}%
    \@toksa={\Crefrangeformat{#1}}%
    \expandafter\the\expandafter\@toksa\expandafter{\@tempFirst}%
%    \end{macrocode}
% Define \cmd{\labelcrefrangeformat} if type has custom label format.
%    \begin{macrocode}
    \@ifundefined{cref@#1@rangelabel}{%
      \@ifundefined{cref@#1@label}{\let\@tempa\relax}{\def\@tempa{}}}%
      {\def\@tempa{}}%
    \ifx\@tempa\@empty\relax%
      \@toksa={\labelcrefrangeformat{#1}}%
      \expandafter\the\expandafter\@toksa\expandafter{%
        \@temprangelabel}%
    \fi%
  \endgroup}%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@crefdefinemultiformat}
%   Construct call to \cmd{\crefmultiformat}.
%    \begin{macrocode}
\def\@crefdefinemultiformat#1{%
  \begingroup%
%    \end{macrocode}
% Put format components into tmp macros.
%    \begin{macrocode}
    \@crefconstructcomponents{#1}%
%    \end{macrocode}
% Assemble the arguments for \cmd{\crefmultiformat},
% \cmd{\Crefmultiformat} and\linebreak[4] \cmd{\labelcrefmultiformat}
% from the components.
%    \begin{macrocode}
    \expandafter\ifx\csname cref@#1@name@plural\endcsname\@empty\relax%
      \expandafter\def\expandafter\@tempfirst%
        \expandafter{\@templabel}%
    \else%
      \expandafter\expandafter\expandafter\def%
      \expandafter\expandafter\expandafter\@tempfirst%
      \expandafter\expandafter\expandafter{%
        \expandafter\@tempnameplural%
        \expandafter\nobreakspace\@templabel@first}%
    \fi%
    \expandafter\ifx\csname Cref@#1@name@plural\endcsname\@empty\relax%
      \expandafter\def\expandafter\@tempFirst%
        \expandafter{\@templabel}%
    \else%
      \expandafter\expandafter\expandafter\def%
      \expandafter\expandafter\expandafter\@tempFirst%
      \expandafter\expandafter\expandafter{%
        \expandafter\@tempNameplural%
        \expandafter\nobreakspace\@templabel@first}%
    \fi%
    \expandafter\def\expandafter\@tempsecond\expandafter{%
      \expandafter\crefpairconjunction\@templabel}%
    \expandafter\def\expandafter\@tempmiddle\expandafter{%
      \expandafter\crefmiddleconjunction\@templabel}%
    \expandafter\def\expandafter\@templast\expandafter{%
      \expandafter\creflastconjunction\@templabel}%
    \expandafter\def\expandafter\@templabel\expandafter{\@templabel}%
%    \end{macrocode}
% Bundle all four arguments for \cmd{\crefmultiformat} in token register
% \cmd{\@toksb}, then call it.
%    \begin{macrocode}
    \toksdef\@toksa=0%
    \toksdef\@toksb=1%
    \@toksb={}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@tempfirst}}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@tempsecond}}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@tempmiddle}}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@templast}}%
    \@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\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@tempFirst}}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@tempsecond}}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@tempmiddle}}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@templast}}%
    \@toksa={\Crefmultiformat{#1}}%
    \expandafter\the\expandafter\@toksa\the\@toksb%
%    \end{macrocode}
% If type has custom label format, bundle all four arguments
% for\linebreak[4] \cmd{\labelcrefmultiformat} in token register
% \cmd{\@toksb}, then call it.
%    \begin{macrocode}
    \@ifundefined{cref@#1@label}{}{%
      \@toksb={}%
      \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
        \expandafter{\@templabel}}%
      \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
        \expandafter{\@tempsecond}}%
      \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
        \expandafter{\@tempmiddle}}%
      \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
        \expandafter{\@templast}}%
      \@toksa={\labelcrefmultiformat{#1}}%
      \expandafter\the\expandafter\@toksa\the\@toksb}%
  \endgroup}%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@crefrangedefinemultiformat}
%   Construct call to \cmd{\crefrangemultiformat}.
%    \begin{macrocode}
\def\@crefrangedefinemultiformat#1{%
  \begingroup%
%    \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}, \cmd{\Crefrangemultiformat} and
% \cmd{\labelcrefrangemultiformat} from the reference components.
%    \begin{macrocode}
    \expandafter\ifx\csname cref@#1@name@plural\endcsname\@empty\relax%
      \expandafter\def\expandafter\@tempfirst%
        \expandafter{\@temprangelabel}%
    \else%
      \expandafter\expandafter\expandafter\def%
      \expandafter\expandafter\expandafter\@tempfirst%
      \expandafter\expandafter\expandafter{%
        \expandafter\@tempnameplural@range%
        \expandafter\nobreakspace\@temprangelabel@first}%
    \fi%
    \expandafter\ifx\csname Cref@#1@name@plural\endcsname\@empty\relax%
      \expandafter\def\expandafter\@tempFirst%
        \expandafter{\@temprangelabel}%
    \else%
      \expandafter\expandafter\expandafter\def%
      \expandafter\expandafter\expandafter\@tempFirst%
      \expandafter\expandafter\expandafter{%
        \expandafter\@tempNameplural@range%
        \expandafter\nobreakspace\@temprangelabel@first}%
    \fi%
    \expandafter\def\expandafter\@tempsecond\expandafter{%
      \expandafter\crefpairconjunction\@temprangelabel}%
    \expandafter\def\expandafter\@tempmiddle\expandafter{%
      \expandafter\crefmiddleconjunction\@temprangelabel}%
    \expandafter\def\expandafter\@templast\expandafter{%
      \expandafter\creflastconjunction\@temprangelabel}%
    \expandafter\def\expandafter\@temprangelabel%
      \expandafter{\@temprangelabel}%
%    \end{macrocode}
% Bundle all four arguments for \cmd{\crefrangemultiformat} in token
% register \cmd{\@toksb}, then call it.
%    \begin{macrocode}
    \toksdef\@toksa=0%
    \toksdef\@toksb=1%
    \@toksb={}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@tempfirst}}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@tempsecond}}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@tempmiddle}}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@templast}}%
    \@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\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@tempFirst}}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@tempsecond}}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@tempmiddle}}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@templast}}%
    \@toksa={\Crefrangemultiformat{#1}}%
    \expandafter\the\expandafter\@toksa\the\@toksb%
%    \end{macrocode}
% If type has custom label format, bundle all four arguments
% for\linebreak[4] \cmd{\labelcrefrangemultiformat} in token register
% \cmd{\@toksb}, then call it.
%    \begin{macrocode}
    \@ifundefined{cref@#1@rangelabel}{%
      \@ifundefined{cref@#1@label}{\let\@tempa\relax}{\def\@tempa{}}}%
        {\def\@tempa{}}%
    \ifx\@tempa\@empty\relax%
      \@toksb={}%
      \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
        \expandafter{\@temprangelabel}}%
      \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
        \expandafter{\@tempsecond}}%
      \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
        \expandafter{\@tempmiddle}}%
      \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
        \expandafter{\@templast}}%
      \@toksa={\labelcrefrangemultiformat{#1}}%
      \expandafter\the\expandafter\@toksa\the\@toksb%
    \fi%
  \endgroup}%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@labelcrefdefinedefaultformats}
%   \cmd{\@labelcrefdefinedefaultformats} defines the default formats for
%   the\linebreak[4] \cmd{\labelcref} command, which are used when no
%   type-specific formats are defined.
%    \begin{macrocode}
\def\@labelcrefdefinedefaultformats{%
  \begingroup%
    \toksdef\@toksa=0%
    \toksdef\@toksb=1%
%    \end{macrocode}
% Assemble the arguments that need to be passed to
% \cmd{\labelcrefformat},\linebreak[4] \cmd{\labelcrefrangeformat},
% \cmd{\labelcrefmultiformat} and\linebreak[4]
% \cmd{\labelcrefrangemultiformat}.
%    \begin{macrocode}
    \let\@templabel\cref@default@label%
    \expandafter\def\expandafter\@tempa\expandafter{%
      \@templabel{####1}{####3}{####4}}%
    \expandafter\def\expandafter\@tempb\expandafter{%
      \@templabel{####2}{####5}{####6}}%
    \@toksa={\def\@temprangelabel##1##2##3##4##5##6}%
    \expandafter\expandafter\expandafter\the%
    \expandafter\expandafter\expandafter\@toksa%
    \expandafter\expandafter\expandafter{%
      \expandafter\expandafter\expandafter\crefrangepreconjunction%
      \expandafter\@tempa\expandafter\crefrangeconjunction\@tempb%
      \crefrangepostconjunction}%
    \expandafter\def\expandafter\@templabel\expandafter{%
      \@templabel{########1}{########2}{########3}}%
    \expandafter\def\expandafter\@temprangelabel\expandafter{%
      \@temprangelabel{########1}{########2}{########3}%
      {########4}{########5}{########6}}%
    \expandafter\def\expandafter\@tempsecond\expandafter{%
      \expandafter\crefpairconjunction\@templabel}%
    \expandafter\def\expandafter\@tempmiddle\expandafter{%
      \expandafter\crefmiddleconjunction\@templabel}%
    \expandafter\def\expandafter\@templast\expandafter{%
      \expandafter\creflastconjunction\@templabel}%
    \expandafter\def\expandafter\@temprangesecond\expandafter{%
      \expandafter\crefpairconjunction\@temprangelabel}%
    \expandafter\def\expandafter\@temprangemiddle\expandafter{%
      \expandafter\crefmiddleconjunction\@temprangelabel}%
    \expandafter\def\expandafter\@temprangelast\expandafter{%
      \expandafter\creflastconjunction\@temprangelabel}%
    \expandafter\def\expandafter\@templabel\expandafter{\@templabel}%
    \expandafter\def\expandafter\@temprangelabel%
      \expandafter{\@temprangelabel}%
%    \end{macrocode}
% Define default \cmd{\labelcrefformat}.
%    \begin{macrocode}
    \@toksa={\labelcrefformat{default}}%
    \expandafter\the\expandafter\@toksa\expandafter{\@templabel}%
%    \end{macrocode}
% Define default \cmd{\labelcrefrangeformat}.
%    \begin{macrocode}
    \@toksa={\labelcrefrangeformat{default}}%
    \expandafter\the\expandafter\@toksa\expandafter{\@temprangelabel}%
%    \end{macrocode}
% Bundle all four arguments for \cmd{\labelcrefmultiformat} in token
% register \cmd{\@toksb}, then call it to define default formats.
%    \begin{macrocode}
    \@toksb={}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@templabel}}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@tempsecond}}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@tempmiddle}}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@templast}}%
    \@toksa={\labelcrefmultiformat{default}}%
    \expandafter\the\expandafter\@toksa\the\@toksb%
%    \end{macrocode}
% Bundle all four arguments for \cmd{\labelcrefrangemultiformat} in token
% register \cmd{\@toksb}, then call it to define default formats.
%    \begin{macrocode}
    \@toksb={}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@temprangelabel}}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@temprangesecond}}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@temprangemiddle}}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@temprangelast}}%
    \@toksa={\labelcrefrangemultiformat{default}}%
    \expandafter\the\expandafter\@toksa\the\@toksb%
  \endgroup}%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@crefdefineallformats}
%   \cmd{\@crefdefineallformats} calls each of the above, to define all
%   formats for the given type from the corresponding components.
%    \begin{macrocode}
\def\@crefdefineallformats#1{%
  \@crefdefineformat{#1}%
  \@crefrangedefineformat{#1}%
  \@crefdefinemultiformat{#1}%
  \@crefrangedefinemultiformat{#1}}%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@crefcopyformats}
%   \cmd{\@crefcopyformats} copies any undefined formats for type |#2|
%   from those for type |#1|.
%    \begin{macrocode}
\def\@crefcopyformats#1#2{%
  \let\@tempf\iffalse%
  \@ifundefined{cref@#2@name}{%
    \edef\@tempa{\expandafter\noexpand\csname cref@#2@name\endcsname}%
    \edef\@tempb{\expandafter\noexpand\csname cref@#1@name\endcsname}%
    \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb%
    \edef\@tempa{\expandafter\noexpand\csname cref@#2@name@plural\endcsname}%
    \edef\@tempb{\expandafter\noexpand\csname cref@#1@name@plural\endcsname}%
    \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb%
  }{%
    \let\@tempf\iftrue%
  }%
  \@ifundefined{Cref@#2@name}{%
    \edef\@tempa{\expandafter\noexpand\csname Cref@#2@name\endcsname}%
    \edef\@tempb{\expandafter\noexpand\csname Cref@#1@name\endcsname}%
    \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb%
    \edef\@tempa{\expandafter\noexpand\csname Cref@#2@name@plural\endcsname}%
    \edef\@tempb{\expandafter\noexpand\csname Cref@#1@name@plural\endcsname}%
    \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb%
  }{%
    \let\@tempf\iftrue%
  }%
  \@ifundefined{cref@#2@label}{%
    \@ifundefined{cref@#1@label}{}{%
      \edef\@tempa{\expandafter\noexpand\csname cref@#2@label\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname cref@#1@label\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}%
  }{%
    \let\@tempf\iftrue%
  }%
  \@ifundefined{cref@#2@rangelabel}{%
    \@ifundefined{cref@#1@rangelabel}{}{%
      \edef\@tempa{\expandafter\noexpand\csname cref@#2@rangelabel\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname cref@#1@rangelabel\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}%
  }{%
    \let\@tempf\iftrue%
  }%
%    \end{macrocode}
% If at least one format component has been customised specifically for
% reference type |#2|, generate its formats from components.
%    \begin{macrocode}
  \@tempf\relax%
    \@crefdefineallformats{#2}%
%    \end{macrocode}
% If no format components have been defined for reference type |#2|, copy
% over the low-level formats from type |#1|.
%    \begin{macrocode}
  \else%
    \@ifundefined{cref@#2@format}{%
      \edef\@tempa{\expandafter\noexpand\csname cref@#2@format\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname cref@#1@format\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{crefrange@#2@format}{%
      \edef\@tempa{\expandafter\noexpand\csname crefrange@#2@format\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname crefrange@#1@format\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{cref@#2@format@first}{%
      \edef\@tempa{\expandafter\noexpand\csname cref@#2@format@first\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname cref@#1@format@first\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{cref@#2@format@second}{%
      \edef\@tempa{\expandafter\noexpand\csname cref@#2@format@second\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname cref@#1@format@second\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{cref@#2@format@middle}{%
      \edef\@tempa{\expandafter\noexpand\csname cref@#2@format@middle\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname cref@#1@format@middle\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{cref@#2@format@last}{%
      \edef\@tempa{\expandafter\noexpand\csname cref@#2@format@last\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname cref@#1@format@last\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{crefrange@#2@format@first}{%
      \edef\@tempa{\expandafter\noexpand\csname crefrange@#2@format@first\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname crefrange@#1@format@first\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{crefrange@#2@format@second}{%
      \edef\@tempa{\expandafter\noexpand\csname crefrange@#2@format@second\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname crefrange@#1@format@second\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{crefrange@#2@format@middle}{%
      \edef\@tempa{\expandafter\noexpand\csname crefrange@#2@format@middle\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname crefrange@#1@format@middle\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{crefrange@#2@format@last}{%
      \edef\@tempa{\expandafter\noexpand\csname crefrange@#2@format@last\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname crefrange@#1@format@last\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
%
    \@ifundefined{Cref@#2@format}{%
      \edef\@tempa{\expandafter\noexpand\csname Cref@#2@format\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname Cref@#1@format\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{Crefrange@#2@format}{%
      \edef\@tempa{\expandafter\noexpand\csname Crefrange@#2@format\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname Crefrange@#1@format\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{Cref@#2@format@first}{%
      \edef\@tempa{\expandafter\noexpand\csname Cref@#2@format@first\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname Cref@#1@format@first\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{Cref@#2@format@second}{%
      \edef\@tempa{\expandafter\noexpand\csname Cref@#2@format@second\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname Cref@#1@format@second\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{Cref@#2@format@middle}{%
      \edef\@tempa{\expandafter\noexpand\csname Cref@#2@format@middle\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname Cref@#1@format@middle\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{Cref@#2@format@last}{%
      \edef\@tempa{\expandafter\noexpand\csname Cref@#2@format@last\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname Cref@#1@format@last\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{Crefrange@#2@format@first}{%
      \edef\@tempa{\expandafter\noexpand\csname Crefrange@#2@format@first\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname Crefrange@#1@format@first\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{Crefrange@#2@format@second}{%
      \edef\@tempa{\expandafter\noexpand\csname Crefrange@#2@format@second\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname Crefrange@#1@format@second\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{Crefrange@#2@format@middle}{%
      \edef\@tempa{\expandafter\noexpand\csname Crefrange@#2@format@middle\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname Crefrange@#1@format@middle\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{Crefrange@#2@format@last}{%
      \edef\@tempa{\expandafter\noexpand\csname Crefrange@#2@format@last\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname Crefrange@#1@format@last\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
%
    \@ifundefined{labelcref@#2@format}{%
      \edef\@tempa{\expandafter\noexpand\csname labelcref@#2@format\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname labelcref@#1@format\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{labelcrefrange@#2@format}{%
      \edef\@tempa{\expandafter\noexpand\csname labelcrefrange@#2@format\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname labelcrefrange@#1@format\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{labelcref@#2@format@first}{%
      \edef\@tempa{\expandafter\noexpand\csname labelcref@#2@format@first\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname labelcref@#1@format@first\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{labelcref@#2@format@second}{%
      \edef\@tempa{\expandafter\noexpand\csname labelcref@#2@format@second\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname labelcref@#1@format@second\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{labelcref@#2@format@middle}{%
      \edef\@tempa{\expandafter\noexpand\csname labelcref@#2@format@middle\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname labelcref@#1@format@middle\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{labelcref@#2@format@last}{%
      \edef\@tempa{\expandafter\noexpand\csname labelcref@#2@format@last\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname labelcref@#1@format@last\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{labelcrefrange@#2@format@first}{%
      \edef\@tempa{\expandafter\noexpand\csname labelcrefrange@#2@format@first\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname labelcrefrange@#1@format@first\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{labelcrefrange@#2@format@second}{%
      \edef\@tempa{\expandafter\noexpand\csname labelcrefrange@#2@format@second\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname labelcrefrange@#1@format@second\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{labelcrefrange@#2@format@middle}{%
      \edef\@tempa{\expandafter\noexpand\csname labelcrefrange@#2@format@middle\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname labelcrefrange@#1@format@middle\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{labelcrefrange@#2@format@last}{%
      \edef\@tempa{\expandafter\noexpand\csname labelcrefrange@#2@format@last\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname labelcrefrange@#1@format@last\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsubsection{Format definition commands}
% \label{sec:crefformat}
% \begin{macro}{\crefformat}
% \begin{macro}{\Crefformat}
% \begin{macro}{\crefrangeformat}
% \begin{macro}{\Crefrangeformat}
% \begin{macro}{\crefmultiformat}
% \begin{macro}{\Crefmultiformat}
% \begin{macro}{\crefrangemultiformat}
% \begin{macro}{\Crefrangemultiformat}
%   \cmd{\crefformat} et al.\ are lower-level commands that give complete
%   control over the format of different reference types. They override
%   the component-based formats, simply using the supplied arguments to
%   define appropriately named formatting macros, which are called by
%   \cmd{\@@setcref} etc. If the corresponding \cmd{\Crefformat} or
%   \cmd{\crefformat} variant is not already defined, they define it to
%   be a version with the first letter capitalised or lower-cased.
%    \begin{macrocode}
\newcommand\crefformat[2]{\@crefformat{cref}{#1}{#2}}%
\newcommand\Crefformat[2]{\@crefformat{Cref}{#1}{#2}}%
\newcommand\crefrangeformat[2]{\@crefrangeformat{crefrange}{#1}{#2}}%
\newcommand\Crefrangeformat[2]{\@crefrangeformat{Crefrange}{#1}{#2}}%
\newcommand\crefmultiformat[5]{%
  \@crefmultiformat{cref}{#1}{#2}{#3}{#4}{#5}}%
\newcommand\Crefmultiformat[5]{%
  \@crefmultiformat{Cref}{#1}{#2}{#3}{#4}{#5}}%
\newcommand\crefrangemultiformat[5]{%
  \@crefrangemultiformat{crefrange}{#1}{#2}{#3}{#4}{#5}}%
\newcommand\Crefrangemultiformat[5]{%
  \@crefrangemultiformat{Crefrange}{#1}{#2}{#3}{#4}{#5}}%
\newcommand\labelcrefformat[2]{%
  \expandafter\gdef\csname labelcref@#1@format\endcsname##1##2##3{#2}}%
\newcommand\labelcrefrangeformat[2]{%
  \expandafter\gdef\csname labelcrefrange@#1@format\endcsname%
  ##1##2##3##4##5##6{#2}}%
\newcommand\labelcrefmultiformat[5]{%
  \expandafter\gdef\csname labelcref@#1@format@first\endcsname%
    ##1##2##3{#2}%
  \expandafter\gdef\csname labelcref@#1@format@second\endcsname%
    ##1##2##3{#3}%
  \expandafter\gdef\csname labelcref@#1@format@middle\endcsname%
    ##1##2##3{#4}%
  \expandafter\gdef\csname labelcref@#1@format@last\endcsname%
    ##1##2##3{#5}}%
\newcommand\labelcrefrangemultiformat[5]{%
  \expandafter\gdef\csname labelcrefrange@#1@format@first\endcsname%
    ##1##2##3##4##5##6{#2}%
  \expandafter\gdef\csname labelcrefrange@#1@format@second\endcsname%
    ##1##2##3##4##5##6{#3}%
  \expandafter\gdef\csname labelcrefrange@#1@format@middle\endcsname%
    ##1##2##3##4##5##6{#4}%
  \expandafter\gdef\csname labelcrefrange@#1@format@last\endcsname%
    ##1##2##3##4##5##6{#5}}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% The utility macros do the real work, by using the first argument
% (``cref'' or ``Cref'', and ``crefrange'' or ``Crefrange'') to determine
% how to define the corresponding command with the other capitalisation.
% \begin{macro}{\@crefformat}
%   \cmd{\@crefformat} defines the macros for single references.
%    \begin{macrocode}
\def\@crefformat#1#2#3{%
  \begingroup%
    \expandafter\gdef\csname #1@#2@format\endcsname##1##2##3{#3}%
%    \end{macrocode}
% If the other capitalisation variant is not already defined\dots
%    \begin{macrocode}
    \cref@othervariant{#1}{\@other}{\@changecase}%
    \@ifundefined{\@other @#2@format}{%
%    \end{macrocode}
% Define \cmd{\@tempa} 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}
      \toksdef\@toksa=0%
      \@toksa={\def\@tempa##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{\@tempa}.
%    \begin{macrocode}
      \expandafter\expandafter\expandafter\the%
      \expandafter\expandafter\expandafter\@toksa%
      \expandafter\expandafter\expandafter{%
        \expandafter\@changecase\@tempa{##1}{##2}{##3}}%
%    \end{macrocode}
% Define the other capitalisation variant to be the partial expansion
% (expanded just once) of \cmd{\@tempa}.
%    \begin{macrocode}
      \@toksa={%
        \expandafter\gdef\csname\@other @#2@format\endcsname##1##2##3}%
      \expandafter\the\expandafter\@toksa\expandafter{%
        \@tempa{##1}{##2}{##3}}%
    }{}%
  \endgroup}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@crefrangeformat}
%   \cmd{\@crefrangeformat} defines the macros for single reference
%   ranges.
%    \begin{macrocode}
\def\@crefrangeformat#1#2#3{%
  \begingroup%
    \expandafter\gdef\csname #1@#2@format\endcsname%
      ##1##2##3##4##5##6{#3}%
%    \end{macrocode}
% If the other capitalisation variant is not already defined\dots
%    \begin{macrocode}
    \cref@othervariant{#1}{\@other}{\@changecase}%
    \@ifundefined{\@other @#2@format}{%
%    \end{macrocode}
% Define \cmd{\@tempa} 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}
      \toksdef\@toksa=0%
      \@toksa={\def\@tempa##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{\@tempa}.
%    \begin{macrocode}
      \expandafter\expandafter\expandafter\the%
      \expandafter\expandafter\expandafter\@toksa%
      \expandafter\expandafter\expandafter{%
        \expandafter\@changecase\@tempa{##1}{##2}{##3}{##4}{##5}{##6}}%
%    \end{macrocode}
% Define the other capitalisation variant to be the partial expansion
% (expanded just once) of \cmd{\@tempa}.
%    \begin{macrocode}
      \@toksa={\expandafter\gdef%
        \csname\@other @#2@format\endcsname##1##2##3##4##5##6}%
      \expandafter\the\expandafter\@toksa\expandafter{%
        \@tempa{##1}{##2}{##3}{##4}{##5}{##6}}%
    }{}%
  \endgroup}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@crefmultiformat}
%   \cmd{\@crefmultiformat} defines the macros for multiple references.
%    \begin{macrocode}
\def\@crefmultiformat#1#2#3#4#5#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}
% If the other capitalisation variant of the first part of the
% multi-format definition is not already defined\dots
%    \begin{macrocode}
    \cref@othervariant{#1}{\@other}{\@changecase}%
    \@ifundefined{\@other @#2@format@first}{%
%    \end{macrocode}
% Define \cmd{\@tempa} 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}
      \toksdef\@toksa=0%
      \@toksa={\def\@tempa##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{\@tempa}.
%    \begin{macrocode}
      \expandafter\expandafter\expandafter\the%
      \expandafter\expandafter\expandafter\@toksa%
      \expandafter\expandafter\expandafter{%
        \expandafter\@changecase\@tempa{##1}{##2}{##3}}%
%    \end{macrocode}
% Define the other capitalisation variant to be the partial expansion
% (expanded just once) of \cmd{\@tempa}.
%    \begin{macrocode}
      \@toksa={%
        \expandafter\gdef\csname\@other @#2@format@first\endcsname%
          ##1##2##3}%
      \expandafter\the\expandafter\@toksa\expandafter{%
        \@tempa{##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\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}
%\end{macro}
%
% \begin{macro}{\@crefrangemultiformat}
%   \cmd{\@crefmultiformat} defines the macros for reference ranges
%   within multiple references.
%    \begin{macrocode}
\def\@crefrangemultiformat#1#2#3#4#5#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}
% If the other capitalisation variant of the first part of the
% multi-format definition is not already defined\dots
%    \begin{macrocode}
    \cref@othervariant{#1}{\@other}{\@changecase}%
    \@ifundefined{\@other @#2@format@first}{%
%    \end{macrocode}
% Define \cmd{\@tempa} 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}
      \toksdef\@toksa=0%
      \@toksa={\def\@tempa##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{\@tempa}.
%    \begin{macrocode}
      \expandafter\expandafter\expandafter\the%
      \expandafter\expandafter\expandafter\@toksa%
      \expandafter\expandafter\expandafter{%
        \expandafter\@changecase\@tempa{##1}{##2}{##3}{##4}{##5}{##6}}%
%    \end{macrocode}
% Define the other capitalisation variant to be the partial expansion
% (expanded just once) of \cmd{\@tempa}.
%    \begin{macrocode}
      \@toksa={%
        \expandafter\gdef\csname\@other @#2@format@first\endcsname%
          ##1##2##3##4##5##6}%
      \expandafter\the\expandafter\@toksa\expandafter{%
        \@tempa{##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\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}
% \end{macro}
%
%
%
% \subsection{Support for Other Packages}
%
% \subsubsection{\package{hyperref} support}
% \begin{macro}{hyperref}
%   If the \package{hyperref} package is loaded, we add hyperlink
%   support to \package{cleveref}. Since \package{hyperref} messes around
%   with some of the same \LaTeX{} internals as we do, we also have to
%   override some of its redefinitions so that they work with
%   \package{cleveref}.
%    \begin{macrocode}
\let\if@cref@hyperrefloaded\iffalse%
\let\cref@addtoreset\@addtoreset%
\@ifpackageloaded{hyperref}{%
  \@ifpackagewith{hyperref}{implicit=false}{%
    \let\if@cref@hyperrefloaded\iftrue%
    \PackageWarning{cleveref}{hyperref package loaded with
      implicit=false option - disabling cleveref's hyperref support.
      This situation is not supported by cleveref, and there's no guarantee
      anything will work. You're on your own!}%
  }{%
    \let\if@cref@hyperrefloaded\iftrue%
    \PackageInfo{cleveref}{`hyperref' support loaded}%
%    \end{macrocode}
% \package{hyperref} redefines the \LaTeX{} kernel \cmd{\@addtoreset}
% macro (sigh), but we sometimes need the vanilla version without the
% \package{hyperref} shennanigans. \package{hyperref} saves the
% original in \cmd{\HyOrg@addtoreset}. So we create yet
% \emph{another} version called \cmd{\cref@addtotreset}, which is always
% let to the original \cmd{\@addtoreset}, whereever that's found.
%    \begin{macrocode}
    \let\cref@addtoreset\HyOrg@addtoreset%
%    \end{macrocode}
% \begin{macro}{\cref@hyperlinkname}
% \begin{macro}{\cref@hyperlinkurl}
%   We define a utility macro to extract the hyperlink supplied by
%   \package{hyperref} (via the \file{aux} file). Note that
%   \package{hyperref} adds the hyperlink info to the standard
%   \cmd{\newlabel} line in the \file{aux} file, so we have to retrieve
%   it from the standard \cmd{\r@\meta{label}}, \emph{not} the one
%   suffixed with |@cref| that we've created ourselves.
%    \begin{macrocode}
    \def\cref@hyperlinkname#1{\expandafter\expandafter\expandafter%
      \@fourthoffive\csname r@#1\endcsname}%
    \def\cref@hyperlinkurl#1{\expandafter\expandafter\expandafter%
      \@fifthoffive\csname r@#1\endcsname}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\cref@hyperlink}
%   Because of the way the cross-referencing formatting commands work, we
%   will need to use a delimited argument to specify the text to be
%   turned into a hyperlink. So we define a variant of
%   \package{hyperref}'s \cmd{\hyper@@link} command that takes the
%   hyperlink text as an argument delimited by |\@nil|, instead of a
%   standard argument. (We only ever need the |link| hyperlink type in
%   \package{cleveref}, so we don't bother providing \cmd{\hyper@@link}'s
%   optional argument.)
%    \begin{macrocode}
    \def\cref@hyperlink#1#2#3\@nil{\hyper@@link[link]{#1}{#2}{#3}}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\H@refstepcounter}
%   The \package{hyperref} package stores the original
%   \cmd{\refstepcounter} definition as\linebreak[4]
%   \cmd{\H@refstepcounter}. Unfortunately, it plasters
%   \cmd{\H@refstepcounter} all over the place, sometimes bypassing
%   \cmd{\refstepcounter} entirely. So we're forced to modify
%   \cmd{\H@refstepcounter} itself, in order to ensure that the extra
%   information we need is stored in \cmd{\cref@currentlabel}.
%    \begin{macrocode}
    \let\cref@old@H@refstepcounter\H@refstepcounter%
    \def\H@refstepcounter#1{%
      \cref@old@H@refstepcounter{#1}%
      \cref@constructprefix{#1}{\cref@result}%
      \@ifundefined{cref@#1@alias}%
        {\def\@tempa{#1}}%
        {\def\@tempa{\csname cref@#1@alias\endcsname}}%
      \protected@edef\cref@currentlabel{%
        [\@tempa][\arabic{#1}][\cref@result]%
        \csname p@#1\endcsname\csname the#1\endcsname}}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\refstepcounter@noarg}
% \begin{macro}{\refstepcounter@optarg}
%   \package{hyperref}'s \cmd{\refstepcounter}, which ends up stored in
%   our\linebreak[4] \cmd{\cref@old@refstepcounter}, already calls
%   \cmd{\H@refstepcounter}, and we just redefined the latter to store
%   the extra information. So we only need to change
%   \cmd{\cref@currentlabel} in \emph{our} \cmd{\refstepcounter} if an
%   optional argument was supplied. Note that, in this case, the
%   mechanism for setting \cmd{\cref@currentlabel} is slightly different
%   than it is without \package{hyperref}: \cmd{\cref@currentlabel} first
%   gets set by our modified \cmd{\H@refstepcounter}, which gets called
%   via \package{hyperref}'s original version, as stored in
%   \cmd{\cref@old@refstepcounter}. The version of
%   \cmd{\cref@refstepcounter@optarg} defined below then overrides the
%   label type.
%    \begin{macrocode}
    \let\refstepcounter@noarg\cref@old@refstepcounter%
    \def\refstepcounter@optarg[#1]#2{%
      \cref@old@refstepcounter{#2}%
      \@ifundefined{cref@#1@alias}%
        {\def\@tempa{#1}}%
        {\def\@tempa{\csname cref@#1@alias\endcsname}}%
      \protected@edef\cref@currentlabel{%
        \expandafter\cref@override@label@type%
          \cref@currentlabel\@nil{\@tempa}}}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\appendix}
%   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}
    \@ifundefined{appendix}{}{%
      \def\appendix{%
        \@ifundefined{chapter}{%
          \def\H@refstepcounter##1{%
            \cref@old@H@refstepcounter{##1}%
            \cref@constructprefix{##1}{\cref@result}%
%    \end{macrocode}
%         We add a large value to the front of the counter data, to force
%         references to anything in appendices to be sorted after
%         everything else.
%    \begin{macrocode}
            \ifx\cref@result\@empty%
              \def\cref@result{2147483647}%
            \else%
              \edef\cref@result{2147483647,\cref@result}%
            \fi%
%    \end{macrocode}
%         Override the cross-reference type of sectioning commands.
%    \begin{macrocode}
            \def\@tempa{##1}%
            \def\@tempb{section}%
            \ifx\@tempa\@tempb%
              \@ifundefined{cref@appendix@alias}%
                {\def\@tempa{appendix}}%
                {\def\@tempa{\cref@appendix@alias}}%
              \protected@edef\cref@currentlabel{%
                [\@tempa][\arabic{##1}][\cref@result]%
                \csname p@##1\endcsname\csname the##1\endcsname}%
            \else%
              \def\@tempa{##1}%
              \def\@tempb{subsection}%
              \ifx\@tempa\@tempb%
                \@ifundefined{cref@subappendix@alias}%
                  {\def\@tempa{subappendix}}%
                  {\def\@tempa{\cref@subappendix@alias}}%
                \protected@edef\cref@currentlabel{%
                  [\@tempa][\arabic{##1}][\cref@result]%
                  \csname p@##1\endcsname\csname the##1\endcsname}%
              \else%
                \def\@tempa{##1}%
                \def\@tempb{subsubsection}%
                \ifx\@tempa\@tempb%
                  \@ifundefined{cref@subsubappendix@alias}%
                    {\def\@tempa{subsubappendix}}%
                    {\def\@tempa{\cref@subsubappendix@alias}}%
                  \protected@edef\cref@currentlabel{%
                    [\@tempa][\arabic{##1}][\cref@result]%
                    \csname p@##1\endcsname\csname the##1\endcsname}%
                \else%
                  \@ifundefined{cref@##1@alias}%
                    {\def\@tempa{##1}}%
                    {\def\@tempa{\csname cref@##1@alias\endcsname}}%
                  \protected@edef\cref@currentlabel{%
                    [\@tempa][\arabic{##1}][\cref@result]%
                    \csname p@##1\endcsname\csname the##1\endcsname}%
                \fi%
              \fi%
            \fi}%
          \cref@old@appendix%
        }{%
          \def\H@refstepcounter##1{%
            \cref@old@H@refstepcounter{##1}%
            \cref@constructprefix{##1}{\cref@result}%
%    \end{macrocode}
%         Again, the large value added to the front of the counter data
%         forces references to appendix items to be sorted last.
%    \begin{macrocode}
            \ifx\cref@result\@empty%
              \def\cref@result{2147483647}%
            \else%
              \edef\cref@result{2147483647,\cref@result}%
            \fi%
%    \end{macrocode}
%         Override the cross-reference type of sectioning commands.
%    \begin{macrocode}
            \def\@tempa{##1}%
            \def\@tempb{chapter}%
            \ifx\@tempa\@tempb%
              \@ifundefined{cref@appendix@alias}%
                {\def\@tempa{appendix}}%
                {\def\@tempa{\cref@appendix@alias}}%
              \protected@edef\cref@currentlabel{%
                [\@tempa][\arabic{##1}][\cref@result]%
                \csname p@##1\endcsname\csname the##1\endcsname}%
            \else%
              \def\@tempa{##1}%
              \def\@tempb{section}%
              \ifx\@tempa\@tempb%
                \@ifundefined{cref@subappendix@alias}%
                  {\def\@tempa{subappendix}}%
                  {\def\@tempa{\cref@subappendix@alias}}%
                \protected@edef\cref@currentlabel{%
                  [\@tempa][\arabic{##1}][\cref@result]%
                  \csname p@##1\endcsname\csname the##1\endcsname}%
              \else%
                \def\@tempa{##1}%
                \def\@tempb{subsection}%
                \ifx\@tempa\@tempb%
                  \@ifundefined{cref@subsubappendix@alias}%
                    {\def\@tempa{subsubappendix}}%
                    {\def\@tempa{\cref@subsubappendix@alias}}%
                  \protected@edef\cref@currentlabel{%
                    [\@tempa][\arabic{##1}][\cref@result]%
                    \csname p@##1\endcsname\csname the##1\endcsname}%
                \else%
                  \def\@tempa{##1}%
                  \def\@tempb{subsubsection}%
                  \ifx\@tempa\@tempb%
                    \@ifundefined{cref@subsubappendix@alias}%
                      {\def\@tempa{subsubsubappendix}}%
                      {\def\@tempa{\cref@subsubsubappendix@alias}}%
                    \protected@edef\cref@currentlabel{%
                      [\@tempa][\arabic{##1}][\cref@result]%
                      \csname p@##1\endcsname\csname the##1\endcsname}%
                  \else%
                    \@ifundefined{cref@##1@alias}%
                      {\def\@tempa{##1}}%
                      {\def\@tempa{\csname cref@##1@alias\endcsname}}%
                    \protected@edef\cref@currentlabel{%
                      [\@tempa][\arabic{##1}][\cref@result]%
                      \csname p@##1\endcsname\csname the##1\endcsname}%
                  \fi%
                \fi%
              \fi%
            \fi}%
      \cref@old@appendix}%
      }%
    }% end of \@ifundefined{appendix}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cref*}
% \begin{macro}{\Cref*}
% \begin{macro}{\@crefstar}
%   We redefine \cmd{\cref} and all the others to allow starred variants,
%   which don't create hyperlinks. The starred variants simply set a
%   flag, which is tested in the very final stage of reference
%   typesetting in \cmd{\@@@setcref}, \cmd{\@@@setcrefrange},
%   \cmd{\@@@setcpageref} and \cmd{\@@@setcpagerefrange} (below).
%    \begin{macrocode}
    \DeclareRobustCommand{\cref}{%
      \@ifstar{\@crefstar{cref}}{\@cref{cref}}}%
    \DeclareRobustCommand{\Cref}{%
      \@ifstar{\@crefstar{Cref}}{\@cref{Cref}}}%
    \def\@crefstar#1#2{%
      \@crefstarredtrue\@cref{#1}{#2}\@crefstarredfalse}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\crefrange*}
% \begin{macro}{\Crefrange*}
% \begin{macro}{\@crefrangestar}
% \begin{macro}{\@crefrangenostar}
%    \begin{macrocode}
    \DeclareRobustCommand{\crefrange}{%
      \@ifstar{\@crefrangestar{cref}}{\@crefrangenostar{cref}}}%
    \DeclareRobustCommand{\Crefrange}{%
      \@ifstar{\@crefrangestar{Cref}}{\@crefrangenostar{Cref}}}%
    \def\@crefrangenostar#1#2#3{\@@setcrefrange{#1}{#2}{#3}{}}
    \def\@crefrangestar#1#2#3{%
      \@crefstarredtrue\@@setcrefrange{#1}{#2}{#3}{}\@crefstarredfalse}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\cpageref*}
% \begin{macro}{\Cpageref*}
%    \begin{macrocode}
    \DeclareRobustCommand{\cpageref}{%
      \@ifstar\@crefstar\@cref{cpageref}}%
    \DeclareRobustCommand{\Cpageref}{%
      \@ifstar\@crefstar\@cref{Cpageref}}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \begin{macro}{\cpagerefrange*}
% \begin{macro}{\Cpagerefrange*}
% \begin{macro}{\@cpagerefrangestar}
%    \begin{macrocode}
    \DeclareRobustCommand{\cpagerefrange}{%
      \@ifstar{\@cpagerefrangestar{cref}}{\@cpagerefrangenostar{cref}}}%
    \DeclareRobustCommand{\Cpagerefrange}{%
      \@ifstar{\@cpagerefrangestar{Cref}}{\@cpagerefrangenostar{Cref}}}%
    \def\@cpagerefrangenostar#1#2#3{%
      \@@setcpagerefrange{#2}{#3}{#1}{}}
    \def\@cpagerefrangestar#1#2#3{%
      \@crefstarredtrue%
      \@@setcpagerefrange{#2}{#3}{#1}{}%
      \@crefstarredfalse}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\labelcref*}
% \begin{macro}{\labelcpageref*}
% \begin{macro}{\@labelcrefstar}
% \begin{macro}{\@labelcpagerefstar}
%    \begin{macrocode}
    \DeclareRobustCommand{\labelcref}{%
      \@ifstar{\@labelcrefstar}{\@cref{labelcref}}}%
    \def\@labelcrefstar#1{%
      \@crefstarredtrue%
      \@cref{labelcref}{#1}%
      \@crefstarredfalse}%
    \DeclareRobustCommand{\labelcpageref}{%
      \@ifstar{\@labelcpagerefstar}{\@cref{labelcpageref}}}%
    \def\@labelcpagerefstar#1{%
      \@crefstarredtrue%
      \@cref{labelcpageref}{#1}%
      \@crefstarredfalse}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@@@setcref}
% \begin{macro}{\@@@setcrefrange}
% \begin{macro}{\@@@setcpageref}
% \begin{macro}{\@@@setcpagerefrange}
%   Redefine the final reference typesetting macros to create hyperlinks
%   (unless the starred flag is set), using the extra arguments supplied
%   in \cmd{\r@\meta{label}} (via the \file{aux} file) by
%   \package{hyperref}.
%    \begin{macrocode}
    \def\@@@setcref#1#2{%
      \cref@getlabel{#2}{\@templabel}%
      \if@crefstarred%
        #1{\@templabel}{}{}%
      \else%
        \edef\@tempname{\cref@hyperlinkname{#2}}%
        \edef\@tempurl{\cref@hyperlinkurl{#2}}%
        #1{\@templabel}{\cref@hyperlink{\@tempurl}{\@tempname}}{\@nil}%
      \fi}%
    \def\@@@setcrefrange#1#2#3{%
      \cref@getlabel{#2}{\@labela}%
      \cref@getlabel{#3}{\@labelb}%
      \if@crefstarred%
        #1{\@labela}{\@labelb}{}{}{}{}%
      \else%
        \edef\@tempnamea{\cref@hyperlinkname{#2}}%
        \edef\@tempurlb{\cref@hyperlinkurl{#3}}%
        \edef\@tempnameb{\cref@hyperlinkname{#3}}%
        \edef\@tempurla{\cref@hyperlinkurl{#2}}%
        #1{\@labela}{\@labelb}%
          {\cref@hyperlink{\@tempurla}{\@tempnamea}}{\@nil}%
          {\cref@hyperlink{\@tempurlb}{\@tempnameb}}{\@nil}%
      \fi}%
    \def\@@@setcpageref#1#2{%
      \cpageref@getlabel{#2}{\@temppage}%
      \if@crefstarred%
        #1{\@temppage}{}{}%
      \else%
        \edef\@tempname{\cref@hyperlinkname{#2}}%
        \edef\@tempurl{\cref@hyperlinkurl{#2}}%
        #1{\@temppage}{\cref@hyperlink{\@tempurl}{\@tempname}}{\@nil}%
      \fi}%
    \def\@@@setcpagerefrange#1#2#3{%
      \cpageref@getlabel{#2}{\@pagea}%
      \cpageref@getlabel{#3}{\@pageb}%
      \if@crefstarred%
        #1{\@pagea}{\@pageb}{}{}{}{}%
      \else%
        \edef\@tempnamea{\cref@hyperlinkname{#2}}%
        \edef\@tempurlb{\cref@hyperlinkurl{#3}}%
        \edef\@tempnameb{\cref@hyperlinkname{#3}}%
        \edef\@tempurla{\cref@hyperlinkurl{#2}}%
        #1{\@pagea}{\@pageb}%
          {\cref@hyperlink{\@tempurla}{\@tempnamea}}{\@nil}%
          {\cref@hyperlink{\@tempurlb}{\@tempnameb}}{\@nil}%
      \fi}%
  }%  end of false case of \@ifpackagewith{hyperref}{implicit=false}
%    \end{macrocode}
%
%
% \subsubsection{\package{revtex4} and \package{revtex4-1} support}
% The \package{revtex4} and \package{revtex4-1} document classes use
% |\H@refstepcounter| to increment section counters, even when
% \package{hyperref} isn't explicitly loaded. Therefore, for these
% docclasses we need to redefine |\H@refstepcounter| even when
% \package{hyperref} is not loaded.
%    \begin{macrocode}
}{% false case of \@ifpackageloaded{hyperref}
  \@ifclassloaded{revtex4}{\let\if@cref@hyperrefloaded\iftrue}{}%
  \@ifclassloaded{revtex4-1}{\let\if@cref@hyperrefloaded\iftrue}{}%
  \if@cref@hyperrefloaded\relax%
    \let\cref@old@H@refstepcounter\H@refstepcounter%
    \def\H@refstepcounter#1{%
      \cref@old@H@refstepcounter{#1}%
      \cref@constructprefix{#1}{\cref@result}%
      \@ifundefined{cref@#1@alias}%
        {\def\@tempa{#1}}%
        {\def\@tempa{\csname cref@#1@alias\endcsname}}%
      \protected@edef\cref@currentlabel{%
        [\@tempa][\arabic{#1}][\cref@result]%
        \csname p@#1\endcsname\csname the#1\endcsname}}%
%    \end{macrocode}
%   We also need to redefine |\appendix| to use
%    \begin{macrocode}
    \@ifundefined{appendix}{}{%
      \def\appendix{%
        \@ifundefined{chapter}{%
          \def\H@refstepcounter##1{%
            \cref@old@H@refstepcounter{##1}%
            \cref@constructprefix{##1}{\cref@result}%
%    \end{macrocode}
%         We add a large value to the front of the counter data, to force
%         references to anything in appendices to be sorted after
%         everything else.
%    \begin{macrocode}
            \ifx\cref@result\@empty%
              \def\cref@result{2147483647}%
            \else%
              \edef\cref@result{2147483647,\cref@result}%
            \fi%
%    \end{macrocode}
%         Override the cross-reference type of sectioning commands.
%    \begin{macrocode}
            \def\@tempa{##1}%
            \def\@tempb{section}%
            \ifx\@tempa\@tempb%
              \protected@edef\cref@currentlabel{%
                [appendix][\arabic{##1}][\cref@result]%
                \csname p@##1\endcsname\csname the##1\endcsname}%
            \else%
              \def\@tempa{##1}%
              \def\@tempb{subsection}%
              \ifx\@tempa\@tempb%
                \protected@edef\cref@currentlabel{%
                  [subappendix][\arabic{##1}][\cref@result]%
                  \csname p@##1\endcsname\csname the##1\endcsname}%
              \else%
                \def\@tempa{##1}%
                \def\@tempb{subsubsection}%
                \ifx\@tempa\@tempb%
                  \protected@edef\cref@currentlabel{%
                    [subsubappendix][\arabic{##1}][\cref@result]%
                    \csname p@##1\endcsname\csname the##1\endcsname}%
                \else%
                  \@ifundefined{cref@##1@alias}%
                    {\def\@tempa{##1}}%
                    {\def\@tempa{\csname cref@##1@alias\endcsname}}%
                  \protected@edef\cref@currentlabel{%
                    [\@tempa][\arabic{##1}][\cref@result]%
                    \csname p@##1\endcsname\csname the##1\endcsname}%
                \fi%
              \fi%
            \fi}%
          \cref@old@appendix%
        }{%
          \def\H@refstepcounter##1{%
            \cref@old@H@refstepcounter{##1}%
            \cref@constructprefix{##1}{\cref@result}%
%    \end{macrocode}
%         Again, the large value added to the front of the counter data
%         forces references to appendix items to be sorted last.
%    \begin{macrocode}
            \ifx\cref@result\@empty%
              \def\cref@result{2147483647}%
            \else%
              \edef\cref@result{2147483647,\cref@result}%
            \fi%
%    \end{macrocode}
%         Override the cross-reference type of sectioning commands.
%    \begin{macrocode}
            \def\@tempa{##1}%
            \def\@tempb{chapter}%
            \ifx\@tempa\@tempb%
              \protected@edef\cref@currentlabel{%
                [appendix][\arabic{##1}][\cref@result]%
                \csname p@##1\endcsname\csname the##1\endcsname}%
            \else%
              \def\@tempa{##1}%
              \def\@tempb{section}%
              \ifx\@tempa\@tempb%
                \protected@edef\cref@currentlabel{%
                  [subappendix][\arabic{##1}][\cref@result]%
                  \csname p@##1\endcsname\csname the##1\endcsname}%
              \else%
                \def\@tempa{##1}%
                \def\@tempb{subsection}%
                \ifx\@tempa\@tempb%
                  \protected@edef\cref@currentlabel{%
                    [subsubappendix][\arabic{##1}][\cref@result]%
                    \csname p@##1\endcsname\csname the##1\endcsname}%
                \else%
                  \def\@tempa{##1}%
                  \def\@tempb{subsubsection}%
                  \ifx\@tempa\@tempb%
                    \protected@edef\cref@currentlabel{%
                      [subsubsubappendix][\arabic{##1}][\cref@result]%
                      \csname p@##1\endcsname\csname the##1\endcsname}%
                  \else%
                    \@ifundefined{cref@##1@alias}%
                      {\def\@tempa{##1}}%
                      {\def\@tempa{\csname cref@##1@alias\endcsname}}%
                    \protected@edef\cref@currentlabel{%
                      [\@tempa][\arabic{##1}][\cref@result]%
                      \csname p@##1\endcsname\csname the##1\endcsname}%
                  \fi%
                \fi%
              \fi%
            \fi}%
      \cref@old@appendix}%
      }%
    }% end of \@ifundefined{appendix}
  \fi% end of \if@cref@hyperrefloaded
  \let\if@cref@hyperrefloaded\iffalse%
}% end of \@ifpackageloaded{hyperref}
%    \end{macrocode}
% Add check to AtBeginDocument to throw error if \package{hyperref} was
% loaded after cleveref.
%    \begin{macrocode}
\AtBeginDocument{%
  \if@cref@hyperrefloaded\else%
    \@ifpackageloaded{hyperref}{%
      \PackageError{cleveref}{cleveref must be loaded after hyperref!}%
        {Package load order is wrong: load cleveref *after* hyperref.}
    }{}%
  \fi}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \end{macro}
%
%
%
% \subsubsection{\package{varioref} support}
% \begin{macro}{varioref}
%   If \package{varioref} is loaded, we redefine its commands to use
%   \cmd{\cref} instead of \cmd{\ref} to produce the reference. Since
%   \cmd{\cref} can cope with multiple references, we extend the page
%   referencing magic of \cmd{\vref} et al.\ to use \cmd{\cpageref}
%   instead, assisted by \cmd{\@@setvpageref} and \cmd{\@vpagerefrange}
%   (which typeset page references using \package{varioref} commands).
%   The former takes care of multi-references, the latter take care of
%   the \package{varioref} page referencing magic.
% \end{macro}
%
%    \begin{macrocode}
\let\if@cref@variorefloaded\iffalse%
\@ifpackageloaded{varioref}{%
  \let\if@cref@variorefloaded\iftrue%
  \PackageInfo{cleveref}{`varioref' support loaded}%
  \PackageInfo{cleveref}{`cleveref' supersedes `varioref's
    \string\labelformat command}%
%    \end{macrocode}
%
%
% \begin{macro}{\cref@old@@vpageref}
%   Unfortunately, \package{varioref}'s |\@@vpageref| macro calls a
%   |\vref@label| \emph{before} it typesets the page reference. The
%   |\protected@write| within |\vref@label| seems to prevent an |\unskip|
%   command coming after the |\vref@label| from removing any space that
%   was inserted before the |\vref@label|. This means that setting a
%   |\reftext|\meta{x} command to |\unskip| won't work; it won't properly
%   remove any preceding space in the event that an empty page reference
%   is typeset.
%
%   This didn't matter in the original \package{varioref} implementation,
%   because it \emph{always} removed any preceding space, then inserted
%   its own space \emph{after} the |\vref@label|, which the |\unskip|
%   could then gobble. But we want to get rid of this irritating
%   always-space-gobbling behaviour here. So we have to redefine
%   |\@@vpageref| (here renamed |\cref@old@@vpageref|) in order to move
%   the |\vref@label| to the end of the macro, after the page reference
%   has been typeset. We also remove the |\unskip| from the start of
%   |\@@vpageref|.
%    \begin{macrocode}
  \def\cref@old@@vpageref#1[#2]#3{%
    \leavevmode%\unskip  <<<
    \global\advance\c@vrcnt\@ne\relax%
    \vref@pagenum\@tempa{\the\c@vrcnt @vr}%
    \vref@pagenum\@tempb{\the\c@vrcnt @xvr}%
    %\vref@label{\the\c@vrcnt @xvr}%  <<<
    \ifx\@tempa\@tempb\else%
      \vref@err{\noexpand\vref or \noexpand\vpageref at page boundary
                \@tempb-\@tempa\space (may loop)%
                }%
    \fi%
    \vrefpagenum\thevpagerefnum{#3}%
    \vref@space%
    \ifx\@tempa\thevpagerefnum%
      \def\@tempc{#1}%
      \ifx\@tempc\@empty%
         \unskip%
      \else%
         #1%
      \fi%
    \else%
      #2%
      \is@pos@number\thevpagerefnum%
         {%
          \is@pos@number\@tempa%
           {\@tempcnta\@tempa%
            \advance\@tempcnta\@ne\relax%
           }%
           {\@tempcnta\maxdimen}%
          \ifnum \thevpagerefnum =\@tempcnta%
           \ifodd\@tempcnta%
             \if@twoside%
               \reftextfaceafter%
             \else%
               \reftextafter%
             \fi%
           \else%
             \reftextafter%
           \fi%
          \else%
            \advance\@tempcnta-2\relax%
            \ifnum \thevpagerefnum =\@tempcnta%
              \ifodd\@tempcnta%
                \reftextbefore%
              \else%
                \if@twoside%
                  \reftextfacebefore%
                \else%
                  \reftextbefore%
                \fi%
              \fi%
            \else%
              \reftextfaraway{#3}%
            \fi%
          \fi%
         }%
         {\reftextfaraway{#3}}%
    \fi%
    \vref@label{\the\c@vrcnt @xvr}%  <<<
    \vref@label{\the\c@vrcnt @vr}%
  }%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\cref@@vpageref}
%   We first enhance the core \package{varioref} |\vpageref| macro to
%   allow it to cope with lists of page references. This is done by
%   defining our version in terms of \package{cleveref}'s \cmd{\cpageref}
%   command, which handles multi-references, but telling \cmd{\cpageref}
%   to typeset the actual page references themselves using
%   \package{varioref}'s own page-referencing commands. (The alternative
%   version of \cmd{\vpagerefrange} is there to facilitate later
%   redefinitions.)
%
%   Most of the work is done by defining suitable |\@setvpageref| etc.\
%   commands (below), called as appropriate by our ever-faithful
%   \cmd{\@cref} work-horse. We only make use of one of the optional
%   arguments to the original \package{varioref} |\@@vpageref| macro,
%   which we store here in \cmd{\cref@@vpageref} for later.
%    \begin{macrocode}
  \def\cref@@vpageref#1[#2]#3{%
    \begingroup%
    \def\cref@@vpageref@arg{#1}%
    \@cref{vpageref}{#3}%
    \endgroup}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cref@vref}
% \begin{macro}{\cref@vrefrange}
% \begin{macro}{\cref@fullref}
%   Now we define \package{cleveref}-enhanced versions of the other
%   \package{varioref} cross-\linebreak[4]referencing commands, which use
%   \cmd{\cref} et al.\ to type set the cross-references, and the
%   \package{cleveref}-enhanced \cmd{\vpageref} et al.\ to typeset page
%   references.
%
%   The original \cmd{\vref} command passes an empty first argument to
%   \cmd{\@@vpageref}, to omit the page reference if it refers to the
%   current page. In our case, we only want to omit it if it's the sole
%   page reference we're printing; otherwise we need to print it even if
%   it refers to the current page. This is taken care of by
%   \cmd{\cref@patchreftexts} (which gets called further down). For this
%   mechanism, it's more convenient to pass \cmd{\reftextcurrent} as the
%   first argument but temporarily redefine it to be empty, instead of
%   passing an empty first argument to \cmd{\cref@@vpageref}.
%    \begin{macrocode}
  \def\cref@vref#1#2{%
    \leavevmode%
    \begingroup%
      \def\reftextcurrent{}%
      \@cref{#1}{#2}\@setcref@space%
      \cref@@vpageref{\reftextcurrent}[]{#2}%
    \endgroup}%
  \def\cref@vrefrange#1#2#3{%
    \@@setcrefrange{#1}{#2}{#3}{}\@setcref@space\vpagerefrange{#2}{#3}}%
  \def\cref@fullref#1#2{%
    \@cref{#1}{#2}\@setcref@space\@cref{fullpageref}{#2}}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\cref@vpagerefconjunction}
%   When typesetting multi-references, we need to add appropriate
%   conjunctions to the page references produced by the
%   \package{varioref} macros. Since we need this in various different
%   commands, we separate it out into a self-contained macro.
%    \begin{macrocode}
  \def\cref@vpagerefconjunction#1{%
    \def\@tempa{#1}%
    \def\@tempb{@second}%
    \ifx\@tempa\@tempb\relax%
      \@setcref@pairconjunction%
    \else%
      \def\@tempb{@middle}%
      \ifx\@tempa\@tempb\relax%
        \@setcref@middleconjunction%
      \else%
        \def\@tempb{@last}%
        \ifx\@tempa\@tempb\relax%
          \@setcref@lastconjunction%
        \fi%
      \fi%
    \fi}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@setcref@space}
%   We separate out the typesetting of the space between the
%   cross-reference and page-reference into a separate macro, to make it
%   easier to implement the \option{poorman} option.
%    \begin{macrocode}
  \def\@setcref@space{ }%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@setvpageref}
%   The \cmd{\@setvpageref} macro is called by \cmd{\@cref} to typeset
%   page references using \package{varioref} commands, tweaked to work
%   with the enhanced \package{cleveref} page-referencing features.
%   |#1| is the reference itself. |#2| is either empty if we're
%   typesetting a single page reference, or one of |@first|, |@second|,
%   |@middle| or |@end|, identifying where the page reference comes in a
%   multi-reference. We only make use of one of the optional arguments to
%   the original \package{varioref} |\@@vpageref| macro, available here
%   as \cmd{\cref@@vpageref@arg} (stored there by \cmd{\cref@@vpageref},
%   above).
%    \begin{macrocode}
  \def\@setvpageref#1#2{%
%    \end{macrocode}
%   Add the appropriate conjunction before the page reference.
%    \begin{macrocode}
    \cref@vpagerefconjunction{#2}%
%    \end{macrocode}
%   Undefining |\vref@space| prevents the original \package{varioref}
%   |\@@vpageref| macro from |\unskip|ing any preceding space and
%   inserting its own. We definitely don't want it to do that here when
%   we're typesetting anything other than the first group of page
%   references, as any preceding space then is part of the preceding
%   conjunction, and should be strictly respected. But, since we're
%   modifying the \package{varioref} commands anyway, we take this
%   opportunity to get rid of the irritating \package{varioref} spacing
%   behaviour even for the first group of page references.
%    \begin{macrocode}
    \def\vref@space{}%
%    \end{macrocode}
%   Modify the \package{varioref} |\reftext|\meta{x} commands as
%   appropriate for the page reference we're currently typesetting, then
%   typeset the page reference.
%    \begin{macrocode}
    \begingroup%
      \cref@patchreftexts{#2}%
      \expandafter\@@@setvpageref\expandafter%
        {\cref@@vpageref@arg}[\vref@space]{#1}%
    \endgroup}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@@setvpageref}
%   We separate out the final type setting step, as always, to make it
%   easier to redefine things later.
%    \begin{macrocode}
  \let\@@@setvpageref\cref@old@@vpageref%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@setvpagerefrange}
%   |\@setvpagerefrange| is similar to |\@setvpageref|, but typesets page
%   ranges. |#1| and |#2| are the labels themselves. |#3| is either empty
%   if we're typesetting a single page range, or one of |@first|,
%   |@second|, |@middle| or |@end|, identifying where the page reference
%   comes in a multi-reference. We only make use of one of the optional
%   arguments to the original \package{varioref} |\@@vpageref| macro,
%   available here as \cmd{\cref@@vpageref@arg} (stored there by
%   \cmd{\cref@@vpageref}, above).
%    \begin{macrocode}
  \def\@setvpagerefrange#1#2#3{%
%    \end{macrocode}
% Add the appropriate conjunction before the page range reference.
%    \begin{macrocode}
    \cref@vpagerefconjunction{#3}%
%    \end{macrocode}
%   Unlike |\vpageref|, \package{varioref}'s |\vpagerefrange| command
%   \emph{doesn't} go in for quite the same space-mangling behaviour. We
%   still undefine \cmd{\vref@space}, though.
%    \begin{macrocode}
    \let\vref@space\relax%
%    \end{macrocode}
% Modify the \package{varioref} |\reftext|\meta{x} commands as
% appropriate for the page range we're currently typesetting, then
% typeset the page range.
%    \begin{macrocode}
    \begingroup%
      \cref@patchreftexts{#3}%
      \expandafter\@@@setvpagerefrange\expandafter%
        [\cref@@vpageref@arg]{#1}{#2}%
    \endgroup}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@@setvpagerefrange}
% Again, we separate out the final typesetting step, to aid later
% redefinition.
%    \begin{macrocode}
  \let\@@@setvpagerefrange\vpagerefrange
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@setfullpageref}
%   Ditto for \cmd{\@setfullpageref}, with |#1| the reference, |#2|
%   either empty, |@first|, |@second|, |@middle| or |@end|.
%    \begin{macrocode}
  \def\@setfullpageref#1#2{%
%    \end{macrocode}
% Add the appropriate conjunction before the page reference.
%    \begin{macrocode}
    \cref@vpagerefconjunction{#2}%
%    \end{macrocode}
% Modify the \package{varioref} |\reftext|\meta{x} commands as
% appropriate for the page reference we're currently typesetting, then
% typeset the page reference.
%    \begin{macrocode}
    \begingroup%
      \cref@patchreftexts{#2}%
      \@@@setfullpageref{#1}%
    \endgroup}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@@setfullpageref}
%   Separate out the final typesetting step, as usual.
%    \begin{macrocode}
  \let\@@@setfullpageref\reftextfaraway%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@setfullpagerefrange}
%   Ditto for \cmd{\@setfullpagerefrange}, with |#1| and |#2| the
%   references, |#3| either empty, |@first|, |@second|, |@middle| or
%   |@end|.
%    \begin{macrocode}
  \def\@setfullpagerefrange#1#2#3{%
%    \end{macrocode}
% Add the appropriate conjunction before the page reference.
%    \begin{macrocode}
    \cref@vpagerefconjunction{#3}%
%    \end{macrocode}
% Modify the \package{varioref} |\reftext|\meta{x} commands as
% appropriate for the page reference we're currently typesetting, then
% typeset the page reference.
%    \begin{macrocode}
    \begingroup%
      \cref@patchreftexts{#3}%
      \@@@setfullpagerefrange{#1}{#2}%
    \endgroup}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@@setfullpagerefrange}
%   Separate out the final typesetting step, as usual.
%    \begin{macrocode}
  \let\@@@setfullpagerefrange\reftextpagerange%
%    \end{macrocode}
% \end{macro}
%
%
% We save the default \package{varioref} |\reftext|\meta{x} commands as
% |\creftext|\meta{x}, before the user's had any chance to redefine them.
% These are used if a |\reftext|\meta{x} is redefined to produce an empty
% reference, to force a non-empty reference within multi-references.
%    \begin{macrocode}
  \let\creftextcurrent\reftextcurrent%
  \let\creftextfaceafter\reftextfaceafter%
  \let\creftextfacebefore\reftextfacebefore%
  \let\creftextafter\reftextafter%
  \let\creftextbefore\reftextbefore%
  \let\creftextfaraway\reftextfaraway%
  \let\creftextpagerange\reftextpagerange%
%    \end{macrocode}
%
% \begin{macro}{\cref@patchreftexts}
% \begin{macro}{\cref@restorereftexts}
%   The |\cref@patchreftexts| command modifies \package{varioref}
%   |\reftext|\meta{x} commands, for use within |\@@setvpageref| and
%   |\@@setvpagerefrange|.
%    \begin{macrocode}
  \def\cref@patchreftexts#1{%
    \cref@patchreftext{reftextcurrent}{#1}%
    \cref@patchreftext{reftextfaceafter}{#1}%
    \cref@patchreftext{reftextfacebefore}{#1}%
    \cref@patchreftext{reftextafter}{#1}%
    \cref@patchreftext{reftextbefore}{#1}}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\cref@patchreftext}
%   |\cref@patchreftext| does the hard work of modifying the
%   |\reftext|\meta{x} command given in |#1| as appropriate for the
%   |\@setvpageref| or |\@setvpagerefrange| command that it's called
%   from. (It can only be called from within one of those commands.)
%   |#2| is empty if we're typesetting a single page reference, or one of
%   |@first|, |@second|, |@middle| or |@end| when typesetting a
%   multi-reference.
% \begin{macrocode}
  \def\cref@patchreftext#1#2{%
    \def\@tempa{#2}%
%    \end{macrocode}
%   If we're typesetting a single page reference\dots
%    \begin{macrocode}
    \ifx\@tempa\@empty%
%    \end{macrocode}
%     if the reftext command produces an empty reference, redefine it to
%     be |\unskip|.
%    \begin{macrocode}
      \def\@tempc{}%
      \expandafter\ifx\csname #1\endcsname\@tempc\relax%
        \expandafter\def\csname #1\endcsname{\unskip}%
          %{\advance\count@group -1\relax\reftextcurrent@orig}%
      \else%
        \long\def\@tempc{}%
        \expandafter\ifx\csname #1\endcsname\@tempc\relax%
          \expandafter\def\csname #1\endcsname{\unskip}%
            %{\advance\count@group -1\relax\reftextcurrent@orig}%
        \fi%
      \fi%
%    \end{macrocode}
%
%   If we're typesetting a multi-reference\dots
%    \begin{macrocode}
    \else%
%    \end{macrocode}
%     if the reftext command produces an empty page reference, patch it
%     to instead use |\creftext|\meta{x}, which always produces a
%     non-empty reference.
%    \begin{macrocode}
      \long\def\@tempc{\unskip}%
      \expandafter\ifx\csname #1\endcsname\@tempc\relax%
        \expandafter\expandafter\expandafter\def%
        \expandafter\expandafter\csname #1\endcsname\expandafter{%
          \csname c#1\endcsname}%
      \else%
        \long\def\@tempc{}%
        \expandafter\ifx\csname #1\endcsname\@tempc\relax%
          \expandafter\expandafter\expandafter\def%
          \expandafter\expandafter\csname #1\endcsname\expandafter{%
            \csname c#1\endcsname}%
        \else%
          \def\@tempc{\unskip}%
          \expandafter\ifx\csname #1\endcsname\@tempc\relax%
            \expandafter\expandafter\expandafter\def%
            \expandafter\expandafter\csname #1\endcsname\expandafter{%
              \csname c#1\endcsname}%
          \else%
            \def\@tempc{}%
            \expandafter\ifx\csname #1\endcsname\@tempc\relax%
              \expandafter\expandafter\expandafter\def%
              \expandafter\expandafter\csname #1\endcsname\expandafter{%
                \csname c#1\endcsname}%
            \fi%
          \fi%
        \fi%
      \fi%
    \fi}%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@setcref@pairconjunction}
% \begin{macro}{\@setcref@middleconjunction}
% \begin{macro}{\@setcref@lastconjunction}
%   We also add an extra macro layer for typesetting the conjunctions,
%   for the same reason. (Note that we only needed to do this for the
%   group conjunctions previously, as the other conjunctions are never
%   used directly in the normal \package{cleveref} commands. But
%   |\@setvpageref| and |\@setvpagerefrange| \emph{do} use them directly,
%   so now we do need macros to separate out the final type setting of
%   the rest of the conjunctions.)
%    \begin{macrocode}
  \def\@setcref@pairconjunction{\crefpairconjunction}%
  \def\@setcref@middleconjunction{\crefmiddleconjunction}%
  \def\@setcref@lastconjunction{\creflastconjunction}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
% We now redefine the original \package{varioref} commands to use the
% \package{cleveref}-enhanced versions. The redefinition of
% \cmd{\@@vpageref} has to be postponed until the beginning of the
% document, to make sure it overrides \package{hyperref}'s redefinition
% (if loaded).
%    \begin{macrocode}
  \AtBeginDocument{%
    \let\@@vpageref\cref@@vpageref%
  }%
%    \end{macrocode}
%
% \begin{macro}{\vref}
% \begin{macro}{\vref*}
% \begin{macro}{\Vref}
% \begin{macro}{\Vref*}
% \begin{macro}{\vrefrange}
% \begin{macro}{\vrefrange*}
% \begin{macro}{\Vrefrange}
% \begin{macro}{\Vrefrange*}
% \begin{macro}{\fullref}
% \begin{macro}{\fullref*}
% \begin{macro}{\Fullref}
% \begin{macro}{\Fullref*}
%   Since we're defining the spacing behaviour of \cmd{\vref} et al.\ to
%   be consistent with the other \package{cleveref} referencing commands,
%   this frees up the starred variants to be used to suppress hyperlinks
%   when \package{hyperref} is loaded, as usual.
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \begin{macrocode}
  \if@cref@hyperrefloaded\relax%  hyperref loaded%
    \DeclareRobustCommand{\vref}{%
      \@ifstar{\cref@vrefstar{cref}}{\cref@vref{cref}}}%
    \DeclareRobustCommand{\Vref}{%
      \@ifstar{\cref@vrefstar{Cref}}{\cref@vref{Cref}}}%
    \DeclareRobustCommand{\vrefrange}{%
      \@ifstar{\cref@vrefrangestar{cref}}{\cref@vrefrange{cref}}}%
    \DeclareRobustCommand{\Vrefrange}{%
      \@ifstar{\cref@vrefrangestar{Cref}}{\cref@vrefrange{Cref}}}%
    \DeclareRobustCommand{\fullref}{%
      \@ifstar{\cref@fullrefstar{cref}}{\cref@fullref{cref}}}%
    \DeclareRobustCommand{\Fullref}{%
      \@ifstar{\cref@fullrefstar{Cref}}{\cref@fullref{Cref}}}%
    \def\cref@vrefstar#1#2{%
      \@crefstarredtrue%
      \cref@vref{#1}{#2}%
      \@crefstarredfalse}%
    \def\cref@vrefrangestar#1#2#3{%
      \@crefstarredtrue%
      \cref@vrefrange{#1}{#2}{#3}%
      \@crefstarredfalse}%
    \def\cref@fullrefstar#1#2{%
      \@crefstarredtrue%
      \cref@fullref{#1}{#2}%
      \@crefstarredfalse}%
  \else%
    \DeclareRobustCommand{\vref}{\cref@vref{cref}}%
    \DeclareRobustCommand{\Vref}{\cref@vref{Cref}}%
    \DeclareRobustCommand{\vrefrange}{\cref@vrefrange{cref}}%
    \DeclareRobustCommand{\Vrefrange}{\cref@vrefrange{Cref}}%
    \DeclareRobustCommand{\fullref}{\cref@fullref{cref}}%
    \DeclareRobustCommand{\Fullref}{\cref@fullref{Cref}}%
  \fi%  end of test for hyperref
}{\let\if@cref@variorefloaded\iffalse}%  end of \@ifpackageloaded{varioref}
%    \end{macrocode}
% Add check to AtBeginDocument to throw error if \package{varioref} was
% loaded after cleveref.
%    \begin{macrocode}
\AtBeginDocument{%
  \if@cref@variorefloaded\relax\else%
    \@ifpackageloaded{varioref}{%
      \PackageError{cleveref}{cleveref must be loaded after varioref!}%
        {Package load order is wrong: load cleveref *after* varioref.}
    }{}%
  \fi}
%    \end{macrocode}
%
%
%
% \subsubsection{\package{amsmath} support}
% \begin{macro}{amsmath}
% \begin{macro}{\label}
% \begin{macro}{\label@in@display}
%   The \package{amsmath} package redefines the \cmd{\label} command
%   within equation environments, so if it is loaded we have to extend
%   the behaviour to support the optional argument. With
%   \package{amsmath}, the original \cmd{\label} command is stored in
%   \cmd{\ltx@label}, and \cmd{\label@in@display} replaces \cmd{\label}
%   inside equations. \cmd{\label@in@display} just saves the label for
%   later, and defining it is left until the end of the equation, when
%   \cmd{\ltx@label} is finally called.
%
%   To allow \cmd{\label} within equations to support an optional
%   argument, we first store the original \cmd{\label@in@display} and 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 braces. These are stripped away again by
%   \cmd{\ltx@label} before calling the \package{cleveref} \cmd{\label}
%   command we defined previously (saved in \cmd{\cref@label}). As
%   before, we must postpone the redefinition of \cmd{\label} until the
%   beginning of the document, since other packages do so.
%    \begin{macrocode}
\let\if@cref@amsmathloaded\iffalse%
\@ifpackageloaded{amsmath}{%
  \let\if@cref@amsmathloaded\iftrue%
  \AtBeginDocument{%
    \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{\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}%
  }%  end of AtBeginDocument
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\measure@}
% \begin{macro}{\gmeasure@}
%   The \package{amsmath} multi-line equation environments scan their
%   bodies twice: once to measure, once to typeset. In the measure phase,
%   the \cmd{\label} command is disabled by letting it to \cmd{\@gobble}.
%   But this isn't sufficient to gobble all the arguments any more if an
%   optional argument is supplied to our new \cmd{\label}, so we have to
%   modify the \package{amsmath} measuring commands so that they let
%   \cmd{\label} to \cmd{\cref@gobble@optarg} instead.
%
%   Unfortunately, \package{amsmath} wasn't designed with redefinitions
%   of \cmd{\label} in mind, so there appears to be no safe way of doing
%   this other than copying the \package{amsmath} definitions and making
%   the modification directly in the macro's code. This is a recipe for
%   future chaos if these commands are ever modified in a new version of
%   \package{amsmath}, but it seems we have no choice. Luckily,
%   \package{amsmath} isn't updated too often!
%    \begin{macrocode}
  \def\measure@#1{%
    \begingroup%
        \measuring@true%
        \global\eqnshift@\z@%
        \global\alignsep@\z@%
        \global\let\tag@lengths\@empty%
        \global\let\field@lengths\@empty%
        \savecounters@%
        \global\setbox0\vbox{%
            \let\math@cr@@@\math@cr@@@align@measure%
            \everycr{\noalign{\global\tag@false%
              \global\let\raise@tag\@empty \global\column@\z@}}%
            \let\label\cref@gobble@optarg%  <<< cleveref modification
            \global\row@\z@%
            \tabskip\z@%
            \halign{\span\align@preamble\crcr%
                #1%
                \math@cr@@@%
                \global\column@\z@%
                \add@amps\maxfields@\cr%
            }%
        }%
        \restorecounters@%
        \ifodd\maxfields@%
            \global\advance\maxfields@\@ne\relax%
        \fi%
        \ifnum\xatlevel@=\tw@%
            \ifnum\maxfields@<\thr@@%
                \let\xatlevel@\z@%
            \fi%
        \fi%
        \setbox\z@\vbox{%
          \unvbox\z@ \unpenalty \global\setbox\@ne\lastbox%
        }%
        \global\totwidth@\wd\@ne%
        \if@fleqn \global\advance\totwidth@\@mathmargin\relax\fi%
        \global\let\maxcolumn@widths\@empty%
        \begingroup%
          \let\or\relax%
          \loop%
            \global\setbox\@ne\hbox{%
              \unhbox\@ne \unskip \global\setbox\thr@@\lastbox%
            }%
          \ifhbox\thr@@%
           \xdef\maxcolumn@widths{ \or \the\wd\thr@@ \maxcolumn@widths}%
          \repeat%
        \endgroup%
        \dimen@\displaywidth%
        \advance\dimen@-\totwidth@\relax%
        \ifcase\xatlevel@%
            \global\alignsep@\z@%
            \let\minalignsep\z@%
            \@tempcntb\z@%
            \if@fleqn%
                \@tempcnta\@ne%
                \global\eqnshift@\@mathmargin%
            \else%
                \@tempcnta\tw@%
                \global\eqnshift@\dimen@%
                \global\divide\eqnshift@\@tempcnta\relax%
            \fi%
        \or%
            \@tempcntb\maxfields@%
            \divide\@tempcntb\tw@\relax%
            \@tempcnta\@tempcntb%
            \advance\@tempcntb\m@ne\relax%
            \if@fleqn%
                \global\eqnshift@\@mathmargin%
                \global\alignsep@\dimen@%
                \global\divide\alignsep@\@tempcnta\relax%
            \else%
                \global\advance\@tempcnta\@ne\relax%
                \global\eqnshift@\dimen@%
                \global\divide\eqnshift@\@tempcnta\relax%
                \global\alignsep@\eqnshift@%
            \fi%
        \or%
            \@tempcntb\maxfields@%
            \divide\@tempcntb\tw@\relax%
            \global\advance\@tempcntb\m@ne\relax%
            \global\@tempcnta\@tempcntb\relax%
            \global\eqnshift@\z@%
            \global\alignsep@\dimen@%
            \if@fleqn%
                \global\advance\alignsep@\@mathmargin\relax%
            \fi%
            \global\divide\alignsep@\@tempcntb\relax%
        \fi%
        \ifdim\alignsep@<\minalignsep\relax%
            \global\alignsep@\minalignsep\relax%
            \ifdim\eqnshift@>\z@%
                \if@fleqn\else%
                    \global\eqnshift@\displaywidth%
                    \global\advance\eqnshift@-\totwidth@\relax%
                    \global\advance\eqnshift@-\@tempcntb\alignsep@\relax%
                    \global\divide\eqnshift@\tw@\relax%
                \fi%
            \fi%
        \fi%
        \ifdim\eqnshift@<\z@%
            \global\eqnshift@\z@%
        \fi%
        \calc@shift@align%
        \global\tagshift@\totwidth@%
        \global\advance\tagshift@\@tempcntb\alignsep@\relax%
        \if@fleqn%
            \ifnum\xatlevel@=\tw@%
                \global\advance\tagshift@-\@mathmargin\relax%
            \fi%
        \else%
            \global\advance\tagshift@\eqnshift@\relax%
        \fi%
        \iftagsleft@ \else%
            \global\advance\tagshift@-\displaywidth\relax%
        \fi%
        \dimen@\minalignsep\relax%
        \global\advance\totwidth@\@tempcntb\dimen@\relax%
        \ifdim\totwidth@>\displaywidth%
            \global\let\displaywidth@\totwidth@%
        \else%
            \global\let\displaywidth@\displaywidth%
        \fi%
    \endgroup%
  }%
  \def\gmeasure@#1{%
    \begingroup%
        \measuring@true%
        \totwidth@\z@%
        \global\let\tag@lengths\@empty%
        \savecounters@%
        \setbox\@ne\vbox{%
            \everycr{\noalign{\global\tag@false%
              \global\let\raise@tag\@empty \global\column@\z@}}%
            \let\label\@gobble%  <<< cleveref modification
            \halign{%
                \setboxz@h{$\m@th\displaystyle{##}$}%
                \ifdim\wdz@>\totwidth@%
                    \global\totwidth@\wdz@%
                \fi%
               &\setboxz@h{\strut@{##}}%
                \savetaglength@%
                \crcr%
                #1%
                \math@cr@@@%
            }%
        }%
        \restorecounters@%
        \if@fleqn%
            \global\advance\totwidth@\@mathmargin\relax%
        \fi%
        \iftagsleft@%
            \ifdim\totwidth@>\displaywidth%
                \global\let\gdisplaywidth@\totwidth@%
            \else%
                \global\let\gdisplaywidth@\displaywidth%
            \fi%
        \fi%
    \endgroup%
}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\multline@}
% \begin{macro}{\mmeasure@}
% \begin{macro}{\label@mmeasure@noarg}
% \begin{macro}{\label@mmeasure@optarg}
%   The |multline| environment works a bit differently to the other
%   \package{amsmath} environments, in that \cmd{\label} is
%   \emph{disabled} during the typesetting phase, and \emph{enabled}
%   during the measuring phase. To cope with \package{cleveref}'s
%   optional argument, we have to define separate versions of
%   \cmd{\label@in@display} specifically for \cmd{\mmeasure@}.
%    \begin{macrocode}
  \def\multline@#1{%
    \Let@%
    \@display@init{\global\advance\row@\@ne\relax\global\dspbrk@lvl\m@ne}%
    \chardef\dspbrk@context\z@%
    \restore@math@cr%
    \let\tag\tag@in@align%
    \global\tag@false \global\let\raise@tag\@empty%
    \mmeasure@{#1}%
    \let\tag\gobble@tag \let\label\cref@gobble@optarg%  <<< cleveref modification
    \tabskip \if@fleqn \@mathmargin \else \z@skip \fi%
    \totwidth@\displaywidth%
    \if@fleqn%
        \advance\totwidth@-\@mathmargin\relax%
    \fi%
    \halign\bgroup%
        \hbox to\totwidth@{%
            \if@fleqn%
                \hskip \@centering \relax%
            \else%
                \hfil%
            \fi%
            \strut@%
            $\m@th\displaystyle{}##\endmultline@math%
            \hfil%
        }% $
        \crcr%
        \if@fleqn%
            \hskip-\@mathmargin%
            \def\multline@indent{\hskip\@mathmargin}%
        \else%
            \hfilneg%
            \def\multline@indent{\hskip\multlinegap}%
        \fi%
        \iftagsleft@%
            \iftag@%
                \begingroup%
                    \ifshifttag@%
                        \rlap{\vbox{%
                                \normalbaselines%
                                \hbox{%
                                    \strut@%
                                    \make@display@tag%
                                }%
                                \vbox to\lineht@{}%
                                \raise@tag%
                        }}%
                        \multline@indent%
                    \else%
                        \setbox\z@\hbox{\make@display@tag}%
                        \dimen@\@mathmargin \advance\dimen@-\wd\z@\relax%
                        \ifdim\dimen@<\multlinetaggap%
                          \dimen@\multlinetaggap%
                        \fi%
                        \box\z@ \hskip\dimen@\relax%
                    \fi%
                \endgroup%
            \else%
                \multline@indent%
            \fi%
        \else%
            \multline@indent%
        \fi%
    #1%
  }%
  \def\mmeasure@#1{%
    \begingroup%
        \measuring@true%
        \def\label{%                  <<< cleveref modification
          \@ifnextchar[\label@in@mmeasure@optarg%]
            \label@in@mmeasure@noarg}%
        \def\math@cr@@@{\cr}%
        \let\shoveleft\@iden \let\shoveright\@iden%
        \savecounters@%
        \global\row@\z@%
        \setbox\@ne\vbox{%
            \global\let\df@tag\@empty%
            \halign{%
                \setboxz@h{\@lign$\m@th\displaystyle{}##$}%
                \iftagsleft@%
                    \ifnum\row@=\@ne%
                        \global\totwidth@\wdz@%
                        \global\lineht@\ht\z@%
                    \fi%
                \else%
                    \global\totwidth@\wdz@%
                    \global\lineht@\dp\z@%
                \fi%
                \crcr%
                #1%
                \crcr%
            }%
        }%
        \ifx\df@tag\@empty\else\global\tag@true\fi%
        \if@eqnsw\global\tag@true\fi%
        \iftag@%
            \setboxz@h{%
                \if@eqnsw%
                    \stepcounter{equation}%
                    \tagform@\theequation%
                \else%
                    \df@tag%
                \fi%
            }%
            \global\tagwidth@\wdz@%
            \dimen@\totwidth@%
            \advance\dimen@\tagwidth@\relax%
            \advance\dimen@\multlinetaggap\relax%
            \iftagsleft@\else%
                \if@fleqn%
                    \advance\dimen@\@mathmargin\relax%
                \fi%
            \fi%
            \ifdim\dimen@>\displaywidth%
                \global\shifttag@true%
            \else%
                \global\shifttag@false%
            \fi%
        \fi%
        \restorecounters@%
    \endgroup%
  }%
  \def\label@in@mmeasure@noarg#1{%
    \begingroup%
      \measuring@false%
      \cref@old@label@in@display{{#1}}%
    \endgroup}%
  \def\label@in@mmeasure@optarg[#1]#2{%
    \begingroup%
      \measuring@false%
      \cref@old@label@in@display{[#1]{#2}}%
    \endgroup}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{subequations}
%   In order for |subequations| to be sorted properly, \package{cleveref}
%   needs to know that the |equation| counter is effectively reset by the
%   |parentequation| counter within the |subequations| environment. This
%   isn't how |amsmath| implements subequations (for obvious reasons!),
%   but we harmlessly add the |equation| counter to the |parentequation|
%   counter's reset list \emph{within} |subequations| environments, so
%   that \package{cleveref}'s sorting mechanism can figure things out. We
%   also harmlessly make sure |parentequation| is reset by the same
%   counter as |equation|.
%
%   We also want to treat subequations as a separate cross-reference type
%   from equations. However, \package{amsmath} still uses the |equation|
%   counter for subequations, not a separate ``subequation'' counter. We
%   therefore temporarily alias |equation| to |subequation| within
%   subequation environments.
%    \begin{macrocode}
  \let\cref@old@subequations\subequations%
  \let\cref@old@endsubequations\endsubequations%
  \cref@resetby{equation}{\cref@result}%
  \ifx\cref@result\relax\else%
    \cref@addtoreset{parentequation}{\cref@result}%
  \fi%
  \renewenvironment{subequations}{%
%    \end{macrocode}
%    Temporarily declare |equation| counter to be reset by |parentequation|.
%    \begin{macrocode}
    \cref@addtoreset{equation}{parentequation}%
%    \end{macrocode}
%    Temporarily alias |equation| to |subequation|, or to whatever
%    |subequation| has been aliased to.
%    \begin{macrocode}
    \let\cref@orig@equation@alias\cref@equation@alias%
    \@ifundefined{cref@subequation@alias}%
      {\crefalias{equation}{subequation}}%
      {\def\@tempa{{equation}}%
       \expandafter\expandafter\expandafter\crefalias%
       \expandafter\@tempa\expandafter{\cref@subequation@alias}}%
    \cref@old@subequations%
  }{%
%    \end{macrocode}
%    Remove |equation| from |parentequation| counter's reset list.
%    \begin{macrocode}
    \gdef\cl@parentequation{}%
    \cref@old@endsubequations%
    \setcounter{parentequation}{0}%
%    \end{macrocode}
%    Restore original |equation| alias (if any).
%    \begin{macrocode}
    \@ifundefined{cref@orig@cref@equation@alias}%
      {\let\cref@equation@alias\relax}%
      {\let\cref@equation@alias\cref@orig@equation@alias\relax}%
    \let\cref@orig@equation@alias\relax%
  }%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\make@df@tag@@}
% \begin{macro}{\make@df@tag@@@}
%   We override the internals of the \package{amsmath} \cmd{\tag} command
%   to add the additional information to the label definition. Since
%   labels produced by \cmd{\tag} have no logical ordering when sorting a
%   list of references, we give them a large numerical value so that they
%   get pushed to the end of sorted cross-reference lists.
%    \begin{macrocode}
  \let\cref@old@make@df@tag@@\make@df@tag@@%
  \def\make@df@tag@@#1{%
    \cref@old@make@df@tag@@{#1}%
    \let\cref@old@df@tag\df@tag%
    \expandafter\gdef\expandafter\df@tag\expandafter{%
      \cref@old@df@tag%
      \def\cref@currentlabel{[equation][2147483647][]#1}}}%
  \let\cref@old@make@df@tag@@@\make@df@tag@@@%
  \def\make@df@tag@@@#1{%
    \cref@old@make@df@tag@@@{#1}%
    \let\cref@old@df@tag\df@tag%
    \expandafter\gdef\expandafter\df@tag\expandafter{%
      \cref@old@df@tag%
      \toks@\@xp{\p@equation{#1}}%
      \edef\cref@currentlabel{[equation][2147483647][]\the\toks@}}}%
}{}%  end of \@ifpackageloaded{amsmath}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% Add check to AtBeginDocument to throw error if \package{amsmath} was
% loaded after cleveref.
%    \begin{macrocode}
\AtBeginDocument{%
  \if@cref@amsmathloaded\else%
    \@ifpackageloaded{amsmath}{%
      \PackageError{cleveref}{cleveref must be loaded after amsmath!}%
        {Package load order is wrong: load cleveref *after* amsmath.}
    }{}%
  \fi}
%
%
%
% \subsubsection{\package{amsthm} support}
% \begin{macro}{amsthm}
%   If \package{amsthm} is loaded, we need to modify its theorem
%   referencing features so that they work with \package{cleveref}.
%    \begin{macrocode}
\@ifpackageloaded{amsthm}{%
  \PackageInfo{cleveref}{`amsthm' support loaded}%
%    \end{macrocode}
%
% \begin{macro}{\@thm}
%   We modify \package{amsthm}'s version of the \cmd{\@thm} macro, to
%   have it call \cmd{\refstepcounter} with an optional argument
%   containing the theorem type.
%    \begin{macrocode}
  \let\cref@thmnoarg\@thm%
  \def\@thm{\@ifnextchar[{\cref@thmoptarg}{\cref@thmnoarg}}%]
  \def\cref@thmoptarg[#1]#2#3#4{%
    \ifhmode\unskip\unskip\par\fi%
    \normalfont%
    \trivlist%
    \let\thmheadnl\relax%
    \let\thm@swap\@gobble%
    \thm@notefont{\fontseries\mddefault\upshape}%
    \thm@headpunct{.}% add period after heading
    \thm@headsep 5\p@ plus\p@ minus\p@\relax%
    \thm@space@setup%
    #2% style overrides
    \@topsep \thm@preskip               % used by thm head
    \@topsepadd \thm@postskip           % used by \@endparenv
    \def\@tempa{#3}\ifx\@empty\@tempa%
      \def\@tempa{\@oparg{\@begintheorem{#4}{}}[]}%
    \else%
      \refstepcounter[#1]{#3}%  <<< cleveref modification
      \def\@tempa{\@oparg{\@begintheorem{#4}{\csname the#3\endcsname}}[]}%
    \fi%
    \@tempa}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@ynthm}
%   We also have to modify \package{amsthm}'s \cmd{\@ynthm} command so
%   that it passes the optional argument to \cmd{\@thm}. Since
%   \package{amsmath}'s \cmd{\@ynthm} takes a different parameter list to
%   the standard \LaTeX{} \cmd{\@ynthm} macro, we deliberately override
%   our previous redefinition, and add the code for the automatic
%   \cmd{\crefname} definitions directly to this version.
%    \begin{macrocode}
  \def\@ynthm#1[#2]#3{%
%    \end{macrocode}
%   Here's the automatic \cmd{\crefname} definition.
%    \begin{macrocode}
    \edef\@tempa{\expandafter\noexpand%
      \csname cref@#1@name@preamble\endcsname}%
    \edef\@tempb{\expandafter\noexpand%
      \csname Cref@#1@name@preamble\endcsname}%
    \def\@tempc{#3}%
    \ifx\@tempc\@empty\relax%
      \expandafter\gdef\@tempa{}%
      \expandafter\gdef\@tempb{}%
    \else%
      \if@cref@capitalise%
        \expandafter\expandafter\expandafter\gdef\expandafter%
          \@tempa\expandafter{\MakeUppercase #3}%
      \else%
        \expandafter\expandafter\expandafter\gdef\expandafter%
          \@tempa\expandafter{\MakeLowercase #3}%
      \fi%
      \expandafter\expandafter\expandafter\gdef\expandafter%
        \@tempb\expandafter{\MakeUppercase #3}%
    \fi%
    \cref@stack@add{#1}{\cref@label@types}%
%    \end{macrocode}
%   Here's the original \package{amsthm} \cmd{\@ynthm} definition, with
%   the \package{cleveref} modification.
%    \begin{macrocode}
    \ifx\relax#2\relax%
      \def\@tempa{\@oparg{\@xthm{#1}{#3}}[]}%
    \else%
      \@ifundefined{c@#2}{%
        \def\@tempa{\@nocounterr{#2}}%
      }{%
        \@xp\xdef\csname the#1\endcsname{\@xp\@nx\csname the#2\endcsname}%
        \toks@{#3}%
        \@xp\xdef\csname#1\endcsname{%
          \@nx\@thm[#1]{%  <<< new optional argument for theorem name
            \let\@nx\thm@swap%
              \if S\thm@swap\@nx\@firstoftwo\else\@nx\@gobble\fi%
            \@xp\@nx\csname th@\the\thm@style\endcsname}%
              {#2}{\the\toks@}}%
        \let\@tempa\relax%
      }%
    \fi%
    \@tempa}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@xnthm}
%   Finally, we have to restore the \package{amsthm} version of
%   \cmd{\@xnthm}, which we stored earlier in \cmd{\cref@old@xnthm} and
%   redefined. With \package{amsthm}, \cmd{\@xnthm} calls \cmd{\@ynthm},
%   so the automatic \cmd{\crefname} definition is already taken care of.
%    \begin{macrocode}
  \let\@xnthm\cref@old@xnthm%
}{}%  end of \@ifpackageloaded{amsthm}
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsubsection{\package{ntheorem} support}
% \begin{macro}{ntheorem}
% \begin{macro}{thref}
%   If \package{ntheorem} is loaded, we need to modify its theorem
%   referencing features so that they work with \package{cleveref}.
%    \begin{macrocode}
\@ifpackageloaded{ntheorem}{%
  \PackageInfo{cleveref}{`ntheorem' support loaded}%
  \@ifpackagewith{ntheorem}{thref}{%
    \PackageWarning{cleveref}{`cleveref' supersedes `ntheorem's `thref'
      option}%
    \renewcommand{\thref}{\cref}}{}%
%    \end{macrocode}
%
% \begin{macro}{\theorem@prework}
%   Newer versions of \package{ntheorem} require a call to
%   \cmd{\theorem@prework} when typesetting theorems. If an older
%   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}{}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@thm}
%   We modify \package{ntheorem}'s version of the \cmd{\@thm} macro very
%   slightly, to have it call \cmd{\refstepcounter} with an optional
%   argument containing the theorem type.
%    \begin{macrocode}
  \gdef\@thm#1#2#3{%
    \if@thmmarks%
      \stepcounter{end\InTheoType ctr}%
    \fi%
    \renewcommand{\InTheoType}{#1}%
    \if@thmmarks%
      \stepcounter{curr#1ctr}%
      \setcounter{end#1ctr}{0}%
    \fi%
    \refstepcounter[#1]{#2}%  <<< cleveref modification
    \theorem@prework%
    \thm@topsepadd \theorempostskipamount%
    \ifvmode \advance\thm@topsepadd\partopsep\relax\fi%
    \trivlist%
    \@topsep \theorempreskipamount%
    \@topsepadd \thm@topsepadd%
    \advance\linewidth -\theorem@indent\relax%
    \advance\@totalleftmargin \theorem@indent\relax%
    \parshape \@ne \@totalleftmargin \linewidth%
    \@ifnextchar[{\@ythm{#1}{#2}{#3}}{\@xthm{#1}{#2}{#3}}%]
  }%
}{}%  end of \@ifpackageloaded{ntheorem}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
%
% \subsubsection{\package{IEEEtrantools} support}
% \begin{macro}{IEEEtrantools}
%   The |IEEEeqnarray| environment and \cmd{\IEEEeqnarraccr} command calls
%   \cmd{\stepcounter} instead of \cmd{\refstepcounter} to increment the
%   equation counters, so they fail to set the cross-reference type for
%   \package{cleveref}. We patch in calls to \cmd{\refstepcounter} to fix
%   this.
%    \begin{macrocode}
\@ifpackageloaded{IEEEtrantools}{%
  \PackageInfo{cleveref}{`IEEEtrantools' support loaded}%
%    \end{macrocode}
%
% \begin{macro}{\@@IEEEeqnarray}
%   Rather than copying the whole of \cmd{\@@IEEEeqnarray} just to patch
%   the \cmd{\stepcounter} line (which would be fragile and liable to
%   breakage), we insert an extra step which calls \cmd{\refstepcounter}
%   to set the cross-reference type, then decrements the |equation|
%   counter by one, before calling the original \cmd{\@@IEEEeqnarray}.
%    \begin{macrocode}
  \let\cref@orig@@IEEEeqnarray\@@IEEEeqnarray%
  \def\@@IEEEeqnarray[#1]#2{%
    \refstepcounter{equation}%
    \addtocounter{equation}{-1}%
    \cref@orig@@IEEEeqnarray[#1]{#2}}%
%    \end{macrocode}
% \end{macro}
%
% We do the same thing with \cmd{\@IEEEeqnarrayXCR}, the last in the
% chain of macros that gets invoked by |\\| (let to
% \cmd{\IEEEeqnarraycr}) within |IEEEeqnarray| environments.
% \begin{macro}{\@IEEEeqnarrayXCR}
%    \begin{macrocode}
  \let\cref@orig@IEEEeqnarrayXCR\@IEEEeqnarrayXCR%
%    \end{macrocode}
% Newer versions of \package{IEEEtrantools} replace
% |\if@IEEEissubequation| conditional with a counter |\c@IEEEsubequation|
% that is $>0$ in subequations.
%    \begin{macrocode}
  \@ifundefined{c@IEEEsubequation}{%
    \def\@IEEEeqnarrayXCR[#1]{%
      \if@eqnsw%
        \if@IEEEissubequation%
          \refstepcounter{IEEEsubequation}%
          \addtocounter{IEEEsubequation}{-1}%
        \else%
          \refstepcounter{equation}%
          \addtocounter{equation}{-1}%
        \fi%
      \fi%
      \cref@orig@IEEEeqnarrayXCR[#1]}%
  }{
    \def\@IEEEeqnarrayXCR[#1]{%
      \if@eqnsw%
        \ifnum\c@IEEEsubequation>0\relax%
          \refstepcounter{IEEEsubequation}%
          \addtocounter{IEEEsubequation}{-1}%
        \else%
          \refstepcounter{equation}%
          \addtocounter{equation}{-1}%
        \fi%
      \fi%
      \cref@orig@IEEEeqnarrayXCR[#1]}%
  }% end of \@ifundefined{c@IEEEsubequation}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\IEEEyessubnumber}
%   And again for \cmd{\IEEEyessubnumber} (used to turn an equation into a
%   subequation).
%    \begin{macrocode}
  \let\cref@orig@IEEEyessubnumber\IEEEyessubnumber%
  \def\IEEEyessubnumber{%
    \if@IEEEeqnarrayISinner%
      \if@IEEElastlinewassubequation\else%
        \setcounter{IEEEsubequation}{0}%
        \refstepcounter{IEEEsubequation}%
      \fi%
    \fi%
    \cref@orig@IEEEyessubnumber}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{IEEEsubequation}
%   To get the subequation formatting right, we harmlessly add the
%   |IEEEsubequation| counter to the |equation| counter reset list so
%   that \package{cleveref} can figure out the subnumbering relationship,
%   and define |IEEEsubequation| to be an alias of the |subequation| format.
%    \begin{macrocode}
  \cref@addtoreset{IEEEsubequation}{subequation}%
  \crefalias{IEEEsubequation}{subequation}%
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
}{}% end of \@ifpackageloaded{IEEEtrantools}
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsubsection{\package{breqn} support}
% \begin{macro}{breqn}
%   The \package{breqn} package uses \cmd{\eq@setcounter} instead of
%   \cmd{\refstepcounter} to set equation numbers, which as usual breaks
%   \package{cleveref}. To fix this, we have to patch
%   \cmd{\eq@setcounter} with similar code to that already added to
%   \cmd{\refstepcounter}.
%    \begin{macrocode}
\@ifpackageloaded{breqn}{%
  \PackageInfo{cleveref}{`breqn' support loaded}%
  \let\cref@old@eq@setnumber\eq@setnumber%
  \def\eq@setnumber{%
    \cref@old@eq@setnumber%
    \cref@constructprefix{equation}{\cref@result}%
    \protected@xdef\cref@currentlabel{%
      [equation][\arabic{equation}][\cref@result]\p@equation\eq@number}}%
}{}% end of \@ifpackageloaded{breqn}
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsubsection{\package{algorithmicx} support}
% \begin{macro}{algorithmicx}
%   If \package{algorithmicx} is loaded, we modify its line numbering
%   mechanism so that labels referring to line numbers in algorithms work
%   with \package{cleveref}.
% \end{macro}
%    \begin{macrocode}
  \@ifpackageloaded{algorithmicx}{%
  \PackageInfo{cleveref}{`algorithmicx' support loaded}%
%    \end{macrocode}
%
% \begin{macro}{\ALG@step}
%   We modify \package{algorithmicx}'s \cmd{\ALG@step} macro, which
%   increments the line number, so that it stores the necessary
%   information in \cmd{\cref@currentlabel}. \cmd{\ALG@step} already
%   increments the line number counter \cmd{\ALG@line} using
%   \cmd{\addtocounter}, but to get \package{cleveref} support working,
%   it's cleaner to hook into the \cmd{\refstepcounter} mechanism, so we
%   first decrement the counter and then re-increment it using
%   \cmd{\refstepcounter}.
%    \begin{macrocode}
  \g@addto@macro\ALG@step{%
    \addtocounter{ALG@line}{-1}%
    \refstepcounter{ALG@line}%
    \expandafter\@cref@getprefix\cref@currentlabel\@nil\cref@currentprefix%
    \xdef\cref@currentprefix{\cref@currentprefix}}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ALG@beginalgorithmic}
%   However, this is not yet sufficient. The \cmd{\refstepcounter} above
%   is called within a group, so the resulting \cmd{\cref@currentlabel}
%   definition will not persist beyond the end of the group. To transfer
%   the information to the ``outside'', we follow \package{algorithmicx}'
%   own method for getting the label information into
%   \cmd{\@currentlabel}: we define \cmd{\cref@currentlabel} within
%   |algorithm| environments to refer specifically to macros that store
%   the line number information. The package conveniently supplies a
%   \cmd{\ALG@beginalgorithmic} hook, so we make use of it here.
%    \begin{macrocode}
  \g@addto@macro\ALG@beginalgorithmic{%
    \def\cref@currentlabel{%
      [line][\arabic{ALG@line}][\cref@currentprefix]\theALG@line}}%
  }{}%  end of \@ifpackageloaded{algorithmicx}
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsubsection{\package{listings} support}
% \begin{macro}{listings}
%   To support cross-references to listings produced by the
%   \package{listings} package, all we need to do is alias the counter it
%   uses, \cmd{\lstnumber}, to the ``listing'' cross-reference type.
%    \begin{macrocode}
  \@ifpackageloaded{listings}{%
    \PackageInfo{cleveref}{`listings' support loaded}%
    \crefalias{lstlisting}{listing}%
    \crefalias{lstnumber}{line}%
%    \end{macrocode}
%
% However, supporting cross-references to the line numbers is
% unfortunately a little more complicated than simply aliasing the
% ``lstnumber'' counter to the ``line'' cross-reference type (above).
% \package{listings} calls \cmd{\refstepcounter} from its
% \cmd{\lsthk@EveryPar} hook. But the hook macro is expanded inside a
% group. So that \cmd{\refstepcounter} call is completely useless:
% neither the \cmd{\@currentlabel} nor the \cmd{\cref@currentlabel}
% definitions make it out of the group, so they have no effect on
% \cmd{\label} definitions!
%
% To make line labels work, \package{listings} sets \cmd{\@currentlabel}
% to \cmd{\thelstnumber} at the beginning of a listing, via the
% \cmd{\lsthk@Init} hook, and it is \emph{this} (and not
% \cmd{\refstepcounter}) which causes the current line number to be
% picked up by \cmd{\label}s. To get line numbers working with
% \package{cleveref} too, we need to replicate this for
% \cmd{\cref@currentlabel}, which is what the following hook code does.
%
% \begin{macro}{\lsthk@Init}
% \begin{macro}{\lsthk@EveryPar}
%    \begin{macrocode}
    \lst@AddToHook{Init}{%
      \def\cref@currentlabel{%
        [line][\arabic{lstnumber}][\cref@currentprefix]\thelstnumber}}%
    \lst@AddToHook{EveryPar}{%
      \expandafter\@cref@getprefix\cref@currentlabel\@nil\cref@currentprefix%
      \xdef\cref@currentprefix{\cref@currentprefix}}%
  }{}%  end of \@ifpackageloaded{listings}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
%
% \subsubsection{\package{algorithm2e} support}
% \begin{macro}{algorithm2e}
%   When \package{hyperref} is not loaded, all we need to do to support
%   the \package{algorithm2e} package is to alias its counters,
%   \cmd{\algocf}, \cmd{AlgoLine} and \cmd{\algocfline}, to the
%   ``algorithm'' and ``line'' cross-reference types.
%    \begin{macrocode}
  \@ifpackageloaded{algorithm2e}{%
    \PackageInfo{cleveref}{`algorithm2e' support loaded}%
    \crefalias{algocf}{algorithm}%
    \crefalias{algocfline}{line}%
    \crefalias{AlgoLine}{line}%
%    \end{macrocode}
% When \package{hyperref} \emph{is} loaded, \package{algorithm2e} does
% some trickery when stepping the line number counter to avoid getting
% duplicate hyperlink anchor names, and updates \cmd{@currentlabel}
% manually. Unfortunately, this by-passes both \cmd{\refstepcounter} and
% \cmd{\H@refstepcounter}, so \cmd{\cref@currentlabel} never gets
% updated. To fix this, we have to hack its \cmd{algocf@nl@sethref} macro
% to update \cmd{cref@currentlabel} along with \cmd{@currentlabel}.
%    \begin{macrocode}
    \let\cref@old@algocf@nl@sethref\algocf@nl@sethref%
    \renewcommand{\algocf@nl@sethref}[1]{%
      \cref@old@algocf@nl@sethref{#1}%
      \cref@constructprefix{AlgoLine}{\cref@result}%
      \@ifundefined{cref@AlgoLine@alias}%
        {\def\@tempa{AlgoLine}}%
        {\def\@tempa{\csname cref@AlgoLine@alias\endcsname}}%
      \xdef\cref@currentlabel{%
        [\@tempa][\arabic{AlgoLine}][\cref@result]%
        \csname p@AlgoLine\endcsname\csname theAlgoLine\endcsname}}%
  }{}%  end of \@ifpackageloaded{algorithm2e}
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsubsection{\package{subfig} support}
% \begin{macro}{subfig}
%   The \package{subfig} package modifies \cmd{\refstepcounter} within
%   floats. Most of the time, this isn't a problem for
%   \package{cleveref}, as \package{subfig}'s modified
%   \cmd{\refstepcounter} calls \package{cleveref}'s version after it's
%   done its stuff. However, this breaks support the
%   \cmd{\refstepcounter} optional argument, so we fix that here.
%
%   \package{Subfig} also redefines \cmd{\label} within subfloats,
%   breaking \package{cleveref}'s optional argument. We also fix that.
%    \begin{macrocode}
\@ifpackageloaded{subfig}{%
  \PackageInfo{cleveref}{`subfig' support loaded}%
%    \end{macrocode}
%
% \begin{macro}{\refsteponlycounter}
%   \package{subfig} replaces \cmd{\refstepcounter} with
%   \cmd{\refsteponlycounter} within floats, which calls the saved
%   \package{cleveref} \cmd{\refstepcounter} after doing some extra
%   \package{subfig}-related processing. We redefine
%   \cmd{\refsteponlycounter} so that passing it an optional argument
%   bypasses \package{subfig}'s code entirely and just calls the
%   \package{cleveref} code directly. Since only
%   \package{cleveref}-specific commands will ever pass an optional
%   argument to \cmd{\refstepcounter}, this won't affect
%   \package{subfig}'s use of \cmd{\refstepcounter}. We have to postpone
%   this redefinition until the beginning of the document because
%   \package{subfig} does.
%    \begin{macrocode}
  \AtBeginDocument{%
    \let\cref@old@refsteponlycounter\refsteponlycounter%
    \def\refsteponlycounter{%
      \@ifnextchar[\refstepcounter@optarg%
        \cref@old@refsteponlycounter%]
    }}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\sf@sub@label}
% \begin{macro}{\sf@old@label}
% \begin{macro}{\cref@old@label}
%   Inside a subfloat, \package{subfig} captures the current \cmd{\label}
%   definition in \cmd{\sf@oldlabel}, then replaces \cmd{\label} with
%   \cmd{\subfloat@label}, which does additional argument and
%   subfloat-related processing before calling \cmd{\sf@oldlabel}. This
%   breaks \package{cleveref}'s \cmd{\label} optional argument.
%
%   We need to insert an extra layer of processing into the chain of
%   redefined \cmd{\label} macro calls, to process \package{cleveref}'s
%   optional argument. We do this by redefining \package{subfig}'s
%   \cmd{\sf@sub@label} command to process \package{subfig}'s optional
%   argument (which uses parentheses rather than square brackets) as usual,
%   but then have it call \cmd{\cref@label} which stores
%   \package{cleveref}'s \cmd{\label} command (recall that we're inside a
%   subfloat here, where \package{subfig} has overridden the \cmd{\label}
%   macro itself), to process \package{cleveref}'s own \cmd{\label}
%   optional argument.
%
%   \cmd{\cref@label} would normally call the original \cmd{\label}
%   definition stored in \cmd{\cref@old@label}, whereas here we want it
%   to instead call \cmd{\sf@@sub@label}, the next layer of the
%   \package{subfig} \cmd{\label} macro stack, otherwise we bypass the
%   rest of the \package{subfig} processing and break it. So we
%   temporarily let \cmd{\cref@old@label} to \cmd{\sf@@sub@label}, so
%   that \cmd{\cref@label} hands back to \package{subfig}'s \cmd{\label}
%   processing when done. (We're inside a group, so \cmd{\cref@old@label}
%   gets restored at the end of the subfloat.)
%
%   The final issue is that \package{subfig} captures the original
%   \cmd{\label} definition in \cmd{\sf@oldlabel} at the beginning of the
%   subfloat. But this captures \package{cleveref}'s
%   definition,\footnote{Actually, because \package{subfig} always loads
%   the \package{caption} package, it captures \package{cleveref}'s
%   \package{caption}-related redefinition of \cmd{\label}.} instead of
%   the original \cmd{\label} definition that needs to be called after
%   \package{subfig} has finished its stuff. So, we let \cmd{\sf@oldlabel}
%   to \cmd{\cref@old@label} before redefining the latter, so that the
%   \package{subfig} \cmd{\label} stack calls the right thing once it's
%   done its own processing. Oof!
%    \begin{macrocode}
  \def\sf@sub@label(#1){%
    \ifhyperrefloaded%
      \protected@edef\@currentlabelname{%
        \expandafter\strip@period #1\relax.\relax\@@@}%
    \fi%
    \let\sf@oldlabel\cref@old@label%
    \let\cref@old@label\sf@@sub@label%
    \cref@label}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
%    \begin{macrocode}
  }{}%  end of \@ifpackageloaded{subfig}
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsubsection{\package{memoir} subfig support}
% \begin{macro}{memoir}
%   We try to stay out of \package{memoir}'s way as much as possible, by
%   using a separate set of parallel label definitions for
%   \package{cleveref}, and leaving the standard labels alone for
%   \package{memoir} and other packages to use as normal. The one
%   remaining point of contention is the \cmd{\label} command itself.
%
% \begin{macro}{\sf@memsub@label}
% \begin{macro}{\@memoldlabel}
% \begin{macro}{\cref@old@label}
%   \package{memoir} contains its own internal re-implementation of
%   \package{subfig}, which redefines \cmd{\label} in a very similar way.
%   We therefore have to replicate the \package{subfig} support for
%   \package{memoir}'s internal re-implementation. (We have to postpone
%   the redefinitions until the beginning of the document because
%   \package{memoir} does, too.)
%    \begin{macrocode}
\@ifclassloaded{memoir}{%
  \AtBeginDocument{%
    \def\sf@memsub@label(#1){%
      \protected@edef\mem@currentlabelname{#1}%
      \let\@memoldlabel\cref@old@label%
      \let\cref@old@label\sf@@memsub@label%
      \cref@label}}%
}{}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
%
% \subsubsection{\package{caption} support}
% \begin{macro}{caption}
%   The \package{caption} package redefines \cmd{\label} within floats.
%   Since version 3.2c, it is careful to redefine \cmd{\label} in a way
%   that doesn't break any optional arguments introduced by other
%   packages (such as \package{cleveref}'s), so we no longer need to add
%   any compatibility hacks.
%
%   Earlier versions of \package{caption} do break \package{cleveref}'s
%   optional argument, however, so we have to fix things here for those
%   versions.
%    \begin{macrocode}
\@ifpackageloaded{caption}{%
  \@ifpackagelater{caption}{2011/08/19}{}{%
    \PackageInfo{cleveref}{`caption' support loaded}%
%    \end{macrocode}
%
% \begin{macro}{\cref@old@caption@xlabel}
% \begin{macro}{\cref@old@label}
% \begin{macro}{\cref@ORI@label}
% \begin{macro}{\caption@ORI@label}
%   We fix the \cmd{\label} argument parsing by redefining
%   \cmd{\caption@xlabel}, the macro which \cmd{\label} is let to inside
%   floats, to juggle around the various \package{cleveref} and
%   \package{caption} \cmd{\label}-processing macros so that everything
%   ultimately gets processed correctly.
%
%   \cmd{\cref@label} stores \package{cleveref}'s \cmd{\label}
%   redefinition (recall that we're inside a float here, where
%   \cmd{\label} itself has been redefined by \package{caption}).
%   \cmd{\cref@label} processes \package{cleveref}'s optional
%   \cmd{\label} argument, if any. It then calls \cmd{\cref@old@label}.
%   But we've let that to \cmd{\cref@old@caption@xlabel}, which stores
%   the original \cmd{\caption@xlabel}. So the net effect is to insert an
%   extra layer of optional argument processing between \cmd{\label} and
%   \cmd{\caption@xlabel}, which can then proceed as before.
%
%   The final issue is that \package{caption} captures the original
%   \cmd{\label} definition in \cmd{\caption@ORI@label}, but this picks
%   up the \package{cleveref} redefinition, which is not what we want. So
%   we let \cmd{\caption@ORI@label} to the original \cmd{\label}
%   definition as captured by \package{cleveref}. Usually, that's stored
%   in \cmd{\cref@old@label}, but we've temporarily redefined that. So we
%   need to save what was originally preserved in \cmd{\cref@old@label}
%   in \cmd{\cref@ORI@old@label}, and make \cmd{\caption@ORI@label} call
%   that. Oof!
%    \begin{macrocode}
    \let\cref@old@caption@xlabel\caption@xlabel%
    \def\caption@xlabel{%
      \let\cref@ORI@label\cref@old@label%
      \let\cref@old@label\cref@old@caption@xlabel%
      \let\caption@ORI@label\cref@ORI@label%
      \cref@label}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
%    \begin{macrocode}
    }% end of \@ifpackagelater
  }{}%  end of \@ifpackageloaded{caption}
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsubsection{\package{aliascnt} support}
% \begin{macro}{aliascnt}
%   For the \package{aliascnt} trick described in \cref{sec:label_type}
%   of the documentation to work, we have to inform \package{cleveref}
%   about how aliased counters get reset. \package{aliascnt}'s
%   \cmd{\newaliascnt} command doesn't add the aliased counter to any
%   reset list, but if the counter it's aliased to gets reset, the
%   aliased counter will get reset too. In order for \package{cleveref}
%   to correctly sort cross-references to the aliased counter, we have to
%   add that counter to the appropriate reset list, even though that
%   isn't necessary to actually reset the counter itself. We add this to
%   the \cmd{\newaliascnt} command.
% \end{macro}
% \begin{macro}{\newaliascnt}
%    \begin{macrocode}
\@ifpackageloaded{aliascnt}{%
  \PackageInfo{cleveref}{`aliascnt' support loaded}%
  \let\cref@old@newaliascnt\newaliascnt%
  \renewcommand*{\newaliascnt}[2]{%
    \cref@old@newaliascnt{#1}{#2}%
    \cref@resetby{#2}{\cref@result}%
    \ifx\cref@result\relax\else%
      \cref@addtoreset{#1}{\cref@result}%
    \fi}%
  }{}%  end of \@ifpackageloaded{aliascnt}
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsection{Poor Man's \package{cleveref}}
% \begin{macro}{poorman}
%   The \option{poorman} option causes a |sed| script to automatically be
%   written. When the original \LaTeX{} source file is processed through
%   this script, it strips out all the \package{cleveref} commands,
%   typesetting all the reference formatting explicitly, and using the
%   standard \cmd{\ref} and \cmd{\pageref} commands to produce the
%   references themselves.
% \end{macro}
%    \begin{macrocode}
\DeclareOption{poorman}{%
  \PackageInfo{cleveref}{option `poorman' loaded}%
%    \end{macrocode}
%
%
% \begin{macro}{\cref@poorman@text}
%   Define global macro \cmd{\cref@poorman@text} to store the text
%   produced by the \cmd{\cref} commands, and open an output stream for
%   writing the script before starting to process the document body.
%    \begin{macrocode}
  \gdef\cref@poorman@text{}%
  \AtBeginDocument{%
    \newwrite\@crefscript%
    \immediate\openout\@crefscript=\jobname.sed}%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{select@language}
% \begin{macro}{foreign@language}
%   If \package{babel} is loaded, we add to the \cmd{\select@language}
%   and \cmd{\foreign@language} commands to make them write substitution
%   rules to the script that replace the cross-reference name and
%   conjunction component macros with the appropriate language-dependent
%   names. We use |sed| line-number addresses in the rules to ensure they
%   are only applied to the regions in which that particular language was
%   in use.
%
%   Note that we write substitution rules for the \emph{previous}
%   language block when the language is changed, because we need the
%   rules to appear in the script \emph{after} all the cross-reference
%   substitution rules for that language block. \cmd{\cref@inputlineno}
%   stores the input-file line-number of the start of the previous
%   language block.
%
%   We postpone the redefinitions until the beginning of the document not
%   only to ensure that they don't get clobbered by other package's
%   redefinitions, but also because we don't want the redefinitions to
%   take effect until after \package{babel} has called
%   \cmd{\selectlanguage} for the main language (remember, the
%   substitution rules for this first language block will get written at
%   the next language change).
%
%   Note that, since we're writing to the script file within
%   \cmd{\AtBeginDocument} and \cmd{\AtEndDocument}, this code has to
%   come \emph{after} the above \cmd{\AtBeginDocument} code which opens
%   the script file for writing, and \emph{before} the later
%   \cmd{\AtEndDocument} code (below) which closes it.
%
%   The |\if@cref@switched@language| flag is set when a \package{babel}
%   language switching command is called. It is checked by
%   \cmd{\cref@writelanguagerules} when writing substitution rules.
%    \begin{macrocode}
  \newif\if@cref@switched@language%
  \@ifpackageloaded{babel}{%
    \AtBeginDocument{%
      \let\cref@old@select@language\select@language%
      \def\select@language{%
        \@cref@switched@languagetrue%
        \cref@writelanguagerules%
        \cref@old@select@language}%
      \let\cref@old@foreign@language\foreign@language%
      \def\foreign@language{%
        \@cref@switched@languagetrue%
        \cref@writelanguagerules%
        \cref@old@foreign@language}%
      \edef\cref@inputlineno{\the\inputlineno}}%
    }{}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% The final set of substitution rules gets written at the end of the
% document. This is the only set of rules that gets written if
% \package{babel} is not loaded.
%    \begin{macrocode}
  \AtEndDocument{%
    \let\select@language\cref@old@select@language%
    \let\foreign@language\cref@old@foreign@language%
    \cref@writelanguagerules}%
%    \end{macrocode}
%
% \begin{macro}{\cref@writelanguagerules}
%   \cmd{\cref@writelanguagerules} does the grunt work of writing out the
%   necessary substitution rules.
%    \begin{macrocode}
  \def\cref@writelanguagerules{%
    \begingroup%
%    \end{macrocode}
% If |\if@cref@switched@language| hasn't been set, then we must be
% writing the final set of substitution rules at the end of a document
% in which no language switching command was ever used. In which case,
% the substitution rules don't specify a line-number address.
%    \begin{macrocode}
      \if@cref@switched@language%
        \edef\@address{\cref@inputlineno,\the\inputlineno}%
      \else%
        \def\@address{}%
      \fi%
      \expandafter\def\expandafter\cref@poorman@text\expandafter{%
        \crefrangeconjunction}%
      \expandafter\def\expandafter\@tempa\expandafter{%
        \expandafter{\@address}{\string\crefrangeconjunction}}%
      \expandafter\cref@writescript\@tempa%
      \expandafter\def\expandafter\cref@poorman@text\expandafter{%
        \crefrangepreconjunction}%
      \expandafter\def\expandafter\@tempa\expandafter{%
        \expandafter{\@address}{\string\crefrangepreconjunction}}%
      \expandafter\cref@writescript\@tempa%
      \expandafter\def\expandafter\cref@poorman@text\expandafter{%
        \crefrangepostconjunction}%
      \expandafter\def\expandafter\@tempa\expandafter{%
        \expandafter{\@address}{\string\crefrangepostconjunction}}%
      \expandafter\cref@writescript\@tempa%
      \expandafter\def\expandafter\cref@poorman@text\expandafter{%
        \crefpairconjunction}%
      \expandafter\def\expandafter\@tempa\expandafter{%
        \expandafter{\@address}{\string\crefpairconjunction}}%
      \expandafter\cref@writescript\@tempa%
      \expandafter\def\expandafter\cref@poorman@text\expandafter{%
        \crefmiddleconjunction}%
      \expandafter\def\expandafter\@tempa\expandafter{%
        \expandafter{\@address}{\string\crefmiddleconjunction}}%
      \expandafter\cref@writescript\@tempa%
      \expandafter\def\expandafter\cref@poorman@text\expandafter{%
        \creflastconjunction}%
      \expandafter\def\expandafter\@tempa\expandafter{%
        \expandafter{\@address}{\string\creflastconjunction}}%
      \expandafter\cref@writescript\@tempa%
      \expandafter\def\expandafter\cref@poorman@text\expandafter{%
        \crefpairgroupconjunction}%
      \expandafter\def\expandafter\@tempa\expandafter{%
        \expandafter{\@address}{\string\crefpairgroupconjunction}}%
      \expandafter\cref@writescript\@tempa%
      \expandafter\def\expandafter\cref@poorman@text\expandafter{%
        \crefmiddlegroupconjunction}%
      \expandafter\def\expandafter\@tempa\expandafter{%
        \expandafter{\@address}{\string\crefmiddlegroupconjunction}}%
      \expandafter\cref@writescript\@tempa%
      \expandafter\def\expandafter\cref@poorman@text\expandafter{%
        \creflastgroupconjunction}%
      \expandafter\def\expandafter\@tempa\expandafter{%
        \expandafter{\@address}{\string\creflastgroupconjunction}}%
      \expandafter\cref@writescript\@tempa%
%    \end{macrocode}
% We write substitution rules for all component-derived cross-reference
% formats, as listed in \cmd{\cref@label@types}.
%    \begin{macrocode}
      \let\@tempstack\cref@label@types%
      \cref@isstackfull{\@tempstack}%
      \@whilesw\if@cref@stackfull\fi{%
%    \end{macrocode}
% \cmd{\cref@\meta{type}@name} substitution rules.
%    \begin{macrocode}
        \edef\@tempa{\cref@stack@top{\@tempstack}}%
        \expandafter\expandafter\expandafter\def%
        \expandafter\expandafter\expandafter\cref@poorman@text%
        \expandafter\expandafter\expandafter{%
          \csname cref@\@tempa @name\endcsname}%
        \edef\@tempa{%
          \string\cref@\expandafter\noexpand\@tempa @name\space}%
        \expandafter\expandafter\expandafter\def%
        \expandafter\expandafter\expandafter\@tempa%
        \expandafter\expandafter\expandafter{%
          \expandafter\expandafter\expandafter{%
            \expandafter\@address\expandafter}%
          \expandafter{\@tempa}}%
        \expandafter\cref@writescript\@tempa%
%    \end{macrocode}
% \cmd{\cref@\meta{type}@name@plural} substitution rules.
%    \begin{macrocode}
        \edef\@tempa{\cref@stack@top{\@tempstack}}%
        \expandafter\expandafter\expandafter\def%
        \expandafter\expandafter\expandafter\cref@poorman@text%
        \expandafter\expandafter\expandafter{%
          \csname cref@\@tempa @name@plural\endcsname}%
        \edef\@tempa{%
          \string\cref@\expandafter\noexpand\@tempa%
          @name@plural\space}%
        \expandafter\expandafter\expandafter\def%
        \expandafter\expandafter\expandafter\@tempa%
        \expandafter\expandafter\expandafter{%
          \expandafter\expandafter\expandafter{%
            \expandafter\@address\expandafter}%
          \expandafter{\@tempa}}%
        \expandafter\cref@writescript\@tempa%
%    \end{macrocode}
% \cmd{\Cref@\meta{type}@name} substitution rules.
%    \begin{macrocode}
        \edef\@tempa{\cref@stack@top{\@tempstack}}%
        \expandafter\expandafter\expandafter\def%
        \expandafter\expandafter\expandafter\cref@poorman@text%
        \expandafter\expandafter\expandafter{%
          \csname Cref@\@tempa @name\endcsname}%
        \edef\@tempa{%
          \string\Cref@\expandafter\noexpand\@tempa @name\space}%
        \expandafter\expandafter\expandafter\def%
        \expandafter\expandafter\expandafter\@tempa%
        \expandafter\expandafter\expandafter{%
          \expandafter\expandafter\expandafter%
          {\expandafter\@address\expandafter}%
          \expandafter{\@tempa}}%
        \expandafter\cref@writescript\@tempa%
%    \end{macrocode}
% \cmd{\Cref@\meta{type}@name@plural} substitution rules.
%    \begin{macrocode}
        \edef\@tempa{\cref@stack@top{\@tempstack}}%
        \expandafter\expandafter\expandafter\def%
        \expandafter\expandafter\expandafter\cref@poorman@text%
        \expandafter\expandafter\expandafter{%
          \csname Cref@\@tempa @name@plural\endcsname}%
        \edef\@tempa{%
          \string\Cref@\expandafter\noexpand\@tempa%
          @name@plural\space}%
        \expandafter\expandafter\expandafter\def%
        \expandafter\expandafter\expandafter\@tempa%
        \expandafter\expandafter\expandafter{%
          \expandafter\expandafter\expandafter%
          {\expandafter\@address\expandafter}%
          \expandafter{\@tempa}}%
        \expandafter\cref@writescript\@tempa%
%    \end{macrocode}
% After the loop over cross-reference types, we set
% \cmd{\cref@inputlineno} to the current input-file line, in preparation
% for the next language block.
%    \begin{macrocode}
        \cref@stack@pop{\@tempstack}%
        \cref@isstackfull{\@tempstack}}%
    \endgroup%
    \edef\cref@inputlineno{\the\inputlineno}}%
%    \end{macrocode}
% \end{macro}
%
%
% 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 appearing 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 (\textbackslash, \{, \} 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`$=13 %$
      \catcode`\=0 \catcode`<=1 \catcode`>=2%
      \catcode`\\=13 \catcode`\{=12 \catcode`\}=12 \catcode`_=12%
      \lccode`/=92%
      \lccode`~=92\lowercase{\def~{\string/\string/}}%
      \lccode`~=42\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@poorman@text}.
%    \begin{macrocode}
      \def\cref@poorman@text{}%
      \immediate\read\@crefscript to \@tempa%
      \ifx\@tempa\@eof%
        \@not@eoffalse%
      \else%
        \@not@eoftrue%
        \edef\@tempa{\@tempa}%
      \fi%
      \@whilesw\if@not@eof\fi{%
        \expandafter\g@addto@macro\expandafter%
          \cref@poorman@text\expandafter{\@tempa^^J}%
        \immediate\read\@crefscript to \@tempa%
        \ifx\@tempa\@eof%
          \@not@eoffalse%
        \else%
          \@not@eoftrue%
          \edef\@tempa{\@tempa}%
        \fi}%
    \endgroup%
    \immediate\closein\@crefscript%
%    \end{macrocode}
% Add some rules to remove other \package{cleveref} commands. We use the
% \cmd{\lowercase} trick again for writing the \textbackslash, \{ and \}
% characters. (This could be done in other ways, but since we're in
% \cmd{\lowercase} mood, why not stick with it.)
%    \begin{macrocode}
    \begingroup%
      \lccode`|=92 \lccode`<=123 \lccode`>=125 \lccode`C=67%
      \lowercase{\def\@tempa{%[|
          s/||label|[[^]]*|]/||label/g}}%
      \expandafter\g@addto@macro\expandafter%
        \cref@poorman@text\expandafter{\@tempa^^J}%
      \lowercase{\edef\@tempa{s/||usepackage|(|[.*|]|)|<0,1|><cleveref>//g}}%
      \expandafter\g@addto@macro\expandafter%
        \cref@poorman@text\expandafter{\@tempa^^J}%
      \lowercase{\edef\@tempa{s/||[cC]refformat<.*><.*>//g}}%
      \expandafter\g@addto@macro\expandafter%
        \cref@poorman@text\expandafter{\@tempa^^J}%
      \lowercase{\edef\@tempa{s/||[cC]refrangeformat<.*><.*>//g}}%
      \expandafter\g@addto@macro\expandafter%
        \cref@poorman@text\expandafter{\@tempa^^J}%
      \lowercase{\edef\@tempa{s/||[cC]refmultiformat<.*><.*><.*><.*>//g}}%
      \expandafter\g@addto@macro\expandafter%
        \cref@poorman@text\expandafter{\@tempa^^J}%
      \lowercase{\edef\@tempa{%
          s/||[cC]refrangemultiformat<.*><.*><.*><.*>//g}}%
      \expandafter\g@addto@macro\expandafter%
        \cref@poorman@text\expandafter{\@tempa^^J}%
      \lowercase{\edef\@tempa{s/||[cC]refname<.*><.*>//g}}%
      \expandafter\g@addto@macro\expandafter%
        \cref@poorman@text\expandafter{\@tempa^^J}%
      \lowercase{\edef\@tempa{s/||[cC]reflabelformat<.*><.*>//g}}%
      \expandafter\g@addto@macro\expandafter%
        \cref@poorman@text\expandafter{\@tempa^^J}%
      \lowercase{\edef\@tempa{s/||[cC]refrangelabelformat<.*><.*>//g}}%
      \expandafter\g@addto@macro\expandafter%
        \cref@poorman@text\expandafter{\@tempa^^J}%
      \lowercase{\edef\@tempa{s/||[cC]refdefaultlabelformat<.*>//g}}%
      \expandafter\g@addto@macro\expandafter%
        \cref@poorman@text\expandafter{\@tempa^^J}%
      \lowercase{\edef\@tempa{%
          s/||renewcommand<||crefpairconjunction><.*>//g}}%
      \expandafter\g@addto@macro\expandafter%
        \cref@poorman@text\expandafter{\@tempa^^J}%
      \lowercase{\edef\@tempa{%
          s/||renewcommand<||crefpairgroupconjunction><.*>//g}}%
      \expandafter\g@addto@macro\expandafter%
        \cref@poorman@text\expandafter{\@tempa^^J}%
      \lowercase{\edef\@tempa{%
          s/||renewcommand<||crefmiddleconjunction><.*>//g}}%
      \expandafter\g@addto@macro\expandafter%
        \cref@poorman@text\expandafter{\@tempa^^J}%
      \lowercase{\edef\@tempa{%
          s/||renewcommand<||crefmiddlegroupconjunction><.*>//g}}%
      \expandafter\g@addto@macro\expandafter%
        \cref@poorman@text\expandafter{\@tempa^^J}%
      \lowercase{\edef\@tempa{%
          s/||renewcommand<||creflastconjunction><.*>//g}}%
      \expandafter\g@addto@macro\expandafter%
        \cref@poorman@text\expandafter{\@tempa^^J}%
      \lowercase{\edef\@tempa{%
          s/||renewcommand<||creflastgroupconjunction><.*>//g}}%
      \expandafter\g@addto@macro\expandafter%
        \cref@poorman@text\expandafter{\@tempa^^J}%
      \lowercase{\edef\@tempa{s/||renewcommand<||[cC]ref><.*>//g}}%
      \expandafter\g@addto@macro\expandafter%
        \cref@poorman@text\expandafter{\@tempa^^J}%
      \lowercase{\edef\@tempa{s/||renewcommand<||[cC]refrange><.*>//g}}%
      \expandafter\g@addto@macro\expandafter%
        \cref@poorman@text\expandafter{\@tempa^^J}%
    \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@poorman@text}%
    \immediate\closeout\@crefscript%
  }%  end of \AtEndDocument
%    \end{macrocode}
%
%
% \begin{macro}{\cref@writescript}
%   The \cmd{\cref@writescript} utility macro does the actual writing of
%   the substitution rule to the script. The first argument is the
%   ``address'', the second argument is the regexp pattern to match,
%   whilst the substitution text is whatever is currently stored in
%   \cmd{\cref@poorman@text}.
%    \begin{macrocode}
  \def\cref@getmeaning#1{\expandafter\@cref@getmeaning\meaning#1\@nil}%
  \def\@cref@getmeaning#1->#2\@nil{#2}%
  \def\cref@writescript#1#2{%
    \edef\@tempa{\cref@getmeaning{\cref@poorman@text}}%
    \immediate\write\@crefscript{#1 s/#2/\@tempa/g}}%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\cref}
% \begin{macro}{\Cref}
% \begin{macro}{\crefrange}
% \begin{macro}{\Crefrange}
% \begin{macro}{\@crefstar}
% \begin{macro}{\@crefnostar}
% \begin{macro}{\@crefrangestar}
% \begin{macro}{\@crefrangenostar}
%   To make use of all the \option{poorman} infrastructure defined above,
%   we must redefine the \package{cleveref} referencing commands
%   themselves. There are two parts to this: at the very top layer of the
%   cross-referencing macro stack, we redefine the user-level commands to
%   first initialise |\cref@poorman@text| to the empty string, then
%   typeset the reference as usual, and finally write a substitution
%   rule to the |sed| script containing whatever has been accumulated in
%   |\cref@poorman@text|. At the very lowest layer of the macro stack, we
%   redefine the macros that actually typeset the various parts of the
%   references to additionally add a copy of whatever they typeset to
%   |\cref@poorman@text|.
%
%   We first 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. Most of the redefinitions differ
%   slightly depending on whether \package{hyperref} is loaded.
%    \begin{macrocode}
  \if@cref@hyperrefloaded\relax%  hyperref loaded
    \def\@crefnostar#1#2{%
      \gdef\cref@poorman@text{}%
      \@cref{#1}{#2}%
%    \end{macrocode}
% We use a temporary \cmd{\@tempa} macro here, which makes use of the
% fact that the first character of \#1 is ``c'' for lower-case and ``C''
% for upper-case in these commands, in order to write out the correct
% capitalisation in the substitution.
%
% FIXME: We only resort to this because |\string\#1| doesn't work. But
% there \emph{must} be a better way to get a backslash character into the
% token stream, obviating the need for the ugly \cmd{\@tempa} macro.
%    \begin{macrocode}
      \def\@tempa##1##2\@nil{%
        \if##1c%
          \cref@writescript{}{\string\cref\string{#2\string}}%
        \else%
          \cref@writescript{}{\string\Cref\string{#2\string}}%
        \fi}%
      \@tempa#1\@nil}%
    \def\@crefstar#1#2{%
      \gdef\cref@poorman@text{}%
      \@crefstarredtrue\@cref{#1}{#2}\@crefstarredfalse%
      \def\@tempa##1##2\@nil{%
        \if##1c%
          \cref@writescript{}{\string\cref*\string{#2\string}}%
        \else%
          \cref@writescript{}{\string\Cref*\string{#2\string}}%
        \fi}%
      \@tempa#1\@nil}%
    \def\@crefrangenostar#1#2#3{%
      \gdef\cref@poorman@text{}%
      \@@setcrefrange{#2}{#3}{#1}{}%
      \def\@tempa##1##2\@nil{%
        \if##1c%
          \cref@writescript{}{%
            \string\crefrange\string{#2\string}\string{#3\string}}%
        \else%
          \cref@writescript{}{%
            \strinsg\Crefrange\string{#2\string}\string{#3\string}}%
        \fi}%
      \@tempa#1\@nil}%
    \def\@crefrangestar#1#2#3{%
      \gdef\cref@poorman@text{}%
      \@crefstarredtrue\@@setcrefrange{#2}{#3}{#1}{}\@crefstarredfalse%
      \def\@tempa##1##2\@nil{%
        \if##1c%
          \cref@writescript{}{%
            \string\crefrange*\string{#2\string}\string{#3\string}}%
        \else%
          \cref@writescript{}{%
            \string\Crefrange*\string{#2\string}\string{#3\string}}%
        \fi}%
      \@tempa#1\@nil}%
    \def\@cpagerefrangenostar#1#2#3{%
      \gdef\cref@poorman@text{}%
      \@@setcpagerefrange{#2}{#3}{#1}{}%
      \def\@tempa##1##2\@nil{%
        \if##1c%
          \cref@writescript{}{%
            \string\cpagerefrange\string{#2\string}\string{#3\string}}%
        \else%
          \cref@writescript{}{%
            \string\Cpagerefrange\string{#2\string}\string{#3\string}}%
        \fi}%
      \@tempa#1\@nil}%
    \def\@cpagerefrangestar#1#2#3{%
      \gdef\cref@poorman@text{}%
      \@crefstarredtrue%
      \@@setcpagerefrange{#2}{#3}{#1}{}%
      \@crefstarredfalse%
      \def\@tempa##1##2\@nil{%
        \if##1c%
          \cref@writescript{}{%
            \string\cpagerefrange*\string{#2\string}\string{#3\string}}%
        \else%
          \cref@writescript{}{%
            \string\Cpagerefrange*\string{#2\string}\string{#3\string}}%
        \fi}%
      \@tempa#1\@nil}%
    \def\@labelcrefnostar#1{%
      \gdef\cref@poorman@text{}%
      \@cref{labelcref}{#1}%
      \cref@writescript{}{\string\labelcref\string{#1\string}}}%
    \def\@labelcrefstar#1{%
      \gdef\cref@poorman@text{}%
      \@crefstarredtrue%
      \@cref{labelcref}{#1}%
      \@crefstarredfalse%
      \cref@writescript{}{\string\labelcref*\string{#1\string}}}%
    \def\@labelcpagerefnostar#1{%
      \gdef\cref@poorman@text{}%
      \@cref{labelcpageref}{#1}%
      \cref@writescript{}{\string\labelcpageref\string{#1\string}}}%
    \def\@labelcpagerefstar#1{%
      \gdef\cref@poorman@text{}%
      \@crefstarredtrue%
      \@cref{labelcpageref}{#1}%
      \@crefstarredfalse%
      \cref@writescript{}{\string\labelcpageref*\string{#1\string}}}%
%
  \else%  hyperref not loaded
    \DeclareRobustCommand{\cref}[1]{%
      \gdef\cref@poorman@text{}%
      \@cref{cref}{#1}%
      \cref@writescript{}{\string\cref\string{#1\string}}}%
    \DeclareRobustCommand{\Cref}[1]{%
      \gdef\cref@poorman@text{}%
      \@cref{Cref}{#1}%
      \cref@writescript{}{\string\Cref\string{#1\string}}}%
    \DeclareRobustCommand{\crefrange}[2]{%
      \gdef\cref@poorman@text{}%
      \@@setcrefrange{#1}{#2}{cref}{}%
      \cref@writescript{}{%
        \string\crefrange\string{#1\string}\string{#2\string}}}%
    \DeclareRobustCommand{\Crefrange}[2]{%
      \gdef\cref@poorman@text{}%
      \@@setcrefrange{#1}{#2}{Cref}{}%
      \cref@writescript{}{%
        \string\Crefrange\string{#1\string}\string{#2\string}}}%
    \DeclareRobustCommand{\cpageref}[1]{%
      \gdef\cref@poorman@text{}%
      \@cref{cpageref}{#1}%
      \cref@writescript{}{\string\cpageref\string{#1\string}}}%
    \DeclareRobustCommand{\Cpageref}[1]{%
      \gdef\cref@poorman@text{}%
      \@cref{Cpageref}{#1}%
      \cref@writescript{}{\string\Cpageref\string{#1\string}}}%
    \DeclareRobustCommand{\cpagerefrange}[2]{%
      \gdef\cref@poorman@text{}%
      \@@setcpagerefrange{#1}{#2}{cref}{}%
      \cref@writescript{}{%
        \string\cpagerefrange\string{#1\string}\string{#2\string}}}%
    \DeclareRobustCommand{\Cpagerefrange}[2]{%
      \gdef\cref@poorman@text{}%
      \@@setcpagerefrange{#1}{#2}{Cref}{}%
      \cref@writescript{}{%
        \string\Cpagerefrange\string{#1\string}\string{#2\string}}}%
    \DeclareRobustCommand{\labelcref}[1]{%
      \gdef\cref@poorman@text{}%
      \@cref{labelcref}{#1}%
      \cref@writescript{}{\string\labelcref\string{#1\string}}}%
    \DeclareRobustCommand{\labelcpageref}[1]{%
      \gdef\cref@poorman@text{}%
      \@cref{labelcpageref}{#1}%
      \cref@writescript{}{\string\labelcpageref\string{#1\string}}}%
  \fi%  end of test for hyperref
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \begin{macro}{\namecref}
% \begin{macro}{\nameCref}
% \begin{macro}{\lcnamecref}
% \begin{macro}{\namecrefs}
% \begin{macro}{\nameCrefs}
% \begin{macro}{\lcnamecrefs}
%   The \cmd{\namecref} et al.\ commands don't do anything different when
%   \package{hyperref} is loaded, so we don't need to test for
%   \package{hyperref} when redefining them.
%    \begin{macrocode}
  \DeclareRobustCommand{\namecref}[1]{%
    \gdef\cref@poorman@text{}%
    \@setnamecref{cref}{#1}{}{}%
    \cref@writescript{}{\string\namecref\string{#1\string}}}%
  \DeclareRobustCommand{\nameCref}[1]{%
    \gdef\cref@poorman@text{}%
    \@setnamecref{Cref}{#1}{}{}%
    \cref@writescript{}{\string\nameCref\string{#1\string}}}%
  \DeclareRobustCommand{\lcnamecref}[1]{%
    \gdef\cref@poorman@text{}%
    \@setnamecref{Cref}{#1}{}{\MakeLowercase}%
    \cref@writescript{}{\string\lcnamecref\string{#1\string}}}%
  \DeclareRobustCommand{\namecrefs}[1]{%
    \gdef\cref@poorman@text{}%
    \@setnamecref{cref}{#1}{@plural}{}%
    \cref@writescript{}{\string\namecrefs\string{#1\string}}}%
  \DeclareRobustCommand{\nameCrefs}[1]{%
    \gdef\cref@poorman@text{}%
    \@setnamecref{Cref}{#1}{@plural}{}%
    \cref@writescript{}{\string\nameCrefs\string{#1\string}}}%
  \DeclareRobustCommand{\lcnamecrefs}[1]{%
    \gdef\cref@poorman@text{}%
    \@setnamecref{Cref}{#1}{@plural}{\MakeLowercase}%
    \cref@writescript{}{\string\lcnamecrefs\string{#1\string}}}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
% \begin{macro}{\@setcref@pairgroupconjunction}
% \begin{macro}{\@setcref@middlegroupconjunction}
% \begin{macro}{\@setcref@lastgroupconjunction}
%   Redefine \cmd{\@@@setcref}, \cmd{\@@@setcrefrange},
%   \cmd{\@@@setcpageref} and\linebreak[4] \cmd{\@@@setcpagerefrange}, as
%   well as the conjunction macros\linebreak[4]
%   \cmd{\@setcref@middlegroupconjunction},
%   \cmd{\@setcref@lastgroupconjunction} and
%   \cmd{\@setcref@pairgroupconjunction}, to append text they typeset
%   to\linebreak[4] the \cmd{\cref@poorman@text} macro, as well as
%   actually doing the typesetting.
%    \begin{macrocode}
  \def\@setcref@pairgroupconjunction{%
    \crefpairgroupconjunction%
    \expandafter\g@addto@macro\expandafter\cref@poorman@text%
      \expandafter{\crefpairgroupconjunction}}%
  \def\@setcref@middlegroupconjunction{%
    \crefmiddlegroupconjunction%
    \expandafter\g@addto@macro\expandafter\cref@poorman@text%
      \expandafter{\crefmiddlegroupconjunction}}%
  \def\@setcref@lastgroupconjunction{%
    \creflastgroupconjunction%
    \expandafter\g@addto@macro\expandafter\cref@poorman@text%
      \expandafter{\creflastgroupconjunction}}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \begin{macro}{\@@@setcref}
% \begin{macro}{\@@@setcrefrange}
% \begin{macro}{\@@@setcpageref}
% \begin{macro}{\@@@setcpagerefrange}
%   The necessary redefinitions of most of the cross-referencing commands
%   differ slightly depending on whether \package{hyperref} is loaded or
%   not.
%    \begin{macrocode}
  \let\old@@@setcref\@@@setcref%
  \let\old@@@setcrefrange\@@@setcrefrange%
  \let\old@@@setcpageref\@@@setcpageref%
  \let\old@@@setcpagerefrange\@@@setcpagerefrange%
  \if@cref@hyperrefloaded\relax%  hyperref loaded
    \def\@@@setcref#1#2{%
      \old@@@setcref{#1}{#2}%
      \if@crefstarred%
        \expandafter\g@addto@macro\expandafter\cref@poorman@text%
          \expandafter{#1{\ref*{#2}}{}{}}%
      \else%
        \expandafter\g@addto@macro\expandafter\cref@poorman@text%
          \expandafter{#1{\ref{#2}}{}{}}%
      \fi}%
    \def\@@@setcrefrange#1#2#3{%
      \old@@@setcrefrange{#1}{#2}{#3}%
      \if@crefstarred%
        \expandafter\g@addto@macro\expandafter\cref@poorman@text%
          \expandafter{#1{\ref*{#2}}{\ref*{#3}}{}{}{}{}}%
      \else%
        \expandafter\g@addto@macro\expandafter\cref@poorman@text%
          \expandafter{#1{\ref{#2}}{\ref{#3}}{}{}{}{}}%
      \fi}%
    \def\@@@setcpageref#1#2{%
      \old@@@setcpageref{#1}{#2}%
      \if@crefstarred%
        \expandafter\g@addto@macro\expandafter\cref@poorman@text%
          \expandafter{#1{\pageref*{#2}}{}{}}%
      \else%
        \expandafter\g@addto@macro\expandafter\cref@poorman@text%
          \expandafter{#1{\pageref{#2}}{}{}}%
      \fi}%
    \def\@@@setcpagerefrange#1#2#3{%
      \old@@@setcpagerefrange{#1}{#2}{#3}%
      \if@crefstarred%
        \expandafter\g@addto@macro\expandafter\cref@poorman@text%
          \expandafter{#1{\pageref*{#2}}{\pageref*{#3}}{}{}{}{}}%
      \else%
        \expandafter\g@addto@macro\expandafter\cref@poorman@text%
          \expandafter{#1{\pageref{#2}}{\pageref{#3}}{}{}{}{}}%
      \fi}%
%
  \else%  hyperref not loaded
    \def\@@@setcref#1#2{%
      \old@@@setcref{#1}{#2}%
      \expandafter\g@addto@macro\expandafter{%
        \expandafter\cref@poorman@text\expandafter}%
        \expandafter{#1{\ref{#2}}{}{}}}%
    \def\@@@setcrefrange#1#2#3{%
      \old@@@setcrefrange{#1}{#2}{#3}%
      \expandafter\g@addto@macro%
        \expandafter{\expandafter\cref@poorman@text\expandafter}%
        \expandafter{#1{\ref{#2}}{\ref{#3}}{}{}{}{}}}%
    \def\@@@setcpageref#1#2{%
      \old@@@setcpageref{#1}{#2}%
      \expandafter\g@addto@macro\expandafter{%
        \expandafter\cref@poorman@text\expandafter}%
        \expandafter{#1{\pageref{#2}}{}{}}}%
    \def\@@@setcpagerefrange#1#2#3{%
      \old@@@setcpagerefrange{#1}{#2}{#3}%
      \expandafter\g@addto@macro%
        \expandafter{\expandafter\cref@poorman@text\expandafter}%
        \expandafter{#1{\pageref{#2}}{\pageref{#3}}{}{}{}{}}}%
  \fi%  end of hyperref test
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \begin{macro}{\@@@setnamecref}
%   The \cmd{\namecref} et al.\ commands don't do anything different when
%   \package{hyperref} is loaded, so we don't need to test for
%   \package{hyperref} when redefining \cmd{\@@@setnamecref}.
%    \begin{macrocode}
  \let\old@@@setnamecref\@@@setnamecref%
  \def\@@@setnamecref#1#2{%
    \old@@@setnamecref{#1}{#2}%
    \expandafter\def\expandafter\@tempa\expandafter{#1}%
    \def\@tempb{#2}%
    \expandafter\expandafter\expandafter\g@addto@macro%
      \expandafter\expandafter\expandafter{%
      \expandafter\expandafter\expandafter\cref@poorman@text%
      \expandafter\expandafter\expandafter}%
      \expandafter\expandafter\expandafter{\expandafter\@tempb\@tempa}}%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{varioref}
%   If \package{varioref} is loaded, do the same for the
%   \package{varioref} commands.
%    \begin{macrocode}
  \@ifpackageloaded{varioref}{%
    \AtBeginDocument{%
%    \end{macrocode}
%
% \begin{macro}{\@@vpageref}
% We redefine \cmd{\@@vpageref} to make it write a substitution rule to
% the script, as well as typesetting the page reference.
%    \begin{macrocode}
      \def\@@vpageref#1[#2]#3{%
        \gdef\cref@poorman@text{}%
        \cref@@vpageref{#1}[#2]{#3}%
        \cref@writescript{}{\string\vpageref\string{#3\string}}}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cref@vref}
%   \cmd{\cref@vref} is similarly redefined to write a substitution rule.
%    \begin{macrocode}
      \let\old@cref@vref\cref@vref%
      \def\cref@vref#1#2{%
        \gdef\cref@poorman@text{}%
        \old@cref@vref{#1}{#2}%
        \def\@tempa##1##2\@nil{%
          \if##1c%
            \if@crefstarred%
              \cref@writescript{}{\string\vref*\string{#2\string}}%
            \else%
              \cref@writescript{}{\string\vref\string{#2\string}}%
            \fi%
          \else%
            \if@crefstarred%
              \cref@writescript{}{\string\Vref*\string{#2\string}}%
            \else%
              \cref@writescript{}{\string\Vref\string{#2\string}}%
            \fi%
          \fi}%
        \@tempa#1\@nil}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cref@fullref}
% \begin{macro}{\cref@vrefrange}
%   \cmd{\cref@fullref} and \cmd{\cref@vrefrange} are also redefined so
%   that they write substitution rules. Strictly speaking, the starred
%   variants of \cmd{\fullref} and \cmd{\vrefrange} are not defined when
%   \package{hyperref} isn't loaded, so we could avoid checking for them
%   in that case. However, the redundant check does no harm, and avoids
%   some code duplication.
%    \begin{macrocode}
      \let\old@cref@fullref\cref@fullref%
      \def\cref@fullref#1#2{%
        \gdef\cref@poorman@text{}%
        \old@cref@fullref{#1}{#2}%
        \def\@tempa##1##2\@nil{%
          \if##1c%
            \if@crefstarred%
              \cref@writescript{}{\string\fullref*\string{#2\string}}%
            \else%
              \cref@writescript{}{\string\fullref\string{#2\string}}%
            \fi%
          \else%
            \if@crefstarred%
              \cref@writescript{}{\string\Fullref*\string{#2\string}}%
            \else%
              \cref@writescript{}{\string\Fullref\string{#2\string}}%
            \fi%
          \fi}%
        \@tempa#1\@nil}%
%
      \let\old@cref@vrefrange\cref@vrefrange%
      \def\cref@vrefrange#1#2#3{%
        \gdef\cref@poorman@text{}%
        \old@cref@vrefrange{#1}{#2}{#3}%
        \def\@tempa##1##2\@nil{%
          \if##1c%
            \if@crefstarred%
              \cref@writescript{}{%
                \string\vrefrange*\string{#2\string}\string{#3\string}}%
            \else%
              \cref@writescript{}{%
                \string\vrefrange\string{#2\string}\string{#3\string}}%
            \fi%
          \else%
            \if@crefstarred%
              \cref@writescript{}{%
                \string\Vrefrange*\string{#2\string}\string{#3\string}}%
            \else%
              \cref@writescript{}{%
                \string\Vrefrange\string{#2\string}\string{#3\string}}%
            \fi%
          \fi}%
        \@tempa#1\@nil}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@@@setvpageref}
% \begin{macro}{\@@@setvpagerefrange}
%   In order to get the appropriate substitution for \package{varioref}
%   commands appended to \cmd{\cref@poorman@text}, we have to redefine
%   \cmd{\@@@setvpageref} and\linebreak[4] \cmd{\@@@setvpagerefrange},
%   which perform the final typesetting of \package{varioref} page
%   references, so that they append an appropriate substitution for the
%   page reference they're typesetting.
%    \begin{macrocode}
      \def\@@@setvpageref#1[#2]#3{%
        \cref@old@@vpageref{#1}[#2]{#3}%
        \g@addto@macro\cref@poorman@text{\vpageref{#3}}}%
      \def\@@@setvpagerefrange[#1]#2#3{%
        \vpagerefrange[#1]{#2}{#3}%
        \g@addto@macro\cref@poorman@text{\vpagerefrange{#2}{#3}}}%
      \def\@@@setfullpageref#1{%
        \reftextfaraway{#1}%
        \g@addto@macro\cref@poorman@text{\reftextfaraway{#1}}}%
      \def\@@@setfullpagerefrange#1#2{%
        \reftextpagerange{#1}{#2}%
        \g@addto@macro\cref@poorman@text{\reftextpagerange{#1}{#2}}}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@setcref@space}
% \begin{macro}{\@setcref@pairconjunction}
% \begin{macro}{\@setcref@middleconjunction}
% \begin{macro}{\@setcref@lastconjunction}
%   Finally, we make sure the conjunctions also get appended to
%   the\linebreak[4] \cmd{\cref@poorman@text} substitution.
%    \begin{macrocode}
      \def\@setcref@space{ % space here is deliberate
        \g@addto@macro\cref@poorman@text{ }}%
      \def\@setcref@pairconjunction{%
        \crefpairconjunction%
        \expandafter\g@addto@macro\expandafter\cref@poorman@text%
          \expandafter{\crefpairconjunction}}%
      \def\@setcref@middleconjunction{%
        \crefmiddleconjunction%
        \expandafter\g@addto@macro\expandafter\cref@poorman@text%
          \expandafter{\crefmiddleconjunction}}%
      \def\@setcref@lastconjunction{%
        \creflastconjunction%
        \expandafter\g@addto@macro\expandafter\cref@poorman@text%
          \expandafter{\creflastconjunction}}%
    }% end of \AtBeginDocument
  }{}% end of \@ifpackageloaded{varioref}
}%  end of poorman option
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
%
% \subsection{Sort and Compress Options}
% \begin{macro}{sort}
% \begin{macro}{compress}
% \begin{macro}{nosort}
% \begin{macro}{\if@cref@sort}
% \begin{macro}{\if@cref@compress}
%   The \option{sort}, \option{compress} or \option{nosort} options
%   determine whether to sort and/or compress lists of multiple
%   references (default is to do both). They work simply by setting the
%   |\if@cref@sort| and |\if@cref@compress| flags appropriately.
%    \begin{macrocode}
\newif\if@cref@sort%
\newif\if@cref@compress%
%    \end{macrocode}
% Default is to both sort and compress references.
%    \begin{macrocode}
\@cref@sorttrue%
\@cref@compresstrue%
%    \end{macrocode}
% Options override default.
%    \begin{macrocode}
\DeclareOption{sort}{%
  \PackageInfo{cleveref}{sorting but not compressing references}%
  \@cref@sorttrue%
  \@cref@compressfalse}%
\DeclareOption{compress}{%
  \PackageInfo{cleveref}{compressing but not sorting references}%
  \@cref@sortfalse%
  \@cref@compresstrue}%
\DeclareOption{sort&compress}{%
  \PackageInfo{cleveref}{sorting and compressing references}%
  \@cref@sorttrue%
  \@cref@compresstrue}%
\DeclareOption{nosort}{%
  \PackageInfo{cleveref}{neither sorting nor compressing references}%
  \@cref@sortfalse%
  \@cref@compressfalse}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
%
% \subsection{Capitalise Option}
% \begin{macro}{capitalise}
% \begin{macro}{\if@cref@capitalise}
%   The \option{capitalise} option causes \package{cleveref} to always
%   use the |\Cref|* variants for typesetting cross-references, so that
%   cross-reference names are always capitalised.
%    \begin{macrocode}
\newif\if@cref@capitalise%
%    \end{macrocode}
% Disabled by default.
%    \begin{macrocode}
\@cref@capitalisefalse%
%    \end{macrocode}
% Option overrides default.
%    \begin{macrocode}
\DeclareOption{capitalise}{%
  \PackageInfo{cleveref}{always capitalise cross-reference names}%
  \@cref@capitalisetrue}%
\DeclareOption{capitalize}{%
  \PackageInfo{cleveref}{always capitalise cross-reference names}%
  \@cref@capitalisetrue}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
%
%
% \subsection{Nameinlink Option}
% \begin{macro}{nameinlink}
% \begin{macro}{\if@cref@nameinlink}
%   The \option{nameinlink} option causes \package{cleveref} to include
%   the cross-reference name as part of the hyperlink target when the
%   \package{hyperref} package is used.
%    \begin{macrocode}
\newif\if@cref@nameinlink%
%    \end{macrocode}
% Disabled by default.
%    \begin{macrocode}
\@cref@nameinlinkfalse%
%    \end{macrocode}
% Option overrides default.
%    \begin{macrocode}
\DeclareOption{nameinlink}{%
  \PackageInfo{cleveref}{include cross-reference names in hyperlinks}%
  \@cref@nameinlinktrue}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
%
%
% \subsection{Noabbrev Option}
% \begin{macro}{noabbrev}
% \begin{macro}{\if@cref@abbrev}
%   The \option{noabbrev} option causes \package{cleveref} to always use
%   the full cross-reference names, instead of abbreviating some of the
%   more common names in the middle of sentences.
%    \begin{macrocode}
\newif\if@cref@abbrev%
%    \end{macrocode}
% Enabled by default.
%    \begin{macrocode}
\@cref@abbrevtrue%
%    \end{macrocode}
% Option overrides default.
%    \begin{macrocode}
\DeclareOption{noabbrev}{%
  \PackageInfo{cleveref}{no abbreviation of names}%
  \@cref@abbrevfalse}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
%
%
% \subsection{Language and \package{babel} Support}
% \label{sec:code:babel}
% Default reference formats for different languages are supported via
% package options, in the usual way.
%
% Any contributions of translations for missing languages are most
% welcome! If you can contribute definitions for a missing language,
% ideally you should add them below the existing ones (using those as a
% model), generate a patch against the original \package{cleveref.dtx}
% file, and send the patch by email to the package author. However, if
% you don't know how to produce a patch, you can instead just send the
% translations as a plain text file.
%
%
% \begin{macro}{\cref@addto}
%   Utility macro to use instead of \package{babel}'s flawed \cmd{\addto}
%   (copied and modified from \package{varioref}).
%    \begin{macrocode}
\def\cref@addto#1#2{%
  \@temptokena{#2}%
  \ifx#1\undefined%
    \edef#1{\the\@temptokena}%
  \else%
    \toks@\expandafter{#1}%
    \edef#1{\the\toks@\the\@temptokena}%
  \fi%
  \@temptokena{}\toks@\@temptokena}%
\@onlypreamble\cref@addto%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cref@addlanguagedefs}
%   Utility macro to add code to \cmd{\extras}\meta{language} or
%   \cmd{\captions}\meta{language}, depending on whether \package{babel}
%   or \package{polyglossia} are loaded.
%    \begin{macrocode}
\long\def\cref@addlanguagedefs#1#2{%
  \@ifpackageloaded{polyglossia}%
    {\AtBeginDocument{%
        \ifcsdef{#1@loaded}{%
          \expandafter\cref@addto\csname captions#1\endcsname{#2}}{}}}%
    {\@ifpackageloaded{babel}{%
      \edef\@curroptions{\@ptionlist{\@currname.\@currext}}%
      \@expandtwoargs\in@{,#1,}{,\@classoptionslist,\@curroptions,}%
      \ifin@%
        \AtBeginDocument{%
          \expandafter\cref@addto\csname extras#1\endcsname{#2}}%
      \fi}{}}}%
%    \end{macrocode}
% \end{macro}
%
%
% Passing a language option to \package{cleveref} defines the
% cross-reference names and conjunctions as appropriate for that
% language. We can't make the definitions straight away, since they would
% prevent the automatic definition of the other capitalisation variant
% from working if the user chooses to change a default definition in the
% preamble, so we postpone them until the beginning of the document.
% However, if each language option were to simply define any formats that
% aren't already defined by the end of the preamble, the \emph{first}
% language option would override all the others. Unfortunately, the
% convention in \LaTeX{} and \package{babel} is for the \emph{last}
% language option to take precedence. So we instead use the
% \cmd{\crefname@preamble} command to save the definitions in
% |\cref@|\meta{type}|@name@preamble| etc., and after all the language
% options have been processed, use the contents of these to set the
% default definitions for any undefined formats.
%
% For \package{babel} support, we add the appropriate redefinitions to
% the\linebreak[4] |\extras|\meta{language} macro, which is called by
% \package{babel}'s \cmd{\selectlanguage} et al.\ commands.  The main
% language (the last one listed in the options) is set up by an automatic
% call to \cmd{\selectlanguage} at the beginning of the document, which
% would clobber any redefinitions made by the user in the preamble. To
% avoid this, we postpone adding the redefinitions to
% |\extras|\meta{language} until the beginning of the document. Since
% \package{cleveref} must always be loaded \emph{after} \package{babel},
% the redefinitions won't be added to |\extras|\meta{language} until
% \emph{after} \package{babel} has already called \cmd{\selectlanguage}
% for the main language. Thus the redefinitions will only be in effect
% when \cmd{\selectlanguage} is called explicitly within the
% document. (The definitions for the main language are taken care of by
% the language options passed to \package{cleveref}, independently of
% \package{babel}.)
%
% Note that we define both capitalisation variants explicitly throughout,
% rather than relying on the automatic definition of the other variant,
% in order to make the code produced by the poor man's |sed| script
% slightly cleaner.
%
%
% \subsubsection{English}
% \begin{macro}{english}
%   English definitions (these are used by default).
% \end{macro}
%
% Set up the definitions used at the beginning of the document to define
% the formats created by the document preamble.
%    \begin{macrocode}
\DeclareOption{english}{%
  \AtBeginDocument{%
    \def\crefrangeconjunction@preamble{ to\nobreakspace}%
    \def\crefrangepreconjunction@preamble{}%
    \def\crefrangepostconjunction@preamble{}%
    \def\crefpairconjunction@preamble{ and\nobreakspace}%
    \def\crefmiddleconjunction@preamble{, }%
    \def\creflastconjunction@preamble{ and\nobreakspace}%
%    \end{macrocode}
% We have to define the group conjunctions explicitly here, rather than
% relying on fall-back definitions in terms of the above conjunctions
% (see \cref{sec:code:default_formats}), in case any other language
% option defines them explicitly and we need to override those.
%    \begin{macrocode}
    \def\crefpairgroupconjunction@preamble{ and\nobreakspace}%
    \def\crefmiddlegroupconjunction@preamble{, }%
    \def\creflastgroupconjunction@preamble{, and\nobreakspace}%
 %
    \Crefname@preamble{equation}{Equation}{Equations}%
    \Crefname@preamble{figure}{Figure}{Figures}%
    \Crefname@preamble{table}{Table}{Tables}%
    \Crefname@preamble{page}{Page}{Pages}%
    \Crefname@preamble{part}{Part}{Parts}%
    \Crefname@preamble{chapter}{Chapter}{Chapters}%
    \Crefname@preamble{section}{Section}{Sections}%
    \Crefname@preamble{appendix}{Appendix}{Appendices}%
    \Crefname@preamble{enumi}{Item}{Items}%
    \Crefname@preamble{footnote}{Footnote}{Footnotes}%
    \Crefname@preamble{theorem}{Theorem}{Theorems}%
    \Crefname@preamble{lemma}{Lemma}{Lemmas}%
    \Crefname@preamble{corollary}{Corollary}{Corollaries}%
    \Crefname@preamble{proposition}{Proposition}{Propositions}%
    \Crefname@preamble{definition}{Definition}{Definitions}%
    \Crefname@preamble{result}{Result}{Results}%
    \Crefname@preamble{example}{Example}{Examples}%
    \Crefname@preamble{remark}{Remark}{Remarks}%
    \Crefname@preamble{note}{Note}{Notes}%
    \Crefname@preamble{algorithm}{Algorithm}{Algorithms}%
    \Crefname@preamble{listing}{Listing}{Listings}%
    \Crefname@preamble{line}{Line}{Lines}%
 %
    \if@cref@capitalise%  capitalise set
      \if@cref@abbrev%
        \crefname@preamble{equation}{Eq.}{Eqs.}%
        \crefname@preamble{figure}{Fig.}{Figs.}%
      \else%
        \crefname@preamble{equation}{Equation}{Equations}%
        \crefname@preamble{figure}{Figure}{Figures}%
      \fi%
      \crefname@preamble{page}{Page}{Pages}%
      \crefname@preamble{table}{Table}{Tables}%
      \crefname@preamble{part}{Part}{Parts}%
      \crefname@preamble{chapter}{Chapter}{Chapters}%
      \crefname@preamble{section}{Section}{Sections}%
      \crefname@preamble{appendix}{Appendix}{Appendices}%
      \crefname@preamble{enumi}{Item}{Items}%
      \crefname@preamble{footnote}{Footnote}{Footnotes}%
      \crefname@preamble{theorem}{Theorem}{Theorems}%
      \crefname@preamble{lemma}{Lemma}{Lemmas}%
      \crefname@preamble{corollary}{Corollary}{Corollaries}%
      \crefname@preamble{proposition}{Proposition}{Propositions}%
      \crefname@preamble{definition}{Definition}{Definitions}%
      \crefname@preamble{result}{Result}{Results}%
      \crefname@preamble{example}{Example}{Examples}%
      \crefname@preamble{remark}{Remark}{Remarks}%
      \crefname@preamble{note}{Note}{Notes}%
      \crefname@preamble{algorithm}{Algorithm}{Algorithms}%
      \crefname@preamble{listing}{Listing}{Listings}%
      \crefname@preamble{line}{Line}{Lines}%
 %
    \else%  capitalise unset
      \if@cref@abbrev%
        \crefname@preamble{equation}{eq.}{eqs.}%
        \crefname@preamble{figure}{fig.}{figs.}%
      \else%
        \crefname@preamble{equation}{equation}{equations}%
        \crefname@preamble{figure}{figure}{figures}%
      \fi%
      \crefname@preamble{page}{page}{pages}%
      \crefname@preamble{table}{table}{tables}%
      \crefname@preamble{part}{part}{parts}%
      \crefname@preamble{chapter}{chapter}{chapters}%
      \crefname@preamble{section}{section}{sections}%
      \crefname@preamble{appendix}{appendix}{appendices}%
      \crefname@preamble{enumi}{item}{items}%
      \crefname@preamble{footnote}{footnote}{footnotes}%
      \crefname@preamble{theorem}{theorem}{theorems}%
      \crefname@preamble{lemma}{lemma}{lemmas}%
      \crefname@preamble{corollary}{corollary}{corollaries}%
      \crefname@preamble{proposition}{proposition}{propositions}%
      \crefname@preamble{definition}{definition}{definitions}%
      \crefname@preamble{result}{result}{results}%
      \crefname@preamble{example}{example}{examples}%
      \crefname@preamble{remark}{remark}{remarks}%
      \crefname@preamble{note}{note}{notes}%
      \crefname@preamble{algorithm}{algorithm}{algorithms}%
      \crefname@preamble{listing}{listing}{listings}%
      \crefname@preamble{line}{line}{lines}%
    \fi%
    \def\cref@language{english}%
  }}% end \AtBeginDocument and \DeclareOption
%    \end{macrocode}
%
% If using \package{babel} and the corresponding option is set, or if
% using \package{polyglossia} and the language has been loaded, add
% format definition commands to \cmd{\extras}\meta{language} or
% \cmd{\captions}\meta{language} so that language switching commands will
% change the cross-reference formats appropriately.
%    \begin{macrocode}
\cref@addlanguagedefs{english}{%
  \PackageInfo{cleveref}{loaded `english' language definitions}%
  \renewcommand{\crefrangeconjunction}{ to\nobreakspace}%
  \renewcommand\crefrangepreconjunction{}%
  \renewcommand\crefrangepostconjunction{}%
  \renewcommand{\crefpairconjunction}{ and\nobreakspace}%
  \renewcommand{\crefmiddleconjunction}{, }%
  \renewcommand{\creflastconjunction}{ and\nobreakspace}%
  \renewcommand{\crefpairgroupconjunction}{ and\nobreakspace}%
  \renewcommand{\crefmiddlegroupconjunction}{, }%
  \renewcommand{\creflastgroupconjunction}{, and\nobreakspace}%
 %
  \Crefname{equation}{Equation}{Equations}%
  \Crefname{figure}{Figure}{Figures}%
  \Crefname{subfigure}{Figure}{Figures}%
  \Crefname{table}{Table}{Tables}%
  \Crefname{subtable}{Table}{Tables}%
  \Crefname{page}{Page}{Pages}%
  \Crefname{part}{Part}{Parts}%
  \Crefname{chapter}{Chapter}{Chapters}%
  \Crefname{section}{Section}{Sections}%
  \Crefname{subsection}{Section}{Sections}%
  \Crefname{subsubsection}{Section}{Sections}%
  \Crefname{appendix}{Appendix}{Appendices}%
  \Crefname{subappendix}{Appendix}{Appendices}%
  \Crefname{subsubappendix}{Appendix}{Appendices}%
  \Crefname{subsubsubappendix}{Appendix}{Appendices}%
  \Crefname{enumi}{Item}{Items}%
  \Crefname{enumii}{Item}{Items}%
  \Crefname{enumiii}{Item}{Items}%
  \Crefname{enumiv}{Item}{Items}%
  \Crefname{enumv}{Item}{Items}%
  \Crefname{footnote}{Footnote}{Footnotes}%
  \Crefname{theorem}{Theorem}{Theorems}%
  \Crefname{lemma}{Lemma}{Lemmas}%
  \Crefname{corollary}{Corollary}{Corollaries}%
  \Crefname{proposition}{Proposition}{Propositions}%
  \Crefname{definition}{Definition}{Definitions}%
  \Crefname{result}{Result}{Results}%
  \Crefname{example}{Example}{Examples}%
  \Crefname{remark}{Remark}{Remarks}%
  \Crefname{note}{Note}{Notes}%
  \Crefname{algorithm}{Algorithm}{Algorithms}%
  \Crefname{listing}{Listing}{Listings}%
  \Crefname{line}{Line}{Lines}%
 %
  \if@cref@capitalise%  capitalise set
    \if@cref@abbrev%
      \crefname{equation}{Eq.}{Eqs.}%
      \crefname{figure}{Fig.}{Figs.}%
      \crefname{subfigure}{Fig.}{Figs.}%
    \else%
      \crefname{equation}{Equation}{Equations}%
      \crefname{figure}{Figure}{Figures}%
      \crefname{subfigure}{Figure}{Figures}%
    \fi%
    \crefname{page}{Page}{Pages}%
    \crefname{table}{Table}{Tables}%
    \crefname{subtable}{Table}{Tables}%
    \crefname{part}{Part}{Parts}%
    \crefname{chapter}{Chapter}{Chapters}%
    \crefname{section}{Section}{Sections}%
    \crefname{subsection}{Section}{Sections}%
    \crefname{subsubsection}{Section}{Sections}%
    \crefname{appendix}{Appendix}{Appendices}%
    \crefname{subappendix}{Appendix}{Appendices}%
    \crefname{subsubappendix}{Appendix}{Appendices}%
    \crefname{subsubsubappendix}{Appendix}{Appendices}%
    \crefname{enumi}{Item}{Items}%
    \crefname{enumii}{Item}{Items}%
    \crefname{enumiii}{Item}{Items}%
    \crefname{enumiv}{Item}{Items}%
    \crefname{enumv}{Item}{Items}%
    \crefname{footnote}{Footnote}{Footnotes}%
    \crefname{theorem}{Theorem}{Theorems}%
    \crefname{lemma}{Lemma}{Lemmas}%
    \crefname{corollary}{Corollary}{Corollaries}%
    \crefname{proposition}{Proposition}{Propositions}%
    \crefname{definition}{Definition}{Definitions}%
    \crefname{result}{Result}{Results}%
    \crefname{example}{Example}{Examples}%
    \crefname{remark}{Remark}{Remarks}%
    \crefname{note}{Note}{Notes}%
    \crefname{algorithm}{Algorithm}{Algorithms}%
    \crefname{listing}{Listing}{Listings}%
    \crefname{line}{Line}{Lines}%
 %
  \else%  capitalise unset
    \if@cref@abbrev%
      \crefname{equation}{eq.}{eqs.}%
      \crefname{figure}{fig.}{figs.}%
      \crefname{subfigure}{fig.}{figs.}%
    \else%
      \crefname{equation}{equation}{equations}%
      \crefname{figure}{figure}{figures}%
      \crefname{subfigure}{figure}{figures}%
    \fi%
    \crefname{table}{table}{tables}%
    \crefname{subtable}{table}{tables}%
    \crefname{page}{page}{pages}%
    \crefname{part}{part}{parts}%
    \crefname{chapter}{chapter}{chapters}%
    \crefname{section}{section}{sections}%
    \crefname{subsection}{section}{sections}%
    \crefname{subsubsection}{section}{sections}%
    \crefname{appendix}{appendix}{appendices}%
    \crefname{subappendix}{appendix}{appendices}%
    \crefname{subsubappendix}{appendix}{appendices}%
    \crefname{subsubsubappendix}{appendix}{appendices}%
    \crefname{enumi}{item}{items}%
    \crefname{enumii}{item}{items}%
    \crefname{enumiii}{item}{items}%
    \crefname{enumiv}{item}{items}%
    \crefname{enumv}{item}{items}%
    \crefname{footnote}{footnote}{footnotes}%
    \crefname{theorem}{theorem}{theorems}%
    \crefname{lemma}{lemma}{lemmas}%
    \crefname{corollary}{corollary}{corollaries}%
    \crefname{proposition}{proposition}{propositions}%
    \crefname{definition}{definition}{definitions}%
    \crefname{result}{result}{results}%
    \crefname{example}{example}{examples}%
    \crefname{remark}{remark}{remarks}%
    \crefname{note}{note}{notes}%
    \crefname{algorithm}{algorithm}{algorithms}%
    \crefname{listing}{listing}{listings}%
    \crefname{line}{line}{lines}%
  \fi}% end \cref@addlangagedefs
%    \end{macrocode}
%
%
%  \subsubsection{German}
% \begin{macro}{german}
%   German translations kindly provided by Stefan Pinnow, abbreviations
%   by Natanael Arndt, and a few additions by the package author (so you
%   know to blame the latter for any errors!).
% \end{macro}
%
% Set up the definitions used at the beginning of the document to define
% the formats created by the document preamble.
%    \begin{macrocode}
\DeclareOption{german}{%
  \AtBeginDocument{%
    \def\crefrangeconjunction@preamble{ bis\nobreakspace}%
    \def\crefrangepreconjunction@preamble{}%
    \def\crefrangepostconjunction@preamble{}%
    \def\crefpairconjunction@preamble{ und\nobreakspace}%
    \def\crefmiddleconjunction@preamble{, }%
    \def\creflastconjunction@preamble{ und\nobreakspace}%
%    \end{macrocode}
% We don't want the extra comma before ``und'' that would be added by the
% default fall-back definitions in terms of the above conjunctions, so we
% define \cmd{\crefpairgroupconjunction} explicitly. In fact, we have to
% define the other group conjunctions explicitly too here, in case any
% other language option defines them explicitly and we need to override
% them.
%    \begin{macrocode}
    \def\crefpairgroupconjunction@preamble{ und\nobreakspace}%
    \def\crefmiddlegroupconjunction@preamble{, }%
    \def\creflastgroupconjunction@preamble{ und\nobreakspace}%
 %
    \Crefname@preamble{equation}{Gleichung}{Gleichungen}%
    \Crefname@preamble{figure}{Abbildung}{Abbildungen}%
    \Crefname@preamble{table}{Tabelle}{Tabellen}%
    \Crefname@preamble{page}{Seite}{Seiten}%
    \Crefname@preamble{part}{Teil}{Teile}%
    \Crefname@preamble{chapter}{Kapitel}{Kapitel}%
    \Crefname@preamble{section}{Abschnitt}{Abschnitte}%
    \Crefname@preamble{appendix}{Anhang}{Anh\"ange}%
    \Crefname@preamble{enumi}{Punkt}{Punkte}%
    \Crefname@preamble{footnote}{Fu\ss note}{Fu\ss noten}%
    \Crefname@preamble{theorem}{Theorem}{Theoreme}%
    \Crefname@preamble{lemma}{Lemma}{Lemmata}%
    \Crefname@preamble{corollary}{Korollar}{Korollare}%
    \Crefname@preamble{proposition}{Satz}{S\"atze}%
    \Crefname@preamble{definition}{Definition}{Definitionen}%
    \Crefname@preamble{result}{Ergebnis}{Ergebnisse}%
    \Crefname@preamble{example}{Beispiel}{Beispiele}%
    \Crefname@preamble{remark}{Bemerkung}{Bemerkungen}%
    \Crefname@preamble{note}{Anmerkung}{Anmerkungen}%
    \Crefname@preamble{algorithm}{Algorithmus}{Algorithmen}%
    \Crefname@preamble{listing}{Listing}{Listings}%
    \Crefname@preamble{line}{Zeile}{Zeilen}%
 %
    \if@cref@abbrev%
      \crefname@preamble{figure}{Abb.}{Abb.}%
    \else%
      \crefname@preamble{figure}{Abbildung}{Abbildungen}%
    \fi%
    \crefname@preamble{equation}{Gleichung}{Gleichungen}%
    \crefname@preamble{table}{Tabelle}{Tabellen}%
    \crefname@preamble{page}{Seite}{Seiten}%
    \crefname@preamble{part}{Teil}{Teile}%
    \crefname@preamble{chapter}{Kapitel}{Kapitel}%
    \crefname@preamble{section}{Abschnitt}{Abschnitte}%
    \crefname@preamble{appendix}{Anhang}{Anh\"ange}%
    \crefname@preamble{enumi}{Punkt}{Punkte}%
    \crefname@preamble{footnote}{Fu\ss note}{Fu\ss noten}%
    \crefname@preamble{theorem}{Theorem}{Theoreme}%
    \crefname@preamble{lemma}{Lemma}{Lemmata}%
    \crefname@preamble{corollary}{Korollar}{Korollare}%
    \crefname@preamble{proposition}{Satz}{S\"atze}%
    \crefname@preamble{definition}{Definition}{Definitionen}%
    \crefname@preamble{result}{Ergebnis}{Ergebnisse}%
    \crefname@preamble{example}{Beispiel}{Beispiele}%
    \crefname@preamble{remark}{Bemerkung}{Bemerkungen}%
    \crefname@preamble{note}{Anmerkung}{Anmerkungen}%
    \crefname@preamble{algorithm}{Algorithmus}{Algorithmen}%
    \crefname@preamble{listing}{Listing}{Listings}%
    \crefname@preamble{line}{Zeile}{Zeilen}%
    \def\cref@language{german}%
  }}% end \AtBeginDocument and \DeclareOption
%    \end{macrocode}
%
% If using \package{babel} and the corresponding option is set, or if
% using \package{polyglossia} and the language has been loaded, add
% format definition commands to \cmd{\extras}\meta{language} or
% \cmd{\captions}\meta{language} so that language switching commands will
% change the cross-reference formats appropriately.
%    \begin{macrocode}
\cref@addlanguagedefs{german}{%
  \PackageInfo{cleveref}{loaded `german language definitions}%
  \renewcommand{\crefrangeconjunction}{ bis\nobreakspace}%
  \renewcommand\crefrangepreconjunction{}%
  \renewcommand\crefrangepostconjunction{}%
  \renewcommand{\crefpairconjunction}{ und\nobreakspace}%
  \renewcommand{\crefmiddleconjunction}{, }%
  \renewcommand{\creflastconjunction}{ und\nobreakspace}%
  \renewcommand{\crefpairgroupconjunction}{ und\nobreakspace}%
  \renewcommand{\crefmiddlegroupconjunction}{, }%
  \renewcommand{\creflastgroupconjunction}{ und\nobreakspace}%
 %
  \Crefname{equation}{Gleichung}{Gleichungen}%
  \Crefname{figure}{Abbildung}{Abbildungen}%
  \Crefname{subfigure}{Abbildung}{Abbildungen}%
  \Crefname{table}{Tabelle}{Tabellen}%
  \Crefname{subtable}{Tabelle}{Tabellen}%
  \Crefname{page}{Seite}{Seiten}%
  \Crefname{part}{Teil}{Teile}%
  \Crefname{chapter}{Kapitel}{Kapitel}%
  \Crefname{section}{Abschnitt}{Abschnitte}%
  \Crefname{subsection}{Abschnitt}{Abschnitte}%
  \Crefname{subsubsection}{Abschnitt}{Abschnitte}%
  \Crefname{appendix}{Anhang}{Anh\"ange}%
  \Crefname{subappendix}{Anhang}{Anh\"ange}%
  \Crefname{subsubappendix}{Anhang}{Anh\"ange}%
  \Crefname{subsubsubappendix}{Anhang}{Anh\"ange}%
  \Crefname{enumi}{Punkt}{Punkte}%
  \Crefname{enumii}{Punkt}{Punkte}%
  \Crefname{enumiii}{Punkt}{Punkte}%
  \Crefname{enumiv}{Punkt}{Punkte}%
  \Crefname{enumv}{Punkt}{Punkte}%
  \Crefname{footnote}{Fu\ss note}{Fu\ss noten}%
  \Crefname{theorem}{Theorem}{Theoreme}%
  \Crefname{lemma}{Lemma}{Lemmata}%
  \Crefname{corollary}{Korollar}{Korollare}%
  \Crefname{proposition}{Satz}{S\"atze}%
  \Crefname{definition}{Definition}{Definitionen}%
  \Crefname{result}{Ergebnis}{Ergebnisse}%
  \Crefname{example}{Beispiel}{Beispiele}%
  \Crefname{remark}{Bemerkung}{Bemerkungen}%
  \Crefname{note}{Anmerkung}{Anmerkungen}%
  \Crefname{algorithm}{Algorithmus}{Algorithmen}%
  \Crefname{listing}{Listing}{Listings}%
  \Crefname{line}{Zeile}{Zeilen}%
 %
  \if@cref@abbrev%
    \crefname{figure}{Abb.}{Abb.}%
    \crefname{subfigure}{Abb.}{Abb.}%
  \else%
    \crefname{figure}{Abbildung}{Abbildungen}%
    \crefname{subfigure}{Abbildung}{Abbildungen}%
  \fi%
  \crefname{equation}{Gleichung}{Gleichungen}%
  \crefname{table}{Tabelle}{Tabellen}%
  \crefname{subtable}{Tabelle}{Tabellen}%
  \crefname{page}{Seite}{Seiten}%
  \crefname{part}{Teil}{Teile}%
  \crefname{chapter}{Kapitel}{Kapitel}%
  \crefname{section}{Abschnitt}{Abschnitte}%
  \crefname{subsection}{Abschnitt}{Abschnitte}%
  \crefname{subsubsection}{Abschnitt}{Abschnitte}%
  \crefname{appendix}{Anhang}{Anh\"ange}%
  \crefname{subappendix}{Anhang}{Anh\"ange}%
  \crefname{subsubappendix}{Anhang}{Anh\"ange}%
  \crefname{subsubsubappendix}{Anhang}{Anh\"ange}%
  \crefname{enumi}{Punkt}{Punkte}%
  \crefname{enumii}{Punkt}{Punkte}%
  \crefname{enumiii}{Punkt}{Punkte}%
  \crefname{enumiv}{Punkt}{Punkte}%
  \crefname{enumv}{Punkt}{Punkte}%
  \crefname{footnote}{Fu\ss note}{Fu\ss noten}%
  \crefname{theorem}{Theorem}{Theoreme}%
  \crefname{lemma}{Lemma}{Lemmata}%
  \crefname{corollary}{Korollar}{Korollare}%
  \crefname{proposition}{Satz}{S\"atze}%
  \crefname{definition}{Definition}{Definitionen}%
  \crefname{result}{Ergebnis}{Ergebnisse}%
  \crefname{example}{Beispiel}{Beispiele}%
  \crefname{remark}{Bemerkung}{Bemerkungen}%
  \crefname{note}{Anmerkung}{Anmerkungen}%
  \crefname{algorithm}{Algorithmus}{Algorithmen}%
  \crefname{listing}{Listing}{Listings}%
  \crefname{line}{Zeile}{Zeilen}}% end \cref@addlangagedefs
%    \end{macrocode}
%
%
% \begin{macro}{ngerman}
%   It so happens that none of the cross-reference names differ in the
%   ``Neuerechtschreibung'', so we make \option{ngerman} execute
%   \option{german}.
% \end{macro}
%    \begin{macrocode}
\DeclareOption{ngerman}{%
  \ExecuteOptions{german}%
  \def\cref@language{ngerman}}%
%    \end{macrocode}
% However, we still need to add the definitions to \cmd{\extrasngerman}
% (note the ``n'') so that \cmd{\selectlanguage} etc.\ will work.
%    \begin{macrocode}
\cref@addlanguagedefs{ngerman}{%
  \PackageInfo{cleveref}{loaded `ngerman' language definitions}%
  \renewcommand{\crefrangeconjunction}{ bis\nobreakspace}%
  \renewcommand\crefrangepreconjunction{}%
  \renewcommand\crefrangepostconjunction{}%
  \renewcommand{\crefpairconjunction}{ und\nobreakspace}%
  \renewcommand{\crefmiddleconjunction}{, }%
  \renewcommand{\creflastconjunction}{ und\nobreakspace}%
  \renewcommand{\crefpairgroupconjunction}{ und\nobreakspace}%
  \renewcommand{\crefmiddlegroupconjunction}{, }%
  \renewcommand{\creflastgroupconjunction}{ und\nobreakspace}%
 %
  \Crefname{equation}{Gleichung}{Gleichungen}%
  \Crefname{figure}{Abbildung}{Abbildungen}%
  \Crefname{subfigure}{Abbildung}{Abbildungen}%
  \Crefname{table}{Tabelle}{Tabellen}%
  \Crefname{subtable}{Tabelle}{Tabellen}%
  \Crefname{page}{Seite}{Seiten}%
  \Crefname{part}{Teil}{Teile}%
  \Crefname{chapter}{Kapitel}{Kapitel}%
  \Crefname{section}{Abschnitt}{Abschnitte}%
  \Crefname{subsection}{Abschnitt}{Abschnitte}%
  \Crefname{subsubsection}{Abschnitt}{Abschnitte}%
  \Crefname{appendix}{Anhang}{Anh\"ange}%
  \Crefname{subappendix}{Anhang}{Anh\"ange}%
  \Crefname{subsubappendix}{Anhang}{Anh\"ange}%
  \Crefname{subsubsubappendix}{Anhang}{Anh\"ange}%
  \Crefname{enumi}{Punkt}{Punkte}%
  \Crefname{enumii}{Punkt}{Punkte}%
  \Crefname{enumiii}{Punkt}{Punkte}%
  \Crefname{enumiv}{Punkt}{Punkte}%
  \Crefname{enumv}{Punkt}{Punkte}%
  \Crefname{footnote}{Fu\ss note}{Fu\ss noten}%
  \Crefname{theorem}{Theorem}{Theoreme}%
  \Crefname{lemma}{Lemma}{Lemmata}%
  \Crefname{corollary}{Korollar}{Korollare}%
  \Crefname{proposition}{Satz}{S\"atze}%
  \Crefname{definition}{Definition}{Definitionen}%
  \Crefname{result}{Ergebnis}{Ergebnisse}%
  \Crefname{example}{Beispiel}{Beispiele}%
  \Crefname{remark}{Bemerkung}{Bemerkungen}%
  \Crefname{note}{Anmerkung}{Anmerkungen}%
  \Crefname{algorithm}{Algorithmus}{Algorithmen}%
  \Crefname{listing}{Listing}{Listings}%
  \Crefname{line}{Zeile}{Zeilen}%
 %
  \if@cref@abbrev%
    \crefname{figure}{Abb.}{Abb.}%
    \crefname{subfigure}{Abb.}{Abb.}%
  \else%
    \crefname{figure}{Abbildung}{Abbildungen}%
    \crefname{subfigure}{Abbildung}{Abbildungen}%
  \fi%
  \crefname{equation}{Gleichung}{Gleichungen}%
  \crefname{table}{Tabelle}{Tabellen}%
  \crefname{subtable}{Tabelle}{Tabellen}%
  \crefname{page}{Seite}{Seiten}%
  \crefname{part}{Teil}{Teile}%
  \crefname{chapter}{Kapitel}{Kapitel}%
  \crefname{section}{Abschnitt}{Abschnitte}%
  \crefname{subsection}{Abschnitt}{Abschnitte}%
  \crefname{subsubsection}{Abschnitt}{Abschnitte}%
  \crefname{appendix}{Anhang}{Anh\"ange}%
  \crefname{subappendix}{Anhang}{Anh\"ange}%
  \crefname{subsubappendix}{Anhang}{Anh\"ange}%
  \crefname{subsubsubappendix}{Anhang}{Anh\"ange}%
  \crefname{enumi}{Punkt}{Punkte}%
  \crefname{enumii}{Punkt}{Punkte}%
  \crefname{enumiii}{Punkt}{Punkte}%
  \crefname{enumiv}{Punkt}{Punkte}%
  \crefname{enumv}{Punkt}{Punkte}%
  \crefname{footnote}{Fu\ss note}{Fu\ss noten}%
  \crefname{theorem}{Theorem}{Theoreme}%
  \crefname{lemma}{Lemma}{Lemmata}%
  \crefname{corollary}{Korollar}{Korollare}%
  \crefname{proposition}{Satz}{S\"atze}%
  \crefname{definition}{Definition}{Definitionen}%
  \crefname{result}{Ergebnis}{Ergebnisse}%
  \crefname{example}{Beispiel}{Beispiele}%
  \crefname{remark}{Bemerkung}{Bemerkungen}%
  \crefname{note}{Anmerkung}{Anmerkungen}%
  \crefname{algorithm}{Algorithmus}{Algorithmen}%
  \crefname{listing}{Listing}{Listings}%
  \crefname{line}{Zeile}{Zeilen}}% end \cref@addlangagedefs
%    \end{macrocode}
%
%
%  \subsubsection{Dutch}
% \begin{macro}{dutch}
%   Dutch translations kindly contributed by Philip H\"olzenspies and Tom Marcoen.
% \end{macro}
%
% Set up the definitions used at the beginning of the document to define
% the formats created by the document preamble.
%    \begin{macrocode}
\DeclareOption{dutch}{%
  \AtBeginDocument{%
    \def\crefrangeconjunction@preamble{ tot\nobreakspace}%
    \def\crefrangepreconjunction@preamble{}%
    \def\crefrangepostconjunction@preamble{}%
    \def\crefpairconjunction@preamble{ en\nobreakspace}%
    \def\crefmiddleconjunction@preamble{, }%
    \def\creflastconjunction@preamble{ en\nobreakspace}%
%    \end{macrocode}
% As in German, we don't want the extra comma before ``en'' that would be
% added by the default fall-back definitions in terms of the above
% conjunctions, so we define \cmd{\crefpairgroupconjunction} explicitly.
% In fact, we have to define the other group conjunctions explicitly too
% here, in case any other language option defines them explicitly and we
% need to override them.
%    \begin{macrocode}
    \def\crefpairgroupconjunction@preamble{ en\nobreakspace}%
    \def\crefmiddlegroupconjunction@preamble{, }%
    \def\creflastgroupconjunction@preamble{ en\nobreakspace}%
 %
    \Crefname@preamble{equation}{Vergel\ij{}king}{Vergel\ij{}kingen}%
    \Crefname@preamble{figure}{Figuur}{Figuren}%
    \Crefname@preamble{table}{Tabel}{Tabellen}%
    \Crefname@preamble{page}{Pagina}{Pagina's}%
    \Crefname@preamble{part}{Deel}{Delen}%
    \Crefname@preamble{chapter}{Hoofdstuk}{Hoofdstukken}%
    \Crefname@preamble{section}{Paragraaf}{Paragrafen}%
    \Crefname@preamble{appendix}{Appendix}{Appendices}%
    \Crefname@preamble{enumi}{Punt}{Punten}%
    \Crefname@preamble{footnote}{Voetnoot}{Voetnoten}%
    \Crefname@preamble{lemma}{Lemma}{Lemma's}%
    \Crefname@preamble{corollary}{Corollarium}{Corollaria}%
    \Crefname@preamble{proposition}{Bewering}{Beweringen}%
    \Crefname@preamble{definition}{Definitie}{Definities}%
    \Crefname@preamble{result}{Resultaat}{Resultaten}%
    \Crefname@preamble{example}{Voorbeeld}{Voorbeelden}%
    \Crefname@preamble{remark}{Opmerking}{Opmerkingen}%
    \Crefname@preamble{note}{Aantekening}{Aantekeningen}%
    \Crefname@preamble{algorithm}{Algoritme}{Algoritmen}%
    \Crefname@preamble{listing}{Listing}{Listings}%
    \Crefname@preamble{line}{Lijn}{Lijnen}%
 %
    \if@cref@capitalise%  capitalise set
      \if@cref@abbrev%
        \crefname@preamble{equation}{Verg.}{Verg.'s}%
        \crefname@preamble{figure}{Fig.}{Fig.'s}%
      \else%
        \crefname@preamble{equation}{Vergel\ij{}king}{Vergel\ij{}kingen}%
        \crefname@preamble{figure}{Figuur}{Figuren}%
      \fi%
      \crefname@preamble{page}{Pagina}{Pagina's}%
      \crefname@preamble{table}{Tabel}{Tabellen}%
      \crefname@preamble{part}{Deel}{Delen}%
      \crefname@preamble{chapter}{Hoofdstuk}{Hoofdstukken}%
      \crefname@preamble{section}{Paragraaf}{Paragrafen}%
      \crefname@preamble{appendix}{Appendix}{Appendices}%
      \crefname@preamble{enumi}{Punt}{Punten}%
      \crefname@preamble{footnote}{Voetnoot}{Voetnoten}%
      \crefname@preamble{theorem}{Theorema}{Theorema's}%
      \crefname@preamble{lemma}{Lemma}{Lemma's}%
      \crefname@preamble{corollary}{Corollarium}{Corollaria}%
      \crefname@preamble{proposition}{Bewering}{Beweringen}%
      \crefname@preamble{definition}{Definitie}{Definities}%
      \crefname@preamble{result}{Resultaat}{Resultaten}%
      \crefname@preamble{example}{Voorbeeld}{Voorbeelden}%
      \crefname@preamble{remark}{Opmerking}{Opmerkingen}%
      \crefname@preamble{note}{Aantekening}{Aantekeningen}%
      \crefname@preamble{algorithm}{Algoritme}{Algoritmen}%
      \crefname@preamble{listing}{Listing}{Listings}%
      \crefname@preamble{line}{Lijn}{Lijnen}%
 %
    \else%  capitalise unset
      \if@cref@abbrev%
        \crefname@preamble{equation}{verg.}{verg.'s}%
        \crefname@preamble{figure}{fig.}{fig.'s}%
      \else%
        \crefname@preamble{equation}{vergel\ij{}king}{vergel\ij{}kingen}%
        \crefname@preamble{figure}{figuur}{figuren}%
      \fi%
      \crefname@preamble{page}{pagina}{pagina's}%
      \crefname@preamble{table}{tabel}{tabellen}%
      \crefname@preamble{part}{deel}{delen}%
      \crefname@preamble{chapter}{hoofdstuk}{hoofdstukken}%
      \crefname@preamble{section}{paragraaf}{paragrafen}%
      \crefname@preamble{appendix}{appendix}{appendices}%
      \crefname@preamble{enumi}{punt}{punten}%
      \crefname@preamble{footnote}{voetnoot}{voetnoten}%
      \crefname@preamble{theorem}{theorema}{theorema's}%
      \crefname@preamble{lemma}{lemma}{lemma's}%
      \crefname@preamble{corollary}{corollarium}{corollaria}%
      \crefname@preamble{proposition}{bewering}{beweringen}%
      \crefname@preamble{definition}{definitie}{definities}%
      \crefname@preamble{result}{resultaat}{resultaten}%
      \crefname@preamble{example}{voorbeeld}{voorbeelden}%
      \crefname@preamble{remark}{opmerking}{opmerkingen}%
      \crefname@preamble{note}{aantekening}{aantekeningen}%
      \crefname@preamble{algorithm}{algoritme}{algoritmen}%
      \crefname@preamble{listing}{listing}{listings}%
      \crefname@preamble{line}{lijn}{lijnen}%
    \fi%
    \def\cref@language{dutch}%
  }}% end \DeclareOption and \AtBeginDocument
%    \end{macrocode}
%
% If using \package{babel} and the corresponding option is set, or if
% using \package{polyglossia} and the language has been loaded, add
% format definition commands to \cmd{\extras}\meta{language} or
% \cmd{\captions}\meta{language} so that language switching commands will
% change the cross-reference formats appropriately.
%    \begin{macrocode}
\cref@addlanguagedefs{dutch}{%
  \PackageInfo{cleveref}{loaded `dutch' language definitions}%
  \renewcommand{\crefrangeconjunction}{ tot\nobreakspace}%
  \renewcommand\crefrangepreconjunction{}%
  \renewcommand\crefrangepostconjunction{}%
  \renewcommand{\crefpairconjunction}{ en\nobreakspace}%
  \renewcommand{\crefmiddleconjunction}{, }%
  \renewcommand{\creflastconjunction}{ en\nobreakspace}%
  \renewcommand{\crefpairgroupconjunction}{ en\nobreakspace}%
  \renewcommand{\crefmiddlegroupconjunction}{, }%
  \renewcommand{\creflastgroupconjunction}{ en\nobreakspace}%
 %
  \Crefname{equation}{Vergel\ij{}king}{Vergel\ij{}kingen}%
  \Crefname{figure}{Figuur}{Figuren}%
  \Crefname{subfigure}{Figuur}{Figuren}%
  \Crefname{table}{Tabel}{Tabellen}%
  \Crefname{subtable}{Tabel}{Tabellen}%
  \Crefname{page}{Pagina}{Pagina's}%
  \Crefname{part}{Deel}{Delen}%
  \Crefname{chapter}{Hoofdstuk}{Hoofdstuken}%
  \Crefname{section}{Paragraaf}{Paragrafen}%
  \Crefname{subsection}{Paragraaf}{Paragrafen}%
  \Crefname{subsubsection}{Paragraaf}{Paragrafen}%
  \Crefname{appendix}{Appendix}{Appendices}%
  \Crefname{subappendix}{Appendix}{Appendices}%
  \Crefname{subsubappendix}{Appendix}{Appendices}%
  \Crefname{subsubsubappendix}{Appendix}{Appendices}%
  \Crefname{enumi}{Punt}{Punten}%
  \Crefname{enumii}{Punt}{Punten}%
  \Crefname{enumiii}{Punt}{Punten}%
  \Crefname{enumiv}{Punt}{Punten}%
  \Crefname{enumv}{Punt}{Punten}%
  \Crefname{footnote}{Voetnote}{Voetnoten}%
  \Crefname{theorem}{Theorema}{Theorema's}%
  \Crefname{lemma}{Lemma}{Lemma's}%
  \Crefname{corollary}{Corollarium}{Corollaria}%
  \Crefname{proposition}{Bewering}{Beweringen}%
  \Crefname{definition}{Definitie}{Definities}%
  \Crefname{result}{Resultaat}{Resultaten}%
  \Crefname{example}{Voorbeeld}{Voorbeelden}%
  \Crefname{remark}{Opmerking}{Opmerkingen}%
  \Crefname{note}{Aantekening}{Aantekeningen}%
  \Crefname{algorithm}{Algoritme}{Algoritmen}%
  \Crefname{listing}{Listing}{Listings}%
  \Crefname{line}{Lijn}{Lijnen}%
 %
  \if@cref@capitalise%  capitalise set
    \if@cref@abbrev%
      \crefname{equation}{Verg.}{Verg's.}%
      \crefname{figure}{Fig.}{Fig's.}%
      \crefname{subfigure}{Fig.}{Fig's.}%
    \else%
      \crefname{equation}{Vergel\ij{}king}{Vergel\ij{}kingen}%
      \crefname{figure}{Figuur}{Figuren}%
      \crefname{subfigure}{Figuur}{Figuren}%
    \fi%
    \crefname{table}{Tabel}{Tabellen}%
    \crefname{subtable}{Tabel}{Tabellen}%
    \crefname{page}{Pagina}{Pagina's}%
    \crefname{part}{Deel}{Delen}%
    \crefname{chapter}{Hoofdstuk}{Hoofdstukken}%
    \crefname{section}{Paragraaf}{Paragrafen}%
    \crefname{appendix}{Appendix}{Appendices}%
    \crefname{enumi}{Punt}{Punten}%
    \crefname{footnote}{Voetnote}{Voetnoten}%
    \crefname{theorem}{Theorema}{Theorema's}%
    \crefname{lemma}{Lemma}{Lemma's}%
    \crefname{corollary}{Corollarium}{Corollaria}%
    \crefname{proposition}{Bewering}{Beweringen}%
    \crefname{definition}{Definitie}{Definities}%
    \crefname{result}{Resultaat}{Resultaten}%
    \crefname{example}{Voorbeeld}{Voorbeelden}%
    \crefname{remark}{Opmerking}{Opmerkingen}%
    \crefname{note}{Aantekening}{Aantekeningen}%
    \crefname{algorithm}{Algoritme}{Algoritmen}%
    \crefname{listing}{Listing}{Listings}%
    \crefname{line}{Lijn}{Lijnen}%
 %
  \else%  capitalise unset
    \if@cref@abbrev%
      \crefname{equation}{verg.}{verg's.}%
      \crefname{figure}{fig.}{fig's.}%
      \crefname{subfigure}{fig.}{fig's.}%
    \else%
      \crefname{equation}{vergel\ij{}king}{vergel\ij{}kingen}%
      \crefname{figure}{figuur}{figuren}%
      \crefname{subfigure}{figuur}{figuren}%
    \fi%
    \crefname{table}{tabel}{tabellen}%
    \crefname{subtable}{tabel}{tabellen}%
    \crefname{page}{pagina}{pagina's}%
    \crefname{part}{deel}{delen}%
    \crefname{chapter}{hoofdstuk}{hoofdstukken}%
    \crefname{section}{paragraaf}{paragrafen}%
    \crefname{appendix}{appendix}{appendices}%
    \crefname{enumi}{punt}{punten}%
    \crefname{footnote}{voetnote}{voetnoten}%
    \crefname{theorem}{theorema}{theorema's}%
    \crefname{lemma}{lemma}{lemma's}%
    \crefname{corollary}{corollarium}{corollaria}%
    \crefname{proposition}{bewering}{beweringen}%
    \crefname{definition}{definitie}{definities}%
    \crefname{result}{resultaat}{resultaten}%
    \crefname{example}{voorbeeld}{voorbeelden}%
    \crefname{remark}{opmerking}{opmerkingen}%
    \crefname{note}{aantekening}{aantekeningen}%
    \crefname{algorithm}{algoritme}{algoritmen}%
    \crefname{listing}{listing}{listings}%
    \crefname{line}{lijn}{lijnen}%
  \fi}% end \cref@addlanguagedefs
%    \end{macrocode}
%
%
%  \subsubsection{French}
% \begin{macro}{french}
%   French translations attempted by the package author (please report
%   any corrections that might be needed!).
% \end{macro}
%
% Set up the definitions used at the beginning of the document to define
% the formats created by the document preamble.
%    \begin{macrocode}
\DeclareOption{french}{%
  \AtBeginDocument{%
    \def\crefrangeconjunction@preamble{ \`a\nobreakspace}%
    \def\crefrangepreconjunction@preamble{}%
    \def\crefrangepostconjunction@preamble{}%
    \def\crefpairconjunction@preamble{ et\nobreakspace}%
    \def\crefmiddleconjunction@preamble{, }%
    \def\creflastconjunction@preamble{ et\nobreakspace}%
%    \end{macrocode}
% Erring on the side of caution, I've left off the extra comma before
% ``et'' between groups, pending more knowledgeable input on punctuation
% rules from a native French speaker.
%    \begin{macrocode}
    \def\crefpairgroupconjunction@preamble{ et\nobreakspace}%
    \def\crefmiddlegroupconjunction@preamble{, }%
    \def\creflastgroupconjunction@preamble{, et\nobreakspace}%
 %
    \Crefname@preamble{equation}{{\'E}quation}{{\'E}quations}%
    \Crefname@preamble{figure}{Figure}{Figures}%
    \Crefname@preamble{table}{Tableau}{Tableaux}%
    \Crefname@preamble{page}{Page}{Pages}%
    \Crefname@preamble{part}{Partie}{Parties}%
    \Crefname@preamble{chapter}{Chapitre}{Chapitres}%
    \Crefname@preamble{section}{Section}{Sections}%
    \Crefname@preamble{appendix}{Annexe}{Annexes}%
    \Crefname@preamble{enumi}{Point}{Points}%
    \Crefname@preamble{footnote}{Note}{Notes}%
    \Crefname@preamble{theorem}{Th\'eor\`eme}{Th\'eor\`emes}%
    \Crefname@preamble{lemma}{Lemme}{Lemmes}%
    \Crefname@preamble{corollary}{Corollaire}{Corollaires}%
    \Crefname@preamble{proposition}{Proposition}{Propositions}%
    \Crefname@preamble{definition}{D\'efinition}{D\'efinitions}%
    \Crefname@preamble{result}{R\'esultat}{R\'esultats}%
    \Crefname@preamble{example}{Exemple}{Exemples}%
    \Crefname@preamble{remark}{Remarque}{Remarques}%
    \Crefname@preamble{algorithm}{Algorithme}{Algorithmes}%
    \Crefname@preamble{listing}{Liste}{Listes}%
    \Crefname@preamble{line}{Ligne}{Lignes}%
 %
    \if@cref@capitalise%  capitalise set
      \crefname@preamble{equation}{{\'E}quation}{{\'E}quations}%
      \crefname@preamble{figure}{Figure}{Figures}%
      \crefname@preamble{table}{Tableau}{Tableaux}%
      \crefname@preamble{page}{Page}{Pages}%
      \crefname@preamble{part}{Partie}{Parties}%
      \crefname@preamble{chapter}{Chapitre}{Chapitres}%
      \crefname@preamble{section}{Section}{Sections}%
      \crefname@preamble{appendix}{Annexe}{Annexes}%
      \crefname@preamble{enumi}{Point}{Points}%
      \crefname@preamble{footnote}{Note}{Notes}%
      \crefname@preamble{theorem}{Th\'eor\`eme}{Th\'eor\`emes}%
      \crefname@preamble{lemma}{Lemme}{Lemmes}%
      \crefname@preamble{corollary}{Corollaire}{Corollaires}%
      \crefname@preamble{proposition}{Proposition}{Propositions}%
      \crefname@preamble{definition}{D\'efinition}{D\'efinitions}%
      \crefname@preamble{result}{R\'esultat}{R\'esultats}%
      \crefname@preamble{example}{Exemple}{Exemples}%
      \crefname@preamble{remark}{Remarque}{Remarques}%
      \crefname@preamble{note}{Commentaire}{Commentaires}%
      \crefname@preamble{algorithm}{Algorithme}{Algorithmes}%
      \crefname@preamble{listing}{Liste}{Listes}%
      \crefname@preamble{line}{Ligne}{Lignes}%
 %
    \else%  capitalise unset
      \crefname@preamble{equation}{{\'e}quation}{{\'e}quations}%
      \crefname@preamble{figure}{figure}{figures}%
      \crefname@preamble{table}{tableau}{tableaux}%
      \crefname@preamble{page}{page}{pages}%
      \crefname@preamble{part}{partie}{parties}%
      \crefname@preamble{chapter}{chapitre}{chapitres}%
      \crefname@preamble{section}{section}{sections}%
      \crefname@preamble{appendix}{annexe}{annexes}%
      \crefname@preamble{enumi}{point}{points}%
      \crefname@preamble{footnote}{note}{notes}%
      \crefname@preamble{theorem}{th\'eor\`eme}{th\'eor\`emes}%
      \crefname@preamble{lemma}{lemme}{lemmes}%
      \crefname@preamble{corollary}{corollaire}{corollaires}%
      \crefname@preamble{proposition}{proposition}{propositions}%
      \crefname@preamble{definition}{d\'efinition}{d\'efinitions}%
      \crefname@preamble{result}{r\'esultat}{r\'esultats}%
      \crefname@preamble{example}{exemple}{exemples}%
      \crefname@preamble{remark}{remarque}{remarques}%
      \crefname@preamble{note}{commentaire}{commentaires}%
      \crefname@preamble{algorithm}{algorithme}{algorithmes}%
      \crefname@preamble{listing}{liste}{listes}%
      \crefname@preamble{line}{ligne}{lignes}%
    \fi%
    \def\cref@language{french}%
  }}% end \DeclareOption and \AtBeginDocument
%    \end{macrocode}
%
% If using \package{babel} and the corresponding option is set, or if
% using \package{polyglossia} and the language has been loaded, add
% format definition commands to \cmd{\extras}\meta{language} or
% \cmd{\captions}\meta{language} so that language switching commands will
% change the cross-reference formats appropriately.
%    \begin{macrocode}
\cref@addlanguagedefs{french}{%
  \PackageInfo{cleveref}{loaded `french' language definitions}%
  \renewcommand{\crefrangeconjunction}{ \`a\nobreakspace}%
  \renewcommand\crefrangepreconjunction{}%
  \renewcommand\crefrangepostconjunction{}%
  \renewcommand{\crefpairconjunction}{ et\nobreakspace}%
  \renewcommand{\crefmiddleconjunction}{, }%
  \renewcommand{\creflastconjunction}{ et\nobreakspace}%
  \renewcommand{\crefpairgroupconjunction}{ et\nobreakspace}%
  \renewcommand{\crefmiddlegroupconjunction}{, }%
  \renewcommand{\creflastgroupconjunction}{ et\nobreakspace}%
 %
  \Crefname{equation}{{\'E}quation}{{\'E}quations}%
  \Crefname{figure}{Figure}{Figures}%
  \Crefname{subfigure}{Figure}{Figures}%
  \Crefname{table}{Tableau}{Tableaux}%
  \Crefname{subtable}{Tableau}{Tableaux}%
  \Crefname{page}{Page}{Pages}%
  \Crefname{part}{Partie}{Parties}%
  \Crefname{chapter}{Chapitre}{Chapitres}%
  \Crefname{section}{Section}{Sections}%
  \Crefname{subsection}{Section}{Sections}%
  \Crefname{subsubsection}{Section}{Sections}%
  \Crefname{appendix}{Annexe}{Annexes}%
  \Crefname{subappendix}{Annexe}{Annexes}%
  \Crefname{subsubappendix}{Annexe}{Annexes}%
  \Crefname{subsubsubappendix}{Annexe}{Annexes}%
  \Crefname{enumi}{Point}{Points}%
  \Crefname{enumii}{Point}{Points}%
  \Crefname{enumiii}{Point}{Points}%
  \Crefname{enumiv}{Point}{Points}%
  \Crefname{enumv}{Point}{Points}%
  \Crefname{footnote}{Note}{Notes}%
  \Crefname{theorem}{Th\'eor\`eme}{Th\'eor\`emes}%
  \Crefname{lemma}{Lemme}{Lemmes}%
  \Crefname{corollary}{Corollaire}{Corollaires}%
  \Crefname{proposition}{Proposition}{Propositions}%
  \Crefname{definition}{D\'efinition}{D\'efinitions}%
  \Crefname{result}{R\'esultat}{R\'esultats}%
  \Crefname{example}{Exemple}{Exemples}%
  \Crefname{remark}{Remarque}{Remarques}%
  \Crefname{note}{Commentaire}{Commentaires}%
  \Crefname{algorithm}{Algorithme}{Algorithmes}%
  \Crefname{listing}{Liste}{Listes}%
  \Crefname{line}{Ligne}{Lignes}%
 %
  \if@cref@capitalise%  capitalise set
    \crefname{equation}{{\'E}quation}{{\'E}quations}%
    \crefname{figure}{Figure}{Figures}%
    \crefname{subfigure}{Figure}{Figures}%
    \crefname{table}{Tableau}{Tableaux}%
    \crefname{subtable}{Tableau}{Tableaux}%
    \crefname{page}{Page}{Pages}%
    \crefname{part}{Partie}{Parties}%
    \crefname{chapter}{Chapitre}{Chapitres}%
    \crefname{section}{Section}{Sections}%
    \crefname{subsection}{Section}{Sections}%
    \crefname{subsubsection}{Section}{Sections}%
    \crefname{appendix}{Annexe}{Annexes}%
    \crefname{subappendix}{Annexe}{Annexes}%
    \crefname{subsubappendix}{Annexe}{Annexes}%
    \crefname{subsubsubappendix}{Annexe}{Annexes}%
    \crefname{enumi}{Point}{Points}%
    \crefname{enumii}{Point}{Points}%
    \crefname{enumiii}{Point}{Points}%
    \crefname{enumiv}{Point}{Points}%
    \crefname{enumv}{Point}{Points}%
    \crefname{footnote}{Note}{Notes}%
    \crefname{theorem}{Th\'eor\`eme}{Th\'eor\`emes}%
    \crefname{lemma}{Lemme}{Lemmes}%
    \crefname{corollary}{Corollaire}{Corollaires}%
    \crefname{proposition}{Proposition}{Propositions}%
    \crefname{definition}{D\'efinition}{D\'efinitions}%
    \crefname{result}{R\'esultat}{R\'esultats}%
    \crefname{example}{Exemple}{Exemples}%
    \crefname{remark}{Remarque}{Remarques}%
    \crefname{note}{Commentaire}{Commentaires}%
    \crefname{algorithm}{Algorithme}{Algorithmes}%
    \crefname{listing}{Liste}{Listes}%
    \crefname{line}{Ligne}{Lignes}%
 %
  \else%  capitalise unset
    \crefname{equation}{{\'e}quation}{{\'e}quations}%
    \crefname{figure}{figure}{figures}%
    \crefname{subfigure}{figure}{figures}%
    \crefname{table}{tableau}{tableaux}%
    \crefname{subtable}{tableau}{tableaux}%
    \crefname{page}{page}{pages}%
    \crefname{part}{partie}{parties}%
    \crefname{chapter}{chapitre}{chapitres}%
    \crefname{section}{section}{sections}%
    \crefname{subsection}{section}{sections}%
    \crefname{subsubsection}{section}{sections}%
    \crefname{appendix}{annexe}{annexes}%
    \crefname{subappendix}{annexe}{annexes}%
    \crefname{subsubappendix}{annexe}{annexes}%
    \crefname{subsubsubappendix}{annexe}{annexes}%
    \crefname{enumi}{point}{points}%
    \crefname{enumii}{point}{points}%
    \crefname{enumiii}{point}{points}%
    \crefname{enumiv}{point}{points}%
    \crefname{enumv}{point}{points}%
    \crefname{footnote}{note}{notes}%
    \crefname{theorem}{th\'eor\`eme}{th\'eor\`emes}%
    \crefname{lemma}{lemme}{lemmes}%
    \crefname{corollary}{corollaire}{corollaires}%
    \crefname{proposition}{proposition}{propositions}%
    \crefname{definition}{d\'efinition}{d\'efinitions}%
    \crefname{result}{r\'esultat}{r\'esultats}%
    \crefname{example}{exemple}{exemples}%
    \crefname{remark}{remarque}{remarques}%
    \crefname{note}{commentaire}{commentaires}%
    \crefname{algorithm}{algorithme}{algorithmes}%
    \crefname{listing}{liste}{listes}%
    \crefname{line}{ligne}{lignes}%
  \fi}% end \cref@loadlanguagedefs
%    \end{macrocode}
%
%
%  \subsubsection{Spanish}
% \begin{macro}{spanish}
%   Spanish translations generously contributed by Gonzalo Medina.
% \end{macro}
%
% Set up the definitions used at the beginning of the document to define
% the formats created by the document preamble.
%    \begin{macrocode}
\DeclareOption{spanish}{%
  \AtBeginDocument{%
    \def\crefrangeconjunction@preamble{ a\nobreakspace}%
    \def\crefrangepreconjunction@preamble{}%
    \def\crefrangepostconjunction@preamble{}%
    \def\crefpairconjunction@preamble{ y\nobreakspace}%
    \def\crefmiddleconjunction@preamble{, }%
    \def\creflastconjunction@preamble{ y\nobreakspace}%
    \def\crefpairgroupconjunction@preamble{ y\nobreakspace}%
    \def\crefmiddlegroupconjunction@preamble{, }%
    \def\creflastgroupconjunction@preamble{ y\nobreakspace}%
 %
    \Crefname@preamble{equation}{Ecuaci\'on}{Ecuaciones}%
    \Crefname@preamble{figure}{Figura}{Figuras}%
    \Crefname@preamble{table}{Cuadro}{Cuadros}%
    \Crefname@preamble{page}{P\'agina}{P\'aginas}%
    \Crefname@preamble{part}{Parte}{Partes}%
    \Crefname@preamble{chapter}{Cap\'itulo}{Cap\'itulos}%
    \Crefname@preamble{section}{Apartado}{Apartados}%
    \Crefname@preamble{appendix}{Ap\'endice}{Ap\'endices}%
    \Crefname@preamble{enumi}{Punto}{Puntos}%
    \Crefname@preamble{footnote}{Nota}{Notas}%
    \Crefname@preamble{theorem}{Teorema}{Teoremas}%
    \Crefname@preamble{lemma}{Lema}{Lemas}%
    \Crefname@preamble{corollary}{Corolario}{Corolarios}%
    \Crefname@preamble{proposition}{Proposici\'on}{Proposiciones}%
    \Crefname@preamble{definition}{Definici\'on}{Definiciones}%
    \Crefname@preamble{result}{Resultado}{Resultados}%
    \Crefname@preamble{example}{Ejemplo}{Ejemplos}%
    \Crefname@preamble{remark}{Observaci\'on}{Observaciones}%
    \Crefname@preamble{note}{Nota}{Notas}%
    \Crefname@preamble{algorithm}{Algoritmo}{Algoritmos}%
    \Crefname@preamble{listing}{Listado}{Listados}%
    \Crefname@preamble{line}{L\'inea}{L\'ineas}%
 %
    \if@cref@capitalise%  capitalise set
      \crefname@preamble{equation}{Ecuaci\'on}{Ecuaciones}%
      \crefname@preamble{figure}{Figura}{Figuras}%
      \crefname@preamble{table}{Cuadro}{Cuadros}%
      \crefname@preamble{page}{P\'agina}{P\'aginas}%
      \crefname@preamble{part}{Parte}{Partes}%
      \crefname@preamble{chapter}{Cap\'itulo}{Cap\'itulos}%
      \crefname@preamble{section}{Apartado}{Apartados}%
      \crefname@preamble{appendix}{Ap\'endice}{Ap\'endices}%
      \crefname@preamble{enumi}{Punto}{Puntos}%
      \crefname@preamble{footnote}{Nota}{Notas}%
      \crefname@preamble{theorem}{Teorema}{Teoremas}%
      \crefname@preamble{lemma}{Lema}{Lemas}%
      \crefname@preamble{corollary}{Corolario}{Corolarios}%
      \crefname@preamble{proposition}{Proposici\'on}{Proposiciones}%
      \crefname@preamble{definition}{Definici\'on}{Definiciones}%
      \crefname@preamble{result}{Resultado}{Resultados}%
      \crefname@preamble{example}{Ejemplo}{Ejemplos}%
      \crefname@preamble{remark}{Observaci\'on}{Observaciones}%
      \crefname@preamble{note}{Nota}{Notas}%
      \crefname@preamble{algorithm}{Algoritmo}{Algoritmos}%
      \crefname@preamble{listing}{Listado}{Listados}%
      \crefname@preamble{line}{L\'inea}{L\'ineas}%
 %
    \else%  capitalise unset
      \crefname@preamble{equation}{ecuaci\'on}{ecuaciones}%
      \crefname@preamble{figure}{figura}{figuras}%
      \crefname@preamble{table}{cuadro}{cuadros}%
      \crefname@preamble{page}{p\'agina}{p\'aginas}%
      \crefname@preamble{part}{parte}{partes}%
      \crefname@preamble{chapter}{cap\'itulo}{cap\'itulos}%
      \crefname@preamble{section}{apartado}{apartados}%
      \crefname@preamble{appendix}{ap\'endice}{ap\'endices}%
      \crefname@preamble{enumi}{punto}{puntos}%
      \crefname@preamble{footnote}{nota}{notas}%
      \crefname@preamble{theorem}{teorema}{teoremas}%
      \crefname@preamble{lemma}{lema}{lemas}%
      \crefname@preamble{corollary}{corolario}{corolarios}%
      \crefname@preamble{proposition}{proposici\'on}{proposiciones}%
      \crefname@preamble{definition}{definici\'on}{definiciones}%
      \crefname@preamble{result}{resultado}{resultados}%
      \crefname@preamble{example}{ejemplo}{ejemplos}%
      \crefname@preamble{remark}{observaci\'on}{observaciones}%
      \crefname@preamble{note}{nota}{notas}%
      \crefname@preamble{algorithm}{algoritmo}{algoritmos}%
      \crefname@preamble{listing}{listado}{listados}%
      \crefname@preamble{line}{l\'inea}{l\'ineas}%
    \fi%
    \def\cref@language{spanish}%
  }}% end \DeclareOption and \AtBeginDocument
%    \end{macrocode}
%
% If using \package{babel} and the corresponding option is set, or if
% using \package{polyglossia} and the language has been loaded, add
% format definition commands to \cmd{\extras}\meta{language} or
% \cmd{\captions}\meta{language} so that language switching commands will
% change the cross-reference formats appropriately.
%    \begin{macrocode}
\cref@addlanguagedefs{spanish}{%
  \PackageInfo{cleveref}{loaded `spanish' language definitions}%
  \renewcommand{\crefrangeconjunction}{ a\nobreakspace}%
  \renewcommand{\crefrangepreconjunction}{}%
  \renewcommand{\crefrangepostconjunction}{}%
  \renewcommand{\crefpairconjunction}{ y\nobreakspace}%
  \renewcommand{\crefmiddleconjunction}{, }%
  \renewcommand{\creflastconjunction}{ y\nobreakspace}%
  \renewcommand{\crefpairgroupconjunction}{ y\nobreakspace}%
  \renewcommand{\crefmiddlegroupconjunction}{, }%
  \renewcommand{\creflastgroupconjunction}{ y\nobreakspace}%
 %
  \Crefname{equation}{Ecuaci\'on}{Ecuaciones}%
  \Crefname{figure}{Figura}{Figuras}%
  \Crefname{subfigure}{Figura}{Figuras}%
  \Crefname{table}{Cuadro}{Cuadros}%
  \Crefname{subtable}{Cuadro}{Cuadros}%
  \Crefname{page}{P\'agina}{P\'aginas}%
  \Crefname{part}{Parte}{Partes}%
  \Crefname{chapter}{Cap\'itulo}{Cap\'itulos}%
  \Crefname{section}{Apartado}{Apartados}%
  \Crefname{subsection}{Apartado}{Apartados}%
  \Crefname{subsubsection}{Apartado}{Apartados}%
  \Crefname{appendix}{Ap\'endice}{Ap\'endices}%
  \Crefname{subappendix}{Ap\'endice}{Ap\'endices}%
  \Crefname{subsubappendix}{Ap\'endice}{Ap\'endices}%
  \Crefname{subsubsubappendix}{Ap\'endice}{Ap\'endices}%
  \Crefname{enumi}{Punto}{Puntos}%
  \Crefname{enumii}{Punto}{Puntos}%
  \Crefname{enumiii}{Punto}{Puntos}%
  \Crefname{enumiv}{Punto}{Puntos}%
  \Crefname{enumv}{Punto}{Puntos}%
  \Crefname{footnote}{Nota}{Notas}%
  \Crefname{theorem}{Teorema}{Teoremas}%
  \Crefname{lemma}{Lema}{Lemas}%
  \Crefname{corollary}{Corolario}{Corolarios}%
  \Crefname{proposition}{Proposici\'on}{Proposiciones}%
  \Crefname{definition}{Definici\'on}{Definiciones}%
  \Crefname{result}{Resultado}{Resultados}%
  \Crefname{example}{Ejemplo}{Ejemplos}%
  \Crefname{remark}{Observaci\'on}{Observaci\'on}%
  \Crefname{note}{Nota}{Notas}%
  \Crefname{algorithm}{Algoritmo}{Algoritmos}%
  \Crefname{listing}{Listado}{Listados}%
  \Crefname{line}{L\'inea}{L\'ineas}%
 %
  \if@cref@capitalise%  capitalise set
    \crefname{equation}{Ecuaci\'on}{Ecuaciones}%
    \crefname{figure}{Figura}{Figuras}%
    \crefname{subfigure}{Figura}{Figuras}%
    \crefname{table}{Cuadro}{Cuadros}%
    \crefname{subtable}{Cuadro}{Cuadros}%
    \crefname{page}{P\'agina}{P\'aginas}%
    \crefname{part}{Parte}{Partes}%
    \crefname{chapter}{Cap\'itulo}{Cap\'itulos}%
    \crefname{section}{Apartado}{Apartados}%
    \crefname{subsection}{Apartado}{Apartados}%
    \crefname{subsubsection}{Apartado}{Apartados}%
    \crefname{appendix}{Ap\'endice}{Ap\'endices}%
    \crefname{subappendix}{Ap\'endice}{Ap\'endices}%
    \crefname{subsubappendix}{Ap\'endice}{Ap\'endices}%
    \crefname{subsubsubappendix}{Ap\'endice}{Ap\'endices}%
    \crefname{enumi}{Punto}{Puntos}%
    \crefname{enumii}{Punto}{Puntos}%
    \crefname{enumiii}{Punto}{Puntos}%
    \crefname{enumiv}{Punto}{Puntos}%
    \crefname{enumv}{Punto}{Puntos}%
    \crefname{footnote}{Nota}{Notas}%
    \crefname{theorem}{Teorema}{Teoremas}%
    \crefname{lemma}{Lema}{Lemas}%
    \crefname{corollary}{Corolario}{Corolarios}%
    \crefname{proposition}{Proposici\'on}{Proposiciones}%
    \crefname{definition}{Definici\'on}{Definiciones}%
    \crefname{result}{Resultado}{Resultados}%
    \crefname{example}{Ejemplo}{Ejemplos}%
    \crefname{remark}{Observaci\'on}{Observaci\'ones}%
    \crefname{note}{Nota}{Notas}%
    \crefname{algorithm}{Algoritmo}{Algoritmos}%
    \crefname{listing}{Listado}{Listados}%
    \crefname{line}{L\'inea}{L\'ineas}%
 %
  \else%  capitalise unset
    \crefname{equation}{ecuaci\'on}{ecuaciones}%
    \crefname{figure}{figura}{figuras}%
    \crefname{subfigure}{figura}{figuras}%
    \crefname{table}{cuadro}{cuadros}%
    \crefname{subtable}{cuadro}{cuadros}%
    \crefname{page}{p\'agina}{p\'aginas}%
    \crefname{part}{parte}{partes}%
    \crefname{chapter}{cap\'itulo}{cap\'itulos}%
    \crefname{section}{apartado}{apartados}%
    \crefname{subsection}{apartado}{apartados}%
    \crefname{subsubsection}{apartado}{apartados}%
    \crefname{appendix}{ap\'endice}{ap\'endices}%
    \crefname{subappendix}{ap\'endice}{ap\'endices}%
    \crefname{subsubappendix}{ap\'endice}{ap\'endices}%
    \crefname{subsubsubappendix}{ap\'endice}{ap\'endices}%
    \crefname{enumi}{punto}{puntos}%
    \crefname{enumii}{punto}{puntos}%
    \crefname{enumiii}{punto}{puntos}%
    \crefname{enumiv}{punto}{puntos}%
    \crefname{enumv}{punto}{puntos}%
    \crefname{footnote}{nota}{notas}%
    \crefname{theorem}{teorema}{teoremas}%
    \crefname{lemma}{lema}{lemas}%
    \crefname{corollary}{corolario}{corolarios}%
    \crefname{proposition}{proposici\'on}{proposiciones}%
    \crefname{definition}{definici\'on}{definiciones}%
    \crefname{result}{resultado}{resultados}%
    \crefname{example}{ejemplo}{ejemplos}%
    \crefname{remark}{observaci\'on}{observaci\'ones}%
    \crefname{note}{nota}{notas}%
    \crefname{algorithm}{algoritmo}{algoritmos}%
    \crefname{listing}{listado}{listados}%
    \crefname{line}{l\'inea}{l\'ineas}%
  \fi}% end \cref@loadlanguagedefs
%    \end{macrocode}
%
%
%  \subsubsection{Italian}
% \begin{macro}{italian}
%   Italian translations kindly contributed by Massimo Redaelli.
% \end{macro}
%
% Set up the definitions used at the beginning of the document to define
% the formats created by the document preamble.
%    \begin{macrocode}
\DeclareOption{italian}{%
  \AtBeginDocument{%
    \def\crefrangeconjunction@preamble{ a\nobreakspace}%
    \def\crefrangepreconjunction@preamble{da\nobreakspace}%
    \def\crefrangepostconjunction@preamble{}%
    \def\crefpairconjunction@preamble{ e\nobreakspace}%
    \def\crefmiddleconjunction@preamble{, }%
    \def\creflastconjunction@preamble{ e\nobreakspace}%
%    \end{macrocode}
% We have to define the group conjunctions explicitly here, rather than
% relying on fall-back definitions in terms of the above conjunctions
% (see \cref{sec:code:default_formats}), in case any other language
% option defines them explicitly and we need to override those.
%    \begin{macrocode}
    \def\crefpairgroupconjunction@preamble{ e\nobreakspace}%
    \def\crefmiddlegroupconjunction@preamble{, }%
    \def\creflastgroupconjunction@preamble{ e\nobreakspace}%
 %
    \Crefname@preamble{equation}{Equazione}{Equazioni}%
    \Crefname@preamble{figure}{Figura}{Figure}%
    \Crefname@preamble{table}{Tabella}{Tabelle}%
    \Crefname@preamble{page}{Pagina}{Pagine}%
    \Crefname@preamble{part}{Parte}{Parti}%
    \Crefname@preamble{chapter}{Capitolo}{Capitoli}%
    \Crefname@preamble{section}{Sezione}{Sezioni}%
    \Crefname@preamble{appendix}{Appendice}{Appendici}%
    \Crefname@preamble{enumi}{Voce}{Voci}%
    \Crefname@preamble{footnote}{Nota}{Note}%
    \Crefname@preamble{theorem}{Teorema}{Teoremi}%
    \Crefname@preamble{lemma}{Lemma}{Lemmi}%
    \Crefname@preamble{corollary}{Corollario}{Corollari}%
    \Crefname@preamble{proposition}{Proposizione}{Proposizioni}%
    \Crefname@preamble{definition}{Definizioni}{Definizioni}%
    \Crefname@preamble{result}{Risultato}{Risultati}%
    \Crefname@preamble{example}{esempio}{esempi}%
    \Crefname@preamble{remark}{Osservazione}{Osservazioni}%
    \Crefname@preamble{note}{Nota}{Note}%
    \Crefname@preamble{algorithm}{Algoritmo}{Algoritmi}%
    \Crefname@preamble{listing}{Elenco}{Elenchi}%
    \Crefname@preamble{line}{Linea}{Linee}%
 %
    \if@cref@capitalise%  capitalise set
      \if@cref@abbrev%
        \crefname@preamble{equation}{Eq.}{Eq.}%
        \crefname@preamble{figure}{Fig.}{Fig.}%
      \else%
        \crefname@preamble{equation}{Equazione}{Equazioni}%
        \crefname@preamble{figure}{Figura}{Figure}%
      \fi%
      \crefname@preamble{table}{Tabella}{Tabelle}%
      \crefname@preamble{page}{Pagina}{Pagine}%
      \crefname@preamble{part}{Parte}{Parti}%
      \crefname@preamble{chapter}{Capitolo}{Capitoli}%
      \crefname@preamble{section}{Sezione}{Sezioni}%
      \crefname@preamble{appendix}{Appendice}{Appendici}%
      \crefname@preamble{enumi}{Voce}{Voci}%
      \crefname@preamble{footnote}{Nota}{Note}%
      \crefname@preamble{theorem}{Teorema}{Teoremi}%
      \crefname@preamble{lemma}{Lemma}{Lemmi}%
      \crefname@preamble{corollary}{Corollario}{Corollari}%
      \crefname@preamble{proposition}{Proposizione}{Proposizioni}%
      \crefname@preamble{definition}{Definizione}{Definizioni}%
      \crefname@preamble{result}{Risultato}{Risultati}%
      \crefname@preamble{example}{Esempio}{Esempi}%
      \crefname@preamble{remark}{Osservazione}{Osservazioni}%
      \crefname@preamble{note}{Nota}{Note}%
      \crefname@preamble{algorithm}{Algoritmo}{Algoritmi}%
      \crefname@preamble{listing}{Elenco}{Elenchi}%
      \crefname@preamble{line}{Linea}{Linee}%
 %
    \else%  capitalise unset
      \if@cref@abbrev%
        \crefname@preamble{equation}{eq.}{eq.}%
        \crefname@preamble{figure}{fig.}{fig.}%
      \else%
        \crefname@preamble{equation}{equazione}{equazioni}%
        \crefname@preamble{figure}{figura}{figure}%
      \fi%
      \crefname@preamble{table}{tabella}{tabelle}%
      \crefname@preamble{page}{pagina}{pagine}%
      \crefname@preamble{part}{parte}{parti}%
      \crefname@preamble{chapter}{capitolo}{capitoli}%
      \crefname@preamble{section}{sezione}{sezioni}%
      \crefname@preamble{appendix}{appendice}{appendici}%
      \crefname@preamble{enumi}{voce}{voci}%
      \crefname@preamble{footnote}{nota}{note}%
      \crefname@preamble{theorem}{teorema}{teoremi}%
      \crefname@preamble{lemma}{lemma}{lemmi}%
      \crefname@preamble{corollary}{corollario}{corollari}%
      \crefname@preamble{proposition}{proposizione}{proposizioni}%
      \crefname@preamble{definition}{definizione}{definizioni}%
      \crefname@preamble{result}{risultato}{risultati}%
      \crefname@preamble{example}{esempio}{esempi}%
      \crefname@preamble{remark}{osservazione}{osservazioni}%
      \crefname@preamble{note}{nota}{note}%
      \crefname@preamble{algorithm}{algoritmo}{algoritmi}%
      \crefname@preamble{listing}{elenco}{elenchi}%
      \crefname@preamble{line}{linea}{linee}%
    \fi%
    \def\cref@language{italian}%
  }}% end \DeclareOption and \AtBeginDocument
%    \end{macrocode}
%
% If using \package{babel} and the corresponding option is set, or if
% using \package{polyglossia} and the language has been loaded, add
% format definition commands to \cmd{\extras}\meta{language} or
% \cmd{\captions}\meta{language} so that language switching commands will
% change the cross-reference formats appropriately.
%    \begin{macrocode}
\cref@addlanguagedefs{italian}{%
  \PackageInfo{cleveref}{loaded `italian' language definitions}%
  \renewcommand{\crefrangeconjunction}{ a\nobreakspace}%
  \renewcommand\crefrangepreconjunction{da\nobreakspace}%
  \renewcommand\crefrangepostconjunction{}%
  \renewcommand{\crefpairconjunction}{ e\nobreakspace}%
  \renewcommand{\crefmiddleconjunction}{, }%
  \renewcommand{\creflastconjunction}{ e\nobreakspace}%
  \renewcommand{\crefpairgroupconjunction}{ e\nobreakspace}%
  \renewcommand{\crefmiddlegroupconjunction}{, }%
  \renewcommand{\creflastgroupconjunction}{ e\nobreakspace}%
 %
  \Crefname{equation}{Equazione}{Equazioni}%
  \Crefname{figure}{Figura}{Figure}%
  \Crefname{subfigure}{Figura}{Figure}%
  \Crefname{table}{Tabella}{Tabelle}%
  \Crefname{subtable}{Tabella}{Tabelle}%
  \Crefname{page}{Pagina}{Pagine}%
  \Crefname{part}{Parte}{Parti}%
  \Crefname{chapter}{Capitolo}{Capitoli}%
  \Crefname{section}{Sezione}{Sezioni}%
  \Crefname{subsection}{Sezione}{Sezioni}%
  \Crefname{subsubsection}{Sezione}{Sezioni}%
  \Crefname{appendix}{Appendice}{Appendici}%
  \Crefname{subappendix}{Appendice}{Appendici}%
  \Crefname{subsubappendix}{Appendice}{Appendici}%
  \Crefname{subsubsubappendix}{Appendice}{Appendici}%
  \Crefname{enumi}{Voce}{Voci}%
  \Crefname{enumii}{Voce}{Voci}%
  \Crefname{enumiii}{Voce}{Voci}%
  \Crefname{enumiv}{Voce}{Voci}%
  \Crefname{enumv}{Voce}{Voci}%
  \Crefname{footnote}{Nota}{Note}%
  \Crefname{theorem}{Teorema}{Teoremi}%
  \Crefname{lemma}{Lemma}{Lemmi}%
  \Crefname{corollary}{Corollario}{Corollari}%
  \Crefname{proposition}{Proposizione}{Proposizioni}%
  \Crefname{definition}{Definizione}{Definizione}%
  \Crefname{result}{Risultato}{Risultati}%
  \Crefname{example}{esempio}{esempi}%
  \Crefname{remark}{Osservazione}{Osservazioni}%
  \Crefname{note}{Nota}{Note}%
  \Crefname{algorithm}{Algoritmo}{Algoritmi}%
  \Crefname{listing}{Elenco}{Elenchi}%
  \Crefname{line}{Linea}{Linee}%
 %
  \if@cref@capitalise%  capitalise set
    \if@cref@abbrev%
      \crefname{equation}{Eq.}{Eq.}%
      \crefname{figure}{Fig.}{Fig.}%
      \crefname{subfigure}{Fig.}{Fig.}%
    \else%
      \crefname{equation}{Equazione}{Equazioni}%
      \crefname{figure}{Figura}{Figure}%
      \crefname{figure}{Figura}{Figure}%
    \fi%
    \crefname{table}{Tabella}{Tabelle}%
    \crefname{page}{Pagina}{Pagine}%
    \crefname{subtable}{Tabella}{Tabelle}%
    \crefname{part}{Parte}{Parti}%
    \crefname{chapter}{Capitolo}{Capitoli}%
    \crefname{section}{Sezione}{Sezioni}%
    \crefname{subsection}{Sezione}{Sezioni}%
    \crefname{subsubsection}{Sezione}{Sezioni}%
    \crefname{appendix}{Appendice}{Appendici}%
    \crefname{subappendix}{Appendice}{Appendici}%
    \crefname{subsubappendix}{Appendice}{Appendici}%
    \crefname{subsubsubappendix}{Appendice}{Appendici}%
    \crefname{enumi}{Voce}{Voci}%
    \crefname{enumii}{Voce}{Voci}%
    \crefname{enumiii}{Voce}{Voci}%
    \crefname{enumiv}{Voce}{Voci}%
    \crefname{enumv}{Voce}{Voci}%
    \crefname{footnote}{Nota}{Note}%
    \crefname{theorem}{Teorema}{Teoremi}%
    \crefname{lemma}{Lemma}{Lemmi}%
    \crefname{corollary}{Corollario}{Corollari}%
    \crefname{proposition}{Proposizione}{Proposizioni}%
    \crefname{definition}{Definizione}{Definizione}%
    \crefname{result}{Risultato}{Risultati}%
    \crefname{example}{Esempio}{Esempi}%
    \crefname{remark}{Osservazione}{Osservazioni}%
    \crefname{note}{Nota}{Note}%
    \crefname{algorithm}{Algoritmo}{Algoritmi}%
    \crefname{listing}{Elenco}{Elenchi}%
    \crefname{line}{Linea}{Linee}%
 %
  \else%  capitalise unset
    \if@cref@abbrev%
      \crefname{equation}{eq.}{eq.}%
      \crefname{figure}{fig.}{fig.}%
      \crefname{subfigure}{fig.}{fig.}%
    \else%
      \crefname{equation}{equazione}{equazioni}%
      \crefname{figure}{figura}{figure}%
      \crefname{figure}{figura}{figure}%
    \fi%
    \crefname{table}{tabella}{tabelle}%
    \crefname{page}{pagina}{pagine}%
    \crefname{subtable}{tabella}{tabelle}%
    \crefname{part}{parte}{parti}%
    \crefname{chapter}{capitolo}{capitoli}%
    \crefname{section}{sezione}{sezioni}%
    \crefname{subsection}{sezione}{sezioni}%
    \crefname{subsubsection}{sezione}{sezioni}%
    \crefname{appendix}{appendice}{appendici}%
    \crefname{subappendix}{appendice}{appendici}%
    \crefname{subsubappendix}{appendice}{appendici}%
    \crefname{subsubsubappendix}{appendice}{appendici}%
    \crefname{enumi}{voce}{voci}%
    \crefname{enumii}{voce}{voci}%
    \crefname{enumiii}{voce}{voci}%
    \crefname{enumiv}{voce}{voci}%
    \crefname{enumv}{voce}{voci}%
    \crefname{footnote}{nota}{note}%
    \crefname{theorem}{teorema}{teoremi}%
    \crefname{lemma}{lemma}{lemmi}%
    \crefname{corollary}{corollario}{corollari}%
    \crefname{proposition}{proposizione}{proposizioni}%
    \crefname{definition}{definizione}{definizione}%
    \crefname{result}{risultato}{risultati}%
    \crefname{example}{esempio}{esempi}%
    \crefname{remark}{osservazione}{osservazioni}%
    \crefname{note}{nota}{note}%
    \crefname{algorithm}{algoritmo}{algoritmi}%
    \crefname{listing}{elenco}{elenchi}%
    \crefname{line}{linea}{linee}%
  \fi}% end \cref@loadlanguagedefs
%    \end{macrocode}
%
%
%  \subsubsection{Russian}
% \begin{macro}{russian}
%   Russian translations generously contributed by Aleksander Gorohovski.
% \end{macro}
%
% Set up the definitions used at the beginning of the document to define
% the formats created by the document preamble.
%    \begin{macrocode}
\DeclareOption{russian}{%
  \AtBeginDocument{%
    \def\crefrangeconjunction@preamble{--}%
    \def\crefrangepreconjunction@preamble{}%
    \def\crefrangepostconjunction@preamble{}%
    \def\crefpairconjunction@preamble{ \cyri\nobreakspace}%
    \def\crefmiddleconjunction@preamble{, }%
    \def\creflastconjunction@preamble{ \cyri\nobreakspace}%
%    \end{macrocode}
% We have to define the group conjunctions explicitly here, rather than
% relying on fall-back definitions in terms of the above conjunctions
% (see \cref{sec:code:default_formats}), in case any other language
% option defines them explicitly and we need to override those.
%    \begin{macrocode}
    \def\crefpairgroupconjunction@preamble{ \cyri\nobreakspace}%
    \def\crefmiddlegroupconjunction@preamble{, }%
    \def\creflastgroupconjunction@preamble%
      {, \cyra\ \cyrt\cyra\cyrk\cyrzh\cyre\nobreakspace}%
 %
      \Crefname@preamble{equation}%
      {\CYRF\cyro\cyrr\cyrm\cyru\cyrl\cyra}%
      {\CYRF\cyro\cyrr\cyrm\cyru\cyrl\cyrery}%
    \Crefname@preamble{figure}%
      {\CYRR\cyri\cyrs\cyru\cyrn\cyro\cyrk}%
      {\CYRR\cyri\cyrs\cyru\cyrn\cyrk\cyri}%
    \Crefname@preamble{table}%
      {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyra}%
      {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyrery}%
    \Crefname@preamble{enumi}%
      {\CYRP\cyru\cyrn\cyrk\cyrt}%
      {\CYRP\cyru\cyrn\cyrk\cyrt\cyrery}%
    \Crefname@preamble{chapter}%
      {\CYRG\cyrl\cyra\cyrv\cyra}%
      {\CYRG\cyrl\cyra\cyrv\cyrery}%
    \Crefname@preamble{section}%
      {\CYRR\cyra\cyrz\cyrd\cyre\cyrl}%
      {\CYRR\cyra\cyrz\cyrd\cyre\cyrl\cyrery}%
    \Crefname@preamble{appendix}%
      {\CYRP\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyre}%
      {\CYRP\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyrya}%
    \Crefname@preamble{footnote}%
      {\CYRS\cyrn\cyro\cyrs\cyrk\cyra}%
      {\CYRS\cyrn\cyro\cyrs\cyrk\cyri}%
    \Crefname@preamble{theorem}%
      {\CYRT\cyre\cyro\cyrr\cyre\cyrm\cyra}%
      {\CYRT\cyre\cyro\cyrr\cyre\cyrm\cyrery}%
    \Crefname@preamble{lemma}%
      {\CYRL\cyre\cyrm\cyrm\cyra}%
      {\CYRL\cyre\cyrm\cyrm\cyrery}%
    \Crefname@preamble{corollary}%
      {\CYRV\cyrery\cyrv\cyro\cyrd}%
      {\CYRV\cyrery\cyrv\cyro\cyrd\cyrery}%
    \Crefname@preamble{proposition}%
      {\CYRU\cyrt\cyrv\cyre\cyrr\cyrzh\cyrd\cyre\cyrn\cyri\cyre}%
      {\CYRU\cyrt\cyrv\cyre\cyrr\cyrzh\cyrd\cyre\cyrn\cyri\cyrya}%
    \Crefname@preamble{definition}%
      {\CYRO\cyrp\cyrr\cyre\cyrd\cyre\cyrl\cyre\cyrn\cyri\cyre}%
      {\CYRO\cyrp\cyrr\cyre\cyrd\cyre\cyrl\cyre\cyrn\cyri\cyrya}%
    \Crefname@preamble{result}%
      {\CYRR\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt}%
      {\CYRR\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt\cyrery}%
    \Crefname@preamble{example}%
      {\CYRP\cyrr\cyri\cyrm\cyre\cyrr}%
      {\CYRP\cyrr\cyri\cyrm\cyre\cyrr\cyrery}%
    \Crefname@preamble{remark}%
      {\CYRP\cyrr\cyri\cyrm\cyre\cyrch\cyra\cyrn\cyri\cyre}%
      {\CYRP\cyrr\cyri\cyrm\cyre\cyrch\cyra\cyrn\cyri\cyrya}%
    \Crefname@preamble{note}%
      {\CYRZ\cyra\cyrm\cyre\cyrt\cyrk\cyra}%
      {\CYRZ\cyra\cyrm\cyre\cyrt\cyrk\cyri}%
    \Crefname@preamble{algorithm}%
      {\CYRA\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm}%
      {\CYRA\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm\cyrery}%
    \Crefname@preamble{listing}%
      {\CYRL\cyri\cyrs\cyrt\cyri\cyrn\cyrg}%
      {\CYRL\cyri\cyrs\cyrt\cyri\cyrn\cyrg\cyri}%
    \Crefname@preamble{line}%
      {\CYRS\cyrt\cyrr\cyro\cyrk\cyra}%
      {\CYRS\cyrt\cyrr\cyro\cyrk\cyri}%
    \Crefname@preamble{page}%
      {\CYRS\cyrt\cyrr\cyra\cyrn\cyri\cyrc\cyra}%
      {\CYRS\cyrt\cyrr\cyra\cyrn\cyri\cyrc\cyrery}%
    \Crefname@preamble{part}%
      {\CYRCH\cyra\cyrs\cyrt\cyrsftsn}%
      {\CYRCH\cyra\cyrs\cyrt\cyri}%
 %
    \if@cref@capitalise%  capitalise set
      \if@cref@abbrev%  abbrev set
        \crefname@preamble{equation}%
          {\CYRF-\cyrl.}%
          {\CYRF-\cyrl.}%
        \crefname@preamble{figure}%
          {\CYRR\cyri\cyrs.}%
          {\CYRR\cyri\cyrs.}%
        \crefname@preamble{table}%
          {\CYRT\cyra\cyrb\cyrl.}%
          {\CYRT\cyra\cyrb\cyrl.}%
        \crefname@preamble{enumi}%
          {\CYRP.}%
          {\CYRP.\cyrp.}%
      \else%
        \crefname@preamble{equation}%
          {\CYRF\cyro\cyrr\cyrm\cyru\cyrl\cyra}%
          {\CYRF\cyro\cyrr\cyrm\cyru\cyrl\cyrery}%
        \crefname@preamble{figure}%
          {\CYRR\cyri\cyrs\cyru\cyrn\cyro\cyrk}%
          {\CYRR\cyri\cyrs\cyru\cyrn\cyrk\cyri}%
        \crefname@preamble{table}%
          {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyra}%
          {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyrery}%
        \crefname@preamble{enumi}%
          {\CYRP\cyru\cyrn\cyrk\cyrt}%
          {\CYRP\cyru\cyrn\cyrk\cyrt\cyrery}%
      \fi%
      \crefname@preamble{chapter}%
        {\CYRG\cyrl\cyra\cyrv\cyra}%
        {\CYRG\cyrl\cyra\cyrv\cyrery}%
      \crefname@preamble{section}%
        {\CYRR\cyra\cyrz\cyrd\cyre\cyrl}%
        {\CYRR\cyra\cyrz\cyrd\cyre\cyrl\cyrery}%
      \crefname@preamble{appendix}%
        {\CYRP\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyre}%
        {\CYRP\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyrya}%
      \crefname@preamble{footnote}%
        {\CYRS\cyrn\cyro\cyrs\cyrk\cyra}%
        {\CYRS\cyrn\cyro\cyrs\cyrk\cyri}%
      \crefname@preamble{theorem}%
        {\CYRT\cyre\cyro\cyrr\cyre\cyrm\cyra}%
        {\CYRT\cyre\cyro\cyrr\cyre\cyrm\cyrery}%
      \crefname@preamble{lemma}%
        {\CYRL\cyre\cyrm\cyrm\cyra}%
        {\CYRL\cyre\cyrm\cyrm\cyrery}%
      \crefname@preamble{corollary}%
        {\CYRV\cyrery\cyrv\cyro\cyrd}%
        {\CYRV\cyrery\cyrv\cyro\cyrd\cyrery}%
      \crefname@preamble{proposition}%
        {\CYRU\cyrt\cyrv\cyre\cyrr\cyrzh\cyrd\cyre\cyrn\cyri\cyre}%
        {\CYRU\cyrt\cyrv\cyre\cyrr\cyrzh\cyrd\cyre\cyrn\cyri\cyrya}%
      \crefname@preamble{definition}%
        {\CYRO\cyrp\cyrr\cyre\cyrd\cyre\cyrl\cyre\cyrn\cyri\cyre}%
        {\CYRO\cyrp\cyrr\cyre\cyrd\cyre\cyrl\cyre\cyrn\cyri\cyrya}%
      \crefname@preamble{result}%
        {\CYRR\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt}%
        {\CYRR\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt\cyrery}%
      \crefname@preamble{example}%
        {\CYRP\cyrr\cyri\cyrm\cyre\cyrr}%
        {\CYRP\cyrr\cyri\cyrm\cyre\cyrr\cyrery}%
      \crefname@preamble{remark}%
        {\CYRP\cyrr\cyri\cyrm\cyre\cyrch\cyra\cyrn\cyri\cyre}%
        {\CYRP\cyrr\cyri\cyrm\cyre\cyrch\cyra\cyrn\cyri\cyrya}%
      \crefname@preamble{note}%
        {\CYRZ\cyra\cyrm\cyre\cyrt\cyrk\cyra}%
        {\CYRZ\cyra\cyrm\cyre\cyrt\cyrk\cyri}%
      \crefname@preamble{algorithm}%
        {\CYRA\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm}%
        {\CYRA\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm\cyrery}%
      \crefname@preamble{listing}%
        {\CYRL\cyri\cyrs\cyrt\cyri\cyrn\cyrg}%
        {\CYRL\cyri\cyrs\cyrt\cyri\cyrn\cyrg\cyri}%
      \crefname@preamble{line}%
        {\CYRS\cyrt\cyrr\cyro\cyrk\cyra}%
        {\CYRS\cyrt\cyrr\cyro\cyrk\cyri}%
      \crefname@preamble{page}%
        {\CYRS\cyrt\cyrr\cyra\cyrn\cyri\cyrc\cyra}%
        {\CYRS\cyrt\cyrr\cyra\cyrn\cyri\cyrc\cyrery}%
      \crefname@preamble{part}%
        {\CYRCH\cyra\cyrs\cyrt\cyrsftsn}%
        {\CYRCH\cyra\cyrs\cyrt\cyri}%
 %
    \else%  capitalise unset
      \if@cref@abbrev%  abbrev set
        \crefname@preamble{equation}%
          {\cyrf-\cyrl.}%
          {\cyrf-\cyrl.}%
        \crefname@preamble{figure}%
          {\cyrr\cyri\cyrs.}%
          {\cyrr\cyri\cyrs.}%
        \crefname@preamble{table}%
          {\cyrt\cyra\cyrb\cyrl.}%
          {\cyrt\cyra\cyrb\cyrl.}%
        \crefname@preamble{enumi}%
          {\cyrp.}%
          {\cyrp.\cyrp.}%
        \crefname@preamble{chapter}%
          {\cyrg\cyrl\cyra\cyrv.}%
          {\cyrg\cyrl\cyra\cyrv.}%
        \crefname@preamble{section}%
          {\cyrr\cyra\cyrz\cyrd.}%
          {\cyrr\cyra\cyrz\cyrd\cyre\cyrl.}%
        \crefname@preamble{appendix}%
          {\cyrp\cyrr\cyri\cyrl\cyro\cyrzh.}%
          {\cyrp\cyrr\cyri\cyrl\cyro\cyrzh.}%
        \crefname@preamble{footnote}%
          {\cyrs\cyrn\cyro\cyrs\cyrk.}%
          {\cyrs\cyrn\cyro\cyrs\cyrk.}%
        \crefname@preamble{theorem}%
          {\cyrt\cyre\cyro\cyrr\cyre\cyrm.}%
          {\cyrt\cyre\cyro\cyrr\cyre\cyrm.}%
        \crefname@preamble{lemma}%
          {\cyrl\cyre\cyrm\cyrm.}%
          {\cyrl\cyre\cyrm\cyrm.}%
        \crefname@preamble{corollary}%
          {\cyrv\cyrery\cyrv\cyro\cyrd}%
          {\cyrv\cyrery\cyrv\cyro\cyrd.}%
        \crefname@preamble{proposition}%
          {\cyru\cyrt\cyrv\cyre\cyrr\cyrzh\cyrd.}%
          {\cyru\cyrt\cyrv\cyre\cyrr\cyrzh\cyrd.}%
        \crefname@preamble{definition}%
          {\cyro\cyrp\cyrr\cyre\cyrd\cyre\cyrl\cyre\cyrn.}%
          {\cyro\cyrp\cyrr\cyre\cyrd\cyre\cyrl\cyre\cyrn.}%
        \crefname@preamble{result}%
          {\cyrr\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt.}%
          {\cyrr\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt.}%
        \crefname@preamble{example}%
          {\cyrp\cyrr\cyri\cyrm.}%
          {\cyrp\cyrr\cyri\cyrm\cyre\cyrr.}%
        \crefname@preamble{remark}%
          {\cyrp\cyrr\cyri\cyrm\cyre\cyrch.}%
          {\cyrp\cyrr\cyri\cyrm\cyre\cyrch.}%
        \crefname@preamble{note}%
          {\cyrz\cyra\cyrm\cyre\cyrt\cyrk.}%
          {\cyrz\cyra\cyrm\cyre\cyrt\cyrk.}%
        \crefname@preamble{algorithm}%
          {\cyra\cyrl\cyrg.}%
          {\cyra\cyrl\cyrg.}%
        \crefname@preamble{listing}%
          {\cyrl\cyri\cyrs\cyrt\cyri\cyrn.}%
          {\cyrl\cyri\cyrs\cyrt\cyri\cyrn\cyrg.}%
        \crefname@preamble{line}%
          {\cyrs\cyrt\cyrr\cyrk.}%
          {\cyrs\cyrt\cyrr\cyrk.}%
      \else%  abbrev unset
        \crefname@preamble{equation}%
          {\cyrf\cyro\cyrr\cyrm\cyru\cyrl\cyra}%
          {\cyrf\cyro\cyrr\cyrm\cyru\cyrl\cyrery}%
        \crefname@preamble{figure}%
          {\cyrr\cyri\cyrs\cyru\cyrn\cyro\cyrk}%
          {\cyrr\cyri\cyrs\cyru\cyrn\cyrk\cyri}%
        \crefname@preamble{table}%
          {\cyrt\cyra\cyrb\cyrl\cyri\cyrc\cyra}%
          {\cyrt\cyra\cyrb\cyrl\cyri\cyrc\cyrery}%
        \crefname@preamble{enumi}%
          {\cyrp\cyru\cyrn\cyrk\cyrt}%
          {\cyrp\cyru\cyrn\cyrk\cyrt\cyrery}%
        \crefname@preamble{chapter}%
          {\cyrg\cyrl\cyra\cyrv\cyra}%
          {\cyrg\cyrl\cyra\cyrv\cyrery}%
        \crefname@preamble{section}%
          {\cyrr\cyra\cyrz\cyrd\cyre\cyrl}%
          {\cyrr\cyra\cyrz\cyrd\cyre\cyrl\cyrery}%
        \crefname@preamble{appendix}%
          {\cyrp\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyre}%
          {\cyrp\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyrya}%
        \crefname@preamble{footnote}%
          {\cyrs\cyrn\cyro\cyrs\cyrk\cyra}%
          {\cyrs\cyrn\cyro\cyrs\cyrk\cyri}%
        \crefname@preamble{theorem}%
          {\cyrt\cyre\cyro\cyrr\cyre\cyrm\cyra}%
          {\cyrt\cyre\cyro\cyrr\cyre\cyrm\cyrery}%
        \crefname@preamble{lemma}%
          {\cyrl\cyre\cyrm\cyrm\cyra}%
          {\cyrl\cyre\cyrm\cyrm\cyrery}%
        \crefname@preamble{corollary}%
          {\cyrv\cyrery\cyrv\cyro\cyrd}%
          {\cyrv\cyrery\cyrv\cyro\cyrd\cyrery}%
        \crefname@preamble{proposition}%
          {\cyru\cyrt\cyrv\cyre\cyrr\cyrzh\cyrd\cyre\cyrn\cyri\cyre}%
          {\cyru\cyrt\cyrv\cyre\cyrr\cyrzh\cyrd\cyre\cyrn\cyri\cyrya}%
        \crefname@preamble{definition}%
          {\cyro\cyrp\cyrr\cyre\cyrd\cyre\cyrl\cyre\cyrn\cyri\cyre}%
          {\cyro\cyrp\cyrr\cyre\cyrd\cyre\cyrl\cyre\cyrn\cyri\cyrya}%
        \crefname@preamble{result}%
          {\cyrr\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt}%
          {\cyrr\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt\cyrery}%
        \crefname@preamble{example}%
          {\cyrp\cyrr\cyri\cyrm\cyre\cyrr}%
          {\cyrp\cyrr\cyri\cyrm\cyre\cyrr\cyrery}%
        \crefname@preamble{remark}%
          {\cyrp\cyrr\cyri\cyrm\cyre\cyrch\cyra\cyrn\cyri\cyre}%
          {\cyrp\cyrr\cyri\cyrm\cyre\cyrch\cyra\cyrn\cyri\cyrya}%
        \crefname@preamble{note}%
          {\cyrz\cyra\cyrm\cyre\cyrt\cyrk\cyra}%
          {\cyrz\cyra\cyrm\cyre\cyrt\cyrk\cyri}%
        \crefname@preamble{algorithm}%
          {\cyra\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm}%
          {\cyra\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm\cyrery}%
        \crefname@preamble{listing}%
          {\cyrl\cyri\cyrs\cyrt\cyri\cyrn\cyrg}%
          {\cyrl\cyri\cyrs\cyrt\cyri\cyrn\cyrg\cyri}%
        \crefname@preamble{line}%
          {\cyrs\cyrt\cyrr\cyro\cyrk\cyra}%
          {\cyrs\cyrt\cyrr\cyro\cyrk\cyri}%
      \fi%
      \crefname@preamble{page}%
        {\cyrs\cyrt\cyrr\cyra\cyrn\cyri\cyrc\cyre}%
        {\cyrs\cyrt\cyrr\cyra\cyrn\cyri\cyrc\cyra\cyrh}%
      \crefname@preamble{part}%
        {\cyrch\cyra\cyrs\cyrt\cyrsftsn}%
        {\cyrch\cyra\cyrs\cyrt\cyri}%
    \fi%
    \def\cref@language{russian}%
  }}% end \DeclareOption and \AtBeginDocument
%    \end{macrocode}
%
% If using \package{babel} and the corresponding option is set, or if
% using \package{polyglossia} and the language has been loaded, add
% format definition commands to \cmd{\extras}\meta{language} or
% \cmd{\captions}\meta{language} so that language switching commands will
% change the cross-reference formats appropriately.
%    \begin{macrocode}
\cref@addlanguagedefs{russian}{%
  \PackageInfo{cleveref}{loaded `russian' language definitions}%
  \renewcommand{\crefrangeconjunction}{--}%
  \renewcommand\crefrangepreconjunction{}%
  \renewcommand\crefrangepostconjunction{}%
  \renewcommand{\crefpairconjunction}{ \cyri\nobreakspace}%
  \renewcommand{\crefmiddleconjunction}{, }%
  \renewcommand{\creflastconjunction}{ \cyri\nobreakspace}%
  \renewcommand{\crefpairgroupconjunction}{ \cyri\nobreakspace}%
  \renewcommand{\crefmiddlegroupconjunction}{, }%
  \renewcommand{\creflastgroupconjunction}%
    {, \cyra\ \cyrt\cyra\cyrk\cyrzh\cyre\nobreakspace}%
 %
    \Crefname{page}%
    {\CYRS\cyrt\cyrr\cyra\cyrn\cyri\cyrc\cyra}%
    {\CYRS\cyrt\cyrr\cyra\cyrn\cyri\cyrc\cyrery}%
  \Crefname{equation}%
    {\CYRF\cyro\cyrr\cyrm\cyru\cyrl\cyra}%
    {\CYRF\cyro\cyrr\cyrm\cyru\cyrl\cyrery}%
  \Crefname{figure}%
    {\CYRR\cyri\cyrs\cyru\cyrn\cyro\cyrk}%
    {\CYRR\cyri\cyrs\cyru\cyrn\cyrk\cyri}%
  \Crefname{subfigure}%
    {\CYRR\cyri\cyrs\cyru\cyrn\cyro\cyrk}%
    {\CYRR\cyri\cyrs\cyru\cyrn\cyrk\cyri}%
  \Crefname{table}%
    {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyra}%
    {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyrery}%
  \Crefname{subtable}%
    {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyra}%
    {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyrery}%
  \Crefname{part}%
    {\CYRCH\cyra\cyrs\cyrt\cyrsftsn}%
    {\CYRCH\cyra\cyrs\cyrt\cyri}%
  \Crefname{chapter}%
    {\CYRG\cyrl\cyra\cyrv\cyra}%
    {\CYRG\cyrl\cyra\cyrv\cyrery}%
  \Crefname{section}%
    {\CYRR\cyra\cyrz\cyrd\cyre\cyrl}%
    {\CYRR\cyra\cyrz\cyrd\cyre\cyrl\cyrery}%
  \Crefname{subsection}%
    {\CYRR\cyra\cyrz\cyrd\cyre\cyrl}%
    {\CYRR\cyra\cyrz\cyrd\cyre\cyrl\cyrery}%
  \Crefname{subsubsection}%
    {\CYRR\cyra\cyrz\cyrd\cyre\cyrl}%
    {\CYRR\cyra\cyrz\cyrd\cyre\cyrl\cyrery}%
  \Crefname{appendix}%
    {\CYRP\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyre}%
    {\CYRP\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyrya}%
  \Crefname{subappendix}%
    {\CYRP\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyre}%
    {\CYRP\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyrya}%
  \Crefname{subsubappendix}%
    {\CYRP\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyre}%
    {\CYRP\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyrya}%
  \Crefname{subsubsubappendix}%
    {\CYRP\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyre}%
    {\CYRP\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyrya}%
  \Crefname{enumi}%
    {\CYRP\cyru\cyrn\cyrk\cyrt}%
    {\CYRP\cyru\cyrn\cyrk\cyrt\cyrery}%
  \Crefname{enumii}%
    {\CYRP\cyru\cyrn\cyrk\cyrt}%
    {\CYRP\cyru\cyrn\cyrk\cyrt\cyrery}%
  \Crefname{enumiii}%
    {\CYRP\cyru\cyrn\cyrk\cyrt}%
    {\CYRP\cyru\cyrn\cyrk\cyrt\cyrery}%
  \Crefname{enumiv}%
    {\CYRP\cyru\cyrn\cyrk\cyrt}%
    {\CYRP\cyru\cyrn\cyrk\cyrt\cyrery}%
  \Crefname{enumv}%
    {\CYRP\cyru\cyrn\cyrk\cyrt}%
    {\CYRP\cyru\cyrn\cyrk\cyrt\cyrery}%
  \Crefname{footnote}%
    {\CYRS\cyrn\cyro\cyrs\cyrk\cyra}%
    {\CYRS\cyrn\cyro\cyrs\cyrk\cyri}%
  \Crefname{theorem}%
    {\CYRT\cyre\cyro\cyrr\cyre\cyrm\cyra}%
    {\CYRT\cyre\cyro\cyrr\cyre\cyrm\cyrery}%
  \Crefname{lemma}%
    {\CYRL\cyre\cyrm\cyrm\cyra}%
    {\CYRL\cyre\cyrm\cyrm\cyrery}%
  \Crefname{corollary}%
    {\CYRV\cyrery\cyrv\cyro\cyrd}%
    {\CYRV\cyrery\cyrv\cyro\cyrd\cyrery}%
  \Crefname{proposition}%
    {\CYRU\cyrt\cyrv\cyre\cyrr\cyrzh\cyrd\cyre\cyrn\cyri\cyre}%
    {\CYRU\cyrt\cyrv\cyre\cyrr\cyrzh\cyrd\cyre\cyrn\cyri\cyrya}%
  \Crefname{definition}%
    {\CYRO\cyrp\cyrr\cyre\cyrd\cyre\cyrl\cyre\cyrn\cyri\cyre}%
    {\CYRO\cyrp\cyrr\cyre\cyrd\cyre\cyrl\cyre\cyrn\cyri\cyrya}%
  \Crefname{result}%
    {\CYRR\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt}%
    {\CYRR\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt\cyrery}%
  \Crefname{example}%
    {\CYRP\cyrr\cyri\cyrm\cyre\cyrr}%
    {\CYRP\cyrr\cyri\cyrm\cyre\cyrr\cyrery}%
  \Crefname{remark}%
    {\CYRP\cyrr\cyri\cyrm\cyre\cyrch\cyra\cyrn\cyri\cyre}%
    {\CYRP\cyrr\cyri\cyrm\cyre\cyrch\cyra\cyrn\cyri\cyrya}%
  \Crefname{note}%
    {\CYRZ\cyra\cyrm\cyre\cyrt\cyrk\cyra}%
    {\CYRZ\cyra\cyrm\cyre\cyrt\cyrk\cyri}%
  \Crefname{algorithm}%
    {\CYRA\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm}%
    {\CYRA\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm\cyrery}%
  \Crefname{listing}%
    {\CYRL\cyri\cyrs\cyrt\cyri\cyrn\cyrg}%
    {\CYRL\cyri\cyrs\cyrt\cyri\cyrn\cyrg\cyri}%
  \Crefname{line}%
    {\CYRS\cyrt\cyrr\cyro\cyrk\cyra}%
    {\CYRS\cyrt\cyrr\cyro\cyrk\cyri}%
 %
  \if@cref@capitalise%  capitalise set
    \if@cref@abbrev%  abbrev set
      \crefname{equation}%
        {\CYRF-\cyrl.}%
        {\CYRF-\cyrl.}%
      \crefname{figure}%
        {\CYRR\cyri\cyrs.}%
        {\CYRR\cyri\cyrs.}%
      \crefname{subfigure}%
        {\CYRR\cyri\cyrs.}%
        {\CYRR\cyri\cyrs.}%
      \crefname{table}%
        {\CYRT\cyra\cyrb\cyrl.}%
        {\CYRT\cyra\cyrb\cyrl.}%
      \crefname{subtable}%
        {\CYRT\cyra\cyrb\cyrl.}%
        {\CYRT\cyra\cyrb\cyrl.}%
      \crefname{enumi}%
        {\CYRP.}%
        {\CYRP.\cyrp.}%
      \crefname{enumii}%
        {\CYRP.}%
        {\CYRP.\cyrp.}%
      \crefname{enumiii}%
        {\CYRP.}%
        {\CYRP.\cyrp.}%
      \crefname{enumiv}%
        {\CYRP.}%
        {\CYRP.\cyrp.}%
      \crefname{enumv}%
        {\CYRP.}%
        {\CYRP.\cyrp.}%
    \else%  abbrev unset
      \crefname{equation}%
        {\CYRF\cyro\cyrr\cyrm\cyru\cyrl\cyra}%
        {\CYRF\cyro\cyrr\cyrm\cyru\cyrl\cyrery}%
      \crefname{figure}%
        {\CYRR\cyri\cyrs\cyru\cyrn\cyro\cyrk}%
        {\CYRR\cyri\cyrs\cyru\cyrn\cyrk\cyri}%
      \crefname{subfigure}%
        {\CYRR\cyri\cyrs\cyru\cyrn\cyro\cyrk}%
        {\CYRR\cyri\cyrs\cyru\cyrn\cyrk\cyri}%
      \crefname{table}%
        {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyra}%
        {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyrery}%
      \crefname{subtable}%
        {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyra}%
        {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyrery}%
      \crefname{enumi}%
        {\CYRP\cyru\cyrn\cyrk\cyrt}%
        {\CYRP\cyru\cyrn\cyrk\cyrt\cyrery}%
      \crefname{enumii}%
        {\CYRP\cyru\cyrn\cyrk\cyrt}%
        {\CYRP\cyru\cyrn\cyrk\cyrt\cyrery}%
      \crefname{enumiii}%
        {\CYRP\cyru\cyrn\cyrk\cyrt}%
        {\CYRP\cyru\cyrn\cyrk\cyrt\cyrery}%
      \crefname{enumiv}%
        {\CYRP\cyru\cyrn\cyrk\cyrt}%
        {\CYRP\cyru\cyrn\cyrk\cyrt\cyrery}%
      \crefname{enumv}%
        {\CYRP\cyru\cyrn\cyrk\cyrt}%
        {\CYRP\cyru\cyrn\cyrk\cyrt\cyrery}%
    \fi%
    \crefname{page}%
      {\CYRS\cyrt\cyrr\cyra\cyrn\cyri\cyrc\cyra}%
      {\CYRS\cyrt\cyrr\cyra\cyrn\cyri\cyrc\cyrery}%
    \crefname{part}%
      {\CYRCH\cyra\cyrs\cyrt\cyrsftsn}%
      {\CYRCH\cyra\cyrs\cyrt\cyri}%
    \crefname{chapter}%
      {\CYRG\cyrl\cyra\cyrv\cyra}%
      {\CYRG\cyrl\cyra\cyrv\cyrery}%
    \crefname{section}%
      {\CYRR\cyra\cyrz\cyrd\cyre\cyrl}%
      {\CYRR\cyra\cyrz\cyrd\cyre\cyrl\cyrery}%
    \crefname{subsection}%
      {\CYRR\cyra\cyrz\cyrd\cyre\cyrl}%
      {\CYRR\cyra\cyrz\cyrd\cyre\cyrl\cyrery}%
    \crefname{subsubsection}%
      {\CYRR\cyra\cyrz\cyrd\cyre\cyrl}%
      {\CYRR\cyra\cyrz\cyrd\cyre\cyrl\cyrery}%
    \crefname{appendix}%
      {\CYRP\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyre}%
      {\CYRP\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyrya}%
    \crefname{subappendix}%
      {\CYRP\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyre}%
      {\CYRP\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyrya}%
    \crefname{subsubappendix}%
      {\CYRP\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyre}%
      {\CYRP\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyrya}%
    \crefname{subsubsubappendix}%
      {\CYRP\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyre}%
      {\CYRP\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyrya}%
    \crefname{footnote}%
      {\CYRS\cyrn\cyro\cyrs\cyrk\cyra}%
      {\CYRS\cyrn\cyro\cyrs\cyrk\cyri}%
    \crefname{theorem}%
      {\CYRT\cyre\cyro\cyrr\cyre\cyrm\cyra}%
      {\CYRT\cyre\cyro\cyrr\cyre\cyrm\cyrery}%
    \crefname{lemma}%
      {\CYRL\cyre\cyrm\cyrm\cyra}%
      {\CYRL\cyre\cyrm\cyrm\cyrery}%
    \crefname{corollary}%
      {\CYRV\cyrery\cyrv\cyro\cyrd}%
      {\CYRV\cyrery\cyrv\cyro\cyrd\cyrery}%
    \crefname{proposition}%
      {\CYRU\cyrt\cyrv\cyre\cyrr\cyrzh\cyrd\cyre\cyrn\cyri\cyre}%
      {\CYRU\cyrt\cyrv\cyre\cyrr\cyrzh\cyrd\cyre\cyrn\cyri\cyrya}%
    \crefname{definition}%
      {\CYRO\cyrp\cyrr\cyre\cyrd\cyre\cyrl\cyre\cyrn\cyri\cyre}%
      {\CYRO\cyrp\cyrr\cyre\cyrd\cyre\cyrl\cyre\cyrn\cyri\cyrya}%
    \crefname{result}%
      {\CYRR\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt}%
      {\CYRR\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt\cyrery}%
    \crefname{example}%
      {\CYRP\cyrr\cyri\cyrm\cyre\cyrr}%
      {\CYRP\cyrr\cyri\cyrm\cyre\cyrr\cyrery}%
    \crefname{remark}%
      {\CYRP\cyrr\cyri\cyrm\cyre\cyrch\cyra\cyrn\cyri\cyre}%
      {\CYRP\cyrr\cyri\cyrm\cyre\cyrch\cyra\cyrn\cyri\cyrya}%
    \crefname{note}%
      {\CYRZ\cyra\cyrm\cyre\cyrt\cyrk\cyra}%
      {\CYRZ\cyra\cyrm\cyre\cyrt\cyrk\cyri}%
    \crefname{algorithm}%
      {\CYRA\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm}%
      {\CYRA\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm\cyrery}%
    \crefname{listing}%
      {\CYRL\cyri\cyrs\cyrt\cyri\cyrn\cyrg}%
      {\CYRL\cyri\cyrs\cyrt\cyri\cyrn\cyrg\cyri}%
    \crefname{line}%
      {\CYRS\cyrt\cyrr\cyro\cyrk\cyra}%
      {\CYRS\cyrt\cyrr\cyro\cyrk\cyri}%
 %
  \else%  capitalise unset
    \if@cref@abbrev%  abbrev set
      \crefname{equation}%
        {\cyrf-\cyrl.}%
        {\cyrf-\cyrl.}%
      \crefname{chapter}%
        {\cyrg\cyrl\cyra\cyrv.}%
        {\cyrg\cyrl\cyra\cyrv.}%
      \crefname{section}%
        {\cyrr\cyra\cyrz\cyrd.}%
        {\cyrr\cyra\cyrz\cyrd\cyre\cyrl.}%
      \crefname{subsection}%
        {\cyrr\cyra\cyrz\cyrd.}%
        {\cyrr\cyra\cyrz\cyrd\cyre\cyrl.}%
      \crefname{subsubsection}%
        {\cyrr\cyra\cyrz\cyrd.}%
        {\cyrr\cyra\cyrz\cyrd\cyre\cyrl.}%
      \crefname{appendix}%
        {\cyrp\cyrr\cyri\cyrl\cyro\cyrzh.}%
        {\cyrp\cyrr\cyri\cyrl\cyro\cyrzh.}%
      \crefname{subappendix}%
        {\cyrp\cyrr\cyri\cyrl\cyro\cyrzh.}%
        {\cyrp\cyrr\cyri\cyrl\cyro\cyrzh.}%
      \crefname{subsubappendix}%
        {\cyrp\cyrr\cyri\cyrl\cyro\cyrzh.}%
        {\cyrp\cyrr\cyri\cyrl\cyro\cyrzh.}%
      \crefname{subsubsubappendix}%
        {\cyrp\cyrr\cyri\cyrl\cyro\cyrzh.}%
        {\cyrp\cyrr\cyri\cyrl\cyro\cyrzh.}%
      \crefname{enumi}%
        {\cyrp.}%
        {\cyrp.\cyrp.}%
      \crefname{enumii}%
        {\cyrp.}%
        {\cyrp.\cyrp.}%
      \crefname{enumiii}%
        {\cyrp.}%
        {\cyrp.\cyrp.}%
      \crefname{enumiv}%
        {\cyrp.}%
        {\cyrp.\cyrp.}%
      \crefname{enumv}%
        {\cyrp.}%
        {\cyrp.\cyrp.}%
      \crefname{footnote}%
        {\cyrs\cyrn\cyro\cyrs\cyrk.}%
        {\cyrs\cyrn\cyro\cyrs\cyrk.}%
      \crefname{figure}%
        {\cyrr\cyri\cyrs.}%
        {\cyrr\cyri\cyrs.}%
      \crefname{subfigure}%
        {\cyrr\cyri\cyrs.}%
        {\cyrr\cyri\cyrs.}%
      \crefname{table}%
        {\cyrt\cyra\cyrb\cyrl.}%
        {\cyrt\cyra\cyrb\cyrl.}%
      \crefname{subtable}%
        {\cyrt\cyra\cyrb\cyrl.}%
        {\cyrt\cyra\cyrb\cyrl.}%
      \crefname{theorem}%
        {\cyrt\cyre\cyro\cyrr\cyre\cyrm.}%
        {\cyrt\cyre\cyro\cyrr\cyre\cyrm.}%
      \crefname{lemma}%
        {\cyrl\cyre\cyrm\cyrm.}%
        {\cyrl\cyre\cyrm\cyrm.}%
      \crefname{corollary}%
        {\cyrv\cyrery\cyrv\cyro\cyrd}%
        {\cyrv\cyrery\cyrv\cyro\cyrd.}%
      \crefname{proposition}%
        {\cyru\cyrt\cyrv\cyre\cyrr\cyrzh\cyrd.}%
        {\cyru\cyrt\cyrv\cyre\cyrr\cyrzh\cyrd.}%
      \crefname{definition}%
        {\cyro\cyrp\cyrr\cyre\cyrd\cyre\cyrl\cyre\cyrn.}%
        {\cyro\cyrp\cyrr\cyre\cyrd\cyre\cyrl\cyre\cyrn.}%
      \crefname{result}%
        {\cyrr\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt.}%
        {\cyrr\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt.}%
      \crefname{example}%
        {\cyrp\cyrr\cyri\cyrm.}%
        {\cyrp\cyrr\cyri\cyrm\cyre\cyrr.}%
      \crefname{remark}%
        {\cyrp\cyrr\cyri\cyrm\cyre\cyrch.}%
        {\cyrp\cyrr\cyri\cyrm\cyre\cyrch.}%
      \crefname{note}%
        {\cyrz\cyra\cyrm\cyre\cyrt\cyrk.}%
        {\cyrz\cyra\cyrm\cyre\cyrt\cyrk.}%
      \crefname{algorithm}%
        {\cyra\cyrl\cyrg.}%
        {\cyra\cyrl\cyrg.}%
      \crefname{listing}%
        {\cyrl\cyri\cyrs\cyrt\cyri\cyrn.}%
        {\cyrl\cyri\cyrs\cyrt\cyri\cyrn\cyrg.}%
      \crefname{line}%
        {\cyrs\cyrt\cyrr\cyrk.}%
        {\cyrs\cyrt\cyrr\cyrk.}%
    \else%  abbrev unset
      \crefname{equation}%
        {\cyrf\cyro\cyrr\cyrm\cyru\cyrl\cyra}%
        {\cyrf\cyro\cyrr\cyrm\cyru\cyrl\cyrery}%
      \crefname{figure}%
        {\cyrr\cyri\cyrs\cyru\cyrn\cyro\cyrk}%
        {\cyrr\cyri\cyrs\cyru\cyrn\cyrk\cyri}%
      \crefname{subfigure}%
        {\cyrr\cyri\cyrs\cyru\cyrn\cyro\cyrk}%
        {\cyrr\cyri\cyrs\cyru\cyrn\cyrk\cyri}%
      \crefname{table}%
        {\cyrt\cyra\cyrb\cyrl\cyri\cyrc\cyra}%
        {\cyrt\cyra\cyrb\cyrl\cyri\cyrc\cyrery}%
      \crefname{subtable}%
        {\cyrt\cyra\cyrb\cyrl\cyri\cyrc\cyra}%
        {\cyrt\cyra\cyrb\cyrl\cyri\cyrc\cyrery}%
      \crefname{enumi}%
        {\cyrp\cyru\cyrn\cyrk\cyrt}%
        {\cyrp\cyru\cyrn\cyrk\cyrt\cyrery}%
      \crefname{enumii}%
        {\cyrp\cyru\cyrn\cyrk\cyrt}%
        {\cyrp\cyru\cyrn\cyrk\cyrt\cyrery}%
      \crefname{enumiii}%
        {\cyrp\cyru\cyrn\cyrk\cyrt}%
        {\cyrp\cyru\cyrn\cyrk\cyrt\cyrery}%
      \crefname{enumiv}%
        {\cyrp\cyru\cyrn\cyrk\cyrt}%
        {\cyrp\cyru\cyrn\cyrk\cyrt\cyrery}%
      \crefname{enumv}%
        {\cyrp\cyru\cyrn\cyrk\cyrt}%
        {\cyrp\cyru\cyrn\cyrk\cyrt\cyrery}%
      \crefname{chapter}%
        {\cyrg\cyrl\cyra\cyrv\cyra}%
        {\cyrg\cyrl\cyra\cyrv\cyrery}%
      \crefname{section}%
        {\cyrr\cyra\cyrz\cyrd\cyre\cyrl}%
        {\cyrr\cyra\cyrz\cyrd\cyre\cyrl\cyrery}%
      \crefname{subsection}%
        {\cyrr\cyra\cyrz\cyrd\cyre\cyrl}%
        {\cyrr\cyra\cyrz\cyrd\cyre\cyrl\cyrery}%
      \crefname{subsubsection}%
        {\cyrr\cyra\cyrz\cyrd\cyre\cyrl}%
        {\cyrr\cyra\cyrz\cyrd\cyre\cyrl\cyrery}%
      \crefname{appendix}%
        {\cyrp\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyre}%
        {\cyrp\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyrya}%
      \crefname{subappendix}%
        {\cyrp\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyre}%
        {\cyrp\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyrya}%
      \crefname{subsubappendix}%
        {\cyrp\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyre}%
        {\cyrp\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyrya}%
      \crefname{subsubsubappendix}%
        {\cyrp\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyre}%
        {\cyrp\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyrya}%
      \crefname{footnote}%
        {\cyrs\cyrn\cyro\cyrs\cyrk\cyra}%
        {\cyrs\cyrn\cyro\cyrs\cyrk\cyri}%
      \crefname{theorem}%
        {\cyrt\cyre\cyro\cyrr\cyre\cyrm\cyra}%
        {\cyrt\cyre\cyro\cyrr\cyre\cyrm\cyrery}%
      \crefname{lemma}%
        {\cyrl\cyre\cyrm\cyrm\cyra}%
        {\cyrl\cyre\cyrm\cyrm\cyrery}%
      \crefname{corollary}%
        {\cyrv\cyrery\cyrv\cyro\cyrd}%
        {\cyrv\cyrery\cyrv\cyro\cyrd\cyrery}%
      \crefname{proposition}%
        {\cyru\cyrt\cyrv\cyre\cyrr\cyrzh\cyrd\cyre\cyrn\cyri\cyre}%
        {\cyru\cyrt\cyrv\cyre\cyrr\cyrzh\cyrd\cyre\cyrn\cyri\cyrya}%
      \crefname{definition}%
        {\cyro\cyrp\cyrr\cyre\cyrd\cyre\cyrl\cyre\cyrn\cyri\cyre}%
        {\cyro\cyrp\cyrr\cyre\cyrd\cyre\cyrl\cyre\cyrn\cyri\cyrya}%
      \crefname{result}%
        {\cyrr\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt}%
        {\cyrr\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt\cyrery}%
      \crefname{example}%
        {\cyrp\cyrr\cyri\cyrm\cyre\cyrr}%
        {\cyrp\cyrr\cyri\cyrm\cyre\cyrr\cyrery}%
      \crefname{remark}%
        {\cyrp\cyrr\cyri\cyrm\cyre\cyrch\cyra\cyrn\cyri\cyre}%
        {\cyrp\cyrr\cyri\cyrm\cyre\cyrch\cyra\cyrn\cyri\cyrya}%
      \crefname{note}%
        {\cyrz\cyra\cyrm\cyre\cyrt\cyrk\cyra}%
        {\cyrz\cyra\cyrm\cyre\cyrt\cyrk\cyri}%
      \crefname{algorithm}%
        {\cyra\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm}%
        {\cyra\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm\cyrery}%
      \crefname{listing}%
        {\cyrl\cyri\cyrs\cyrt\cyri\cyrn\cyrg}%
        {\cyrl\cyri\cyrs\cyrt\cyri\cyrn\cyrg\cyri}%
      \crefname{line}%
        {\cyrs\cyrt\cyrr\cyro\cyrk\cyra}%
        {\cyrs\cyrt\cyrr\cyro\cyrk\cyri}%
    \fi%
    \crefname{page}%
      {\cyrs\cyrt\cyrr\cyra\cyrn\cyri\cyrc\cyre}%
      {\cyrs\cyrt\cyrr\cyra\cyrn\cyri\cyrc\cyra\cyrh}%
    \crefname{part}%
      {\cyrch\cyra\cyrs\cyrt\cyrsftsn}%
      {\cyrch\cyra\cyrs\cyrt\cyri}%
  \fi}% end \cref@loadlanguagedefs
%    \end{macrocode}
%
%
%  \subsubsection{Ukrainian}
% \begin{macro}{ukrainian}
%   Ukrainian translations courtesy of Aleksander Gorohovski.
% \end{macro}
%
% Set up the definitions used at the beginning of the document to define
% the formats created by the document preamble.
%    \begin{macrocode}
\DeclareOption{ukrainian}{%
  \AtBeginDocument{%
    \def\crefrangeconjunction@preamble{--}%
    \def\crefrangepreconjunction@preamble{}%
    \def\crefrangepostconjunction@preamble{}%
    \def\crefpairconjunction@preamble{ \cyrii\nobreakspace}%
    \def\crefmiddleconjunction@preamble{, }%
    \def\creflastconjunction@preamble{ \cyrii\nobreakspace}%
%    \end{macrocode}
% We have to define the group conjunctions explicitly here, rather than
% relying on fall-back definitions in terms of the above conjunctions
% (see \cref{sec:code:default_formats}), in case any other language
% option defines them explicitly and we need to override those.
%    \begin{macrocode}
    \def\crefpairgroupconjunction@preamble{ \cyrt\cyra\nobreakspace}%
    \def\crefmiddlegroupconjunction@preamble{, }%
    \def\creflastgroupconjunction@preamble%
      {, \cyra\ \cyrt\cyra\cyrk\cyro\cyrzh\nobreakspace}%
 %
    \Crefname@preamble{equation}%
      {\CYRF\cyro\cyrr\cyrm\cyru\cyrl\cyra}%
      {\CYRF\cyro\cyrr\cyrm\cyru\cyrl\cyri}%
    \Crefname@preamble{figure}%
      {\CYRR\cyri\cyrs\cyru\cyrn\cyro\cyrk}%
      {\CYRR\cyri\cyrs\cyru\cyrn\cyrk\cyri}%
    \Crefname@preamble{table}%
      {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyrya}%
      {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyrii}%
    \Crefname@preamble{enumi}%
      {\CYRP\cyru\cyrn\cyrk\cyrt}%
      {\CYRP\cyru\cyrn\cyrk\cyrt\cyri}%
    \Crefname@preamble{chapter}%
      {\CYRG\cyrl\cyra\cyrv\cyra}%
      {\CYRG\cyrl\cyra\cyrv\cyri}%
    \Crefname@preamble{section}%
      {\CYRR\cyro\cyrz\cyrd\cyrii\cyrl}%
      {\CYRR\cyro\cyrz\cyrd\cyrii\cyrl\cyri}%
    \Crefname@preamble{appendix}%
      {\CYRD\cyro\cyrd\cyra\cyrt\cyro\cyrk}%
      {\CYRD\cyro\cyrd\cyra\cyrt\cyrk\cyri}%
    \Crefname@preamble{footnote}%
      {\CYRV\cyri\cyrn\cyro\cyrs\cyrk\cyra}%
      {\CYRV\cyri\cyrn\cyro\cyrs\cyrk\cyri}%
    \Crefname@preamble{theorem}%
      {\CYRT\cyre\cyro\cyrr\cyre\cyrm\cyra}%
      {\CYRT\cyre\cyro\cyrr\cyre\cyrm\cyri}%
    \Crefname@preamble{lemma}%
      {\CYRL\cyre\cyrm\cyrm\cyra}%
      {\CYRL\cyre\cyrm\cyrm\cyri}%
    \Crefname@preamble{corollary}%
      {\CYRV\cyri\cyrs\cyrn\cyro\cyrv\cyro\cyrk}%
      {\CYRV\cyri\cyrs\cyrn\cyro\cyrv\cyrk\cyri}%
    \Crefname@preamble{proposition}%
      {\CYRT\cyrv\cyre\cyrr\cyrd\cyrzh\cyre\cyrn\cyrn\cyrya}%
      {\CYRT\cyrv\cyre\cyrr\cyrd\cyrzh\cyre\cyrn\cyrn\cyrya}%
    \Crefname@preamble{definition}%
      {\CYRV\cyri\cyrz\cyrn\cyra\cyrch\cyre\cyrn\cyrn\cyrya}%
      {\CYRV\cyri\cyrz\cyrn\cyra\cyrch\cyre\cyrn\cyrn\cyrya}%
    \Crefname@preamble{result}%
      {\CYRR\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt}%
      {\CYRR\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt\cyri}%
    \Crefname@preamble{example}%
      {\CYRP\cyrr\cyri\cyrk\cyrl\cyra\cyrd}%
      {\CYRP\cyrr\cyri\cyrk\cyrl\cyra\cyrd\cyri}%
    \Crefname@preamble{remark}%
      {\CYRP\cyrr\cyri\cyrm\cyrii\cyrt\cyrk\cyra}%
      {\CYRP\cyrr\cyri\cyrm\cyrii\cyrt\cyrk\cyri}%
    \Crefname@preamble{note}%
      {\CYRZ\cyra\cyrm\cyrii\cyrt\cyrk\cyra}%
      {\CYRZ\cyra\cyrm\cyrii\cyrt\cyrk\cyri}%
    \Crefname@preamble{algorithm}%
      {\CYRA\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm}%
      {\CYRA\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm\cyri}%
    \Crefname@preamble{listing}%
      {\CYRL\cyrii\cyrs\cyrt\cyri\cyrn\cyrg}%
      {\CYRL\cyrii\cyrs\cyrt\cyri\cyrn\cyrg\cyri}%
    \Crefname@preamble{line}%
      {\CYRS\cyrt\cyrr\cyro\cyrk\cyra}%
      {\CYRS\cyrt\cyrr\cyro\cyrk\cyri}%
    \Crefname@preamble{page}%
      {\CYRS\cyrt\cyro\cyrr\cyri\cyrn\cyrk\cyra}%
      {\CYRS\cyrt\cyro\cyrr\cyrii\cyrn\cyrk\cyri}%
    \Crefname@preamble{part}%
      {\CYRCH\cyra\cyrs\cyrt\cyri\cyrn\cyra}%
      {\CYRCH\cyra\cyrs\cyrt\cyri\cyrn\cyri}%
 %
    \if@cref@capitalise%  capitalise set
      \if@cref@abbrev%  abbrev set
        \crefname@preamble{equation}%
          {\CYRF-\cyrl.}%
          {\CYRF-\cyrl.}%
        \crefname@preamble{figure}%
          {\CYRR\cyri\cyrs.}%
          {\CYRR\cyri\cyrs.}%
        \crefname@preamble{table}%
          {\CYRT\cyra\cyrb\cyrl.}%
          {\CYRT\cyra\cyrb\cyrl.}%
        \crefname@preamble{enumi}%
          {\CYRP.}%
          {\CYRP.\cyrp.}%
      \else%
        \crefname@preamble{equation}%
          {\CYRF\cyro\cyrr\cyrm\cyru\cyrl\cyra}%
          {\CYRF\cyro\cyrr\cyrm\cyru\cyrl\cyri}%
        \crefname@preamble{figure}%
          {\CYRR\cyri\cyrs\cyru\cyrn\cyro\cyrk}%
          {\CYRR\cyri\cyrs\cyru\cyrn\cyrk\cyri}%
        \crefname@preamble{table}%
          {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyrya}%
          {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyrii}%
        \crefname@preamble{enumi}%
          {\CYRP\cyru\cyrn\cyrk\cyrt}%
          {\CYRP\cyru\cyrn\cyrk\cyrt\cyri}%
      \fi%
      \crefname@preamble{chapter}%
        {\CYRG\cyrl\cyra\cyrv\cyra}%
        {\CYRG\cyrl\cyra\cyrv\cyri}%
      \crefname@preamble{section}%
        {\CYRR\cyro\cyrz\cyrd\cyrii\cyrl}%
        {\CYRR\cyro\cyrz\cyrd\cyrii\cyrl\cyri}%
      \crefname@preamble{appendix}%
        {\CYRD\cyro\cyrd\cyra\cyrt\cyro\cyrk}%
        {\CYRD\cyro\cyrd\cyra\cyrt\cyrk\cyri}%
      \crefname@preamble{footnote}%
        {\CYRV\cyri\cyrn\cyro\cyrs\cyrk\cyra}%
        {\CYRV\cyri\cyrn\cyro\cyrs\cyrk\cyri}%
      \crefname@preamble{theorem}%
        {\CYRT\cyre\cyro\cyrr\cyre\cyrm\cyra}%
        {\CYRT\cyre\cyro\cyrr\cyre\cyrm\cyri}%
      \crefname@preamble{lemma}%
        {\CYRL\cyre\cyrm\cyrm\cyra}%
        {\CYRL\cyre\cyrm\cyrm\cyri}%
      \crefname@preamble{corollary}%
        {\CYRV\cyri\cyrs\cyrn\cyro\cyrv\cyro\cyrk}%
        {\CYRV\cyri\cyrs\cyrn\cyro\cyrv\cyrk\cyri}%
      \crefname@preamble{proposition}%
        {\CYRT\cyrv\cyre\cyrr\cyrd\cyrzh\cyre\cyrn\cyrn\cyrya}%
        {\CYRT\cyrv\cyre\cyrr\cyrd\cyrzh\cyre\cyrn\cyrn\cyrya}%
      \crefname@preamble{definition}%
        {\CYRV\cyri\cyrz\cyrn\cyra\cyrch\cyre\cyrn\cyrn\cyrya}%
        {\CYRV\cyri\cyrz\cyrn\cyra\cyrch\cyre\cyrn\cyrn\cyrya}%
      \crefname@preamble{result}%
        {\CYRR\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt}%
        {\CYRR\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt\cyri}%
      \crefname@preamble{example}%
        {\CYRP\cyrr\cyri\cyrk\cyrl\cyra\cyrd}%
        {\CYRP\cyrr\cyri\cyrk\cyrl\cyra\cyrd\cyri}%
      \crefname@preamble{remark}%
        {\CYRP\cyrr\cyri\cyrm\cyrii\cyrt\cyrk\cyra}%
        {\CYRP\cyrr\cyri\cyrm\cyrii\cyrt\cyrk\cyri}%
      \crefname@preamble{note}%
        {\CYRZ\cyra\cyrm\cyrii\cyrt\cyrk\cyra}%
        {\CYRZ\cyra\cyrm\cyrii\cyrt\cyrk\cyri}%
      \crefname@preamble{algorithm}%
        {\CYRA\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm}%
        {\CYRA\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm\cyri}%
      \crefname@preamble{listing}%
        {\CYRL\cyrii\cyrs\cyrt\cyri\cyrn\cyrg}%
        {\CYRL\cyrii\cyrs\cyrt\cyri\cyrn\cyrg\cyri}%
      \crefname@preamble{line}%
        {\CYRS\cyrt\cyrr\cyro\cyrk\cyra}%
        {\CYRS\cyrt\cyrr\cyro\cyrk\cyri}%
      \crefname@preamble{page}%
        {\CYRS\cyrt\cyro\cyrr\cyri\cyrn\cyrk\cyra}%
        {\CYRS\cyrt\cyro\cyrr\cyrii\cyrn\cyrk\cyri}%
      \crefname@preamble{part}%
        {\CYRCH\cyra\cyrs\cyrt\cyri\cyrn\cyra}%
        {\CYRCH\cyra\cyrs\cyrt\cyri\cyrn\cyri}%
 %
    \else%  capitalise unset
      \if@cref@abbrev%  abbrev set
        \crefname@preamble{equation}%
          {\cyrf-\cyrl.}%
          {\cyrf-\cyrl.}%
        \crefname@preamble{figure}%
          {\cyrr\cyri\cyrs.}%
          {\cyrr\cyri\cyrs.}%
        \crefname@preamble{table}%
          {\cyrt\cyra\cyrb\cyrl.}%
          {\cyrt\cyra\cyrb\cyrl.}%
        \crefname@preamble{enumi}%
          {\cyrp.}%
          {\cyrp.\cyrp.}%
        \crefname@preamble{chapter}%
          {\cyrg\cyrl\cyra\cyrv.}%
          {\cyrg\cyrl\cyra\cyrv.}%
        \crefname@preamble{section}%
          {\cyrr\cyro\cyrz\cyrd.}%
          {\cyrr\cyro\cyrz\cyrd\cyrii\cyrl.}%
        \crefname@preamble{appendix}%
          {\cyrd\cyro\cyrd\cyra\cyrt.}%
          {\cyrd\cyro\cyrd\cyra\cyrt\cyrk.}%
        \crefname@preamble{footnote}%
          {\cyrv\cyri\cyrn\cyro\cyrs\cyrk.}%
          {\cyrv\cyri\cyrn\cyro\cyrs\cyrk.}%
        \crefname@preamble{theorem}%
          {\cyrt\cyre\cyro\cyrr\cyre\cyrm.}%
          {\cyrt\cyre\cyro\cyrr\cyre\cyrm.}%
        \crefname@preamble{lemma}%
          {\cyrl\cyre\cyrm\cyrm.}%
          {\cyrl\cyre\cyrm\cyrm.}%
        \crefname@preamble{corollary}%
          {\cyrv\cyri\cyrs\cyrn\cyro\cyrv.}%
          {\cyrv\cyri\cyrs\cyrn\cyro\cyrv\cyrk.}%
        \crefname@preamble{proposition}%
          {\cyrt\cyrv\cyre\cyrr\cyrd\cyrzh\cyre\cyrn\cyrn.}%
          {\cyrt\cyrv\cyre\cyrr\cyrd\cyrzh\cyre\cyrn\cyrn.}%
        \crefname@preamble{definition}%
          {\cyrv\cyri\cyrz\cyrn\cyra\cyrch\cyre\cyrn\cyrn.}%
          {\cyrv\cyri\cyrz\cyrn\cyra\cyrch\cyre\cyrn\cyrn.}%
        \crefname@preamble{result}%
          {\cyrr\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt.}%
          {\cyrr\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt.}%
        \crefname@preamble{example}%
          {\cyrp\cyrr\cyri\cyrk\cyrl.}%
          {\cyrp\cyrr\cyri\cyrk\cyrl\cyra\cyrd.}%
        \crefname@preamble{remark}%
          {\cyrp\cyrr\cyri\cyrm\cyrii\cyrt.}%
          {\cyrp\cyrr\cyri\cyrm\cyrii\cyrt.}%
        \crefname@preamble{note}%
          {\cyrz\cyra\cyrm\cyrii\cyrt.}%
          {\cyrz\cyra\cyrm\cyrii\cyrt.}%
        \crefname@preamble{algorithm}%
          {\cyra\cyrl\cyrg.}%
          {\cyra\cyrl\cyrg.}%
        \crefname@preamble{listing}%
          {\cyrl\cyrii\cyrs\cyrt\cyri\cyrn.}%
          {\cyrl\cyrii\cyrs\cyrt\cyri\cyrn\cyrg.}%
        \crefname@preamble{line}%
          {\cyrs\cyrt\cyrr\cyrk.}%
          {\cyrs\cyrt\cyrr\cyrk.}%
      \else%  abbrev unset
        \crefname@preamble{equation}%
          {\cyrf\cyro\cyrr\cyrm\cyru\cyrl\cyra}%
          {\cyrf\cyro\cyrr\cyrm\cyru\cyrl\cyri}%
        \crefname@preamble{figure}%
          {\cyrr\cyri\cyrs\cyru\cyrn\cyro\cyrk}%
          {\cyrr\cyri\cyrs\cyru\cyrn\cyrk\cyri}%
        \crefname@preamble{table}%
          {\cyrt\cyra\cyrb\cyrl\cyri\cyrc\cyrya}%
          {\cyrt\cyra\cyrb\cyrl\cyri\cyrc\cyrii}%
        \crefname@preamble{enumi}%
          {\cyrp\cyru\cyrn\cyrk\cyrt}%
          {\cyrp\cyru\cyrn\cyrk\cyrt\cyri}%
        \crefname@preamble{chapter}%
          {\cyrg\cyrl\cyra\cyrv\cyra}%
          {\cyrg\cyrl\cyra\cyrv\cyri}%
        \crefname@preamble{section}%
          {\cyrr\cyro\cyrz\cyrd\cyrii\cyrl}%
          {\cyrr\cyro\cyrz\cyrd\cyrii\cyrl\cyri}%
        \crefname@preamble{appendix}%
          {\cyrd\cyro\cyrd\cyra\cyrt\cyro\cyrk}%
          {\cyrd\cyro\cyrd\cyra\cyrt\cyrk\cyri}%
        \crefname@preamble{footnote}%
          {\cyrv\cyri\cyrn\cyro\cyrs\cyrk\cyra}%
          {\cyrv\cyri\cyrn\cyro\cyrs\cyrk\cyri}%
        \crefname@preamble{theorem}%
          {\cyrt\cyre\cyro\cyrr\cyre\cyrm\cyra}%
          {\cyrt\cyre\cyro\cyrr\cyre\cyrm\cyri}%
        \crefname@preamble{lemma}%
          {\cyrl\cyre\cyrm\cyrm\cyra}%
          {\cyrl\cyre\cyrm\cyrm\cyri}%
        \crefname@preamble{corollary}%
          {\cyrv\cyri\cyrs\cyrn\cyro\cyrv\cyro\cyrk}%
          {\cyrv\cyri\cyrs\cyrn\cyro\cyrv\cyrk\cyri}%
        \crefname@preamble{proposition}%
          {\cyrt\cyrv\cyre\cyrr\cyrd\cyrzh\cyre\cyrn\cyrn\cyrya}%
          {\cyrt\cyrv\cyre\cyrr\cyrd\cyrzh\cyre\cyrn\cyrn\cyrya}%
        \crefname@preamble{definition}%
          {\cyrv\cyri\cyrz\cyrn\cyra\cyrch\cyre\cyrn\cyrn\cyrya}%
          {\cyrv\cyri\cyrz\cyrn\cyra\cyrch\cyre\cyrn\cyrn\cyrya}%
        \crefname@preamble{result}%
          {\cyrr\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt}%
          {\cyrr\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt\cyri}%
        \crefname@preamble{example}%
          {\cyrp\cyrr\cyri\cyrk\cyrl\cyra\cyrd}%
          {\cyrp\cyrr\cyri\cyrk\cyrl\cyra\cyrd\cyri}%
        \crefname@preamble{remark}%
          {\cyrp\cyrr\cyri\cyrm\cyrii\cyrt\cyrk\cyra}%
          {\cyrp\cyrr\cyri\cyrm\cyrii\cyrt\cyrk\cyri}%
        \crefname@preamble{note}%
          {\cyrz\cyra\cyrm\cyrii\cyrt\cyrk\cyra}%
          {\cyrz\cyra\cyrm\cyrii\cyrt\cyrk\cyri}%
        \crefname@preamble{algorithm}%
          {\cyra\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm}%
          {\cyra\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm\cyri}%
        \crefname@preamble{listing}%
          {\cyrl\cyrii\cyrs\cyrt\cyri\cyrn\cyrg}%
          {\cyrl\cyrii\cyrs\cyrt\cyri\cyrn\cyrg\cyri}%
        \crefname@preamble{line}%
          {\cyrs\cyrt\cyrr\cyro\cyrk\cyra}%
          {\cyrs\cyrt\cyrr\cyro\cyrk\cyri}%
      \fi%
      \crefname@preamble{page}%
        {\cyrs\cyrt\cyro\cyrr\cyri\cyrn\cyrc\cyrii}%
        {\cyrs\cyrt\cyro\cyrr\cyrii\cyrn\cyrk\cyra\cyrh}%
      \crefname@preamble{part}%
        {\cyrch\cyra\cyrs\cyrt\cyri\cyrn\cyra}%
        {\cyrch\cyra\cyrs\cyrt\cyri\cyrn\cyri}%
    \fi%
    \def\cref@language{ukrainian}%
  }}% end \DeclareOption and \AtBeginDocument
%    \end{macrocode}
%
% If using \package{babel} and the corresponding option is set, or if
% using \package{polyglossia} and the language has been loaded, add
% format definition commands to \cmd{\extras}\meta{language} or
% \cmd{\captions}\meta{language} so that language switching commands will
% change the cross-reference formats appropriately.
%    \begin{macrocode}
\cref@addlanguagedefs{ukrainian}{%
  \PackageInfo{cleveref}{loaded `ukrainian' language definitions}%
  \renewcommand{\crefrangeconjunction}{--}%
  \renewcommand\crefrangepreconjunction{}%
  \renewcommand\crefrangepostconjunction{}%
  \renewcommand{\crefpairconjunction}{ \cyrii\nobreakspace}%
  \renewcommand{\crefmiddleconjunction}{, }%
  \renewcommand{\creflastconjunction}{ \cyrii\nobreakspace}%
  \renewcommand{\crefpairgroupconjunction}%
    { \cyrt\cyra\nobreakspace}%
  \renewcommand{\crefmiddlegroupconjunction}{, }%
  \renewcommand{\creflastgroupconjunction}%
    {, \cyra\ \cyrt\cyra\cyrk\cyro\cyrzh\nobreakspace}%
 %
    \Crefname{equation}%
    {\CYRF\cyro\cyrr\cyrm\cyru\cyrl\cyra}%
    {\CYRF\cyro\cyrr\cyrm\cyru\cyrl\cyri}%
  \Crefname{figure}%
    {\CYRR\cyri\cyrs\cyru\cyrn\cyro\cyrk}%
    {\CYRR\cyri\cyrs\cyru\cyrn\cyrk\cyri}%
  \Crefname{subfigure}%
    {\CYRR\cyri\cyrs\cyru\cyrn\cyro\cyrk}%
    {\CYRR\cyri\cyrs\cyru\cyrn\cyrk\cyri}%
  \Crefname{table}%
    {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyrya}%
    {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyrii}%
  \Crefname{subtable}%
    {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyrya}%
    {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyrii}%
  \Crefname{enumi}%
    {\CYRP\cyru\cyrn\cyrk\cyrt}%
    {\CYRP\cyru\cyrn\cyrk\cyrt\cyri}%
  \Crefname{enumii}%
    {\CYRP\cyru\cyrn\cyrk\cyrt}%
    {\CYRP\cyru\cyrn\cyrk\cyrt\cyri}%
  \Crefname{enumiii}%
    {\CYRP\cyru\cyrn\cyrk\cyrt}%
    {\CYRP\cyru\cyrn\cyrk\cyrt\cyri}%
  \Crefname{enumiv}%
    {\CYRP\cyru\cyrn\cyrk\cyrt}%
    {\CYRP\cyru\cyrn\cyrk\cyrt\cyri}%
  \Crefname{enumv}%
    {\CYRP\cyru\cyrn\cyrk\cyrt}%
    {\CYRP\cyru\cyrn\cyrk\cyrt\cyri}%
  \Crefname{chapter}%
    {\CYRG\cyrl\cyra\cyrv\cyra}%
    {\CYRG\cyrl\cyra\cyrv\cyri}%
  \Crefname{section}%
    {\CYRR\cyro\cyrz\cyrd\cyrii\cyrl}%
    {\CYRR\cyro\cyrz\cyrd\cyrii\cyrl\cyri}%
  \Crefname{subsection}%
    {\CYRR\cyro\cyrz\cyrd\cyrii\cyrl}%
    {\CYRR\cyro\cyrz\cyrd\cyrii\cyrl\cyri}%
  \Crefname{subsubsection}%
    {\CYRR\cyro\cyrz\cyrd\cyrii\cyrl}%
    {\CYRR\cyro\cyrz\cyrd\cyrii\cyrl\cyri}%
  \Crefname{appendix}%
    {\CYRD\cyro\cyrd\cyra\cyrt\cyro\cyrk}%
    {\CYRD\cyro\cyrd\cyra\cyrt\cyrk\cyri}%
  \Crefname{subappendix}%
    {\CYRD\cyro\cyrd\cyra\cyrt\cyro\cyrk}%
    {\CYRD\cyro\cyrd\cyra\cyrt\cyrk\cyri}%
  \Crefname{subsubappendix}%
    {\CYRD\cyro\cyrd\cyra\cyrt\cyro\cyrk}%
    {\CYRD\cyro\cyrd\cyra\cyrt\cyrk\cyri}%
  \Crefname{subsubsubappendix}%
    {\CYRD\cyro\cyrd\cyra\cyrt\cyro\cyrk}%
    {\CYRD\cyro\cyrd\cyra\cyrt\cyrk\cyri}%
  \Crefname{footnote}%
    {\CYRV\cyri\cyrn\cyro\cyrs\cyrk\cyra}%
    {\CYRV\cyri\cyrn\cyro\cyrs\cyrk\cyri}%
  \Crefname{theorem}%
    {\CYRT\cyre\cyro\cyrr\cyre\cyrm\cyra}%
    {\CYRT\cyre\cyro\cyrr\cyre\cyrm\cyri}%
  \Crefname{lemma}%
    {\CYRL\cyre\cyrm\cyrm\cyra}%
    {\CYRL\cyre\cyrm\cyrm\cyri}%
  \Crefname{corollary}%
    {\CYRV\cyri\cyrs\cyrn\cyro\cyrv\cyro\cyrk}%
    {\CYRV\cyri\cyrs\cyrn\cyro\cyrv\cyrk\cyri}%
  \Crefname{proposition}%
    {\CYRT\cyrv\cyre\cyrr\cyrd\cyrzh\cyre\cyrn\cyrn\cyrya}%
    {\CYRT\cyrv\cyre\cyrr\cyrd\cyrzh\cyre\cyrn\cyrn\cyrya}%
  \Crefname{definition}%
    {\CYRV\cyri\cyrz\cyrn\cyra\cyrch\cyre\cyrn\cyrn\cyrya}%
    {\CYRV\cyri\cyrz\cyrn\cyra\cyrch\cyre\cyrn\cyrn\cyrya}%
  \Crefname{result}%
    {\CYRR\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt}%
    {\CYRR\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt\cyri}%
  \Crefname{example}%
    {\CYRP\cyrr\cyri\cyrk\cyrl\cyra\cyrd}%
    {\CYRP\cyrr\cyri\cyrk\cyrl\cyra\cyrd\cyri}%
  \Crefname{remark}%
    {\CYRP\cyrr\cyri\cyrm\cyrii\cyrt\cyrk\cyra}%
    {\CYRP\cyrr\cyri\cyrm\cyrii\cyrt\cyrk\cyri}%
  \Crefname{note}%
    {\CYRZ\cyra\cyrm\cyrii\cyrt\cyrk\cyra}%
    {\CYRZ\cyra\cyrm\cyrii\cyrt\cyrk\cyri}%
  \Crefname{algorithm}%
    {\CYRA\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm}%
    {\CYRA\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm\cyri}%
  \Crefname{listing}%
    {\CYRL\cyrii\cyrs\cyrt\cyri\cyrn\cyrg}%
    {\CYRL\cyrii\cyrs\cyrt\cyri\cyrn\cyrg\cyri}%
  \Crefname{line}%
    {\CYRS\cyrt\cyrr\cyro\cyrk\cyra}%
    {\CYRS\cyrt\cyrr\cyro\cyrk\cyri}%
  \Crefname{page}%
    {\CYRS\cyrt\cyro\cyrr\cyri\cyrn\cyrk\cyra}%
    {\CYRS\cyrt\cyro\cyrr\cyrii\cyrn\cyrk\cyri}%
  \Crefname{part}%
    {\CYRCH\cyra\cyrs\cyrt\cyri\cyrn\cyra}%
    {\CYRCH\cyra\cyrs\cyrt\cyri\cyrn\cyri}%
 %
  \if@cref@capitalise%  capitalise set
    \if@cref@abbrev%  abbrev set
      \crefname{equation}%
        {\CYRF-\cyrl.}%
        {\CYRF-\cyrl.}%
      \crefname{figure}%
        {\CYRR\cyri\cyrs.}%
        {\CYRR\cyri\cyrs.}%
      \crefname{subfigure}%
        {\CYRR\cyri\cyrs.}%
        {\CYRR\cyri\cyrs.}%
      \crefname{table}%
        {\CYRT\cyra\cyrb\cyrl.}%
        {\CYRT\cyra\cyrb\cyrl.}%
      \crefname{subtable}%
        {\CYRT\cyra\cyrb\cyrl.}%
        {\CYRT\cyra\cyrb\cyrl.}%
      \crefname{enumi}%
        {\CYRP.}%
        {\CYRP.\cyrp.}%
      \crefname{enumii}%
        {\CYRP.}%
        {\CYRP.\cyrp.}%
      \crefname{enumiii}%
        {\CYRP.}%
        {\CYRP.\cyrp.}%
      \crefname{enumiv}%
        {\CYRP.}%
        {\CYRP.\cyrp.}%
      \crefname{enumv}%
        {\CYRP.}%
        {\CYRP.\cyrp.}%
    \else%  abbrev unset
      \crefname{equation}%
        {\CYRF\cyro\cyrr\cyrm\cyru\cyrl\cyra}%
        {\CYRF\cyro\cyrr\cyrm\cyru\cyrl\cyri}%
      \crefname{figure}%
        {\CYRR\cyri\cyrs\cyru\cyrn\cyro\cyrk}%
        {\CYRR\cyri\cyrs\cyru\cyrn\cyrk\cyri}%
      \crefname{subfigure}%
        {\CYRR\cyri\cyrs\cyru\cyrn\cyro\cyrk}%
        {\CYRR\cyri\cyrs\cyru\cyrn\cyrk\cyri}%
      \crefname{table}%
        {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyrya}%
        {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyrii}%
      \crefname{subtable}%
        {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyrya}%
        {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyrii}%
      \crefname{enumi}%
        {\CYRP\cyru\cyrn\cyrk\cyrt}%
        {\CYRP\cyru\cyrn\cyrk\cyrt\cyri}%
      \crefname{enumii}%
        {\CYRP\cyru\cyrn\cyrk\cyrt}%
        {\CYRP\cyru\cyrn\cyrk\cyrt\cyri}%
      \crefname{enumiii}%
        {\CYRP\cyru\cyrn\cyrk\cyrt}%
        {\CYRP\cyru\cyrn\cyrk\cyrt\cyri}%
      \crefname{enumiv}%
        {\CYRP\cyru\cyrn\cyrk\cyrt}%
        {\CYRP\cyru\cyrn\cyrk\cyrt\cyri}%
      \crefname{enumv}%
        {\CYRP\cyru\cyrn\cyrk\cyrt}%
        {\CYRP\cyru\cyrn\cyrk\cyrt\cyri}%
    \fi%
    \crefname{chapter}%
      {\CYRG\cyrl\cyra\cyrv\cyra}%
      {\CYRG\cyrl\cyra\cyrv\cyri}%
    \crefname{section}%
      {\CYRR\cyro\cyrz\cyrd\cyrii\cyrl}%
      {\CYRR\cyro\cyrz\cyrd\cyrii\cyrl\cyri}%
    \crefname{subsection}%
      {\CYRR\cyro\cyrz\cyrd\cyrii\cyrl}%
      {\CYRR\cyro\cyrz\cyrd\cyrii\cyrl\cyri}%
    \crefname{subsubsection}%
      {\CYRR\cyro\cyrz\cyrd\cyrii\cyrl}%
      {\CYRR\cyro\cyrz\cyrd\cyrii\cyrl\cyri}%
    \crefname{appendix}%
      {\CYRD\cyro\cyrd\cyra\cyrt\cyro\cyrk}%
      {\CYRD\cyro\cyrd\cyra\cyrt\cyrk\cyri}%
    \crefname{subappendix}%
      {\CYRD\cyro\cyrd\cyra\cyrt\cyro\cyrk}%
      {\CYRD\cyro\cyrd\cyra\cyrt\cyrk\cyri}%
    \crefname{subsubappendix}%
      {\CYRD\cyro\cyrd\cyra\cyrt\cyro\cyrk}%
      {\CYRD\cyro\cyrd\cyra\cyrt\cyrk\cyri}%
    \crefname{subsubsubappendix}%
      {\CYRD\cyro\cyrd\cyra\cyrt\cyro\cyrk}%
      {\CYRD\cyro\cyrd\cyra\cyrt\cyrk\cyri}%
    \crefname{footnote}%
      {\CYRV\cyri\cyrn\cyro\cyrs\cyrk\cyra}%
      {\CYRV\cyri\cyrn\cyro\cyrs\cyrk\cyri}%
    \crefname{theorem}%
      {\CYRT\cyre\cyro\cyrr\cyre\cyrm\cyra}%
      {\CYRT\cyre\cyro\cyrr\cyre\cyrm\cyri}%
    \crefname{lemma}%
      {\CYRL\cyre\cyrm\cyrm\cyra}%
      {\CYRL\cyre\cyrm\cyrm\cyri}%
    \crefname{corollary}%
      {\CYRV\cyri\cyrs\cyrn\cyro\cyrv\cyro\cyrk}%
      {\CYRV\cyri\cyrs\cyrn\cyro\cyrv\cyrk\cyri}%
    \crefname{proposition}%
      {\CYRT\cyrv\cyre\cyrr\cyrd\cyrzh\cyre\cyrn\cyrn\cyrya}%
      {\CYRT\cyrv\cyre\cyrr\cyrd\cyrzh\cyre\cyrn\cyrn\cyrya}%
    \crefname{definition}%
      {\CYRV\cyri\cyrz\cyrn\cyra\cyrch\cyre\cyrn\cyrn\cyrya}%
      {\CYRV\cyri\cyrz\cyrn\cyra\cyrch\cyre\cyrn\cyrn\cyrya}%
    \crefname{result}%
      {\CYRR\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt}%
      {\CYRR\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt\cyri}%
    \crefname{example}%
      {\CYRP\cyrr\cyri\cyrk\cyrl\cyra\cyrd}%
      {\CYRP\cyrr\cyri\cyrk\cyrl\cyra\cyrd\cyri}%
    \crefname{remark}%
      {\CYRP\cyrr\cyri\cyrm\cyrii\cyrt\cyrk\cyra}%
      {\CYRP\cyrr\cyri\cyrm\cyrii\cyrt\cyrk\cyri}%
    \crefname{note}%
      {\CYRZ\cyra\cyrm\cyrii\cyrt\cyrk\cyra}%
      {\CYRZ\cyra\cyrm\cyrii\cyrt\cyrk\cyri}%
    \crefname{algorithm}%
      {\CYRA\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm}%
      {\CYRA\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm\cyri}%
    \crefname{listing}%
      {\CYRL\cyrii\cyrs\cyrt\cyri\cyrn\cyrg}%
      {\CYRL\cyrii\cyrs\cyrt\cyri\cyrn\cyrg\cyri}%
    \crefname{line}%
      {\CYRS\cyrt\cyrr\cyro\cyrk\cyra}%
      {\CYRS\cyrt\cyrr\cyro\cyrk\cyri}%
    \crefname{page}%
      {\CYRS\cyrt\cyro\cyrr\cyri\cyrn\cyrk\cyra}%
      {\CYRS\cyrt\cyro\cyrr\cyrii\cyrn\cyrk\cyri}%
    \crefname{part}%
      {\CYRCH\cyra\cyrs\cyrt\cyri\cyrn\cyra}%
      {\CYRCH\cyra\cyrs\cyrt\cyri\cyrn\cyri}%
 %
  \else%  capitalise unset
    \if@cref@abbrev%  abbrev set
      \crefname{equation}%
        {\cyrf-\cyrl.}%
        {\cyrf-\cyrl.}%
      \crefname{chapter}%
        {\cyrg\cyrl\cyra\cyrv.}%
        {\cyrg\cyrl\cyra\cyrv.}%
      \crefname{section}%
        {\cyrr\cyro\cyrz\cyrd.}%
        {\cyrr\cyro\cyrz\cyrd\cyrii\cyrl.}%
      \crefname{subsection}%
        {\cyrr\cyro\cyrz\cyrd.}%
        {\cyrr\cyro\cyrz\cyrd\cyrii\cyrl.}%
      \crefname{subsubsection}%
        {\cyrr\cyro\cyrz\cyrd.}%
        {\cyrr\cyro\cyrz\cyrd\cyrii\cyrl.}%
      \crefname{appendix}%
        {\cyrd\cyro\cyrd\cyra\cyrt.}%
        {\cyrd\cyro\cyrd\cyra\cyrt\cyrk.}%
      \crefname{subappendix}%
        {\cyrd\cyro\cyrd\cyra\cyrt.}%
        {\cyrd\cyro\cyrd\cyra\cyrt\cyrk.}%
      \crefname{subsubappendix}%
        {\cyrd\cyro\cyrd\cyra\cyrt.}%
        {\cyrd\cyro\cyrd\cyra\cyrt\cyrk.}%
      \crefname{subsubsubappendix}%
        {\cyrd\cyro\cyrd\cyra\cyrt.}%
        {\cyrd\cyro\cyrd\cyra\cyrt\cyrk.}%
      \crefname{enumi}%
        {\cyrp.}%
        {\cyrp.\cyrp.}%
      \crefname{enumii}%
        {\cyrp.}%
        {\cyrp.\cyrp.}%
      \crefname{enumiii}%
        {\cyrp.}%
        {\cyrp.\cyrp.}%
      \crefname{enumiv}%
        {\cyrp.}%
        {\cyrp.\cyrp.}%
      \crefname{enumv}%
        {\cyrp.}%
        {\cyrp.\cyrp.}%
      \crefname{footnote}%
        {\cyrv\cyri\cyrn\cyro\cyrs\cyrk.}%
        {\cyrv\cyri\cyrn\cyro\cyrs\cyrk.}%
      \crefname{figure}%
        {\cyrr\cyri\cyrs.}%
        {\cyrr\cyri\cyrs.}%
      \crefname{subfigure}%
        {\cyrr\cyri\cyrs.}%
        {\cyrr\cyri\cyrs.}%
      \crefname{table}%
        {\cyrt\cyra\cyrb\cyrl.}%
        {\cyrt\cyra\cyrb\cyrl.}%
      \crefname{subtable}%
        {\cyrt\cyra\cyrb\cyrl.}%
        {\cyrt\cyra\cyrb\cyrl.}%
      \crefname{theorem}%
        {\cyrt\cyre\cyro\cyrr\cyre\cyrm.}%
        {\cyrt\cyre\cyro\cyrr\cyre\cyrm.}%
      \crefname{lemma}%
        {\cyrl\cyre\cyrm\cyrm.}%
        {\cyrl\cyre\cyrm\cyrm.}%
      \crefname{corollary}%
        {\cyrv\cyri\cyrs\cyrn\cyro\cyrv.}%
        {\cyrv\cyri\cyrs\cyrn\cyro\cyrv\cyrk.}%
      \crefname{proposition}%
        {\cyrt\cyrv\cyre\cyrr\cyrd\cyrzh\cyre\cyrn\cyrn.}%
        {\cyrt\cyrv\cyre\cyrr\cyrd\cyrzh\cyre\cyrn\cyrn.}%
      \crefname{definition}%
        {\cyrv\cyri\cyrz\cyrn\cyra\cyrch\cyre\cyrn\cyrn.}%
        {\cyrv\cyri\cyrz\cyrn\cyra\cyrch\cyre\cyrn\cyrn.}%
      \crefname{result}%
        {\cyrr\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt.}%
        {\cyrr\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt.}%
      \crefname{example}%
        {\cyrp\cyrr\cyri\cyrk\cyrl.}%
        {\cyrp\cyrr\cyri\cyrk\cyrl\cyra\cyrd.}%
      \crefname{remark}%
        {\cyrp\cyrr\cyri\cyrm\cyrii\cyrt.}%
        {\cyrp\cyrr\cyri\cyrm\cyrii\cyrt.}%
      \crefname{note}%
        {\cyrz\cyra\cyrm\cyrii\cyrt.}%
        {\cyrz\cyra\cyrm\cyrii\cyrt.}%
      \crefname{algorithm}%
        {\cyra\cyrl\cyrg.}%
        {\cyra\cyrl\cyrg.}%
      \crefname{listing}%
        {\cyrl\cyrii\cyrs\cyrt\cyri\cyrn.}%
        {\cyrl\cyrii\cyrs\cyrt\cyri\cyrn\cyrg.}%
      \crefname{line}%
        {\cyrs\cyrt\cyrr\cyrk.}%
        {\cyrs\cyrt\cyrr\cyrk.}%
    \else%  abbrev unset
      \crefname{equation}%
        {\cyrf\cyro\cyrr\cyrm\cyru\cyrl\cyra}%
        {\cyrf\cyro\cyrr\cyrm\cyru\cyrl\cyri}%
      \crefname{figure}%
        {\cyrr\cyri\cyrs\cyru\cyrn\cyro\cyrk}%
        {\cyrr\cyri\cyrs\cyru\cyrn\cyrk\cyri}%
      \crefname{subfigure}%
        {\cyrr\cyri\cyrs\cyru\cyrn\cyro\cyrk}%
        {\cyrr\cyri\cyrs\cyru\cyrn\cyrk\cyri}%
      \crefname{table}%
        {\cyrt\cyra\cyrb\cyrl\cyri\cyrc\cyrya}%
        {\cyrt\cyra\cyrb\cyrl\cyri\cyrc\cyrii}%
      \crefname{subtable}%
        {\cyrt\cyra\cyrb\cyrl\cyri\cyrc\cyrya}%
        {\cyrt\cyra\cyrb\cyrl\cyri\cyrc\cyrii}%
      \crefname{enumi}%
        {\cyrp\cyru\cyrn\cyrk\cyrt}%
        {\cyrp\cyru\cyrn\cyrk\cyrt\cyri}%
      \crefname{enumii}%
        {\cyrp\cyru\cyrn\cyrk\cyrt}%
        {\cyrp\cyru\cyrn\cyrk\cyrt\cyri}%
      \crefname{enumiii}%
        {\cyrp\cyru\cyrn\cyrk\cyrt}%
        {\cyrp\cyru\cyrn\cyrk\cyrt\cyri}%
      \crefname{enumiv}%
        {\cyrp\cyru\cyrn\cyrk\cyrt}%
        {\cyrp\cyru\cyrn\cyrk\cyrt\cyri}%
      \crefname{enumv}%
        {\cyrp\cyru\cyrn\cyrk\cyrt}%
        {\cyrp\cyru\cyrn\cyrk\cyrt\cyri}%
      \crefname{chapter}%
        {\cyrg\cyrl\cyra\cyrv\cyra}%
        {\cyrg\cyrl\cyra\cyrv\cyri}%
      \crefname{section}%
        {\cyrr\cyro\cyrz\cyrd\cyrii\cyrl}%
        {\cyrr\cyro\cyrz\cyrd\cyrii\cyrl\cyri}%
      \crefname{subsection}%
        {\cyrr\cyro\cyrz\cyrd\cyrii\cyrl}%
        {\cyrr\cyro\cyrz\cyrd\cyrii\cyrl\cyri}%
      \crefname{subsubsection}%
        {\cyrr\cyro\cyrz\cyrd\cyrii\cyrl}%
        {\cyrr\cyro\cyrz\cyrd\cyrii\cyrl\cyri}%
      \crefname{appendix}%
        {\cyrd\cyro\cyrd\cyra\cyrt\cyro\cyrk}%
        {\cyrd\cyro\cyrd\cyra\cyrt\cyrk\cyri}%
      \crefname{subappendix}%
        {\cyrd\cyro\cyrd\cyra\cyrt\cyro\cyrk}%
        {\cyrd\cyro\cyrd\cyra\cyrt\cyrk\cyri}%
      \crefname{subsubappendix}%
        {\cyrd\cyro\cyrd\cyra\cyrt\cyro\cyrk}%
        {\cyrd\cyro\cyrd\cyra\cyrt\cyrk\cyri}%
      \crefname{subsubsubappendix}%
        {\cyrd\cyro\cyrd\cyra\cyrt\cyro\cyrk}%
        {\cyrd\cyro\cyrd\cyra\cyrt\cyrk\cyri}%
      \crefname{footnote}%
        {\cyrv\cyri\cyrn\cyro\cyrs\cyrk\cyra}%
        {\cyrv\cyri\cyrn\cyro\cyrs\cyrk\cyri}%
      \crefname{theorem}%
        {\cyrt\cyre\cyro\cyrr\cyre\cyrm\cyra}%
        {\cyrt\cyre\cyro\cyrr\cyre\cyrm\cyri}%
      \crefname{lemma}%
        {\cyrl\cyre\cyrm\cyrm\cyra}%
        {\cyrl\cyre\cyrm\cyrm\cyri}%
      \crefname{corollary}%
        {\cyrv\cyri\cyrs\cyrn\cyro\cyrv\cyro\cyrk}%
        {\cyrv\cyri\cyrs\cyrn\cyro\cyrv\cyrk\cyri}%
      \crefname{proposition}%
        {\cyrt\cyrv\cyre\cyrr\cyrd\cyrzh\cyre\cyrn\cyrn\cyrya}%
        {\cyrt\cyrv\cyre\cyrr\cyrd\cyrzh\cyre\cyrn\cyrn\cyrya}%
      \crefname{definition}%
        {\cyrv\cyri\cyrz\cyrn\cyra\cyrch\cyre\cyrn\cyrn\cyrya}%
        {\cyrv\cyri\cyrz\cyrn\cyra\cyrch\cyre\cyrn\cyrn\cyrya}%
      \crefname{result}%
        {\cyrr\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt}%
        {\cyrr\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt\cyri}%
      \crefname{example}%
        {\cyrp\cyrr\cyri\cyrk\cyrl\cyra\cyrd}%
        {\cyrp\cyrr\cyri\cyrk\cyrl\cyra\cyrd\cyri}%
      \crefname{remark}%
        {\cyrp\cyrr\cyri\cyrm\cyrii\cyrt\cyrk\cyra}%
        {\cyrp\cyrr\cyri\cyrm\cyrii\cyrt\cyrk\cyri}%
      \crefname{note}%
        {\cyrz\cyra\cyrm\cyrii\cyrt\cyrk\cyra}%
        {\cyrz\cyra\cyrm\cyrii\cyrt\cyrk\cyri}%
      \crefname{algorithm}%
        {\cyra\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm}%
        {\cyra\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm\cyri}%
      \crefname{listing}%
        {\cyrl\cyrii\cyrs\cyrt\cyri\cyrn\cyrg}%
        {\cyrl\cyrii\cyrs\cyrt\cyri\cyrn\cyrg\cyri}%
      \crefname{line}%
        {\cyrs\cyrt\cyrr\cyro\cyrk\cyra}%
        {\cyrs\cyrt\cyrr\cyro\cyrk\cyri}%
    \fi%
    \crefname{page}%
      {\cyrs\cyrt\cyro\cyrr\cyri\cyrn\cyrc\cyrii}%
      {\cyrs\cyrt\cyro\cyrr\cyrii\cyrn\cyrk\cyra\cyrh}%
    \crefname{part}%
      {\cyrch\cyra\cyrs\cyrt\cyri\cyrn\cyra}%
      {\cyrch\cyra\cyrs\cyrt\cyri\cyrn\cyri}%
  \fi}% end \cref@loadlanguagedefs
%    \end{macrocode}
%
%
%  \subsubsection{Norwegian}
% \begin{macro}{norsk}
%   Norwegian translations kindly donated by Sveinung Heggen.
% \end{macro}
%
% Set up the definitions used at the beginning of the document to define
% the formats created by the document preamble.
%    \begin{macrocode}
\DeclareOption{norsk}{%
  \AtBeginDocument{%
    \def\crefrangeconjunction@preamble{ til\nobreakspace}%
    \def\crefrangepreconjunction@preamble{}%
    \def\crefrangepostconjunction@preamble{}%
    \def\crefpairconjunction@preamble{ og\nobreakspace}%
    \def\crefmiddleconjunction@preamble{, }%
    \def\creflastconjunction@preamble{ og\nobreakspace}%
%    \end{macrocode}
% We have to define the group conjunctions explicitly here, rather than
% relying on fall-back definitions in terms of the above conjunctions
% (see \cref{sec:code:default_formats}), in case any other language
% option defines them explicitly and we need to override those.
%    \begin{macrocode}
    \def\crefpairgroupconjunction@preamble{ og\nobreakspace}%
    \def\crefmiddlegroupconjunction@preamble{, }%
    \def\creflastgroupconjunction@preamble{ og\nobreakspace}%
 %
    \Crefname@preamble{equation}{Likning}{Likningene}%
    \Crefname@preamble{figure}{Figur}{Figurene}%
    \Crefname@preamble{table}{Tabell}{Tabellene}%
    \Crefname@preamble{page}{Side}{Siden}%
    \Crefname@preamble{part}{Del}{Delene}%
    \Crefname@preamble{chapter}{Kapittel}{Kapitlene}%
    \Crefname@preamble{section}{Avsnitt}{Avsnittene}%
    \Crefname@preamble{appendix}{Tillegg}{Tilleggene}%
    \Crefname@preamble{enumi}{Punkt}{Punktene}%
    \Crefname@preamble{footnote}{Fotnote}{Fotnotene}%
    \Crefname@preamble{theorem}{Teorem}{Teoremene}%
    \Crefname@preamble{lemma}{Lemma}{Lemma}%
    \Crefname@preamble{corollary}{Korollar}{Korollarene}%
    \Crefname@preamble{proposition}{P\aa stand}{P\aa standene}%
    \Crefname@preamble{definition}{Definisjon}{Definisjonene}%
    \Crefname@preamble{result}{Resultat}{Resultatene}%
    \Crefname@preamble{example}{Eksempel}{Eksemplene}%
    \Crefname@preamble{remark}{Bemerkning}{Bemerkningene}%
    \Crefname@preamble{note}{Note}{Notene}%
    \Crefname@preamble{algorithm}{Algoritme}{Algoritmene}%
    \Crefname@preamble{listing}{Opplisting}{Opplistingene}%
    \Crefname@preamble{line}{Linje}{Linjene}%
 %
    \if@cref@capitalise%
      \crefname@preamble{page}{Side}{Siden}%
      \crefname@preamble{equation}{Likning}{Likningene}%
      \crefname@preamble{figure}{Figur}{Figurene}%
      \crefname@preamble{table}{Tabell}{Tabellene}%
      \crefname@preamble{part}{Del}{Delene}%
      \crefname@preamble{chapter}{Kapittel}{Kapitlene}%
      \crefname@preamble{section}{Avsnitt}{Avsnittene}%
      \crefname@preamble{appendix}{Tillegg}{Tilleggene}%
      \crefname@preamble{enumi}{Punkt}{Punktene}%
      \crefname@preamble{footnote}{Fotnote}{Fotnotene}%
      \crefname@preamble{theorem}{Teorem}{Teoremene}%
      \crefname@preamble{lemma}{Lemma}{Lemma}%
      \crefname@preamble{corollary}{Korollar}{Korollarene}%
      \crefname@preamble{proposition}{P\aa stand}{P\aa standene}%
      \crefname@preamble{definition}{Definisjon}{Definisjonene}%
      \crefname@preamble{result}{Resultat}{Resultatene}%
      \crefname@preamble{example}{Eksempel}{Eksemplene}%
      \crefname@preamble{remark}{Bemerkning}{Bemerkningene}%
      \crefname@preamble{note}{Note}{Notene}%
      \crefname@preamble{algorithm}{Algoritme}{Algoritmene}%
      \crefname@preamble{listing}{Opplisting}{Opplistingene}%
      \crefname@preamble{line}{Linje}{Linjene}%
 %
    \else%
      \crefname@preamble{equation}{likning}{likningene}%
      \crefname@preamble{figure}{figur}{figurene}%
      \crefname@preamble{table}{tabell}{tabeller}%
      \crefname@preamble{page}{side}{siden}%
      \crefname@preamble{part}{del}{delene}%
      \crefname@preamble{chapter}{kapittel}{kapitlene}%
      \crefname@preamble{section}{avsnitt}{avsnittene}%
      \crefname@preamble{appendix}{tillegg}{tilleggene}%
      \crefname@preamble{enumi}{punkt}{punktene}%
      \crefname@preamble{footnote}{fotnote}{fotnotene}%
      \crefname@preamble{theorem}{teorem}{teoremene}%
      \crefname@preamble{lemma}{lemma}{lemma}%
      \crefname@preamble{corollary}{korollar}{korollarene}%
      \crefname@preamble{proposition}{p\aa stand}{p\aa standene}%
      \crefname@preamble{definition}{definisjon}{definisjonene}%
      \crefname@preamble{result}{resultat}{resultatene}%
      \crefname@preamble{example}{eksempel}{eksemplene}%
      \crefname@preamble{remark}{bemerkning}{bemerkningene}%
      \crefname@preamble{note}{note}{notene}%
      \crefname@preamble{algorithm}{algoritme}{algoritmene}%
      \crefname@preamble{listing}{opplisting}{opplistingene}%
      \crefname@preamble{line}{linje}{linjene}%
    \fi%
    \def\cref@language{norsk}%
  }}% end \DeclareOption and \AtBeginDocument
%    \end{macrocode}
%
% If using \package{babel} and the corresponding option is set, or if
% using \package{polyglossia} and the language has been loaded, add
% format definition commands to \cmd{\extras}\meta{language} or
% \cmd{\captions}\meta{language} so that language switching commands will
% change the cross-reference formats appropriately.
%    \begin{macrocode}
\cref@addlanguagedefs{norsk}{%
  \PackageInfo{cleveref}{loaded `norsk' language definitions}%
  \renewcommand{\crefrangeconjunction}{ til\nobreakspace}%
  \renewcommand\crefrangepreconjunction{}%
  \renewcommand\crefrangepostconjunction{}%
  \renewcommand{\crefpairconjunction}{ og\nobreakspace}%
  \renewcommand{\crefmiddleconjunction}{, }%
  \renewcommand{\creflastconjunction}{ og\nobreakspace}%
  \renewcommand{\crefpairgroupconjunction}{ og\nobreakspace}%
  \renewcommand{\crefmiddlegroupconjunction}{, }%
  \renewcommand{\creflastgroupconjunction}{ og\nobreakspace}%
 %
  \Crefname{equation}{Likning}{Likningene}%
  \Crefname{figure}{Figur}{Figurene}%
  \Crefname{subfigure}{Figur}{Figurene}%
  \Crefname{table}{Tabell}{Tabellene}%
  \Crefname{subtable}{Tabell}{Tabellene}%
  \Crefname{page}{Side}{Siden}%
  \Crefname{part}{Del}{Delene}%
  \Crefname{chapter}{Kapittel}{Kapitlene}%
  \Crefname{section}{Avsnitt}{Avsnittene}%
  \Crefname{subsection}{Avsnitt}{Avsnittene}%
  \Crefname{subsubsection}{Avsnitt}{Avsnittene}%
  \Crefname{appendix}{Tillegg}{Tilleggene}%
  \Crefname{subappendix}{Tillegg}{Tilleggene}%
  \Crefname{subsubappendix}{Tillegg}{Tilleggene}%
  \Crefname{subsubsubappendix}{Tillegg}{Tilleggene}%
  \Crefname{enumi}{Punkt}{Punktene}%
  \Crefname{enumii}{Punkt}{Punktene}%
  \Crefname{enumiii}{Punkt}{Punktene}%
  \Crefname{enumiv}{Punkt}{Punktene}%
  \Crefname{enumv}{Punkt}{Punktene}%
  \Crefname{footnote}{Fotnote}{Fotnotene}%
  \Crefname{theorem}{Teorem}{Teoremene}%
  \Crefname{lemma}{Lemma}{Lemma}%
  \Crefname{corollary}{Korollar}{Korollarene}%
  \Crefname{proposition}{P\aa stand}{P\aa standene}%
  \Crefname{definition}{Definisjon}{Definisjonene}%
  \Crefname{result}{Resultat}{Resultatene}%
  \Crefname{example}{Eksempel}{Eksemplene}%
  \Crefname{remark}{Bemerkning}{Bemerkningene}%
  \Crefname{note}{Note}{Notene}%
  \Crefname{algorithm}{Algoritme}{Algoritmene}%
  \Crefname{listing}{Opplisting}{Opplistingene}%
  \Crefname{line}{Linje}{Linjene}%
 %
  \if@cref@capitalise%
    \crefname{equation}{Likning}{Likningene}%
    \crefname{figure}{Figur}{Figurene}%
    \crefname{subfigure}{Figur}{Figurene}%
    \crefname{table}{Tabell}{Tabellene}%
    \crefname{subtable}{Tabell}{Tabellene}%
    \crefname{page}{Side}{Siden}%
    \crefname{part}{Del}{Delene}%
    \crefname{chapter}{Kapittel}{Kapitlene}%
    \crefname{section}{Avsnitt}{Avsnittene}%
    \crefname{subsection}{Avsnitt}{Avsnittene}%
    \crefname{subsubsection}{Avsnitt}{Avsnittene}%
    \crefname{appendix}{Tillegg}{Tilleggene}%
    \crefname{subappendix}{Tillegg}{Tilleggene}%
    \crefname{subsubappendix}{Tillegg}{Tilleggene}%
    \crefname{subsubsubappendix}{Tillegg}{Tilleggene}%
    \crefname{enumi}{Punkt}{Punktene}%
    \crefname{enumii}{Punkt}{Punktene}%
    \crefname{enumiii}{Punkt}{Punktene}%
    \crefname{enumiv}{Punkt}{Punktene}%
    \crefname{enumv}{Punkt}{Punktene}%
    \crefname{footnote}{Fotnote}{Fotnotene}%
    \crefname{theorem}{Teorem}{Teoremene}%
    \crefname{lemma}{Lemma}{Lemma}%
    \crefname{corollary}{Korollar}{Korollarene}%
    \crefname{proposition}{P\aa stand}{P\aa standene}%
    \crefname{definition}{Definisjon}{Definisjonene}%
    \crefname{result}{Resultat}{Resultatene}%
    \crefname{example}{Eksempel}{Eksemplene}%
    \crefname{remark}{Bemerkning}{Bemerkningene}%
    \crefname{note}{Note}{Notene}%
    \crefname{algorithm}{Algoritme}{Algoritmene}%
    \crefname{listing}{Opplisting}{Opplistingene}%
    \crefname{line}{Linje}{Linjene}%
 %
  \else%
    \crefname{equation}{likning}{likningene}%
    \crefname{figure}{figur}{figurene}%
    \crefname{subfigure}{figur}{figurene}%
    \crefname{table}{tabell}{tabellene}%
    \crefname{subtable}{tabell}{tabellene}%
    \crefname{page}{side}{siden}%
    \crefname{part}{del}{delene}%
    \crefname{chapter}{kapittel}{kapitlene}%
    \crefname{section}{avsnitt}{avsnittene}%
    \crefname{subsection}{avsnitt}{avsnittene}%
    \crefname{subsubsection}{avsnitt}{avsnittene}%
    \crefname{appendix}{tillegg}{tilleggene}%
    \crefname{subappendix}{tillegg}{tilleggene}%
    \crefname{subsubappendix}{tillegg}{tilleggene}%
    \crefname{subsubsubappendix}{tillegg}{tilleggene}%
    \crefname{enumi}{punkt}{punktene}%
    \crefname{enumii}{punkt}{punktene}%
    \crefname{enumiii}{punkt}{punktene}%
    \crefname{enumiv}{punkt}{punktene}%
    \crefname{enumv}{punkt}{punktene}%
    \crefname{footnote}{fotnote}{fotnotene}%
    \crefname{theorem}{teorem}{teoremene}%
    \crefname{lemma}{lemma}{lemma}%
    \crefname{corollary}{korollar}{korollarene}%
    \crefname{proposition}{p\aa stand}{p\aa standene}%
    \crefname{definition}{definisjon}{definisjonene}%
    \crefname{result}{resultat}{resultatene}%
    \crefname{example}{eksempel}{eksemplene}%
    \crefname{remark}{bemerkning}{bemerkningene}%
    \crefname{note}{note}{notene}%
    \crefname{algorithm}{algoritme}{algoritmene}%
    \crefname{listing}{opplisting}{opplistingene}%
    \crefname{line}{linje}{linjene}%
  \fi}% end \cref@loadlanguagedefs
%    \end{macrocode}
%
%
% \subsubsection{Danish}
% \begin{macro}{danish}
%   Danish translations courtesy of Benjamin H{\o}yer.
% \end{macro}
%
% Set up the definitions used at the beginning of the document to define
% the formats created by the document preamble.
%    \begin{macrocode}
\DeclareOption{danish}{%
  \AtBeginDocument{%
    \def\crefrangeconjunction@preamble{ til\nobreakspace}%
    \def\crefrangepreconjunction@preamble{}%
    \def\crefrangepostconjunction@preamble{}%
    \def\crefpairconjunction@preamble{ og\nobreakspace}%
    \def\crefmiddleconjunction@preamble{, }%
    \def\creflastconjunction@preamble{ og\nobreakspace}%
%    \end{macrocode}
% We have to define the group conjunctions explicitly here, rather than
% relying on fall-back definitions in terms of the above conjunctions
% (see \cref{sec:code:default_formats}), in case any other language
% option defines them explicitly and we need to override those.
%    \begin{macrocode}
    \def\crefpairgroupconjunction@preamble{ og\nobreakspace}%
    \def\crefmiddlegroupconjunction@preamble{, }%
    \def\creflastgroupconjunction@preamble{ og\nobreakspace}%
 %
    \Crefname@preamble{equation}{Ligning}{Ligninger}%
    \Crefname@preamble{figure}{Figur}{Figurer}%
    \Crefname@preamble{table}{Tabel}{Tabeller}%
    \Crefname@preamble{page}{Side}{Sider}%
    \Crefname@preamble{part}{Del}{Dele}%
    \Crefname@preamble{chapter}{Kapitel}{Kapitler}%
    \Crefname@preamble{section}{Afsnit}{Afsnit}%
    \Crefname@preamble{appendix}{Appendiks}{Appendiks}%
    \Crefname@preamble{enumi}{Punkt}{Punkter}%
    \Crefname@preamble{footnote}{Fodnote}{Fodnoter}%
    \Crefname@preamble{theorem}{Teorem}{Teoremer}%
    \Crefname@preamble{lemma}{Lemma}{Lemma}%
    \Crefname@preamble{corollary}{F\o lgeslutning}{F\o lgeslutninger}%
    \Crefname@preamble{proposition}{Udsagn}{Udsagn}%
    \Crefname@preamble{definition}{Definition}{Definitioner}%
    \Crefname@preamble{result}{Resultat}{Resultater}%
    \Crefname@preamble{example}{Eksempel}{Eksempler}%
    \Crefname@preamble{remark}{Bem\ae rkning}{Bem\ae rkninger}%
    \Crefname@preamble{note}{Note}{Noter}%
    \Crefname@preamble{algorithm}{Algoritme}{Algoritmer}%
    \Crefname@preamble{line}{Linje}{Linjer}%
 %
    \if@cref@capitalise%
      \crefname@preamble{equation}{Ligning}{Ligninger}%
      \crefname@preamble{figure}{Figur}{Figurer}%
      \crefname@preamble{table}{Tabel}{Tabeller}%
      \crefname@preamble{page}{Side}{Sider}%
      \crefname@preamble{part}{Del}{Dele}%
      \crefname@preamble{chapter}{Kapitel}{Kapitler}%
      \crefname@preamble{section}{Afsnit}{Afsnit}%
      \crefname@preamble{appendix}{Appendiks}{Appendiks}%
      \crefname@preamble{enumi}{Punkt}{Punkter}%
      \crefname@preamble{footnote}{Fodnote}{Fodnoter}%
      \crefname@preamble{theorem}{Teorem}{Teoremer}%
      \crefname@preamble{lemma}{Lemma}{Lemma}%
      \crefname@preamble{corollary}{F\o lgeslutning}{F\o lgeslutninger}%
      \crefname@preamble{proposition}{Udsagn}{Udsagn}%
      \crefname@preamble{definition}{Definition}{Definitioner}%
      \crefname@preamble{result}{Resultat}{Resultater}%
      \crefname@preamble{example}{Eksempel}{Eksempler}%
      \crefname@preamble{remark}{Bem\ae rkning}{Bem\ae rkninger}%
      \crefname@preamble{note}{Note}{Noter}%
      \crefname@preamble{algorithm}{Algoritme}{Algoritmer}%
      \crefname@preamble{line}{Linje}{Linjer}%
 %
    \else%
      \crefname@preamble{equation}{ligning}{ligninger}%
      \crefname@preamble{figure}{figur}{figurer}%
      \crefname@preamble{table}{tabel}{tabeller}%
      \crefname@preamble{page}{side}{sider}%
      \crefname@preamble{part}{del}{dele}%
      \crefname@preamble{chapter}{kapitel}{kapitler}%
      \crefname@preamble{section}{afsnit}{afsnit}%
      \crefname@preamble{appendix}{appendiks}{appendiks}%
      \crefname@preamble{enumi}{punkt}{punkter}%
      \crefname@preamble{footnote}{fodnote}{fodnoter}%
      \crefname@preamble{theorem}{teorem}{teoremer}%
      \crefname@preamble{lemma}{lemma}{lemma}%
      \crefname@preamble{corollary}{f\o lgeslutning}{f\o lgeslutninger}%
      \crefname@preamble{proposition}{udsagn}{udsagn}%
      \crefname@preamble{definition}{definition}{definitioner}%
      \crefname@preamble{result}{resultat}{resultater}%
      \crefname@preamble{example}{eksempel}{eksempler}%
      \crefname@preamble{remark}{bem\ae rkning}{bem\ae rkninger}%
      \crefname@preamble{note}{note}{noter}%
      \crefname@preamble{algorithm}{algoritme}{algoritmer}%
      \crefname@preamble{line}{linje}{linjer}%
    \fi%
    \def\cref@language{danish}%
  }}% end \DeclareOption and \AtBeginDocument
%    \end{macrocode}
%
% If using \package{babel} and the corresponding option is set, or if
% using \package{polyglossia} and the language has been loaded, add
% format definition commands to \cmd{\extras}\meta{language} or
% \cmd{\captions}\meta{language} so that language switching commands will
% change the cross-reference formats appropriately.
%    \begin{macrocode}
\cref@addlanguagedefs{danish}{%
  \PackageInfo{cleveref}{loaded `danish' language definitions}%
  \renewcommand{\crefrangeconjunction@preamble}{ til\nobreakspace}%
  \renewcommand\crefrangepreconjunction@preamble{}%
  \renewcommand\crefrangepostconjunction@preamble{}%
  \renewcommand{\crefpairconjunction@preamble}{ og\nobreakspace}%
  \renewcommand{\crefmiddleconjunction@preamble}{, }%
  \renewcommand{\creflastconjunction@preamble}{ og\nobreakspace}%
  \renewcommand{\crefpairgroupconjunction@preamble}{ og\nobreakspace}%
  \renewcommand{\crefmiddlegroupconjunction@preamble}{, }%
  \renewcommand{\creflastgroupconjunction@preamble}{ og\nobreakspace}%
 %
  \Crefname{equation}{Ligning}{Ligninger}%
  \Crefname{figure}{Figur}{Figurer}%
  \Crefname{subfigure}{Figur}{Figurer}%
  \Crefname{table}{Tabel}{Tabeller}%
  \Crefname{subtable}{Tabel}{Tabeller}%
  \Crefname{page}{Side}{Sider}%
  \Crefname{part}{Del}{Dele}%
  \Crefname{chapter}{Kapitel}{Kapitler}%
  \Crefname{section}{Afsnit}{Afsnit}%
  \Crefname{subsection}{Afsnit}{Afsnit}%
  \Crefname{subsubsection}{Afsnit}{Afsnit}%
  \Crefname{appendix}{Appendiks}{Appendiks}%
  \Crefname{subappendix}{Appendiks}{Appendiks}%
  \Crefname{subsubappendix}{Appendiks}{Appendiks}%
  \Crefname{subsubsubappendix}{Appendiks}{Appendiks}%
  \Crefname{enumi}{Punkt}{Punkter}%
  \Crefname{enumii}{Punkt}{Punkter}%
  \Crefname{enumiii}{Punkt}{Punkter}%
  \Crefname{enumiv}{Punkt}{Punkter}%
  \Crefname{enumv}{Punkt}{Punkter}%
  \Crefname{footnote}{Fodnote}{Fodnoter}%
  \Crefname{theorem}{Teorem}{Teoremer}%
  \Crefname{lemma}{Lemma}{Lemma}%
  \Crefname{corollary}{F\o lgeslutning}{F\o lgeslutninger}%
  \Crefname{proposition}{Udsagn}{Udsagn}%
  \Crefname{definition}{Definition}{Definitioner}%
  \Crefname{result}{Resultat}{Resultater}%
  \Crefname{example}{Eksempel}{Eksempler}%
  \Crefname{remark}{Bem\ae rkning}{Bem\ae rkninger}%
  \Crefname{note}{Note}{Noter}%
  \Crefname{algorithm}{Algoritme}{Algoritmer}%
  \Crefname{line}{Linje}{Linjer}%
 %
  \if@cref@capitalise%
    \crefname{equation}{Ligning}{Ligninger}%
    \crefname{figure}{Figur}{Figurer}%
    \crefname{subfigure}{Figur}{Figurer}%
    \crefname{table}{Tabel}{Tabeller}%
    \crefname{subtable}{Tabel}{Tabeller}%
    \crefname{page}{Side}{Sider}%
    \crefname{part}{Del}{Dele}%
    \crefname{chapter}{Kapitel}{Kapitler}%
    \crefname{section}{Afsnit}{Afsnit}%
    \crefname{subsection}{Afsnit}{Afsnit}%
    \crefname{subsubsection}{Afsnit}{Afsnit}%
    \crefname{appendix}{Appendiks}{Appendiks}%
    \crefname{subappendix}{Appendiks}{Appendiks}%
    \crefname{subsubappendix}{Appendiks}{Appendiks}%
    \crefname{subsubsubappendix}{Appendiks}{Appendiks}%
    \crefname{enumi}{Punkt}{Punkter}%
    \crefname{enumii}{Punkt}{Punkter}%
    \crefname{enumiii}{Punkt}{Punkter}%
    \crefname{enumiv}{Punkt}{Punkter}%
    \crefname{enumv}{Punkt}{Punkter}%
    \crefname{footnote}{Fodnote}{Fodnoter}%
    \crefname{theorem}{Teorem}{Teoremer}%
    \crefname{lemma}{Lemma}{Lemma}%
    \crefname{corollary}{F\o lgeslutning}{F\o lgeslutninger}%
    \crefname{proposition}{Udsagn}{Udsagn}%
    \crefname{definition}{Definition}{Definitioner}%
    \crefname{result}{Resultat}{Resultater}%
    \crefname{example}{Eksempel}{Eksempler}%
    \crefname{remark}{Bem\ae rkning}{Bem\ae rkninger}%
    \crefname{note}{Note}{Noter}%
    \crefname{algorithm}{Algoritme}{Algoritmer}%
    \crefname{line}{Linje}{Linjer}%
 %
  \else%
    \crefname{equation}{ligning}{ligninger}%
    \crefname{figure}{figur}{figurer}%
    \crefname{subfigure}{figur}{figurer}%
    \crefname{table}{tabel}{tabeller}%
    \crefname{subtable}{tabel}{tabeller}%
    \crefname{page}{side}{sider}%
    \crefname{part}{del}{dele}%
    \crefname{chapter}{kapitel}{kapitler}%
    \crefname{section}{afsnit}{afsnit}%
    \crefname{subsection}{afsnit}{afsnit}%
    \crefname{subsubsection}{afsnit}{afsnit}%
    \crefname{appendix}{appendiks}{appendiks}%
    \crefname{subappendix}{appendiks}{appendiks}%
    \crefname{subsubappendix}{appendiks}{appendiks}%
    \crefname{subsubsubappendix}{appendiks}{appendiks}%
    \crefname{enumi}{punkt}{punkter}%
    \crefname{enumii}{punkt}{punkter}%
    \crefname{enumiii}{punkt}{punkter}%
    \crefname{enumiv}{punkt}{punkter}%
    \crefname{enumv}{punkt}{punkter}%
    \crefname{footnote}{fodnote}{fodnoter}%
    \crefname{theorem}{teorem}{teoremer}%
    \crefname{lemma}{lemma}{lemma}%
    \crefname{corollary}{f\o lgeslutning}{f\o lgeslutninger}%
    \crefname{proposition}{udsagn}{udsagn}%
    \crefname{definition}{definition}{definitioner}%
    \crefname{result}{resultat}{resultater}%
    \crefname{example}{eksempel}{eksempler}%
    \crefname{remark}{bem\ae rkning}{bem\ae rkninger}%
    \crefname{note}{note}{noter}%
    \crefname{algorithm}{algoritme}{algoritmer}%
    \crefname{line}{linje}{linjer}%
  \fi}% end \cref@loadlanguagedefs
%    \end{macrocode}
%
%
% \subsubsection{Esperanto}
% \begin{macro}{esperanto}
%   Esperanto translations courtesy of Johannes Mueller.
% \end{macro}
%
% Set up the definitions used at the beginning of the document to define
% the formats created by the document preamble.
%    \begin{macrocode}
\DeclareOption{esperanto}{%
  \AtBeginDocument{%
    \def\crefrangeconjunction@preamble{ \^gis\nobreakspace}%
    \def\crefrangepreconjunction@preamble{}%
    \def\crefrangepostconjunction@preamble{}%
    \def\crefpairconjunction@preamble{ kaj\nobreakspace}%
    \def\crefmiddleconjunction@preamble{, }%
    \def\creflastconjunction@preamble{ kaj\nobreakspace}%
    \def\crefpairgroupconjunction@preamble{ kaj\nobreakspace}%
    \def\crefmiddlegroupconjunction@preamble{, }%
    \def\creflastgroupconjunction@preamble{ kaj\nobreakspace}%
%
    \Crefname@preamble{equation}{Ekvacio}{Ekvacioj}%
    \Crefname@preamble{part}{Parto}{Partoj}%
    \Crefname@preamble{chapter}{\^Capitro}{\^Capitroj}%
    \Crefname@preamble{section}{Sekcio}{Sekcioj}%
    \Crefname@preamble{appendix}{Aldono}{Aldonoj}%
    \Crefname@preamble{enumi}{Punkto}{Punktoj}%
    \Crefname@preamble{footnote}{Piednoto}{Piednotoj}%
    \Crefname@preamble{figure}{Figuro}{Figuroj}%
    \Crefname@preamble{table}{Tabelo}{Tabeloj}%
    \Crefname@preamble{theorem}{Teoremo}{Teoremoj}%
    \Crefname@preamble{lemma}{Lemo}{Lemoj}%
    \Crefname@preamble{corollary}{Korolario}{Korolarioj}%
    \Crefname@preamble{proposition}{Propozicio}{Propozicioj}%
    \Crefname@preamble{definition}{Defino}{Definoj}%
    \Crefname@preamble{result}{Rezulto}{Rezultoj}%
    \Crefname@preamble{example}{Ekzemplo}{Ekzemploj}%
    \Crefname@preamble{remark}{Rimarko}{Rimarkoj}%
    \Crefname@preamble{note}{Noto}{Notoj}%
    \Crefname@preamble{algorithm}{Algoritmo}{Algoritmoj}%
    \Crefname@preamble{listing}{Listado}{Listadoj}%
    \Crefname@preamble{line}{Linio}{Linioj}%
%
    \if@cref@capitalise%
      \crefname@preamble{equation}{Ekvacio}{Ekvacioj}%
      \crefname@preamble{part}{Parto}{Partoj}%
      \crefname@preamble{chapter}{\^Capitro}{\^Capitroj}%
      \crefname@preamble{section}{Sekcio}{Sekcioj}%
      \crefname@preamble{appendix}{Aldono}{Aldonoj}%
      \crefname@preamble{enumi}{Punkto}{Punktoj}%
      \crefname@preamble{footnote}{Piednoto}{Piednotoj}%
      \crefname@preamble{figure}{Figuro}{Figuroj}%
      \crefname@preamble{table}{Tabelo}{Tabeloj}%
      \crefname@preamble{theorem}{Teoremo}{Teoremoj}%
      \crefname@preamble{lemma}{Lemo}{Lemoj}%
      \crefname@preamble{corollary}{Korolario}{Korolarioj}%
      \crefname@preamble{proposition}{Propozicio}{Propozicioj}%
      \crefname@preamble{definition}{Defino}{Definoj}%
      \crefname@preamble{result}{Rezulto}{Rezultoj}%
      \crefname@preamble{example}{Ekzemplo}{Ekzemploj}%
      \crefname@preamble{remark}{Rimarko}{Rimarkoj}%
      \crefname@preamble{note}{Noto}{Notoj}%
      \crefname@preamble{algorithm}{Algoritmo}{Algoritmoj}%
      \crefname@preamble{listing}{Listado}{Listadoj}%
      \crefname@preamble{line}{Linio}{Linioj}%
%
    \else%
      \crefname@preamble{equation}{ekvacio}{ekvacioj}%
      \crefname@preamble{part}{parto}{partoj}%
      \crefname@preamble{chapter}{\^capitro}{\^capitroj}%
      \crefname@preamble{section}{sekcio}{sekcioj}%
      \crefname@preamble{appendix}{aldono}{aldonoj}%
      \crefname@preamble{enumi}{punkto}{punktoj}%
      \crefname@preamble{footnote}{piednoto}{piednotoj}%
      \crefname@preamble{figure}{figuro}{figuroj}%
      \crefname@preamble{table}{tabelo}{tabeloj}%
      \crefname@preamble{theorem}{teoremo}{teoremoj}%
      \crefname@preamble{lemma}{lemo}{lemoj}%
      \crefname@preamble{corollary}{korolario}{korolarioj}%
      \crefname@preamble{proposition}{propozicio}{propozicioj}%
      \crefname@preamble{definition}{defino}{definoj}%
      \crefname@preamble{result}{rezulto}{rezultoj}%
      \crefname@preamble{example}{ekzemplo}{ekzemploj}%
      \crefname@preamble{remark}{rimarko}{rimarkoj}%
      \crefname@preamble{note}{noto}{notoj}%
      \crefname@preamble{algorithm}{algoritmo}{algoritmoj}%
      \crefname@preamble{listing}{listado}{listadoj}%
      \crefname@preamble{line}{linio}{linioj}%
    \fi%
    \def\cref@language{esperanto}%
  }}% end \DeclareOption and \AtBeginDocument
% \end{macrocode}
%
% If using \package{babel} and the corresponding option is set, or if
% using \package{polyglossia} and the language has been loaded, add
% format definition commands to \cmd{\extras}\meta{language} or
% \cmd{\captions}\meta{language} so that language switching commands will
% change the cross-reference formats appropriately.
%    \begin{macrocode}
\cref@addlanguagedefs{esperanto}{%
  \PackageInfo{cleveref}{loaded `esperanto' language definitions}%
  \renewcommand{\crefrangeconjunction}{ \^gis\nobreakspace}%
  \renewcommand{\crefrangepreconjunction}{}%
  \renewcommand{\crefrangepostconjunction}{}%
  \renewcommand{\crefpairconjunction}{ kaj\nobreakspace}%
  \renewcommand{\crefmiddleconjunction}{, }%
  \renewcommand{\creflastconjunction}{ kaj\nobreakspace}%
  \renewcommand{\crefpairgroupconjunction}{ kaj\nobreakspace}%
  \renewcommand{\crefmiddlegroupconjunction}{, }%
  \renewcommand{\creflastgroupconjunction}{ kaj\nobreakspace}%
%
  \Crefname{equation}{Ekvacio}{Ekvacioj}%
  \Crefname{part}{Parto}{Partoj}%
  \Crefname{chapter}{\^Capitro}{\^Capitroj}%
  \Crefname{section}{Sekcio}{Sekcioj}%
  \Crefname{appendix}{Aldono}{Aldonoj}%
  \Crefname{enumi}{Punkto}{Punktoj}%
  \Crefname{footnote}{Piednoto}{Piednotoj}%
  \Crefname{figure}{Figuro}{Figuroj}%
  \Crefname{table}{Tabelo}{Tabeloj}%
  \Crefname{theorem}{Teoremo}{Teoremoj}%
  \Crefname{lemma}{Lemo}{Lemoj}%
  \Crefname{corollary}{Korolario}{Korolarioj}%
  \Crefname{proposition}{Propozicio}{Propozicioj}%
  \Crefname{definition}{Defino}{Definoj}%
  \Crefname{result}{Rezulto}{Rezultoj}%
  \Crefname{example}{Ekzemplo}{Ekzemploj}%
  \Crefname{remark}{Rimarko}{Rimarkoj}%
  \Crefname{note}{Noto}{Notoj}%
  \Crefname{algorithm}{Algoritmo}{Algoritmoj}%
  \Crefname{listing}{Listado}{Listadoj}%
  \Crefname{line}{Linio}{Linioj}%
%
  \if@cref@capitalise%
    \crefname{equation}{Ekvacio}{Ekvacioj}%
    \crefname{part}{Parto}{Partoj}%
    \crefname{chapter}{\^Capitro}{\^Capitroj}%
    \crefname{section}{Sekcio}{Sekcioj}%
    \crefname{appendix}{Aldono}{Aldonoj}%
    \crefname{enumi}{Punkto}{Punktoj}%
    \crefname{footnote}{Piednoto}{Piednotoj}%
    \crefname{figure}{Figuro}{Figuroj}%
    \crefname{table}{Tabelo}{Tabeloj}%
    \crefname{theorem}{Teoremo}{Teoremoj}%
    \crefname{lemma}{Lemo}{Lemoj}%
    \crefname{corollary}{Korolario}{Korolarioj}%
    \crefname{proposition}{Propozicio}{Propozicioj}%
    \crefname{definition}{Defino}{Definoj}%
    \crefname{result}{Rezulto}{Rezultoj}%
    \crefname{example}{Ekzemplo}{Ekzemploj}%
    \crefname{remark}{Rimarko}{Rimarkoj}%
    \crefname{note}{Noto}{Notoj}%
    \crefname{algorithm}{Algoritmo}{Algoritmoj}%
    \crefname{listing}{Listado}{Listadoj}%
    \crefname{line}{Linio}{Linioj}%
%
  \else%
    \crefname{equation}{ekvacio}{ekvacioj}%
    \crefname{part}{parto}{partoj}%
    \crefname{chapter}{\^capitro}{\^capitroj}%
    \crefname{section}{sekcio}{sekcioj}%
    \crefname{appendix}{aldono}{aldonoj}%
    \crefname{enumi}{punkto}{punktoj}%
    \crefname{footnote}{piednoto}{piednotoj}%
    \crefname{figure}{figuro}{figuroj}%
    \crefname{table}{tabelo}{tabeloj}%
    \crefname{theorem}{teoremo}{teoremoj}%
    \crefname{lemma}{lemo}{lemoj}%
    \crefname{corollary}{korolario}{korolarioj}%
    \crefname{proposition}{propozicio}{propozicioj}%
    \crefname{definition}{defino}{definoj}%
    \crefname{result}{rezulto}{rezultoj}%
    \crefname{example}{ekzemplo}{ekzemploj}%
    \crefname{remark}{rimarko}{rimarkoj}%
    \crefname{note}{noto}{notoj}%
    \crefname{algorithm}{algoritmo}{algoritmoj}%
    \crefname{listing}{listado}{listadoj}%
    \crefname{line}{linio}{linioj}%
  \fi}% end \cref@loadlanguagedefs
%    \end{macrocode}
%
%
% \subsubsection{Swedish}
% \begin{macro}{swedish}
%   Swedish definitions thanks to Simon Sigurdhsson.
% \end{macro}
%
% Set up the definitions used at the beginning of the document to define
% the formats created by the document preamble.
%    \begin{macrocode}
\DeclareOption{swedish}{%
  \AtBeginDocument{%
    \def\crefrangeconjunction@preamble{ till\nobreakspace}%
    \def\crefrangepreconjunction@preamble{}%
    \def\crefrangepostconjunction@preamble{}%
    \def\crefpairconjunction@preamble{ och\nobreakspace}%
    \def\crefmiddleconjunction@preamble{, }%
    \def\creflastconjunction@preamble{ och\nobreakspace}%
%    \end{macrocode}
% We have to define the group conjunctions explicitly here, rather than
% relying on fall-back definitions in terms of the above conjunctions
% (see \cref{sec:code:default_formats}), in case any other language
% option defines them explicitly and we need to override those.
%    \begin{macrocode}
    \def\crefpairgroupconjunction@preamble{ och\nobreakspace}%
    \def\crefmiddlegroupconjunction@preamble{, }%
    \def\creflastgroupconjunction@preamble{, och\nobreakspace}%
 %
    \Crefname@preamble{equation}{Ekvation}{Ekvation}%
    \Crefname@preamble{figure}{Figur}{Figur}%
    \Crefname@preamble{table}{Tabell}{Tabell}%
    \Crefname@preamble{page}{Sida}{Sida}%
    \Crefname@preamble{part}{Del}{Del}%
    \Crefname@preamble{chapter}{Kapitel}{Kapitel}%
    \Crefname@preamble{section}{Avsnitt}{Avsnitt}%
    \Crefname@preamble{appendix}{Appendix}{Appendix}%
    \Crefname@preamble{enumi}{Punkt}{Punkt}%
    \Crefname@preamble{footnote}{Fotnot}{Fotnot}%
    \Crefname@preamble{theorem}{Sats}{Sats}%
    \Crefname@preamble{lemma}{Lemma}{Lemmas}%
    \Crefname@preamble{corollary}{F\"oljdsats}{F\"oljdsats}%
    \Crefname@preamble{proposition}{Proposition}{Proposition}%
    \Crefname@preamble{definition}{Definition}{Definition}%
    \Crefname@preamble{result}{Resultat}{Resultat}%
    \Crefname@preamble{example}{Exempel}{Exempel}%
    \Crefname@preamble{remark}{Anm\"arkning}{Anm\"arkning}%
    \Crefname@preamble{note}{Notering}{Notering}%
    \Crefname@preamble{algorithm}{Algoritm}{Algoritm}%
    \Crefname@preamble{listing}{Kodlistning}{Kodlistning}%
    \Crefname@preamble{line}{Rad}{Rad}%
 %
    \if@cref@capitalise%  capitalise set
      \if@cref@abbrev%
        \crefname@preamble{equation}{Ekv.}{Ekv.}%
        \crefname@preamble{figure}{Fig.}{Fig.}%
      \else%
        \crefname@preamble{equation}{Ekvation}{Ekvation}%
        \crefname@preamble{figure}{Figur}{Figur}%
      \fi%
      \crefname@preamble{page}{Sida}{Sida}%
      \crefname@preamble{table}{Tabell}{Tabell}%
      \crefname@preamble{part}{Del}{Del}%
      \crefname@preamble{chapter}{Kapitel}{Kapitel}%
      \crefname@preamble{section}{Avsnitt}{Avsnitt}%
      \crefname@preamble{appendix}{Appendix}{Appendix}%
      \crefname@preamble{enumi}{Punkt}{Punkt}%
      \crefname@preamble{footnote}{Fotnot}{Fotnot}%
      \crefname@preamble{theorem}{Sats}{Sats}%
      \crefname@preamble{lemma}{Lemma}{Lemmas}%
      \crefname@preamble{corollary}{F\"oljdsats}{F\"oljdsats}%
      \crefname@preamble{proposition}{Proposition}{Proposition}%
      \crefname@preamble{definition}{Definition}{Definition}%
      \crefname@preamble{result}{Resultat}{Resultat}%
      \crefname@preamble{example}{Exempel}{Exempel}%
      \crefname@preamble{remark}{Anm\"arkning}{Anm\"arkning}%
      \crefname@preamble{note}{Notering}{Notering}%
      \crefname@preamble{algorithm}{Algoritm}{Algoritm}%
      \crefname@preamble{listing}{Kodlistning}{Kodlistning}%
      \crefname@preamble{line}{Rad}{Rad}%
 %
    \else%  capitalise unset
      \if@cref@abbrev%
        \crefname@preamble{equation}{ekv.}{ekv.}%
        \crefname@preamble{figure}{fig.}{fig.}%
        \crefname@preamble{page}{s.}{ss.}%
      \else%
        \crefname@preamble{equation}{ekvation}{ekvation}%
        \crefname@preamble{figure}{figur}{figur}%
        \crefname@preamble{page}{sida}{sida}%
      \fi%
      \crefname@preamble{table}{tabell}{tabell}%
      \crefname@preamble{part}{del}{del}%
      \crefname@preamble{chapter}{kapitel}{kapitel}%
      \crefname@preamble{section}{avsnitt}{avsnitt}%
      \crefname@preamble{appendix}{appendix}{appendix}%
      \crefname@preamble{enumi}{punkt}{punkt}%
      \crefname@preamble{footnote}{fotnot}{fotnot}%
      \crefname@preamble{theorem}{sats}{sats}%
      \crefname@preamble{lemma}{lemma}{lemmas}%
      \crefname@preamble{corollary}{f\"oljdsats}{f\"oljdsats}%
      \crefname@preamble{proposition}{proposition}{proposition}%
      \crefname@preamble{definition}{definition}{definition}%
      \crefname@preamble{result}{resultat}{resultat}%
      \crefname@preamble{example}{exempel}{exempel}%
      \crefname@preamble{remark}{anm\"arkning}{anm\"arkning}%
      \crefname@preamble{note}{notering}{notering}%
      \crefname@preamble{algorithm}{algoritm}{algoritm}%
      \crefname@preamble{listing}{kodlistning}{kodlistning}%
      \crefname@preamble{line}{rad}{rad}%
    \fi%
    \def\cref@language{swedish}%
  }}% end \AtBeginDocument and \DeclareOption
%    \end{macrocode}
%
% If using \package{babel} and the corresponding option is set, or if
% using \package{polyglossia} and the language has been loaded, add
% format definition commands to \cmd{\extras}\meta{language} or
% \cmd{\captions}\meta{language} so that language switching commands will
% change the cross-reference formats appropriately.
%    \begin{macrocode}
\cref@addlanguagedefs{swedish}{%
  \PackageInfo{cleveref}{loaded `swedish' language definitions}%
  \renewcommand{\crefrangeconjunction}{ till\nobreakspace}%
  \renewcommand\crefrangepreconjunction{}%
  \renewcommand\crefrangepostconjunction{}%
  \renewcommand{\crefpairconjunction}{ och\nobreakspace}%
  \renewcommand{\crefmiddleconjunction}{, }%
  \renewcommand{\creflastconjunction}{ och\nobreakspace}%
  \renewcommand{\crefpairgroupconjunction}{ and\nobreakspace}%
  \renewcommand{\crefmiddlegroupconjunction}{, }%
  \renewcommand{\creflastgroupconjunction}{, and\nobreakspace}%
 %
  \Crefname{equation}{Ekvation}{Ekvation}%
  \Crefname{figure}{Figur}{Figur}%
  \Crefname{subfigure}{Figur}{Figur}%
  \Crefname{table}{Tabell}{Tabell}%
  \Crefname{subtable}{Tabell}{Tabell}%
  \Crefname{page}{Sida}{Sida}%
  \Crefname{part}{Del}{Del}%
  \Crefname{chapter}{Kapitel}{Kapitel}%
  \Crefname{section}{Avsnitt}{Avsnitt}%
  \Crefname{subsection}{Avsnitt}{Avsnitt}%
  \Crefname{subsubsection}{Avsnitt}{Avsnitt}%
  \Crefname{appendix}{Appendix}{Appendix}%
  \Crefname{subappendix}{Appendix}{Appendix}%
  \Crefname{subsubappendix}{Appendix}{Appendix}%
  \Crefname{subsubsubappendix}{Appendix}{Appendix}%
  \Crefname{enumi}{Punkt}{Punkt}%
  \Crefname{enumii}{Punkt}{Punkt}%
  \Crefname{enumiii}{Punkt}{Punkt}%
  \Crefname{enumiv}{Punkt}{Punkt}%
  \Crefname{enumv}{Punkt}{Punkt}%
  \Crefname{footnote}{Fotnot}{Fotnot}%
  \Crefname{theorem}{Sats}{Sats}%
  \Crefname{lemma}{Lemma}{Lemmas}%
  \Crefname{corollary}{F\"oljdsats}{F\"oljdsats}%
  \Crefname{proposition}{Proposition}{Proposition}%
  \Crefname{definition}{Definition}{Definition}%
  \Crefname{result}{Resultat}{Resultat}%
  \Crefname{example}{Exempel}{Exempel}%
  \Crefname{remark}{Anm\"arkning}{Anm\"arkning}%
  \Crefname{note}{Notering}{Notering}%
  \Crefname{algorithm}{Algoritm}{Algoritm}%
  \Crefname{listing}{Kodlistning}{Kodlistning}%
  \Crefname{line}{Rad}{Rad}%
 %
  \if@cref@capitalise%  capitalise set
    \if@cref@abbrev%
      \crefname{equation}{Ekv.}{Ekv.}%
      \crefname{figure}{Fig.}{Fig.}%
      \crefname{subfigure}{Fig.}{Fig.}%
    \else%
      \crefname{equation}{Ekvation}{Ekvation}%
      \crefname{figure}{Figur}{Figur}%
      \crefname{subfigure}{Figur}{Figur}%
    \fi%
    \crefname{page}{Sida}{Sida}%
    \crefname{table}{Tabell}{Tabell}%
    \crefname{subtable}{Tabell}{Tabell}%
    \crefname{part}{Del}{Del}%
    \crefname{chapter}{Kapitel}{Kapitel}%
    \crefname{section}{Avsnitt}{Avsnitt}%
    \crefname{subsection}{Avsnitt}{Avsnitt}%
    \crefname{subsubsection}{Avsnitt}{Avsnitt}%
    \crefname{appendix}{Appendix}{Appendix}%
    \crefname{subappendix}{Appendix}{Appendix}%
    \crefname{subsubappendix}{Appendix}{Appendix}%
    \crefname{subsubsubappendix}{Appendix}{Appendix}%
    \crefname{enumi}{Punkt}{Punkt}%
    \crefname{enumii}{Punkt}{Punkt}%
    \crefname{enumiii}{Punkt}{Punkt}%
    \crefname{enumiv}{Punkt}{Punkt}%
    \crefname{enumv}{Punkt}{Punkt}%
    \crefname{footnote}{Fotnot}{Fotnot}%
    \crefname{theorem}{Sats}{Sats}%
    \crefname{lemma}{Lemma}{Lemmas}%
    \crefname{corollary}{F\"oljdsats}{F\"oljdsats}%
    \crefname{proposition}{Proposition}{Proposition}%
    \crefname{definition}{Definition}{Definition}%
    \crefname{result}{Resultat}{Resultat}%
    \crefname{example}{Exempel}{Exempel}%
    \crefname{remark}{Anm\"arkning}{Anm\"arkning}%
    \crefname{note}{Notering}{Notering}%
    \crefname{algorithm}{Algoritm}{Algoritm}%
    \crefname{listing}{Kodlistning}{Kodlistnings}%
    \crefname{line}{Rad}{Rad}%
 %
  \else%  capitalise unset
    \if@cref@abbrev%
      \crefname{equation}{ekv.}{ekv.}%
      \crefname{figure}{fig.}{fig.}%
      \crefname{subfigure}{fig.}{fig.}%
      \crefname{page}{s.}{ss.}%
    \else%
      \crefname{equation}{ekvation}{ekvation}%
      \crefname{figure}{figur}{figur}%
      \crefname{subfigure}{figur}{figur}%
      \crefname{page}{sida}{sida}%
    \fi%
    \crefname{table}{tabell}{tabell}%
    \crefname{subtable}{tabell}{tabell}%
    \crefname{part}{del}{del}%
    \crefname{chapter}{kapitel}{kapitel}%
    \crefname{section}{avsnitt}{avsnitt}%
    \crefname{subsection}{avsnitt}{avsnitt}%
    \crefname{subsubsection}{avsnitt}{avsnitt}%
    \crefname{appendix}{appendix}{appendix}%
    \crefname{subappendix}{appendix}{appendix}%
    \crefname{subsubappendix}{appendix}{appendix}%
    \crefname{subsubsubappendix}{appendix}{appendix}%
    \crefname{enumi}{punkt}{punkt}%
    \crefname{enumii}{punkt}{punkt}%
    \crefname{enumiii}{punkt}{punkt}%
    \crefname{enumiv}{punkt}{punkt}%
    \crefname{enumv}{punkt}{punkt}%
    \crefname{footnote}{fotnot}{fotnot}%
    \crefname{theorem}{sats}{sats}%
    \crefname{lemma}{lemma}{lemmas}%
    \crefname{corollary}{f\"oljdsats}{f\"oljdsats}%
    \crefname{proposition}{proposition}{proposition}%
    \crefname{definition}{definition}{definition}%
    \crefname{result}{resultat}{resultat}%
    \crefname{example}{exempel}{exempel}%
    \crefname{remark}{anm\"arkning}{anm\"arkning}%
    \crefname{note}{notering}{notering}%
    \crefname{algorithm}{algoritm}{algoritm}%
    \crefname{listing}{kodlistning}{kodlistnings}%
    \crefname{line}{rad}{rad}%
  \fi}% end \cref@addlangagedefs
%    \end{macrocode}
%
%
% \subsubsection{Brazilian}
% \begin{macro}{brazilian}
%   Brazilian translations courtesy of Paulo Roberto Massa Cereda.
% \end{macro}
%    \begin{macrocode}
\DeclareOption{brazilian}{%
  \AtBeginDocument{%
    \def\crefrangeconjunction@preamble{ a\nobreakspace}%
    \def\crefrangepreconjunction@preamble{}%
    \def\crefrangepostconjunction@preamble{}%
    \def\crefpairconjunction@preamble{ e\nobreakspace}%
    \def\crefmiddleconjunction@preamble{, }%
    \def\creflastconjunction@preamble{ e\nobreakspace}%
%    \end{macrocode}
% We have to define the group conjunctions explicitly here, rather than
% relying on fall-back definitions in terms of the above conjunctions
% (see \cref{sec:code:default_formats}), in case any other language
% option defines them explicitly and we need to override those.
%    \begin{macrocode}
    \def\crefpairgroupconjunction@preamble{ e\nobreakspace}%
    \def\crefmiddlegroupconjunction@preamble{, }%
    \def\creflastgroupconjunction@preamble{, e\nobreakspace}%
 %
    \Crefname@preamble{equation}{Equa\c c\~ao}{Equa\c c\~oes}%
    \Crefname@preamble{figure}{Figura}{Figuras}%
    \Crefname@preamble{table}{Tabela}{Tabelas}%
    \Crefname@preamble{page}{P\'agina}{P\'aginas}%
    \Crefname@preamble{part}{Parte}{Partes}%
    \Crefname@preamble{chapter}{Cap\'itulo}{Cap\'itulos}%
    \Crefname@preamble{section}{Se\c c\~ao}{Se\c c\~oes}%
    \Crefname@preamble{appendix}{Ap\^endice}{Ap\^endices}%
    \Crefname@preamble{enumi}{Item}{Itens}%
    \Crefname@preamble{footnote}{Nota de rodap\'e}{Notas de rodap\'e}%
    \Crefname@preamble{theorem}{Teorema}{Teoremas}%
    \Crefname@preamble{lemma}{Lema}{Lemas}%
    \Crefname@preamble{corollary}{Corol\'ario}{Corol\'arios}%
    \Crefname@preamble{proposition}{Proposi\c c\~ao}{Proposi\c c\~oes}%
    \Crefname@preamble{definition}{Defini\c c\~ao}{Defini\c c\~oes}%
    \Crefname@preamble{result}{Resultado}{Resultados}%
    \Crefname@preamble{example}{Exemplo}{Exemplos}%
    \Crefname@preamble{remark}{Observa\c c\~ao}{Observa\c c\~oes}%
    \Crefname@preamble{note}{Nota}{Notas}%
    \Crefname@preamble{algorithm}{Algoritmo}{Algoritmos}%
    \Crefname@preamble{listing}{Listagem}{Listagens}%
    \Crefname@preamble{line}{Linha}{Linhas}%
 %
    \if@cref@capitalise%  capitalise set
      \if@cref@abbrev%
        \crefname@preamble{equation}{Eq.}{Eqs.}%
        \crefname@preamble{figure}{Fig.}{Figs.}%
      \else%
        \crefname@preamble{equation}{Equa\c c\~ao}{Equa\c c\~oes}%
        \crefname@preamble{figure}{Figura}{Figuras}%
      \fi%
      \crefname@preamble{page}{P\'agina}{P\'aginas}%
      \crefname@preamble{table}{Tabela}{Tabelas}%
      \crefname@preamble{part}{Parte}{Partes}%
      \crefname@preamble{chapter}{Cap\'itulo}{Cap\'itulos}%
      \crefname@preamble{section}{Se\c c\~ao}{Se\c c\~oes}%
      \crefname@preamble{appendix}{Ap\^endice}{Ap\^endices}%
      \crefname@preamble{enumi}{Item}{Itens}%
      \crefname@preamble{footnote}{Nota de rodap\'e}{Notas de rodap\'e}%
      \crefname@preamble{theorem}{Teorema}{Teoremas}%
      \crefname@preamble{lemma}{Lema}{Lemas}%
      \crefname@preamble{corollary}{Corol\'ario}{Corol\'arios}%
      \crefname@preamble{proposition}{Proposi\c c\~ao}{Proposi\c c\~oes}%
      \crefname@preamble{definition}{Defini\c c\~ao}{Defini\c c\~oes}%
      \crefname@preamble{result}{Resultado}{Resultados}%
      \crefname@preamble{example}{Exemplo}{Exemplos}%
      \crefname@preamble{remark}{Observa\c c\~ao}{Observa\c c\~oes}%
      \crefname@preamble{note}{Nota}{Notas}%
      \crefname@preamble{algorithm}{Algoritmo}{Algoritmos}%
      \crefname@preamble{listing}{Listagem}{Listagens}%
      \crefname@preamble{line}{Linha}{Linhas}%
 %
    \else%  capitalise unset
      \if@cref@abbrev%
        \crefname@preamble{equation}{eq.}{eqs.}%
        \crefname@preamble{figure}{fig.}{figs.}%
      \else%
        \crefname@preamble{equation}{equa\c c\~ao}{equa\c c\~oes}%
        \crefname@preamble{figure}{figura}{figuras}%
      \fi%
      \crefname@preamble{page}{p\'agina}{p\'aginas}%
      \crefname@preamble{table}{tabela}{tabelas}%
      \crefname@preamble{part}{parte}{partes}%
      \crefname@preamble{chapter}{cap\'itulo}{cap\'itulos}%
      \crefname@preamble{section}{se\c c\~ao}{se\c c\~oes}%
      \crefname@preamble{appendix}{ap\^endice}{ap\^endices}%
      \crefname@preamble{enumi}{item}{itens}%
      \crefname@preamble{footnote}{nota de rodap\'e}{notas de rodap\'e}%
      \crefname@preamble{theorem}{teorema}{teoremas}%
      \crefname@preamble{lemma}{lema}{lemas}%
      \crefname@preamble{corollary}{corol\'ario}{corol\'arios}%
      \crefname@preamble{proposition}{proposi\c c\~ao}{proposi\c c\~oes}%
      \crefname@preamble{definition}{defini\c c\~ao}{defini\c c\~oes}%
      \crefname@preamble{result}{resultado}{resultados}%
      \crefname@preamble{example}{exemplo}{exemplos}%
      \crefname@preamble{remark}{observa\c c\~ao}{observa\c c\~oes}%
      \crefname@preamble{note}{nota}{notas}%
      \crefname@preamble{algorithm}{algoritmo}{algoritmos}%
      \crefname@preamble{listing}{listagem}{listagens}%
      \crefname@preamble{line}{linha}{linhas}%
    \fi%
    \def\cref@language{brazilian}%
  }}% end \AtBeginDocument and \DeclareOption
%    \end{macrocode}
%
% If using \package{babel} and the corresponding option is set, or if
% using \package{polyglossia} and the language has been loaded, add
% format definition commands to \cmd{\extras}\meta{language} or
% \cmd{\captions}\meta{language} so that language switching commands will
% change the cross-reference formats appropriately.
%    \begin{macrocode}
\cref@addlanguagedefs{brazilian}{%
  \PackageInfo{cleveref}{loaded `brazilian' language definitions}%
  \renewcommand{\crefrangeconjunction}{ a\nobreakspace}%
  \renewcommand\crefrangepreconjunction{}%
  \renewcommand\crefrangepostconjunction{}%
  \renewcommand{\crefpairconjunction}{ e\nobreakspace}%
  \renewcommand{\crefmiddleconjunction}{, }%
  \renewcommand{\creflastconjunction}{ e\nobreakspace}%
  \renewcommand{\crefpairgroupconjunction}{ e\nobreakspace}%
  \renewcommand{\crefmiddlegroupconjunction}{, }%
  \renewcommand{\creflastgroupconjunction}{ e\nobreakspace}%
 %
  \Crefname{equation}{Equa\c c\~ao}{Equa\c c\~oes}%
  \Crefname{figure}{Figura}{Figuras}%
  \Crefname{subfigure}{Figura}{Figuras}%
  \Crefname{table}{Tabela}{Tabelas}%
  \Crefname{subtable}{Tabela}{Tabelas}%
  \Crefname{page}{P\'agina}{P\'aginas}%
  \Crefname{part}{Parte}{Partes}%
  \Crefname{chapter}{Cap\'itulo}{Cap\'itulos}%
  \Crefname{section}{Se\c c\~ao}{Se\c c\~oes}%
  \Crefname{subsection}{Se\c c\~ao}{Se\c c\~oes}%
  \Crefname{subsubsection}{Se\c c\~ao}{Se\c c\~oes}%
  \Crefname{appendix}{Ap\^endice}{Ap\^endices}%
  \Crefname{subappendix}{Ap\^endice}{Ap\^endices}%
  \Crefname{subsubappendix}{Ap\^endice}{Ap\^endices}%
  \Crefname{subsubsubappendix}{Ap\^endice}{Ap\^endices}%
  \Crefname{enumi}{Item}{Itens}%
  \Crefname{enumii}{Item}{Itens}%
  \Crefname{enumiii}{Item}{Itens}%
  \Crefname{enumiv}{Item}{Itens}%
  \Crefname{enumv}{Item}{Itens}%
  \Crefname{footnote}{Nota de rodap\'e}{Notas de rodap\'e}%
  \Crefname{theorem}{Teorema}{Teoremas}%
  \Crefname{lemma}{Lema}{Lemas}%
  \Crefname{corollary}{Corol\'ario}{Corol\'arios}%
  \Crefname{proposition}{Proposi\c c\~ao}{Proposi\c c\~oes}%
  \Crefname{definition}{Defini\c c\~ao}{Defini\c c\~oes}%
  \Crefname{result}{Resultado}{Resultados}%
  \Crefname{example}{Exemplo}{Exemplos}%
  \Crefname{remark}{Observa\c c\~ao}{Observa\c c\~oes}%
  \Crefname{note}{Nota}{Notas}%
  \Crefname{algorithm}{Algoritmo}{Algoritmos}%
  \Crefname{listing}{Listagem}{Listagens}%
  \Crefname{line}{Linha}{Linhas}%
 %
  \if@cref@capitalise%  capitalise set
    \if@cref@abbrev%
      \crefname{equation}{Eq.}{Eqs.}%
      \crefname{figure}{Fig.}{Figs.}%
      \crefname{subfigure}{Fig.}{Figs.}%
    \else%
      \crefname{equation}{Equa\c c\~ao}{Equa\c c\~oes}%
      \crefname{figure}{Figura}{Figuras}%
      \crefname{subfigure}{Figura}{Figuras}%
    \fi%
    \crefname{page}{P\'agina}{P\'aginas}%
    \crefname{table}{Tabela}{Tabelas}%
    \crefname{subtable}{Tabela}{Tabelas}%
    \crefname{part}{Parte}{Partes}%
    \crefname{chapter}{Cap\'itulo}{Cap\'itulos}%
    \crefname{section}{Se\c c\~ao}{Se\c c\~oes}%
    \crefname{subsection}{Se\c c\~ao}{Se\c c\~oes}%
    \crefname{subsubsection}{Se\c c\~ao}{Se\c c\~oes}%
    \crefname{appendix}{Ap\^endice}{Ap\^endices}%
    \crefname{subappendix}{Ap\^endice}{Ap\^endices}%
    \crefname{subsubappendix}{Ap\^endice}{Ap\^endices}%
    \crefname{subsubsubappendix}{Ap\^endice}{Ap\^endices}%
    \crefname{enumi}{Item}{Itens}%
    \crefname{enumii}{Item}{Itens}%
    \crefname{enumiii}{Item}{Itens}%
    \crefname{enumiv}{Item}{Itens}%
    \crefname{enumv}{Item}{Itens}%
    \crefname{footnote}{Nota de rodap\'e}{Notas de rodap\'e}%
    \crefname{theorem}{Teorema}{Teoremas}%
    \crefname{lemma}{Lema}{Lemas}%
    \crefname{corollary}{Corol\'ario}{Corol\'arios}%
    \crefname{proposition}{Proposi\c c\~ao}{Proposi\c c\~oes}%
    \crefname{definition}{Defini\c c\~ao}{Defini\c c\~oes}%
    \crefname{result}{Resultado}{Resultados}%
    \crefname{example}{Exemplo}{Exemplos}%
    \crefname{remark}{Observa\c c\~ao}{Observa\c c\~oes}%
    \crefname{note}{Nota}{Notas}%
    \crefname{algorithm}{Algoritmo}{Algoritmos}%
    \crefname{listing}{Listagem}{Listagens}%
    \crefname{line}{Linha}{Linhas}%
 %
  \else%  capitalise unset
    \if@cref@abbrev%
      \crefname{equation}{eq.}{eqs.}%
      \crefname{figure}{fig.}{figs.}%
      \crefname{subfigure}{fig.}{figs.}%
    \else%
      \crefname{equation}{equa\c c\~ao}{equa\c c\~oes}%
      \crefname{figure}{figura}{figuras}%
      \crefname{subfigure}{figura}{figuras}%
    \fi%
    \crefname{table}{tabela}{tabelas}%
    \crefname{subtable}{tabela}{tabelas}%
    \crefname{page}{p\'agina}{p\'aginas}%
    \crefname{part}{parte}{partes}%
    \crefname{chapter}{cap\'itulo}{cap\'itulos}%
    \crefname{section}{se\c c\~ao}{se\c c\~oes}%
    \crefname{subsection}{se\c c\~ao}{se\c c\~oes}%
    \crefname{subsubsection}{se\c c\~ao}{se\c c\~oes}%
    \crefname{appendix}{ap\^endice}{ap\^endices}%
    \crefname{subappendix}{ap\^endice}{ap\^endices}%
    \crefname{subsubappendix}{ap\^endice}{ap\^endices}%
    \crefname{subsubsubappendix}{ap\^endice}{ap\^endices}%
    \crefname{enumi}{item}{itens}%
    \crefname{enumii}{item}{itens}%
    \crefname{enumiii}{item}{itens}%
    \crefname{enumiv}{item}{itens}%
    \crefname{enumv}{item}{itens}%
    \crefname{footnote}{nota de rodap\'e}{notas de rodap\'e}%
    \crefname{theorem}{teorema}{teoremas}%
    \crefname{lemma}{lema}{lemas}%
    \crefname{corollary}{corol\'ario}{corol\'arios}%
    \crefname{proposition}{proposi\c c\~ao}{proposi\c c\~oes}%
    \crefname{definition}{defini\c c\~ao}{defini\c c\~oes}%
    \crefname{result}{resultado}{resultados}%
    \crefname{example}{exemplo}{exemplos}%
    \crefname{remark}{observa\c c\~ao}{observa\c c\~oes}%
    \crefname{note}{nota}{notas}%
    \crefname{algorithm}{algoritmo}{algoritmos}%
    \crefname{listing}{listagem}{listagens}%
    \crefname{line}{linha}{linhas}%
  \fi}% end \cref@addlangagedefs
%    \end{macrocode}
%
%
% \subsubsection{Catalan}
% \begin{macro}{catalan}
%   Catalan definitions thanks to Rafel Jaume Deya and Eva Bosch Roura.
% \end{macro}
%
% Set up the definitions used at the beginning of the document to define
% the formats created by the document preamble.
%    \begin{macrocode}
\DeclareOption{catalan}{%
  \AtBeginDocument{%
    \def\crefrangeconjunction@preamble{ a\nobreakspace}%
    \def\crefrangepreconjunction@preamble{}%
    \def\crefrangepostconjunction@preamble{}%
    \def\crefpairconjunction@preamble{ i\nobreakspace}%
    \def\crefmiddleconjunction@preamble{, }%
    \def\creflastconjunction@preamble{ i\nobreakspace}%
%    \end{macrocode}
% We have to define the group conjunctions explicitly here, rather than
% relying on fall-back definitions in terms of the above conjunctions
% (see \cref{sec:code:default_formats}), in case any other language
% option defines them explicitly and we need to override those.
%    \begin{macrocode}
    \def\crefpairgroupconjunction@preamble{ i\nobreakspace}%
    \def\crefmiddlegroupconjunction@preamble{, }%
    \def\creflastgroupconjunction@preamble{ i\nobreakspace}%
 %
    \Crefname@preamble{equation}{Equaci\'o}{Equacions}%
    \Crefname@preamble{figure}{Gr\`afic}{Gr\`afics}%
    \Crefname@preamble{table}{Taula}{Taules}%
    \Crefname@preamble{page}{P\`agina}{P\`agines}%
    \Crefname@preamble{part}{Part}{Parts}%
    \Crefname@preamble{chapter}{Cap\'itol}{Cap\'itols}%
    \Crefname@preamble{section}{Secci\'o}{Seccions}%
    \Crefname@preamble{appendix}{Ap\`endix}{Ap\`endixs}%
    \Crefname@preamble{enumi}{Punt}{Punts}%
    \Crefname@preamble{footnote}{Nota}{Notes}%
    \Crefname@preamble{theorem}{Teorema}{Teoremes}%
    \Crefname@preamble{lemma}{Lema}{Lemes}%
    \Crefname@preamble{corollary}{Coro\lgem ari}{Coro\lgem aris}%
    \Crefname@preamble{proposition}{Proposici\'o}{Proposicions}%
    \Crefname@preamble{definition}{Definici\'o}{Definicions}%
    \Crefname@preamble{result}{Resultat}{Resultats}%
    \Crefname@preamble{example}{Exemple}{Exemples}%
    \Crefname@preamble{remark}{Observaci\'o}{Observacions}%
    \Crefname@preamble{note}{Nota}{Notes}%
    \Crefname@preamble{algorithm}{Algorisme}{Algorismes}%
    \Crefname@preamble{listing}{Llistat}{Llistats}%
    \Crefname@preamble{line}{L\'inia}{L\'inies}%
 %
    \if@cref@capitalise%  capitalise set
      \crefname@preamble{equation}{Equaci\'o}{Equacions}%
      \crefname@preamble{figure}{Gr\`afic}{Gr\`afics}%
      \crefname@preamble{table}{Taula}{Taules}%
      \crefname@preamble{page}{P\`agina}{P\`agines}%
      \crefname@preamble{part}{Part}{Parts}%
      \crefname@preamble{chapter}{Cap\'itol}{Cap\'itols}%
      \crefname@preamble{section}{Secci\'o}{Seccions}%
      \crefname@preamble{appendix}{Ap\`endix}{Ap\`endixs}%
      \crefname@preamble{enumi}{Punt}{Punts}%
      \crefname@preamble{footnote}{Nota}{Notes}%
      \crefname@preamble{theorem}{Teorema}{Teoremes}%
      \crefname@preamble{lemma}{Lema}{Lemes}%
      \crefname@preamble{corollary}{Coro\lgem ari}{Coro\lgem aris}%
      \crefname@preamble{proposition}{Proposici\'o}{Proposicions}%
      \crefname@preamble{definition}{Definici\'o}{Definicions}%
      \crefname@preamble{result}{Resultat}{Resultats}%
      \crefname@preamble{example}{Exemple}{Exemples}%
      \crefname@preamble{remark}{Observaci\'o}{Observacions}%
      \crefname@preamble{note}{Nota}{Notes}%
      \crefname@preamble{algorithm}{Algorisme}{Algorismes}%
      \crefname@preamble{listing}{Llistat}{Llistats}%
      \crefname@preamble{line}{L\'inia}{L\'inies}%
 %
    \else%  capitalise unset
      \crefname@preamble{equation}{equaci\'o}{equacions}%
      \crefname@preamble{figure}{gr\`afic}{gr\`afics}%
      \crefname@preamble{table}{taula}{taules}%
      \crefname@preamble{page}{p\`agina}{p\`agines}%
      \crefname@preamble{part}{part}{parts}%
      \crefname@preamble{chapter}{cap\'itol}{cap\'itols}%
      \crefname@preamble{section}{secci\'o}{seccions}%
      \crefname@preamble{appendix}{ap\`endix}{ap\`endixs}%
      \crefname@preamble{enumi}{punt}{punts}%
      \crefname@preamble{footnote}{nota}{notes}%
      \crefname@preamble{theorem}{teorema}{teoremes}%
      \crefname@preamble{lemma}{lema}{lemes}%
      \crefname@preamble{corollary}{coro\lgem ari}{coro\lgem aris}%
      \crefname@preamble{proposition}{proposici\'o}{proposicions}%
      \crefname@preamble{definition}{definici\'o}{definicions}%
      \crefname@preamble{result}{resultat}{resultats}%
      \crefname@preamble{example}{exemple}{exemples}%
      \crefname@preamble{remark}{observaci\'o}{observacions}%
      \crefname@preamble{note}{nota}{notes}%
      \crefname@preamble{algorithm}{algorisme}{algorismes}%
      \crefname@preamble{listing}{llistat}{llistats}%
      \crefname@preamble{line}{l\'inia}{l\'inies}%
    \fi%
    \def\cref@language{catalan}%
  }}% end \AtBeginDocument and \DeclareOption
%    \end{macrocode}
%
% If using \package{babel} and the corresponding option is set, or if
% using \package{polyglossia} and the language has been loaded, add
% format definition commands to \cmd{\extras}\meta{language} or
% \cmd{\captions}\meta{language} so that language switching commands will
% change the cross-reference formats appropriately.
%    \begin{macrocode}
\cref@addlanguagedefs{catalan}{%
  \PackageInfo{cleveref}{loaded `catalan language definitions}%
  \renewcommand{\crefrangeconjunction}{ a\nobreakspace}%
  \renewcommand{\crefrangepreconjunction}{}%
  \renewcommand{\crefrangepostconjunction}{}%
  \renewcommand{\crefpairconjunction}{ i\nobreakspace}%
  \renewcommand{\crefmiddleconjunction}{, }%
  \renewcommand{\creflastconjunction}{ i\nobreakspace}%
  \renewcommand{\crefpairgroupconjunction}{ i\nobreakspace}%
  \renewcommand{\crefmiddlegroupconjunction}{, }%
  \renewcommand{\creflastgroupconjunction}{ i\nobreakspace}%
 %
  \Crefname{equation}{Equaci\'o}{Equacions}%
  \Crefname{figure}{Gr\`afic}{Gr\`afics}%
  \Crefname{subfigure}{Gr\`afic}{Gr\`afics}%
  \Crefname{table}{Taula}{Taules}%
  \Crefname{subtable}{Taula}{Taules}%
  \Crefname{page}{P\`agina}{P\`aginas}%
  \Crefname{part}{Part}{Parts}%
  \Crefname{chapter}{Cap\'itol}{Cap\'itols}%
  \Crefname{section}{Secci\'o}{Seccions}%
  \Crefname{subsection}{Secci\'o}{Seccions}%
  \Crefname{subsubsection}{Secci\'o}{Seccions}%
  \Crefname{appendix}{Ap\`endix}{Ap\`endixs}%
  \Crefname{subappendix}{Ap\`endix}{Ap\`endixs}%
  \Crefname{subsubappendix}{Ap\`endix}{Ap\`endixs}%
  \Crefname{subsubsubappendix}{Ap\`endix}{Ap\`endixs}%
  \Crefname{enumi}{Punt}{Punts}%
  \Crefname{enumii}{Punt}{Punts}%
  \Crefname{enumiii}{Punt}{Punts}%
  \Crefname{enumiv}{Punt}{Punts}%
  \Crefname{enumv}{Punt}{Punts}%
  \Crefname{footnote}{Nota}{Notes}%
  \Crefname{theorem}{Teorema}{Teoremes}%
  \Crefname{lemma}{Lema}{Lemes}%
  \Crefname{corollary}{Coro\lgem ari}{Coro\lgem aris}%
  \Crefname{proposition}{Proposici\'o}{Proposicions}%
  \Crefname{definition}{Definici\'o}{Definicions}%
  \Crefname{result}{Resultat}{Resultats}%
  \Crefname{example}{Exemple}{Exemples}%
  \Crefname{remark}{Observaci\'o}{Observacions}%
  \Crefname{note}{Nota}{Notes}%
  \Crefname{algorithm}{Algorisme}{Algorismes}%
  \Crefname{listing}{Llistat}{Llistats}%
  \Crefname{line}{L\'inia}{L\'inies}%
 %
  \if@cref@capitalise%  capitalise set
    \crefname{equation}{Equaci\'o}{Equacions}%
    \crefname{figure}{Gr\`afic}{Gr\`afics}%
    \crefname{subfigure}{Gr\`afic}{Gr\`afics}%
    \crefname{table}{Taula}{Taules}%
    \crefname{subtable}{Taula}{Taules}%
    \crefname{page}{P\`agina}{P\`aginas}%
    \crefname{part}{Part}{Parts}%
    \crefname{chapter}{Cap\'itol}{Cap\'itols}%
    \crefname{section}{Secci\'o}{Seccions}%
    \crefname{subsection}{Secci\'o}{Seccions}%
    \crefname{subsubsection}{Secci\'o}{Seccions}%
    \crefname{appendix}{Ap\`endix}{Ap\`endixs}%
    \crefname{subappendix}{Ap\`endix}{Ap\`endixs}%
    \crefname{subsubappendix}{Ap\`endix}{Ap\`endixs}%
    \crefname{subsubsubappendix}{Ap\`endix}{Ap\`endixs}%
    \crefname{enumi}{Punt}{Punts}%
    \crefname{enumii}{Punt}{Punts}%
    \crefname{enumiii}{Punt}{Punts}%
    \crefname{enumiv}{Punt}{Punts}%
    \crefname{enumv}{Punt}{Punts}%
    \crefname{footnote}{Nota}{Notes}%
    \crefname{theorem}{Teorema}{Teoremes}%
    \crefname{lemma}{Lema}{Lemes}%
    \crefname{corollary}{Coro\lgem ari}{Coro\lgem aris}%
    \crefname{proposition}{Proposici\'o}{Proposicions}%
    \crefname{definition}{Definici\'o}{Definicions}%
    \crefname{result}{Resultat}{Resultats}%
    \crefname{example}{Exemple}{Exemples}%
    \crefname{remark}{Observaci\'o}{Observacions}%
    \crefname{note}{Nota}{Notes}%
    \crefname{algorithm}{Algorisme}{Algorismes}%
    \crefname{listing}{Llistat}{Llistats}%
    \crefname{line}{L\'inia}{L\'inies}%
 %
  \else%  capitalise unset
    \crefname{equation}{equaci\'o}{equacions}%
    \crefname{figure}{gr\`afic}{gr\`afics}%
    \crefname{subfigure}{gr\`afic}{gr\`afics}%
    \crefname{table}{taula}{taules}%
    \crefname{subtable}{taula}{taules}%
    \crefname{page}{p\`agina}{p\`aginas}%
    \crefname{part}{part}{parts}%
    \crefname{chapter}{cap\'itol}{cap\'itols}%
    \crefname{section}{secci\'o}{seccions}%
    \crefname{subsection}{secci\'o}{seccions}%
    \crefname{subsubsection}{secci\'o}{seccions}%
    \crefname{appendix}{ap\`endix}{ap\`endixs}%
    \crefname{subappendix}{ap\`endix}{ap\`endixs}%
    \crefname{subsubappendix}{ap\`endix}{ap\`endixs}%
    \crefname{subsubsubappendix}{ap\`endix}{ap\`endixs}%
    \crefname{enumi}{punt}{punts}%
    \crefname{enumii}{punt}{punts}%
    \crefname{enumiii}{punt}{punts}%
    \crefname{enumiv}{punt}{punts}%
    \crefname{enumv}{punt}{punts}%
    \crefname{footnote}{nota}{notes}%
    \crefname{theorem}{teorema}{teoremes}%
    \crefname{lemma}{lema}{lemes}%
    \crefname{corollary}{coro\lgem ari}{coro\lgem aris}%
    \crefname{proposition}{proposici\'o}{proposicions}%
    \crefname{definition}{definici\'o}{definicions}%
    \crefname{result}{resultat}{resultats}%
    \crefname{example}{exemple}{exemples}%
    \crefname{remark}{observaci\'o}{observacions}%
    \crefname{note}{nota}{notes}%
    \crefname{algorithm}{algorisme}{algorismes}%
    \crefname{listing}{llistat}{llistats}%
    \crefname{line}{l\'inia}{l\'inies}%
  \fi}% end \cref@loadlanguagedefs
%    \end{macrocode}
%
%
% \subsection{Default Cross-Reference Formats}
% \label{sec:code:default_formats}
% The \option{capitalise} and \option{nameinlink} options must be
% processed before we process any language options and define the default
% formats, so that they take effect in the default format definitions.
% Therefore, we have to manually check whether they're present, and force
% processing of those before the other options.
%    \begin{macrocode}
\edef\@curroptions{\@ptionlist{\@currname.\@currext}}%
\@expandtwoargs\in@{,capitalise,}{%
  ,\@classoptionslist,\@curroptions,}%
\ifin@%
  \ExecuteOptions{capitalise}%
\else%
  \@expandtwoargs\in@{,capitalize,}{%
    ,\@classoptionslist,\@curroptions,}%
  \ifin@%
    \ExecuteOptions{capitalise}%
  \fi%
\fi%
\@expandtwoargs\in@{,nameinlink,}{%
  ,\@classoptionslist,\@curroptions,}%
\ifin@%
  \ExecuteOptions{nameinlink}%
\fi%
%    \end{macrocode}
%
%
% \begin{macro}{\crefdefaultlabelformat}
% \begin{macro}{\creflabelformat}
%   Define the default label formats, which don't depend on language. We
%   override the default format for equations, to follow the near
%   universal convention of enclosing equation labels in parentheses.
%   However, if the \option{nameinlink} option is enabled, the end of the
%   hyperlink must come outside the group or it will cause \LaTeX{}
%   grouping errors, so we must define it differently in that case.
%    \begin{macrocode}
\crefdefaultlabelformat{#2#1#3}%
\if@cref@nameinlink%
  \creflabelformat{equation}{#2\textup{(#1)}#3}%
\else%
  \creflabelformat{equation}{\textup{(#2#1#3)}}%
\fi%
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
%
% Set up the default English format definitions, then process options in
% the order they were supplied.
%    \begin{macrocode}
\@ifpackageloaded{polyglossia}%
  {\ifcsdef{languagename}%
    {\ExecuteOptions{\languagename}}%
    {\PackageWarning{cleveref}%
       {`polyglossia' loaded but default language not set
         - defaulting to english}%
     \ExecuteOptions{english}}}%
  {\ExecuteOptions{english}}%
\ProcessOptions*\relax%
%    \end{macrocode}
%
%
% Define the component-derived formats.
%    \begin{macrocode}
\AtBeginDocument{%
%    \end{macrocode}
% Use whatever's in the \dots|@preamble| definitions at the beginning of
% the document to set up the default cross-reference names, unless
% overridden by explicit definitions.
%    \begin{macrocode}
  \edef\@tempa{%
    \expandafter\noexpand\csname extras\cref@language\endcsname}%
  \@ifundefined{crefrangeconjunction}{%
    \let\crefrangeconjunction\crefrangeconjunction@preamble%
  }{%
    \expandafter\def\expandafter\@tempb\expandafter{%
      \expandafter\renewcommand\expandafter%
      {\expandafter\crefrangeconjunction\expandafter}%
      \expandafter{\crefrangeconjunction}}%
    \expandafter\expandafter\expandafter\cref@addto%
      \expandafter\@tempa\expandafter{\@tempb}%
  }%
  \@ifundefined{crefrangepreconjunction}{%
    \let\crefrangepreconjunction\crefrangepreconjunction@preamble%
  }{%
    \expandafter\def\expandafter\@tempb\expandafter{%
      \expandafter\renewcommand\expandafter%
      {\expandafter\crefrangepreconjunction\expandafter}%
      \expandafter{\crefrangepreconjunction}}%
    \expandafter\expandafter\expandafter\cref@addto%
      \expandafter\@tempa\expandafter{\@tempb}%
  }%
  \@ifundefined{crefrangepostconjunction}{%
    \let\crefrangepostconjunction\crefrangepostconjunction@preamble%
  }{%
    \expandafter\def\expandafter\@tempb\expandafter{%
      \expandafter\renewcommand\expandafter%
      {\expandafter\crefrangepostconjunction\expandafter}%
      \expandafter{\crefrangepostconjunction}}%
    \expandafter\expandafter\expandafter\cref@addto%
      \expandafter\@tempa\expandafter{\@tempb}%
  }%
%    \end{macrocode}
% If the group conjunctions haven't been defined, but explicit
% definitions \emph{have} been given for the reference list conjunctions,
% define the group conjunctions to be identical to the reference
% conjunctions.
%    \begin{macrocode}
  \@ifundefined{crefpairconjunction}{%
    \let\crefpairconjunction\crefpairconjunction@preamble%
  }{%
    \expandafter\def\expandafter\@tempb\expandafter{%
      \expandafter\renewcommand\expandafter%
      {\expandafter\crefpairconjunction\expandafter}%
      \expandafter{\crefpairconjunction}}%
    \expandafter\expandafter\expandafter\cref@addto%
      \expandafter\@tempa\expandafter{\@tempb}%
    \@ifundefined{crefpairgroupconjunction}{%
      \let\crefpairgroupconjunction\crefpairconjunction}{}%
  }%
  \@ifundefined{crefmiddleconjunction}{%
    \let\crefmiddleconjunction\crefmiddleconjunction@preamble%
  }{%
    \expandafter\def\expandafter\@tempb\expandafter{%
      \expandafter\renewcommand\expandafter%
      {\expandafter\crefmiddleconjunction\expandafter}%
      \expandafter{\crefmiddleconjunction}}%
    \expandafter\expandafter\expandafter\cref@addto%
      \expandafter\@tempa\expandafter{\@tempb}%
    \@ifundefined{crefmiddlegroupconjunction}{%
      \let\crefmiddlegroupconjunction\crefmiddleconjunction}{}%
  }%
  \@ifundefined{creflastconjunction}{%
    \let\creflastconjunction\creflastconjunction@preamble%
  }{%
    \expandafter\def\expandafter\@tempb\expandafter{%
      \expandafter\renewcommand\expandafter%
      {\expandafter\creflastconjunction\expandafter}%
      \expandafter{\creflastconjunction}}%
    \expandafter\expandafter\expandafter\cref@addto%
      \expandafter\@tempa\expandafter{\@tempb}%
%    \end{macrocode}
% Define the last group conjunction to include an extra comma.
%    \begin{macrocode}
    \@ifundefined{creflastgroupconjunction}{%
      \edef\creflastgroupconjunction{, \creflastconjunction}}{}%
  }%
  \@ifundefined{crefpairgroupconjunction}{%
    \let\crefpairgroupconjunction%
    \crefpairgroupconjunction@preamble%
  }{%
    \expandafter\def\expandafter\@tempb\expandafter{%
      \expandafter\renewcommand\expandafter%
      {\expandafter\crefpairgroupconjunction\expandafter}%
      \expandafter{\crefpairgroupconjunction}}%
    \expandafter\expandafter\expandafter\cref@addto%
      \expandafter\@tempa\expandafter{\@tempb}%
  }%
  \@ifundefined{crefmiddlegroupconjunction}{%
    \let\crefmiddlegroupconjunction%
      \crefmiddlegroupconjunction@preamble%
  }{%
    \expandafter\def\expandafter\@tempb\expandafter{%
      \expandafter\renewcommand\expandafter%
      {\expandafter\crefmiddlegroupconjunction\expandafter}%
      \expandafter{\crefmiddlegroupconjunction}}%
    \expandafter\expandafter\expandafter\cref@addto%
      \expandafter\@tempa\expandafter{\@tempb}%
  }%
  \@ifundefined{creflastgroupconjunction}{%
    \let\creflastgroupconjunction%
      \creflastgroupconjunction@preamble%
  }{%
    \expandafter\def\expandafter\@tempb\expandafter{%
      \expandafter\renewcommand\expandafter%
      {\expandafter\creflastgroupconjunction\expandafter}%
      \expandafter{\creflastgroupconjunction}}%
    \expandafter\expandafter\expandafter\cref@addto%
      \expandafter\@tempa\expandafter{\@tempb}%
  }%
%    \end{macrocode}
%
% Define any undefined formats listed in \cmd{\cref@label@types} using
% the components.
%    \begin{macrocode}
  \let\@tempstack\cref@label@types%
  \cref@isstackfull{\@tempstack}%
  \@whilesw\if@cref@stackfull\fi{%
    \edef\@tempa{\cref@stack@top{\@tempstack}}%
    \@ifundefined{cref@\@tempa @name}{%
      \expandafter\def\expandafter\@tempb\expandafter{%
        \csname cref@\@tempa @name\endcsname}%
      \expandafter\def\expandafter\@tempc\expandafter{%
        \csname cref@\@tempa @name@preamble\endcsname}%
      \expandafter\expandafter\expandafter%
        \let\expandafter\@tempb\@tempc%
      \expandafter\def\expandafter\@tempb\expandafter{%
        \csname cref@\@tempa @name@plural\endcsname}%
      \expandafter\def\expandafter\@tempc\expandafter{%
        \csname cref@\@tempa @name@plural@preamble\endcsname}%
      \expandafter\expandafter\expandafter%
        \let\expandafter\@tempb\@tempc%
    }{%
      \edef\@tempb{%
        \expandafter\noexpand\csname extras\cref@language\endcsname}%
      \expandafter\def\expandafter\@tempc\expandafter{%
        \expandafter\crefname\expandafter{\@tempa}}%
      \expandafter\expandafter\expandafter\cref@addto%
      \expandafter\expandafter\expandafter\@tempc%
      \expandafter\expandafter\expandafter{%
        \expandafter\expandafter\expandafter{%
          \csname cref@\@tempa @name\endcsname}}%
      \expandafter\expandafter\expandafter\cref@addto%
      \expandafter\expandafter\expandafter\@tempc%
      \expandafter\expandafter\expandafter{%
        \expandafter\expandafter\expandafter{%
          \csname cref@\@tempa @name@plural\endcsname}}%
      \expandafter\expandafter\expandafter\cref@addto%
        \expandafter\@tempb\expandafter{\@tempc}%
    }%
    \@ifundefined{Cref@\@tempa @name}{%
      \expandafter\def\expandafter\@tempb\expandafter{%
        \csname Cref@\@tempa @name\endcsname}%
      \expandafter\def\expandafter\@tempc\expandafter{%
        \csname Cref@\@tempa @name@preamble\endcsname}%
      \expandafter\expandafter\expandafter%
        \let\expandafter\@tempb\@tempc%
      \expandafter\def\expandafter\@tempb\expandafter{%
        \csname Cref@\@tempa @name@plural\endcsname}%
      \expandafter\def\expandafter\@tempc\expandafter{%
        \csname Cref@\@tempa @name@plural@preamble\endcsname}%
      \expandafter\expandafter\expandafter%
        \let\expandafter\@tempb\@tempc%
    }{%
      \edef\@tempb{%
        \expandafter\noexpand\csname extras\cref@language\endcsname}%
      \expandafter\def\expandafter\@tempc\expandafter{%
        \expandafter\Crefname\expandafter{\@tempa}}%
      \expandafter\expandafter\expandafter\cref@addto%
      \expandafter\expandafter\expandafter\@tempc%
      \expandafter\expandafter\expandafter{%
        \expandafter\expandafter\expandafter{%
          \csname Cref@\@tempa @name\endcsname}}%
      \expandafter\expandafter\expandafter\cref@addto%
      \expandafter\expandafter\expandafter\@tempc%
      \expandafter\expandafter\expandafter{%
        \expandafter\expandafter\expandafter{%
          \csname Cref@\@tempa @name@plural\endcsname}}%
      \expandafter\expandafter\expandafter\cref@addto%
        \expandafter\@tempb\expandafter{\@tempc}%
    }%
%    \end{macrocode}
% We only define the reference-range and multi-reference formats if the
% plural form of the name is defined in the corresponding
% \cmd{\cref\meta{type}@name@plural}. Though \cmd{\crefname} and
% \cmd{\Crefname} always define both the singular and plural forms
% together, cross-reference names can also be defined automatically by
% \cmd{\newtheorem}, which can only define the singular form. For
% symmetry, we apply the same logic to the normal cross-reference format
% definition (only defining it if the singular form of the name is
% defined in \cmd{\cref\meta{type}@name}), though this should always be
% the case.
%    \begin{macrocode}
    \@ifundefined{cref@\@tempa @format}{%
      \@ifundefined{cref@\@tempa @name}{}{%
        \expandafter\@crefdefineformat\expandafter{\@tempa}}}{}%
    \@ifundefined{crefrange@\@tempa @format}{%
      \@ifundefined{cref@\@tempa @name@plural}{}{%
        \expandafter\@crefrangedefineformat\expandafter{\@tempa}}}{}%
    \@ifundefined{cref@\@tempa @format@first}{%
      \@ifundefined{cref@\@tempa @name@plural}{}{%
        \expandafter\@crefdefinemultiformat\expandafter{\@tempa}}}{}%
    \@ifundefined{crefrange@\@tempa @format@first}{%
      \@ifundefined{cref@\@tempa @name@plural}{}{%
        \expandafter\@crefrangedefinemultiformat%
        \expandafter{\@tempa}}}{}%
    \cref@stack@pop{\@tempstack}%
    \cref@isstackfull{\@tempstack}}%
%    \end{macrocode}
%
% If formats for subsections are undefined, define them to be identical
% to the formats for sections. Similarly for subsections within
% appendices, subfigures, subtables, subequations and enums.
%    \begin{macrocode}
  \@crefcopyformats{section}{subsection}%
  \@crefcopyformats{subsection}{subsubsection}%
  \@crefcopyformats{appendix}{subappendix}%
  \@crefcopyformats{subappendix}{subsubappendix}%
  \@crefcopyformats{figure}{subfigure}%
  \@crefcopyformats{table}{subtable}%
  \@crefcopyformats{equation}{subequation}%
%
  \@crefcopyformats{enumi}{enumii}%
  \@crefcopyformats{enumii}{enumiii}%
  \@crefcopyformats{enumiii}{enumiv}%
  \@crefcopyformats{enumiv}{enumv}%
%    \end{macrocode}
% Definition of default |\labelcref| formats also needs to be postponed
% until beginning of document, in case |\crefdefaultlabelformat| has been
% modified.
%    \begin{macrocode}
  \@labelcrefdefinedefaultformats%
  %
  \let\cref@language\relax%
}%  end of \AtBeginDocument
%    \end{macrocode}
%
%
%
% \subsection{\file{cleveref.cfg} Config File}
% \begin{macro}{cleveref.cfg}
%   If \LaTeX{} can find a \file{cleveref.cfg} file in its search path,
%   then we read in whatever's in it. The intended use of
%   \file{cleveref.cfg} is to make it easy for authors to customise the
%   cross-reference formats for all their documents, without having to
%   manually include the definitions in every document preamble. In order
%   for these customisations to override the default formats, we input
%   \file{cleveref.cfg} right at the end, after the rest of
%   \package{cleveref} has loaded.
%    \begin{macrocode}
\InputIfFileExists{cleveref.cfg}%
  {\PackageInfo{cleveref}{reading definitions from cleveref.cfg}}{}%
%    \end{macrocode}
% \end{macro}
%
%
%
% \Finale
\endinput
%%
%% End of file `cleveref.dtx'.

%%% Local Variables:
%%% mode: doctex
%%% TeX-command-default: "Make"
%%% fill-column: 73
%%% TeX-master: t
%%% End: