| 1 |
\def\fileversion{1.0} |
| 2 |
\def\filedate{2001/05/19} |
| 3 |
\def\docdate{2001/05/19} |
| 4 |
% |
| 5 |
% \changes{v1.0}{19 May 200}{First Release} |
| 6 |
% |
| 7 |
% \MakeShortVerb{\|} |
| 8 |
% \title{Cross-referencing technical Documents with \texttt{crossreference}} |
| 9 |
% \author{Vince Filby} |
| 10 |
% \maketitle |
| 11 |
% \begin{abstract} |
| 12 |
% This is the instruction manual for using |
| 13 |
% \texttt{crossreference}. |
| 14 |
% \end{abstract} |
| 15 |
% |
| 16 |
% \section{Introduction} |
| 17 |
% This package allows authors to maintain a crossreference section in technical |
| 18 |
% documents easily and efficiently without having to worry about reordering, |
| 19 |
% removing or otherwise altering the crossreference numbers because they are |
| 20 |
% automatically generated. |
| 21 |
% |
| 22 |
% This package was originally designed to maintain the crossreference section |
| 23 |
% of software requirements document and a software design document. |
| 24 |
% |
| 25 |
% \section{Documentation Driver} |
| 26 |
% This code will generate the documentation. Since |
| 27 |
% it is the first peice of code in this file, the documentation |
| 28 |
% can obtained by simply processing this file with \LaTeXe |
| 29 |
% \begin{macrocode} |
| 30 |
%<*driver> |
| 31 |
\documentclass{ltxdoc} |
| 32 |
\EnableCrossrefs |
| 33 |
\CodelineIndex |
| 34 |
\RecordChanges |
| 35 |
\begin{document} |
| 36 |
\DocInput{crossreference.dtx} \PrintIndex \PrintChanges |
| 37 |
\end{document} |
| 38 |
%</driver> |
| 39 |
% \end{macrocode} |
| 40 |
% \section{User Interface} |
| 41 |
% This section defines everything that an average user should know. |
| 42 |
% |
| 43 |
% \begin{macrocode} |
| 44 |
%<*crossreference> |
| 45 |
\NeedsTeXFormat{LaTeX2e} |
| 46 |
\ProvidesPackage{crossreference}[\filedate\space\fileversion\space |
| 47 |
Crossreferencing for technical documents (V. Filby)] |
| 48 |
\newcounter{xref} |
| 49 |
% \end{macrocode} |
| 50 |
% \DescribeMacro{\crossreferences} |
| 51 |
% The command|\crossreferences| will print out the crossreference table. |
| 52 |
% The format is simple and uses the "list of figures" table of contents style. |
| 53 |
% You can change the format of the table by changing this macro. If you |
| 54 |
% choose to use a tabular format you will have to change the output lines |
| 55 |
% to include \&'s. |
| 56 |
% \begin{macrocode} |
| 57 |
\newcommand\crossreferences{% |
| 58 |
\if@twocolumn |
| 59 |
\@restonecoltrue\onecolumn |
| 60 |
\else |
| 61 |
\@restonecolfalse |
| 62 |
\fi |
| 63 |
\@starttoc{xref} |
| 64 |
\if@restonecol\twocolumn\fi |
| 65 |
} |
| 66 |
% \end{macrocode} |
| 67 |
% |
| 68 |
% \DescribeMacro{\addxref} |
| 69 |
% The command |\addxref| will add a a line to the crossreference |
| 70 |
% table containing the number, label and section label. |
| 71 |
% |
| 72 |
% \begin{macrocode} |
| 73 |
\newcommand{\addxref}[1]{% |
| 74 |
\protected@write{\@auxout}{}{\protect\@writefile{xref}{ |
| 75 |
\string\contentsline{figure}{\string\numberline {\thexref}{\string\ignorespaces{#1}}}{\@currentlabel} |
| 76 |
}} |
| 77 |
\xreflabel{#1} |
| 78 |
\stepcounter{xref} |
| 79 |
} |
| 80 |
% \end{macrocode} |
| 81 |
% |
| 82 |
% \DescribeMacro{\xref} |
| 83 |
% The command |\xref| can be used to refer to an item that has been |
| 84 |
% added to the crossreference table. |
| 85 |
% \begin{macrocode} |
| 86 |
\newcommand{\xref}[1]{~[REF \pageref{#1}]} |
| 87 |
% \end{macrocode} |
| 88 |
% |
| 89 |
% \section{Definitions} |
| 90 |
% This section contains the internal counters and macros that are used |
| 91 |
% to keep track of the crossreference labels. |
| 92 |
% \begin{macrocode} |
| 93 |
\def\G@refundefinedtrue{% |
| 94 |
\gdef\@refundefined{% |
| 95 |
\@latex@warning@no@line{There were undefined references}}} |
| 96 |
\let\@refundefined\relax |
| 97 |
|
| 98 |
\def\@setref#1#2#3{% |
| 99 |
\ifx#1\relax |
| 100 |
\protect\G@refundefinedtrue |
| 101 |
\nfss@text{\reset@font\bfseries ??}% |
| 102 |
\@latex@warning{Reference `#3' on page \thepage \space |
| 103 |
undefined}% |
| 104 |
\else |
| 105 |
\expandafter#2#1\null |
| 106 |
\fi} |
| 107 |
|
| 108 |
\def\ref#1{\expandafter\@setref\csname r@#1\endcsname\@firstoftwo{#1}} |
| 109 |
|
| 110 |
\def\pageref#1{\expandafter\@setref\csname r@#1\endcsname |
| 111 |
\@secondoftwo{#1}} |
| 112 |
\def\@newl@bel#1#2#3{% |
| 113 |
\@ifundefined{#1@#2}% |
| 114 |
\relax |
| 115 |
{\gdef \@multiplelabels {% |
| 116 |
\@latex@warning@no@line{There were multiply-defined labels}}% |
| 117 |
\@latex@warning@no@line{Label `#2' multiply defined}}% |
| 118 |
\global\@namedef{#1@#2}{#3}} |
| 119 |
|
| 120 |
\def\newlabel{\@newl@bel r} |
| 121 |
\@onlypreamble\@newl@bel |
| 122 |
|
| 123 |
\let \@multiplelabels \relax |
| 124 |
|
| 125 |
\def\xreflabel#1{\@bsphack |
| 126 |
\protected@write\@auxout{}% |
| 127 |
{\string\newlabel{#1}{{#1}{\thexref}}}% |
| 128 |
\@esphack} |
| 129 |
|
| 130 |
\def\refstepcounter#1{\stepcounter{#1}% |
| 131 |
\protected@edef\@currentlabel |
| 132 |
{\csname p@#1\endcsname\csname the#1\endcsname}% |
| 133 |
} |
| 134 |
|
| 135 |
\def\@currentlabel{} |
| 136 |
%</crossreference> |
| 137 |
% \end{macrocode} |
| 138 |
% |
| 139 |
% \section{Example Document} |
| 140 |
% This is a sample document to show how to use the crossreference system |
| 141 |
% when you unpacked the dtx it should have generated this file called |
| 142 |
% xrefexample.tex |
| 143 |
% \begin{macrocode} |
| 144 |
%<*example> |
| 145 |
\documentclass{article} |
| 146 |
|
| 147 |
\usepackage{crossreference} |
| 148 |
|
| 149 |
\begin{document} |
| 150 |
|
| 151 |
\section{Animals} |
| 152 |
\addxref{Animals} |
| 153 |
Animals can eat other animals\xref{Animals} or plants\xref{Plants}. |
| 154 |
|
| 155 |
\section{Plants} |
| 156 |
\addxref{Plants} |
| 157 |
Plants are mostly green and are eaten by Animals\xref{Animals}. |
| 158 |
|
| 159 |
\section{Books and Writings} |
| 160 |
\addxref{Books and Writings} |
| 161 |
Books and writings are general not read by animals\xref{Animals} or plants\xref{Plants}. |
| 162 |
|
| 163 |
\section{Humans} |
| 164 |
Humans can read books and writings\xref{Books and Writings}. |
| 165 |
\newpage |
| 166 |
\section{Cross-References} |
| 167 |
\crossreferences |
| 168 |
|
| 169 |
\end{document} |
| 170 |
\endinput |
| 171 |
%</example> |
| 172 |
% \end{macrocode} |
| 173 |
% \Finale |