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

\def\@setref#1#2#3{%
  \ifx#1\relax
   \protect\G@refundefinedtrue
   \nfss@text{\reset@font\bfseries ??}%
   \@latex@warning{Reference `#3' on page \thepage \space
             undefined}%
  \else
   \expandafter#2#1\null
  \fi}

\def\ref#1{\expandafter\@setref\csname r@#1\endcsname\@firstoftwo{#1}}

\def\pageref#1{\expandafter\@setref\csname r@#1\endcsname
                                   \@secondoftwo{#1}}
\def\@newl@bel#1#2#3{%
  \@ifundefined{#1@#2}%
    \relax
    {\gdef \@multiplelabels {%
       \@latex@warning@no@line{There were multiply-defined labels}}%
     \@latex@warning@no@line{Label `#2' multiply defined}}%
  \global\@namedef{#1@#2}{#3}}

\def\newlabel{\@newl@bel r}
\@onlypreamble\@newl@bel

\let \@multiplelabels \relax

\def\xreflabel#1{\@bsphack
  \protected@write\@auxout{}%
         {\string\newlabel{#1}{{#1}{\thexref}}}%
  \@esphack}

\def\refstepcounter#1{\stepcounter{#1}%
    \protected@edef\@currentlabel
       {\csname p@#1\endcsname\csname the#1\endcsname}%
}

\def\@currentlabel{}
%</crossreference>
%    \end{macrocode}
%
% \section{Example Document}
% This is a sample document to show how to use the crossreference system
% when you unpacked the dtx it should have generated this file called
% xrefexample.tex
%    \begin{macrocode}
%<*example>
\documentclass{article}

\usepackage{crossreference}

\begin{document}

\section{Animals}
\addxref{Animals}
Animals can eat other animals\xref{Animals} or plants\xref{Plants}.

\section{Plants}
\addxref{Plants}
Plants are mostly green and are eaten by Animals\xref{Animals}.

\section{Books and Writings}
\addxref{Books and Writings}
Books and writings are general not read by animals\xref{Animals} or plants\xref{Plants}.

\section{Humans}
Humans can read books and writings\xref{Books and Writings}.
\newpage
\section{Cross-References}
\crossreferences 

\end{document}
\endinput
%</example>
%    \end{macrocode}
% \Finale