%\newcommand{\Xref}[1]{\xref[\toupper]{#1}}
% \end{listing}
%
+% \DescribeMacro\formatxref
+% The reference itself is typeset by calling
+% \syntax{"\\formatxref{"<mangle>"}{"<string>"}{"<label>"}"}, which can do as
+% it pleases: the \<mangle> token is from the |\xref| invocation; the
+% \<string> is category of thing being referred to (as established by
+% |\defxref| below); and \<label> is the label, again from |\xref| . The
+% default behaviour is to print
+% \syntax{<mangle>"{"<string>"}~\\ref{"<label>"}"}, but this can be
+% overridden.
+% (Not quite true: in fact, the default does something better if
+% \package{hyperref} is detected, but the idea is basically the same.)
+%
% All that remains is to define the strings to be typeset for various kinds
% of labels.
% \DescribeMacro\defxref
% \end{macrocode}
% \end{macro}
%
+% \begin{macro}{\formatxref}
+% Output a cross-reference in the right way.
+% \begin{macrocode}
+\def\formatxref#1#2#3{%
+ \ifx\hyperref\@@undefined #1{#2}~\ref{#3}%
+ \else \hyperref[#3]{#1{#2}~\ref*{#3}}\fi%
+}
+% \end{macrocode}
+% \end{macro}
+%
% \begin{macro}{\xref}
% We're meant to typeset a reference. The first job is to see whether
% there's an optional argument. If so, grab it; otherwise |\relax| will do.
\ifx\@tempa\relax%
\PackageError{xref}{Unknown ref kind `#2'}%
\else%
- \toks@{#1}\toks\tw@\expandafter{\@tempa}%
- \edef\next@{\the\toks@{\the\toks\tw@}}%
- \next@~\ref{#2:#3}%
+ \toks@\expandafter{\@tempa}%
+ \edef\next@##1{##1{\the\toks@}}%
+ \next@{\formatxref{#1}}{#2:#3}%
\fi%
\fi%
}