The referencing package^{∗}

Andrew D. Lewis

1998/04/11

1 Using the referencing macros

The package referencing is designed to provide a convenient and flexible tool for cross referencing in L^{A}TEX. You select a new type of reference with the macro

\newrefformat  \newrefformat whose syntax is

\newrefformat{name}{full-text}{short-text}

Here name is a string to help you remember the thing you are referencing. For example, you might choose “chap” for chapters, “sec” for sections, “eq” for equations, etc. Then you will label each occurence of that object by \label{name:label}. For example, you might label a chapter by \label{chap:intro}. Make sure there are no colons in label! The string full-text indicates how the “full” reference should appear. Thus, for a chapter, you might make full-text Chapter~#1 which will make the word “Chapter” appear before the number. You can also do any additional typesetting for the reference here. For those times when you do not want a “full” reference, use short-text to specify what you want. For example, for the chapter, you may just want to make short-text #1, but you can do what ever you like! In both case, simply put #1 where you want the number (or whatever will be referenced). So, to summarise, to specify a chapter reference format you may type

     \newrefformat{chap}{Chapter~#1}{#1}

Any \newrefformat commands should appear only in the preamble.

The commands \ref and \pageref work as before. If you want to use the

\fref formatting you set up, use the command \fref to retrieve the “full” reference \sref and \sref to get the “short” reference.

2 Predefined reference formats

I have defined a number of reference formats that I often use, so they are available by default. These are eq For equations. Brackets are placed around the equation number.

∗This file has version number v1.0c, last revised 1998/04/11.

the For theorems. The word “Theorem” appears before the number in the “full”

version. In both versions, the number is displayed in the font set by the

\procreffont        \procreffont command. The default is \relax.

prop For propositions. The word “Proposition” appears before the number in the “full” version.

lem For lemmas. The word “Lemma” appears before the number in the “full” version.

plem For lemmas in proofs. The word “Lemma” appears before the number in the “full” version.

sublem For sublemmas. The word “Sublemma” appears before the number in the “full” version.

psublem For sublemmas in proofs. The word “Sublemma” appears before the number in the “full” version.

cor For corollaries. The word “Corollary” appears before the number in the “full” version.

claim For claims. The word “Claim” appears before the number in the “full” version.

conj For conjectures. The word “Conjecture” appears before the number in the “full” version.

ax For axioms. The word “Axiom” appears before the number in the “full” version.

post For postulate. The word “Postulate” appears before the number in the “full” version.

ths For theses. The word “Thesis” appears before the number in the “full” version.

def For definitions. The word “Definition” appears before the number in the “full” version.

rem For remarks. The word “Remark” appears before the number in the “full” version.

eq For examples. The word “Example” appears before the number in the “full” version.

countereg For counterexampless. The word “Counterexample” appears before the number in the “full” version. notn For notation. The word “Notation” appears before the number in the “full”

version.

ques For questions. The word “Question” appears before the number in the “full” version.

ass For assumptions. The word “Assumption” appears before the number in the “full” version.

alg For algorithms. The word “Algorithm” appears before the number in the “full” version.

proc For procedures. The word “Procedure” appears before the number in the “full” version.

ex For exercises. The word “Exercise” appears before the number in the “full” version. This is the last of the theorem-like reference formats.

fig For figures. The word defined by \figurename appears before the number in

the “full” format. The font for the number in this and the tab format is set

\floatreffont  by the \floatreffont command. The default is \relax.

tab For tables. The word defined by \tablename appears before the number in the “full” format.

part For parts. The word defined by \partname appears before the number in

the “full” format. The font of the number is determined by the command

\secreffont \setreffont whose default value leaves things as whatever the background font is use when the reference is made. This is the case for all the section reference formats.

chap For chapters. The word defined by \chaptername appears before the number in the “full” format.

app For appendices. The word defined by \appendixname appears before the number in the “full” format.

sec For sections. The word “Section” appears before the number in the “full” format.

subsec For subsections. The word “Section” appears before the number in the “full” format.

subsubsec For subsubsections. The word “Section” appears before the number in the “full” format. This ends the section reference formats.

pl For proclist items. If you are using the proclist package this will properly

format the references. The reference will be displayed in the font set by

\plreffont \plreffont whose default value is to do nothing.

enum For enumerate items. The reference will be displayed in the font set by

\enumreffont \enumreffont whose default value is to do nothing.

3 Implementation

1 ⟨∗package⟩

Load amsmath so it works by itself.

2

 3 \RequirePackage{amsmath}

The command for setting up new reference formats. This is borrowed from Kevin Ruland’s prettyref package, but I have modified it for “full” and “short” reference formats.

4

 5 \def\newrefformat#1#2#3{%
 6 \@namedef{@ADLfr@#1}##1##2{#2}%
 7 \@namedef{@ADLsr@#1}##1##2{#3}}

8

 9 \def\fref#1{\@ADL@fref#1:}
10 \def\@ADL@fref#1:#2:{%
11 \expandafter\ifx\csname @ADLfr@#1\endcsname\relax%
12  \PackageWarning{referencing}{Reference format #1\space undefined}%
13  \ref{#1:#2}%
14 \else%
15  \csname @ADLfr@#1\endcsname{\ref{#1:#2}}{\pageref{#1:#2}}%
16 \fi%

17 }

18

19 \def\sref#1{\@ADL@sref#1:}
20 \def\@ADL@sref#1:#2:{%
21 \expandafter\ifx\csname @ADLsr@#1\endcsname\relax%
22  \PackageWarning{referencing}{Reference format #1\space undefined}%
23  \ref{#1:#2}%
24 \else%
25  \csname @ADLsr@#1\endcsname{\ref{#1:#2}}{\pageref{#1:#2}}%
26 \fi%

27 }

The eq format. Also change the tag for displayed equations so it is not always upright. I hate that about the AMS macros…

28

29 \newrefformat{eq}{\tagform@{#1}}{\tagform@{#1}}
30 \renewcommand\maketag@@@[1]{\hbox{\m@th#1}}

Here are the theorem-like reference formats.

31

32 \newcommand\procreffont[1]{\gdef\@ADL@procreffont{#1}}
33 \procreffont{\relax}
34 \newrefformat{the}{Theorem~\mbox{\@ADL@procreffont#1}}
35 {\mbox{\@ADL@procreffont#1}}
36 \newrefformat{prop}{Proposition~\mbox{\@ADL@procreffont#1}}
37 {\mbox{\@ADL@procreffont#1}}
38 \newrefformat{lem}{Lemma~\mbox{\@ADL@procreffont#1}}
39 {\mbox{\@ADL@procreffont#1}}

40 \newrefformat{plem}{Lemma~\mbox{\@ADL@procreffont#1}}
41 {\mbox{\@ADL@procreffont#1}}
42 \newrefformat{sublem}{Sublemma~\mbox{\@ADL@procreffont#1}}
43 {\mbox{\@ADL@procreffont#1}}
44 \newrefformat{psublem}{Sublemma~\mbox{\@ADL@procreffont#1}}
45 {\mbox{\@ADL@procreffont#1}}
46 \newrefformat{cor}{Corollary~\mbox{\@ADL@procreffont#1}}
47 {\mbox{\@ADL@procreffont#1}}
48 \newrefformat{claim}{Claim~\mbox{\@ADL@procreffont#1}}
49 {\mbox{\@ADL@procreffont#1}}
50 \newrefformat{conj}{Conjecture~\mbox{\@ADL@procreffont#1}}
51 {\mbox{\@ADL@procreffont#1}}
52 \newrefformat{ax}{Axiom~\mbox{\@ADL@procreffont#1}}
53 {\mbox{\@ADL@procreffont#1}}
54 \newrefformat{post}{Postulate~\mbox{\@ADL@procreffont#1}}
55 {\mbox{\@ADL@procreffont#1}}
56 \newrefformat{ths}{Thesis~\mbox{\@ADL@procreffont#1}}
57 {\mbox{\@ADL@procreffont#1}}
58 \newrefformat{def}{Definition~\mbox{\@ADL@procreffont#1}}
59 {\mbox{\@ADL@procreffont#1}}
60 \newrefformat{rem}{Remark~\mbox{\@ADL@procreffont#1}}
61 {\mbox{\@ADL@procreffont#1}}
62 \newrefformat{eg}{Example~\mbox{\@ADL@procreffont#1}}
63 {\mbox{\@ADL@procreffont#1}}
64 \newrefformat{counteg}{Counterexample~\mbox{\@ADL@procreffont#1}}
65 {\mbox{\@ADL@procreffont#1}}
66 \newrefformat{notn}{Notation~\mbox{\@ADL@procreffont#1}}
67 {\mbox{\@ADL@procreffont#1}}
68 \newrefformat{ques}{Question~\mbox{\@ADL@procreffont#1}}
69 {\mbox{\@ADL@procreffont#1}}
70 \newrefformat{ass}{Assumption~\mbox{\@ADL@procreffont#1}}
71 {\mbox{\@ADL@procreffont#1}}
72 \newrefformat{alg}{Algorithm~\mbox{\@ADL@procreffont#1}}
73 {\mbox{\@ADL@procreffont#1}}
74 \newrefformat{proc}{Procedure~\mbox{\@ADL@procreffont#1}}
75 {\mbox{\@ADL@procreffont#1}}
76 \newrefformat{prob}{Problem~\mbox{\@ADL@procreffont#1}}
77 {\mbox{\@ADL@procreffont#1}}
78 \newrefformat{subprob}{\tagform@{#1}}
79 {\tagform@{#1}}

See if \@ADL@exfont has been set for exercises.

80

81 \@ifundefined{@ADL@exfont}{%
82 \newrefformat{ex}{Exercise~\mbox{\@ADL@procreffont#1}}
83 {\mbox{\@ADL@procreffont#1}}
84 \newrefformat{subex}{\mbox{\@ADL@procreffont(#1)}}
85 {\mbox{\@ADL@procreffont(#1)}}}
86 {%
87 \newrefformat{ex}{Exercise~\mbox{\@ADL@exfont#1}}

 88 {\mbox{\@ADL@exfont#1}}
 89 \newrefformat{subex}{\mbox{\@ADL@exfont(#1)}}
 90 {\mbox{\@ADL@exfont(#1)}}}

Here are the float reference formats.

91

 92 \newcommand\floatreffont[1]{\gdef\@ADL@floatreffont{#1}}
 93 \floatreffont{\relax}
 94 \newrefformat{fig}{\figurename~\mbox{\@ADL@floatreffont#1}}
 95 {\mbox{\@ADL@floatreffont#1}}
 96 \newrefformat{tab}{\tablename~\mbox{\@ADL@floatreffont#1}}
 97 {\mbox{\@ADL@floatreffont#1}}

Here are the sectioning reference formats.

98

 99 \newcommand\secreffont[1]{\gdef\@ADL@secreffont{#1}}
100 \secreffont{\relax}
101 \newrefformat{vol}{\volname~\mbox{\@ADL@secreffont#1}}
102 {\mbox{\@ADL@secreffont#1}}
103 \newcommand\volname{Volume}
104 \newrefformat{part}{\partname~\mbox{\@ADL@secreffont#1}}
105 {\mbox{\@ADL@secreffont#1}}
106 \newrefformat{chap}{\chaptername~\mbox{\@ADL@secreffont#1}}
107 {\mbox{\@ADL@secreffont#1}}
108 \newrefformat{app}{\appendixname~\mbox{\@ADL@secreffont#1}}
109 {\mbox{\@ADL@secreffont#1}}
110 \newrefformat{sec}{Section~\mbox{\@ADL@secreffont#1}}
111 {\mbox{\@ADL@secreffont#1}}
112 \newrefformat{subsec}{Section~\mbox{\@ADL@secreffont#1}}
113 {\mbox{\@ADL@secreffont#1}}
114 \newrefformat{subsubsec}{Section~\mbox{\@ADL@secreffont#1}}
115 {\mbox{\@ADL@secreffont#1}}

Here are the listing reference formats.

116

117 \newcommand\plreffont[1]{\gdef\@ADL@plreffont{#1}}
118 \newcommand\enumreffont[1]{\gdef\@ADL@enumreffont{#1}}
119 \plreffont{\relax}\enumreffont{\relax}
120 \newrefformat{pl}{\mbox{\@ADL@plreffont(#1)}}{\mbox{\@ADL@plreffont(#1)}}
121 \newrefformat{enum}{\mbox{\@ADL@enumreffont#1}}{\mbox{\@ADL@enumreffont#1}}

122

The double referencing commands.

123

124 \newcommand\fpldblref[2]{\mbox{\fref{#1}\fref{#2}}}
125 \newcommand\spldblref[2]{\mbox{\sref{#1}\sref{#2}}}
126 \newcommand\fenumdblref[2]{\mbox{\fref{#1}%
127 {\@ADL@enumreffont\textendash}\fref{#2}}}
128 \newcommand\senumdblref[2]{\mbox{\sref{#1}%
129 {\@ADL@enumreffont\textendash}\sref{#2}}}
130 % Only allow style changes and format specifications in preamble.
131 %    \begin{macrocode}

133 \@onlypreamble\newrefformat
134 \@onlypreamble\procreffont
135 \@onlypreamble\floatreffont
136 \@onlypreamble\secreffont
137 \@onlypreamble\plreffont
138 \@onlypreamble\enumreffont

139

140 %    \begin{macrocode}

141 ⟨/package⟩