% \begin{meta-comment} %% %% mdwref package -- slightly fancy cross-referencing stuff %% Copyright (c) 2007, 2019 Mark Wooding %% %% This file is part of the `mdwtools' LaTeX package collection. %% %% `mdwtools' is free software: you can redistribute it and/or modify it %% under the terms of the GNU General Public License as published by the %% Free Software Foundation; either version 2 of the License, or (at your %% option) any later version. %% %% `mdwtools' is distributed in the hope that it will be useful, but %% WITHOUT ANY WARRANTY; without even the implied warranty of %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU %% General Public License for more details. %% %% You should have received a copy of the GNU General Public License %% along with `mdwtools'. If not, write to the Free Software Foundation, %% Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. %% % \end{meta-comment} % % \begin{meta-comment} %<+package>\NeedsTeXFormat{LaTeX2e} %<+package>\ProvidesPackage{mdwref} %<+package> [2020/09/06 1.14.0 Cross-referencing] % \end{meta-comment} % % \CheckSum{131} %% \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 \~} %% % % \begin{meta-comment} % %<*driver> \input{mdwtools} \describespackage{mdwref} \usepackage{mdwtab} \mdwdoc % % % \end{meta-comment} % %^^A------------------------------------------------------------------------- % % \section{User guide} % % I always name my cross-reference labels with a prefix telling me what kind % of thing they are. A figure might be |fig:foo| or a table |tab:bar|. When % I refer to the thing, then, I basically have to repeat myself: % `|see table~\ref{tab:bar}|'. Kinda silly. % % \DescribeMacro\xref % The |\xref| command understands my prefixing system. I can say % `|\xref{tab:bar}|' and it inserts a reference to `table~4', for example. % This is, of course, useless if you want to put the reference at the % beginning of a sentence: `Table~4 shows\dots'. % \DescribeMacro\Xref % The |\Xref| command (note the initial capital) handles this properly, so % you just type `|\Xref{tab:bar} shows|\dots'. % % The full syntax of the |\xref| command is like this. % \begin{grammar} % ::= \[[ % "\\xref" % \[ "[" "]" \] % "{" "}" % \]] % \end{grammar} % The optional \ argument is a command to be applied to the generated % text: it \emph{must} be a single token. Rather than printing `table', or % whatever, it prints \syntax{"{table}"}. % The most obvious application of this is the |\Xref| command, which uses a % helper |\toupper|. % \DescribeMacro\toupper % The call \syntax{"\\toupper{""}"} typesets \ with the first % character in uppercase. So |\Xref| is defined simply as\footnote{Modulo % the fact that the author is a dreadful \TeX\ hacker.} % \begin{listing} %\newcommand{\Xref}[1]{\xref[\toupper]{#1}} % \end{listing} % % All that remains is to define the strings to be typeset for various kinds % of labels. % \DescribeMacro\defxref % For this, we use the |\defxref| command: % \begin{grammar} % ::= \[[ % "\\defxref" % "{" "}" % "{" "}" % \]] % \end{grammar} % The \ is what you put on the front of your labels; the \ is % 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} % ::= \[[ % "\\defxref*" % "{" "}" % "{" "}" % \]] % \end{grammar} % The \ 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 \ token, or |\relax|. % \item |#4| is the reference name itself. % \end{itemize} % % \DescribeMacro\formatxref % Simple references are typeset by calling % \syntax{"\\formatxref{""}{""}{" % \end{macrocode} % \nopagebreak % % \hfill Mark Wooding, \today % % \Finale % \endinput