Use this for equation numbers, which are traditionally just set in
parentheses.
% the string to be typeset by |\xref|. Such references are typeset using
% |\formatxref|, described below.
%
% the string to be typeset by |\xref|. Such references are typeset using
% |\formatxref|, described below.
%
+% For references that don't fit into this pattern, there's a more complex
+% definition syntax using |\defxref*|:
+% \begin{grammar}
+% <definition> ::= \[[
+% "\\defxref*"
+% "{" <prefix> "}"
+% "{" <expansion> "}"
+% \]]
+% \end{grammar}
+% The \<expansion> is given four arguments.
+% \begin{itemize}
+% \item |#1| is the name of a macro which should be given two arguments,
+% respectively the reference name and the body of the hyperlink to
+% generate.
+% \item |#2| is the name of a macro to apply to the reference name to typeset
+% the actual reference.
+% \item |#3| is the \<mangle> token, or |\relax|.
+% \item |#4| is the reference name itself.
+% \end{itemize}
+%
% \DescribeMacro\formatxref
% Simple references are typeset by calling
% \syntax{"\\formatxref{"<mangle>"}{"<string>"}{"<label>"}"}, which can do as
% \DescribeMacro\formatxref
% Simple references are typeset by calling
% \syntax{"\\formatxref{"<mangle>"}{"<string>"}{"<label>"}"}, which can do as
% \texttt{cor} & corollary $n$ \\
% \texttt{fig} & figure $n$ \\
% \texttt{tab} & table $n$ \\
% \texttt{cor} & corollary $n$ \\
% \texttt{fig} & figure $n$ \\
% \texttt{tab} & table $n$ \\
-% \texttt{eq} & equation $n$ \\
+% \texttt{eq} & ($n$) \\
% \texttt{i} & item $n$ \\
% \texttt{ex} & exercise $n$ \\
% \hlx*{vh}\end{tabular}
% \texttt{i} & item $n$ \\
% \texttt{ex} & exercise $n$ \\
% \hlx*{vh}\end{tabular}
% called \syntax{"\\xref$"<prefix>}, which takes two arguments: a \<mangle>
% token (or |\relax|), and the reference name.
% \begin{macrocode}
% called \syntax{"\\xref$"<prefix>}, which takes two arguments: a \<mangle>
% token (or |\relax|), and the reference name.
% \begin{macrocode}
+\def\defxref{\@ifstar\defxref@raw\defxref@cooked}
+\def\defxref@cooked#1#2%
{\expandafter\def\csname xref$#1\endcsname##1##2{\formatxref{##1}{#2}{##2}}}
{\expandafter\def\csname xref$#1\endcsname##1##2{\formatxref{##1}{#2}{##2}}}
+\def\defxref@raw#1#2{%
+ \expandafter\edef\csname xref$#1\endcsname
+ {\noexpand\xrefdispatch\expandafter\noexpand\csname xref$$#1\endcsname}%
+ \expandafter\def\csname xref$$#1\endcsname##1##2##3##4{#2}%
+}
% \end{macrocode}
% \end{macro}
%
% \end{macrocode}
% \end{macro}
%
\defxref{cor}{corollary}
\defxref{fig}{figure}
\defxref{tab}{table}
\defxref{cor}{corollary}
\defxref{fig}{figure}
\defxref{tab}{table}
+\defxref*{eq}{#1{#4}{(#2{#4})}}
\defxref{i}{item}
\defxref{ex}{exercise}
% \end{macrocode}
\defxref{i}{item}
\defxref{ex}{exercise}
% \end{macrocode}