X-Git-Url: https://git.distorted.org.uk/~mdw/mdwtools/blobdiff_plain/9d809eaca2b424a34222f8912d58d476720ffa24..e0464890d25b3299ff008d946e49d3fcf657694b:/mdwref.dtx

diff --git a/mdwref.dtx b/mdwref.dtx
index f1da45c..58bec2e 100644
--- a/mdwref.dtx
+++ b/mdwref.dtx
@@ -103,6 +103,18 @@
 %\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
@@ -158,6 +170,16 @@
 %    \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.
@@ -183,9 +205,9 @@
     \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%
 }
