Debian Codegraph @

texmf-dist/source/latex/fancyref/fancyref.dtx

raw
1 % \iffalse
2 %
3 % fancyref.dtx
4 % Docstrip archive, run through LaTeX.
5 %
6 % Copyright (C) 1999 Axel Reichert
7 % See the files README and COPYING.
8 %
9 % \fi
10 %
11 % \CheckSum{754}
12 %
13 %% \CharacterTable
14 %% {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
15 %% 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
16 %% Digits \0\1\2\3\4\5\6\7\8\9
17 %% Exclamation \! Double quote \" Hash (number) \#
18 %% Dollar \$ Percent \% Ampersand \&
19 %% Acute accent \' Left paren \( Right paren \)
20 %% Asterisk \* Plus \+ Comma \,
21 %% Minus \- Point \. Solidus \/
22 %% Colon \: Semicolon \; Less than \<
23 %% Equals \= Greater than \> Question mark \?
24 %% Commercial at \@ Left bracket \[ Backslash \\
25 %% Right bracket \] Circumflex \^ Underscore \_
26 %% Grave accent \` Left brace \{ Vertical bar \|
27 %% Right brace \} Tilde \~}
28 %
29 % \newcommand*{\ac}[1]{{\small #1}}
30 % \newcommand*{\booktitle}[1]{\emph{#1}}
31 % \newcommand*{\delimitor}[1]{\texttt{#1}}
32 % \newcommand*{\env}[1]{\texttt{#1}}
33 % \newcommand*{\error}[1]{\texttt{#1}}
34 % \newcommand*{\file}[1]{\texttt{#1}}
35 % \newcommand*{\format}[1]{\texttt{#1}}
36 % \newcommand*{\frowney}{\texttt{)-:}}
37 % \newcommand*{\labelname}[1]{\texttt{#1}}
38 % \newcommand*{\mantitle}[1]{\emph{#1}}
39 % \newcommand*{\option}[1]{\texttt{#1}}
40 % \newcommand*{\package}[1]{\texttt{#1}}
41 % \newcommand*{\person}[1]{\textsc{#1}}
42 % \newcommand*{\prefix}[1]{\texttt{#1}}
43 % \newcommand*{\sampleoutput}[1]{``#1''}
44 % \newcommand*{\smiley}{\texttt{(-:}}
45 % \newcommand*{\socalled}[1]{``#1''}
46 % \newcommand*{\source}[1]{\texttt{#1}}
47 % \newcommand*{\stringdef}[1]{``#1''}
48 % \newcommand*{\winkey}{\texttt{(-;}}
49 %
50 % \changes{v0.9b}{1999-02-02}{First release}
51 % \changes{v0.9c}{1999-02-03}{%
52 % Bug fixed in \fancyrefaddcaptions (\person{Felix Neubauer}%
53 % }
54 %
55 % \title{Fancy Cross-referencing}
56 % \author{Axel Reichert}
57 % \date{1999-02-03}
58 % \maketitle
59 % \begin{abstract}
60 % \noindent
61 % \file{fancyref.sty} is a package for fancy
62 % cross-referencing. See the files \file{README} and
63 % \file{COPYING} for additional information.
64 % \end{abstract}
65 % \tableofcontents
66 %
67 %
68 % \section{Introduction}
69 %
70 % Besides the notorious FAQ problem ``I get a section number when
71 % refering to a figure!''\footnote{Just put \cmd{\label}
72 % \emph{after} \cmd{\caption}.}, cross-referencing with \LaTeX{} is
73 % simple: You set a \cmd{\label} and refer to it with \cmd{\ref}
74 % and \cmd{\pageref}. These commands just work.
75 %
76 % Some lazy people soon had the idea to write a \cmd{\fullref}
77 % command to save some keystrokes:
78 %\begin{verbatim}
79 % \newcommand*{\fullref}[1]{\ref{#1} on page~\pageref{#1}}
80 %\end{verbatim}
81 % After that, people sometimes got page references to the current
82 % page which cluttered the text with redundant information.
83 %
84 % Perhaps one of these people was \person{Frank Mittelbach}, who
85 % was so annoyed that he wrote the \package{varioref} package
86 % \cite{Mittelbach:1998}. It provides a \cmd{\vref} command which
87 % generates output dependent on the difference between the page
88 % number of the label and the page number of the cross-reference,
89 % e.\,g.\ like \sampleoutput{on the next page} or \sampleoutput{on
90 % page~27}. No output will be generated if label and
91 % cross-reference fall onto the same page. This is really great,
92 % especially as the package supports lots of \emph{languages}.
93 %
94 % If you write larger documents with lots of sections and figures,
95 % you probably will find out that it is important to keep track of
96 % your labels. If you have a section labeled \labelname{britain}
97 % and a figure labeled \labelname{england}, it is only a question
98 % of time until you mix them up. To avoid this, most people
99 % \emph{prefix} the label with an abbreviation for the type of the
100 % referenced object, e.\,g.\ \prefix{fig} is widely used for figure
101 % labels. Also it is common practice to separate this classifying
102 % prefix from the label by a \emph{delimitor} character, normally
103 % \delimitor{:} is used by convention
104 % \cite[p.\,41]{Goossens:1994}. If your labels look like
105 % \labelname{sec:britain} or \labelname{fig:england} a mix-up will
106 % belong to the past.
107 %
108 % In almost all cases when you are referencing to a figure, you
109 % will add a descriptive \emph{string} like \sampleoutput{Figure},
110 % because the counter only is not very helpful to the
111 % reader. Hence, some people write macros for this purpose:
112 %\begin{verbatim}
113 % \newcommand*{\figref}[1]{\figurename~\ref{#1}}
114 %\end{verbatim}
115 % \cmd{\figurename} is much better than hard-coding
116 % \sampleoutput{Figure} into the macro, because in this way the
117 % command not only works in other languages, but also if you
118 % redefine the string:
119 %\begin{verbatim}
120 % \renewcommand*{\figurename}{Picture}
121 %\end{verbatim}
122 % Both captions of figures and cross-references will now happily
123 % use the new string.
124 %
125 % In many journals cross-references to figures are emphasized by
126 % usage of bold face or (much worse) underlining. This enables the
127 % reader (who is normally quickly browsing through an article) to
128 % find the description of an interesting figure. Of course you can
129 % add a \cmd{\textbf} to the definition above, however, you will
130 % run into trouble, if you want to use the \package{varioref}
131 % package. Neither
132 %\begin{verbatim}
133 % \newcommand*{\figref}[1]{\textbf{\figurename~\vref{#1}}}
134 %\end{verbatim}
135 % nor
136 %\begin{verbatim}
137 % \newcommand*{\figref}[1]{\textbf{\figurename}~\vref{#1}}
138 %\end{verbatim}
139 % will produce the desired output: You will get
140 % \sampleoutput{\textbf{\figurename~1 on page~2}} or
141 % \sampleoutput{\textbf{\figurename}~1 on page~2} instead of
142 % \sampleoutput{\textbf{\figurename~1} on page~2}. What you can do
143 % in this case is to hack the strings used by \file{varioref.sty},
144 % e.\,g.\ like:
145 %\begin{verbatim}
146 % \renewcommand*{\reftextfaraway}[1]{%
147 % \normalfont on page~\pageref{#1}%
148 % }
149 %\end{verbatim}
150 % But this is dependent on the language and does not work within
151 % italic text.
152 %
153 % Also, you will not want bold face for every cross-reference to a
154 % figure, only for the \socalled{main} cross-reference. And you
155 % will not want the page number to appear in every cross-reference
156 % when explaining a picture consisting of subfigures:
157 % \sampleoutput{The left part of Figure~1 on the following page
158 % shows England. The right part of Figure~1 on the next page shows
159 % Great Britain.} So your set of macros will grow further by
160 % \cmd{\mainfigref} and \cmd{\shortfigref}. And of course the same
161 % applies to tables as well. Slowly, cross-referencing starts to
162 % get messy~\ldots
163 %
164 % Ok, you got the idea. I felt the need for a more general
165 % solution. The \package{fancyref} package supports different
166 % \emph{languages} (at the moment only english and german) and
167 % allows customization of the classifying \emph{prefixes}, the
168 % \emph{delimitor} character and the \emph{strings} used in
169 % cross-references. Most important, it provides user-definable
170 % \emph{formats}. Enough advocacy, here we go!
171 %
172 %
173 % \section{Loading\label{sec:loading}}
174 %
175 % You will need:
176 % \begin{enumerate}
177 % \item \LaTeXe{} (at least the 1995/06/01 release)
178 % \item The \package{varioref} package (part of the standard
179 % \LaTeX{} tools, normally included in every distribution)
180 % \item The \package{german} or \package{babel} package
181 % \cite{Raichle:1996, Braams:1997} (if you want to write not only
182 % in english)
183 % \end{enumerate}
184 %
185 % The loading is simple:
186 %\begin{verbatim}
187 % \usepackage{fancyref}
188 %\end{verbatim}
189 % English is used as the default language.
190 %
191 %
192 % \subsection{Language Options}
193 %
194 % At the moment only english and german are supported languages,
195 % others might follow.
196 %
197 % If you write a german text:
198 % \DescribeMacro{german}
199 %\begin{verbatim}
200 % \usepackage{german} % \usepackage[german]{babel}
201 % \usepackage[german]{fancyref}
202 %\end{verbatim}
203 % \DescribeMacro{english}
204 % If you write a mixed english/german text:
205 %\begin{verbatim}
206 % \usepackage{german} % \usepackage[english,german]{babel}
207 % \usepackage[english,german]{fancyref}
208 %\end{verbatim}
209 % As with \file{babel.sty} the last language given in the optional
210 % argument is the current language. For \file{german.sty} you will
211 % have to use the \cmd{\selectlanguage} command
212 % \cite[p.\,7]{Raichle:1996} for english as current language.
213 %
214 % Do \emph{not} pass the language as a global option to the
215 % document class! Due to a feature of the \LaTeX{} option handler
216 %\begin{verbatim}
217 % \documentclass[english,danish]{article}
218 % \usepackage{babel,fancyref}
219 %\end{verbatim}
220 % will result in danish headings (\sampleoutput{Figur}) and english
221 % strings for the cross-references (\sampleoutput{Figure}),
222 % without a warning or an error \cite[p.\,20]{LaTeX:1998}. The
223 % correct usage
224 %\begin{verbatim}
225 % \documentclass{article}
226 % \usepackage[english,danish]{babel,fancyref}
227 %\end{verbatim}
228 % gives a package error, as expected, because danish is not (yet)
229 % supported (see \fref{sec:names}).
230 %
231 %
232 % \subsection{Spacing Options}
233 %
234 % The spacing between the string and the counter can be adjusted,
235 % see also \fref{sec:spacing}.
236 %
237 % \DescribeMacro{loose}
238 % Loose spacing, like in \sampleoutput{Figure~1}, which is the
239 % default, can be turned on explicitly by:
240 %\begin{verbatim}
241 % \usepackage[loose]{fancyref}
242 %\end{verbatim}
243 % \DescribeMacro{tight}
244 % Tight spacing, like in \sampleoutput{Figure\,1} will be obtained
245 % with:
246 %\begin{verbatim}
247 % \usepackage[tight]{fancyref}
248 %\end{verbatim}
249 %
250 % Most textbooks on typography recommend loose spacing (i.\,e.\ a
251 % normal word space) in this context, but tight spacing (half a
252 % word space) is recommended in abbreviated formats like
253 % \sampleoutput{Fig.\,1} \cite[p.\,220]{Willberg:1997}.
254 %
255 %
256 % \subsection{Format Options}
257 %
258 % The usage of page numbers for the cross-references can be
259 % controlled by using different \package{fancyref} formats, see
260 % \fref{sec:formats}. The two most common variants are provided
261 % also as package options.
262 %
263 % \DescribeMacro{plain}
264 % Output without a page number, like \sampleoutput{Figure~1}, is
265 % used if the \option{plain} option is specified:
266 %\begin{verbatim}
267 % \usepackage[plain]{fancyref}
268 %\end{verbatim}
269 % \DescribeMacro{vario}
270 % Output like from the \package{varioref} package
271 % (\sampleoutput{Figure~1 on the following page}) is used by
272 % default, but you could give the \option{vario} option
273 % explicitely:
274 %\begin{verbatim}
275 % \usepackage[vario]{fancyref}
276 %\end{verbatim}
277 %
278 %
279 % \subsection{Hook Options}
280 %
281 % The appearance of a cross-reference can not only be controlled by
282 % individual formats
283 % \marginpar{\raggedleft\footnotesize$\rightarrow$
284 % Sec.\,\ref{sec:formats}, p.\,\pageref{sec:formats}} which depend
285 % on the type of the referenced object, but also by a \emph{hook}
286 % which is executed for \emph{every} cross-reference, see
287 % \fref{sec:hooks}. Two variants of this hook can be activated by
288 % package options (but only one at a time).
289 %
290 % \DescribeMacro{margin}
291 % You can place all cross-references into the margin, like
292 % above. This is achieved by:
293 %\begin{verbatim}
294 % \usepackage[margin]{fancyref}
295 %\end{verbatim}
296 % If you want to do this, you should be aware of the limited space
297 % in the margin and use abbreviated formats. In my opinion marginal
298 % cross-references are sensible only for floats, for which I
299 % already defined the \option{margin} formats
300 % (see~\fref{sec:formats}), so this option should better be
301 % considered as an example of a hook. The above example was indeed
302 % done manually. \winkey
303 %
304 % \DescribeMacro{paren}
305 % You can put all cross-references into parentheses, like this:
306 % (\fref{sec:usage}). This is achieved by:
307 %\begin{verbatim}
308 % \usepackage[paren]{fancyref}
309 %\end{verbatim}
310 % Neither use this option in combination with the \option{margin}
311 % option nor with the \format{margin} formats!
312 %
313 %
314 % \section{Usage\label{sec:usage}}
315 %
316 % The cross-referencing is done by two almost identical macros.
317 %
318 % \DescribeMacro{\fref}
319 % \cmd{\fref} is used within a sentence and gives lower-case
320 % output, like \sampleoutput{figure~1}.
321 %
322 % \DescribeMacro{\Fref}
323 % \cmd{\Fref} is used at the beginning of a sentence and gives
324 % output with normal capitalization, like
325 % \sampleoutput{Figure~1}. For german users the macros make no
326 % difference, \sampleoutput{Abbildung~1} remains
327 % \sampleoutput{Abbildung~1} even within a sentence. How sensible!
328 % \winkey
329 %
330 % There seems to be no reliable heuristic to determine the start of
331 % a sentence, so you either have to cope with two macros or accept
332 % \sampleoutput{Figure~1} even within a sentence.
333 %
334 % Both macros take one optional argument, the format of the
335 % cross-reference, and one mandatory argument, consisting of the
336 % classifying prefix, the delimitor character and the label itself:
337 % \begin{tabbing}
338 % \small
339 % | \fref[|\meta{format}|]{|\meta{prefix}\meta{delim}\meta{label}|}| \\
340 % \small
341 % | \Fref[|\meta{format}|]{|\meta{prefix}\meta{delim}\meta{label}|}|
342 % \end{tabbing}
343 % A typical cross-reference will thus look like this,
344 %\begin{verbatim}
345 % \fref{fig:england}
346 %\end{verbatim}
347 % with \prefix{fig} as the prefix, \delimitor{:} as the delimitor
348 % and \labelname{britain} as the label, using the default
349 % format. The formats, the prefixes and the delimitor character are
350 % described in detail in the following section.
351 %
352 %
353 % \section{Customization}
354 %
355 %
356 % \subsection{Prefixes\label{sec:prefixes}}
357 %
358 % \DescribeMacro{\...labelprefix}
359 % The following table shows the defaults of the various prefixes I
360 % already defined for you.
361 % \begin{center}
362 % \begin{tabular}{@{}lll@{}}
363 % \hline
364 % Object &
365 % Macro &
366 % Prefix \\
367 % \hline
368 % Chapter & \cmd{\fancyrefchaplabelprefix} &
369 % \prefix{\fancyrefchaplabelprefix} \\
370 % Section & \cmd{\fancyrefseclabelprefix} &
371 % \prefix{\fancyrefseclabelprefix} \\
372 % Equation & \cmd{\fancyrefeqlabelprefix} &
373 % \prefix{\fancyrefeqlabelprefix} \\
374 % Figure & \cmd{\fancyreffiglabelprefix} &
375 % \prefix{\fancyreffiglabelprefix} \\
376 % Table & \cmd{\fancyreftablabelprefix} &
377 % \prefix{\fancyreftablabelprefix} \\
378 % Enumeration & \cmd{\fancyrefenumlabelprefix} &
379 % \prefix{\fancyrefenumlabelprefix} \\
380 % Footnote & \cmd{\fancyreffnlabelprefix} &
381 % \prefix{\fancyreffnlabelprefix} \\
382 % \hline
383 % \end{tabular}
384 % \end{center}
385 %
386 % If you need to add a prefix, use the following syntax:
387 % \begin{tabbing}
388 % \small
389 % | \newcommand*{|\meta{macro}|}{|\meta{prefix}|}|
390 % \end{tabbing}
391 % For example, if you need theorems in your document, you could
392 % use:
393 %\begin{verbatim}
394 % \newcommand*{\fancyrefthmlabelprefix}{thm}
395 %\end{verbatim}
396 % Note that the name of the macro does not matter, but names
397 % fitting into the scheme are highly recommended. Be consistent.
398 % After that, you will need to define your own \package{fancyref}
399 % formats for the new prefixes. Read \fref{sec:formats}. And let me
400 % know of objects for which I should supply prefixes.
401 %
402 % \DescribeMacro{\...changeprefix}
403 % If you need to change a prefix (either one I already provided or
404 % one you added later), use the following syntax:
405 % \begin{tabbing}
406 % \small
407 % | \fancyrefchangeprefix{|\meta{macro}|}{|\meta{prefix}|}|
408 % \end{tabbing}
409 % For example, if you are labeling your equations with \prefix{eqn}
410 % instead of \prefix{eq} (I guess this will be the most common
411 % change):
412 %\begin{verbatim}
413 % \fancyrefchangeprefix{\fancyrefeqlabelprefix}{eqn}
414 %\end{verbatim}
415 %
416 %
417 % \subsection{Delimitors\label{sec:delimitors}}
418 %
419 % \DescribeMacro{\fancyrefargdelim}
420 % The default delimitor character is the colon (\delimitor{:}). If
421 % you need to change it, for example to \delimitor{-}, use the
422 % following syntax:
423 %\begin{verbatim}
424 % \renewcommand*{\fancyrefargdelim}{-}
425 %\end{verbatim}
426 % There is no restriction to one character, you could also use
427 % \delimitor{too-long}, but you definitely should use a delimitor
428 % that never, ever occurs within the real label. A single
429 % \emph{letter} would be a very bad idea.
430 %
431 %
432 % \subsection{Spacing\label{sec:spacing}}
433 %
434 % \DescribeMacro{\...spacing}
435 % Quite unlikely that someone is not happy with at least one of the
436 % package options for this purpose, but one never knows~\ldots
437 %
438 % The following table shows the definition of the spacing macros.
439 % \begin{center}
440 % \begin{tabular}{@{}lll@{}}
441 % \hline
442 % Macro & Definition & Example \\
443 % \hline
444 % \cmd{\fancyrefloosespacing} & |~| &
445 % \Freffigname\fancyrefloosespacing 1 \\
446 % \cmd{\fancyreftightspacing} & \cmd{\,} &
447 % \Freffigname\fancyreftightspacing 1 \\
448 % \cmd{\fancyrefdefaultspacing} &
449 % \cmd{\fancyrefloosespacing} &
450 % \Freffigname\fancyrefdefaultspacing 1 \\
451 % \hline
452 % \end{tabular}
453 % \end{center}
454 %
455 % You could switch from loose to tight spacing and vice versa even
456 % after the package is loaded:
457 %\begin{verbatim}
458 % \renewcommand*{\fancyrefdefaultspacing}{%
459 % \fancyreftightspacing
460 % }
461 %\end{verbatim}
462 %
463 % You could loosen the tight spacing or tighten the loose spacing
464 % by using for example
465 %\begin{verbatim}
466 % \renewcommand*{\fancyrefloosespacing}{\kern.25em}
467 %\end{verbatim}
468 % but you should not change \cmd{\fancyrefdefaultspacing} in this
469 % way, because you would lose flexibility: Almost all
470 % \package{fancyref} formats (except the \format{margin} formats)
471 % use \cmd{\fancyrefdefaultspacing}, so it is clever to adjust
472 % \cmd{\fancyreftightspacing} and \cmd{\fancyrefloosespacing} and
473 % then to switch between the two variants. But I doubt that this
474 % will ever be necessary.
475 %
476 %
477 % \subsection{Names\label{sec:names}}
478 %
479 % \DescribeMacro{\...name}
480 % The following table shows some strings that are already provided
481 % by many document classes. If they do not exist, I will define
482 % them, otherwise I will not touch their values (in case you have
483 % changed them already).
484 % \begin{center}
485 % \begin{tabular}{@{}lll@{}}
486 % \hline
487 % Macro &
488 % English string &
489 % German string \\
490 % \hline
491 % \cmd{\chaptername} & \chaptername & Kapitel \\
492 % \cmd{\figurename} & \figurename & Abbildung \\
493 % \cmd{\pagename} & \pagename & Seite \\
494 % \cmd{\tablename} & \tablename & Tabelle \\
495 % \hline
496 % \end{tabular}
497 % \end{center}
498 %
499 % \DescribeMacro{\Fref...name}
500 % The next table shows the strings used for cross-references at the
501 % beginning of a sentence.
502 % \begin{center}
503 % \begin{tabular}{@{}lll@{}}
504 % \hline
505 % Macro &
506 % English string &
507 % German string \\
508 % \hline
509 % \cmd{\Frefchapname} & \cmd{\chaptername} & \cmd{\chaptername} \\
510 % \cmd{\Frefenumname} & \Frefenumname & Punkt \\
511 % \cmd{\Frefeqname} & \Frefeqname & Gleichung \\
512 % \cmd{\Freffigname} & \cmd{\figurename} & \cmd{\figurename} \\
513 % \cmd{\Freffnname} & \Freffnname & Fu\ss note \\
514 % \cmd{\Frefonname} & \Frefonname & Auf \\
515 % \cmd{\Frefpgname} & \cmd{\pagename} & \cmd{\pagename} \\
516 % \cmd{\Frefsecname} & \Frefsecname & Abschnitt \\
517 % \cmd{\Frefseename} & \Frefseename & Siehe \\
518 % \cmd{\Freftabname} & \cmd{\tablename} & \cmd{\tablename} \\
519 % \hline
520 % \end{tabular}
521 % \end{center}
522 %
523 % The \package{fancyref} package uss own macros to achieve maximum
524 % flexibility: If you redefine \cmd{\figurename} to
525 % \stringdef{Picture}, both the caption and the cross-references
526 % will use this string. If brevity is more important to you than
527 % consistency, you could also use \stringdef{Picture} within the
528 % caption and \stringdef{Pic.} for the cross-references. The
529 % necessary code is:
530 %\begin{verbatim}
531 % \renewcommand*{\figurename}{Picture}
532 % \renewcommand*{\Freffigname}{Pic.}
533 %\end{verbatim}
534 %
535 % \DescribeMacro{\fref...name}
536 % Within a sentence you should use \stringdef{picture} instead of
537 % \stringdef{Picture}. The \package{fancyref} package takes care of
538 % this for you and defines the corresponding macros
539 % (\cmd{\fref...name}) with automatically generated lower-case
540 % strings.
541 %
542 % \DescribeMacro{\Frefonname}
543 % \cmd{\Frefonname} and \cmd{\Frefseename} are not used by any
544 % \package{fancyref} formats, but you could use them for your
545 % additional formats.
546 % \DescribeMacro{\Frefseename}
547 % An interesting idea would be to use an arrow ($\mathsurround
548 % 0pt\rightarrow$) for \cmd{\Frefseename}:
549 %\begin{verbatim}
550 % \renewcommand*{\Frefseename}{%
551 % \ensuremath{\mathsurround 0pt\rightarrow}%
552 % }
553 %\end{verbatim}
554 % If do this, there will be no need to redefine \cmd{\frefseename}
555 % manually, because the \cmd{\MakeLowercase} command
556 % \cite[p.\,26]{LaTeX:1998} used internally to generate the
557 % lower-case strings can cope even with such strange
558 % things. \smiley
559 %
560 % \DescribeMacro{\Fref...shortname}
561 % The table shows some abbreviated strings used for
562 % cross-references with the \format{margin} formats. I do not like
563 % abbreviations very much,\footnote{I am stubborn, \person{Dirk},
564 % am I not? \winkey} because they need to be introduced carefully
565 % (written out at the first occurrence) and even then make a
566 % document less readable. Also, at the beginning of a sentence,
567 % abbreviations should be written out, so you run into
568 % inconsistencies (also known as trouble). In my opinion they are
569 % reasonable for the \format{margin} formats, so only the strings
570 % necessary for these formats are defined. If you are a big fan of
571 % \ac{PCMCIA}\footnote{People Cannot Memorize Computer Industry's
572 % Acronyms.} or abbreviations or simply do not bear my propaganda,
573 % you are on your own.
574 % \begin{center}
575 % \begin{tabular}{@{}lll@{}}
576 % \hline
577 % Macro &
578 % English string &
579 % German string \\
580 % \hline
581 % \cmd{\Freffigshortname} & \Freffigshortname & Abb. \\
582 % \cmd{\Frefpgshortname} & \Frefpgshortname & S. \\
583 % \cmd{\Freftabshortname} & \Freftabshortname & Tab. \\
584 % \hline
585 % \end{tabular}
586 % \end{center}
587 % Lower-case versions of these strings (\cmd{\fref...shortname})
588 % are generated automatically again.
589 %
590 % \DescribeMacro{\...addcaptions}
591 % If you add new prefixes (\fref{sec:prefixes}), you will probably
592 % also need further strings, e.\,g.\ \cmd{\frefthmname}. If you
593 % write a multilingual document, they should automatically be
594 % changed with the active language. For this case the
595 % \package{fancyref} package offers the following command,
596 % \begin{tabbing}
597 % \small
598 % | \fancyrefaddcaptions{|\meta{language}|}{|\meta{stringdefs}|}|
599 % \end{tabbing}
600 % which can be used only in the preamble of the document. In the
601 % above example you would use:
602 %\begin{verbatim}
603 % \fancyrefaddcaptions{english}{%
604 % \newcommand*{\Frefthmname}{Theorem}%
605 % \newcommand*{\frefthmname}{%
606 % \MakeLowercase{\Frefthmname}%
607 % }%
608 % }
609 % \fancyrefaddcaptions{german}{%
610 % \newcommand*{\Frefthmname}{Satz}%
611 % \newcommand*{\frefthmname}{\Frefthmname}%
612 % }
613 %\end{verbatim}
614 % If you can supply such additional strings or further languages,
615 % please do and send me a mail.
616 %
617 %
618 % \subsection{Formats\label{sec:formats}}
619 %
620 % The output of the \cmd{\fref} and \cmd{\Fref} commands depends on
621 % the used \package{fancyref} format. For all the different objects
622 % that can be cross-referenced, two \package{fancyref} formats,
623 % \format{plain} and \format{vario}, are already defined. In
624 % addition, for the floating objects (\env{figure} or \env{table}
625 % environments) two other \package{fancyref} format called
626 % \format{margin} and \format{main} are available. The following
627 % table shows sample output of these \package{fancyref} formats.
628 % \begin{center}
629 % \begin{tabular}{@{}lll@{}}
630 % \hline
631 % Object &
632 % Format &
633 % Output \\
634 % \hline
635 % Chapter & \prefix{vario} &
636 % \frefchapname\fancyrefdefaultspacing 1 on the following page \\
637 % & \prefix{plain} & \Frefchapname\fancyrefdefaultspacing 1 \\
638 % Equation & \prefix{vario} &
639 % \Frefeqname\fancyrefdefaultspacing (1) on the previous page \\
640 % & \prefix{plain} & \frefeqname\fancyrefdefaultspacing (1) \\
641 % Figure & \prefix{margin} & \footnotesize$\rightarrow$~%
642 % \Freffigshortname\fancyreftightspacing 1,
643 % p.\fancyreftightspacing 1 \\
644 % & \prefix{main} &
645 % \textbf{\freffigname\fancyrefdefaultspacing 1} on the
646 % facing page \\
647 % & \prefix{vario} & \Freffigname\fancyrefdefaultspacing 1 on
648 % the page before \\
649 % & \prefix{plain} & \freffigname\fancyrefdefaultspacing 1 \\
650 % \hline
651 % \end{tabular}
652 % \end{center}
653 % The \package{fancyref} formats for sections, enumerations and
654 % footnotes give output similar to those for chapters, whereas the
655 % formats for tables correspond to the \package{fancyref} formats
656 % for figures.
657 %
658 % \DescribeMacro{\...defaultformat}
659 % If no optional argument is specified for the \cmd{\fref} or
660 % \cmd{\Fref} command, the \format{vario} format will be used. You
661 % can change this default \package{fancyref} format to
662 % \format{plain}:
663 %\begin{verbatim}
664 % \renewcommand{\fancyrefdefaultformat}{plain}
665 %\end{verbatim}
666 %
667 % If you do not like some of these \package{fancyref} formats or
668 % you need some more, e.\,g.\ for theorems, algorithms etc., you
669 % will have to define them yourself. If you define some nice
670 % formats, please let me know, perhaps I will add them in a future
671 % version of this package.
672 %
673 % \DescribeMacro{\frefformat}
674 % The definition is done by means of two almost identical
675 % macros. \cmd{\frefformat} declares (or changes) the formats used
676 % within a
677 % \DescribeMacro{\Frefformat}
678 % sentence, whereas \cmd{\Frefformat} does the same for the formats
679 % used at the beginning of a sentence. Unfortunately this means
680 % that you need to do the work twice. \frowney
681 %
682 % Both macros take three mandatory arguments, the name of the
683 % \package{fancyref} format, the prefix macro and the description
684 % of the format itself:
685 % \begin{tabbing}
686 % \small
687 % | \frefformat{|\meta{format}|}{|\meta{prefix macro}\meta{output}|}| \\
688 % \small
689 % | \Frefformat{|\meta{format}|}{|\meta{prefix macro}\meta{output}|}|
690 % \end{tabbing}
691 % Within the third argument |#1| will be replaced by the counter of
692 % the referenced object (i.\,e.\ the output of a \cmd{\ref}
693 % command), |#2| will be replaced by the page number (i.\,e.\ the
694 % output of a \cmd{\pageref} command) and |#3| will be replaced by
695 % the output of a \cmd{\vpageref} command (\sampleoutput{on the
696 % facing page}, \sampleoutput{on page~1}).
697 %
698 % As an example, I will modify the output foss-references to
699 % figures done with the \format{main} format:
700 %\begin{verbatim}
701 % \frefformat{main}{\fancyreffiglabelprefix}{%
702 % \MakeUppercase{\freffigname}\fancyrefdefaultspacing#1#2%
703 % }%
704 % \Frefformat{main}{\fancyreffiglabelprefix}{%
705 % \MakeUppercase{\Freffigname}\fancyrefdefaultspacing#1#2%
706 % }%
707 %\end{verbatim}
708 % These redefinitions will make |\fref[main]{fig:foo}| come out as
709 % \sampleoutput{FIGURE~1 on page~1}. The page number will always be
710 % printed explicitly, not like \file{varioref.sty} output. By use
711 % of the \cmd{\freffigname}, \cmd{\Freffigname} and
712 % \cmd{\fancyrefdefaultspacing} commands it is ensured that further
713 % modifications of the string as well as the spacing and language
714 % options of the package will work. A quick and dirty hack would
715 % have been:
716 %\begin{verbatim}
717 % \frefformat{main}{\fancyreffiglabelprefix}{FIGURE~#1#2}
718 % \Frefformat{main}{\fancyreffiglabelprefix}{FIGURE~#1#2}
719 %\end{verbatim}
720 %
721 % The usage of the defined macros for spacing and naming like in
722 % the first example is of course highly recommended. Do not blame
723 % me, if your lazyness leads to inconsistencies. \winkey
724 %
725 % Note that in either case you \emph{must} use the prefix
726 % \emph{macro}, not the string itself!
727 %
728 %
729 % \subsection{Hooks\label{sec:hooks}}
730 %
731 % \DescribeMacro{\fancyrefhook}
732 % After all the work of the \package{fancyref} formats has been
733 % done, the result is passed as an argument to a hook command
734 % called \cmd{\fancyrefhook}. Normally, this hook does nothing but
735 % simply passing on the output. If you want to change this hook,
736 % use the following syntax:
737 % \begin{tabbing}
738 % \small
739 % | \renewcommand{\fancyrefhook}[1]{|\meta{definition}|}|
740 % \end{tabbing}
741 % Within \meta{definition}, |#1| will be replaced by the output of
742 % the \package{fancyref} format.
743 %
744 % You can use this hook for all kinds of weird stuff, e.\,g.\ if
745 % you want to have huge cross-references, use the following code:
746 %\begin{verbatim}
747 % \renewcommand*{\fancyrefhook}[1]{{\huge #1}}
748 %\end{verbatim}
749 % In this simple example the |*|-form of \cmd{\renewcommand} may be
750 % used, because the hook does not contain whole paragraphs
751 % \cite[p.\,14]{LaTeX:1997}. This makes debugging of your code
752 % easier.
753 %
754 % A more complex (and totally brain-dead) example does not work
755 % with the |*|-form:
756 %\begin{verbatim}
757 % \renewcommand{\fancyrefhook}[1]{%
758 % \begin{itemize}%
759 % \item #1%
760 % \end{itemize}%
761 % }
762 %\end{verbatim}
763 % If you define really \emph{useful} and \socalled{typographically
764 % correct} hooks, please send me a mail, so I can include your work
765 % in future versions of this package. \winkey
766 %
767 %
768 % \section{Examples}
769 %
770 % See the example file \file{freftest.tex} and its output,
771 % \file{freftest.dvi}.
772 %
773 %
774 % \section{Bugs}
775 %
776 % None, as my beta testers, \person{Dirk Kuypers} and
777 % \person{Robin~S.~Socha}, told me. \winkey
778 %
779 % If you encounter problems after having changed all your
780 % cross-references to the macros provided by \file{fancyref.sty},
781 % please go through the following checklist:
782 % \begin{enumerate}
783 % \item Make sure that you either use \delimitor{:} as a delimitor
784 % or that have changed it as described in \fref{sec:delimitors}.
785 % \item Make sure that you either use the default prefixes or that
786 % you have changed them as described in
787 % \fref{sec:prefixes}. Especially do \emph{not} try to modify the
788 % prefixes with the \cmd{\renewcommand} command.
789 % \item Make sure that you have defined all necessary formats in
790 % addition to those provided by me. The definition of
791 % \package{fancyref} formats is described in \fref{sec:formats}.
792 % \item Make sure that you have eliminated all old superfluous
793 % strings like \source{Figure} or \cmd{\figurename} in your source
794 % code. Just replacing all \cmd{\ref} commands with \cmd{\fref}
795 % will \emph{not} be sufficient.
796 % \end{enumerate}
797 %
798 % As far as I know, there is only one \emph{real} problem: If you
799 % are working on a multi-author document where each author is used
800 % to a different set of prefixes and prefers a different delimitor,
801 % be \emph{extremely cautious} when redefining the prefixes and the
802 % delimitor. You will get really funny errors, if the current
803 % delimitor is \delimitor{-}, the prefix for equations is
804 % \prefix{eqn} and you try to make a cross-reference to an equation
805 % in a part written by another author who used \delimitor{:} and
806 % \prefix{eq} in his \cmd{\label} commands.
807 %
808 % With the current implementation the only solution is to
809 % temporarily redefine the prefix and the deliminator, do the
810 % cross-reference and switch back to the original definitions
811 % again. This is annoying, of course. \frowney
812 %
813 % As a consequence, I would recommend either to drop this
814 % cross-reference or to try to convince your co-authors that your
815 % prefixes and delimitor are the best. Sorry.
816 %
817 %
818 % \section{Implementation}
819 %
820 %
821 % \subsection{Documentation Driver}
822 %
823 % \begin{macrocode}
824 %<*driver>
825 \documentclass[12pt,a4paper]{ltxdoc} \usepackage{fancyref}
826 \begin{document}
827 \DocInput{fancyref.dtx}
828 \end{document}
829 %</driver>
830 % \end{macrocode}
831 % \StopEventually{
832 % \font\logosl=logosl10 scaled\magstep1
833 % \begin{thebibliography}{1}
834 % \bibitem{AMS:1996}
835 % American Mathematical Society.
836 % \newblock \mantitle{$\cal{AMS}$-\LaTeX{} Version~1.2 User's
837 % Guide}, Nov.~1996.
838 % \newblock Version~1.02.
839 % \bibitem{Braams:1997}
840 % \person{Braams,~J.}: \mantitle{Babel, a multilingual package for
841 % use with \LaTeX's standard document classes}.
842 % \newblock Zoetermeer, Jan.~1997.
843 % \bibitem{Franz:1998}
844 % \person{Franz,~M.}: \mantitle{The \package{soul} package}, Dec.~1998.
845 % \newblock Version~1.1a.
846 % \bibitem{Goossens:1994}
847 % \person{Goossens,~M.; Mittelbach,~F.; Samarin,~A.}: \booktitle{Der
848 % \LaTeX-Begleiter}.
849 % \newblock Addison-Wesley, Bonn, 1st~edn., 1994.
850 % \bibitem{LaTeX:1997}
851 % \LaTeX3 Project Team.
852 % \newblock \mantitle{\LaTeXe{} for authors}, Jun.~1997.
853 % \bibitem{LaTeX:1998}
854 % \LaTeX3 Project Team.
855 % \newblock \mantitle{\LaTeXe{} for class and package writers},
856 % Jun.~1998.
857 % \bibitem{Mittelbach:1998}
858 % \person{Mittelbach,~F.}: \mantitle{The \package{varioref} package}.
859 % \newblock Mainz, May~1998.
860 % \newblock Version~1.1g.
861 % \bibitem{Raichle:1996}
862 % \person{Raichle,~B.}:
863 % \mantitle{Kurzbeschreibung~--~\file{german.sty} (Version~2.5)}.
864 % \newblock Deutschsprachige Anwendervereinigung \TeX{}~e.\,V.,
865 % May~1996.
866 % \newblock Version~2.5c.
867 % \bibitem{Willberg:1997}
868 % \person{Willberg,~H.\,P.; Forssman,~F.}:
869 % \booktitle{Lesetypographie}.
870 % \newblock Hermann Schmidt, Mainz, 1997.
871 % \end{thebibliography}
872 % }
873 %
874 %
875 % \subsection{\file{fancyref.sty}}
876 %
877 % \begin{macrocode}
878 %<*package>
879 % \end{macrocode}
880 %
881 %
882 % \subsubsection{Identification}
883 %
884 % As this package uses the \cmd{\MakeLowercase} command, it does
885 % not work with older \LaTeXe{} versions.
886 % \begin{macrocode}
887 \NeedsTeXFormat{LaTeX2e}[1995/06/01]%
888 % \end{macrocode}
889 % The package identifies itself with its release date, a version
890 % number and a short description.
891 % \begin{macrocode}
892 \ProvidesPackage{fancyref}[%
893 1999/02/03 v0.9c Fancy cross-referencing%
894 ]%
895 % \end{macrocode}
896 %
897 %
898 % \subsubsection{Initialization}
899 %
900 % \begin{macro}{\@fancyref@add@to}
901 % This macro is adapted from \file{babel.def}. If a command (the
902 % first argument) is undefined, it will be defined by the content
903 % of the second argument. If the command is defined already, the
904 % content of the second argument will be appended to the old
905 % definition of the command. The macro will be used to add further
906 % definitions to the \cmd{\captions...} commands provided by the
907 % \package{babel}~package or \file{german.sty}.
908 % \begin{macrocode}
909 \newcommand*{\@fancyref@add@to}[2]{%
910 \ifx#1\@undefined
911 \newcommand*{#1}{#2}%
912 \else
913 \ifx#1\relax
914 \newcommand*{#1}{#2}%
915 \else
916 \bgroup
917 \toks@\expandafter{#1#2}%
918 \xdef#1{\the\toks@}%
919 \egroup
920 \fi
921 \fi
922 }%
923 % \end{macrocode}
924 % \end{macro}
925 % \begin{macro}{\...addcaptions}
926 % This macro adds strings (the second argument) to the
927 % \cmd{\captions...} commands\footnote{Credits go to \person{Bernd
928 % Raichle} who told me how to do this in a politically correct
929 % way.} provided by the \package{babel} package or
930 % \file{german.sty}, or it simply defines these new strings. The
931 % name of the language is given in the first argument.
932 %
933 % To make the new strings become effective, the current language is
934 % saved\footnote{Credits go to \person{Felix Neubauer}, who pointed
935 % out that this should be done in a temporary command rather than
936 % a token register to avoid an error in combination with
937 % \file{babel.sty} or \file{german.sty} and automatically
938 % generated lists like the \file{toc}, \file{lof} or \file{lot}
939 % files.} at the beginning of the document, the code defining the
940 % strings is executed and the language for the captions is
941 % switched back again.
942 % \begin{macrocode}
943 \newcommand*{\@fancyref@temp}{\@empty}%
944 \newcommand*{\fancyrefaddcaptions}[2]{%
945 \@ifundefined{captions#1}{%
946 #2%
947 }{%
948 \expandafter
949 \@fancyref@add@to\csname captions#1\endcsname{#2}%
950 \AtBeginDocument{%
951 \let\@fancyref@temp=\languagename
952 \csname captions#1\endcsname
953 \csname captions\@fancyref@temp\endcsname
954 \let\@fancyref@temp=\@empty
955 }%
956 }%
957 }%
958 % \end{macrocode}
959 % \end{macro}
960 % \begin{macro}{\fancyrefhook}
961 % \label{sec:fancyrefhook}
962 % It may be clever to define a hook that is executed for every
963 % \cmd{\fref} or \cmd{\Fref} command. For the moment the hook does
964 % nothing but simply inserting its argument. I will do something
965 % more useful with it later in this file. \emph{You} can use it
966 % also for the way of cross-referencing the world is waiting for.
967 % \winkey
968 %
969 % Send me a mail, if you think you have defined a really nifty
970 % hook, so I can include it in future versions of this package.
971 % \begin{macrocode}
972 \newcommand*{\fancyrefhook}[1]{#1}%
973 % \end{macrocode}
974 % \end{macro}
975 % \begin{macro}{\...spacing}
976 % These two macros are used to define the spacing between the type
977 % of the referenced object and the counter of the object, for
978 % example between \sampleoutput{Figure} and \sampleoutput{1} in
979 % \sampleoutput{Figure~1}. Normally there is no need to change
980 % these definitions.
981 % \begin{macrocode}
982 \newcommand*{\fancyrefloosespacing}{~}%
983 \newcommand*{\fancyreftightspacing}{\,}%
984 % \end{macrocode}
985 % \end{macro}
986 % \begin{macro}{\...defaultformat}
987 % Now the default \package{fancyref} format is initialized. The
988 % real value will be set later depending on the package options.
989 % \begin{macrocode}
990 \newcommand*{\fancyrefdefaultformat}{\@empty}%
991 % \end{macrocode}
992 % \end{macro}
993 % Now some strings are initialized. The real values will be
994 % declared later depending on the package options.
995 % \begin{macrocode}
996 \newcommand*{\Frefchapname}{\@empty}%
997 \newcommand*{\Frefenumname}{\@empty}%
998 \newcommand*{\Frefeqname}{\@empty}%
999 \newcommand*{\Freffigname}{\@empty}%
1000 \newcommand*{\Freffnname}{\@empty}%
1001 \newcommand*{\Frefonname}{\@empty}%
1002 \newcommand*{\Frefpgname}{\@empty}%
1003 \newcommand*{\Frefsecname}{\@empty}%
1004 \newcommand*{\Frefseename}{\@empty}%
1005 \newcommand*{\Freftabname}{\@empty}%
1006 \newcommand*{\Freffigshortname}{\@empty}%
1007 \newcommand*{\Frefpgshortname}{\@empty}%
1008 \newcommand*{\Freftabshortname}{\@empty}%
1009 \newcommand*{\frefchapname}{\@empty}%
1010 \newcommand*{\frefenumname}{\@empty}%
1011 \newcommand*{\frefeqname}{\@empty}%
1012 \newcommand*{\freffigname}{\@empty}%
1013 \newcommand*{\freffnname}{\@empty}%
1014 \newcommand*{\frefonname}{\@empty}%
1015 \newcommand*{\frefpgname}{\@empty}%
1016 \newcommand*{\frefsecname}{\@empty}%
1017 \newcommand*{\frefseename}{\@empty}%
1018 \newcommand*{\freftabname}{\@empty}%
1019 \newcommand*{\freffigshortname}{\@empty}%
1020 \newcommand*{\frefpgshortname}{\@empty}%
1021 \newcommand*{\freftabshortname}{\@empty}%
1022 % \end{macrocode}
1023 %
1024 %
1025 % \subsubsection{Option Declaration}
1026 %
1027 % \DescribeMacro{english}
1028 % Now the package options are declared. Send me a mail, if you
1029 % define options for other languages than english or german.
1030 % \begin{macrocode}
1031 \DeclareOption{english}{%
1032 % \end{macrocode}
1033 % Some strings for cross-referencing in english are added (if the
1034 % command \cmd{\captionsenglish} is existing) or simply defined.
1035 % \begin{macrocode}
1036 \fancyrefaddcaptions{english}{%
1037 % \end{macrocode}
1038 % I better do not touch these strings, because they are used in
1039 % many document classes and may be already changed by the user.
1040 % Therefore they will be defined only if they did not exist before
1041 % \cite{LaTeX:1997}.
1042 % \begin{macrocode}
1043 \providecommand*{\chaptername}{Chapter}%
1044 \providecommand*{\figurename}{Figure}%
1045 \providecommand*{\pagename}{Page}%
1046 \providecommand*{\tablename}{Table}%
1047 % \end{macrocode}
1048 % \begin{macro}{\Fref...name}
1049 % The \package{fancyref} package uses its own strings for
1050 % cross-referencing purposes. In this way you can use
1051 % \stringdef{Chapter} for chapter headings but \stringdef{Chap.}
1052 % for cross-referencing.
1053 %
1054 % However, I do not recommend abbreviations for cross-references,
1055 % because they look ugly at the beginning of a sentence and should
1056 % be avoided in these places according to most typographers. Also,
1057 % the scientific publisher Springer does not allow abbreviation of
1058 % the words \sampleoutput{table} or \sampleoutput{Tabelle} (I
1059 % suppose because of ambuigity with \sampleoutput{tabbing} or
1060 % \sampleoutput{Tabulator}).
1061 %
1062 % The macros \cmd{\Frefonname} and \cmd{\Frefseename} may be useful
1063 % in new, user-defined \package{fancyref} formats
1064 % (\frefseename~\frefpgname~\pageref{sec:fancyrefformats}).
1065 %
1066 % All macro names start with a capital \source{S}, because they
1067 % will be used for cross-references at the beginning of a sentence,
1068 % where usually capital letters are used.
1069 % \begin{macrocode}
1070 \renewcommand*{\Frefchapname}{\chaptername}%
1071 \renewcommand*{\Frefenumname}{Item}%
1072 \renewcommand*{\Frefeqname}{Equation}%
1073 \renewcommand*{\Freffigname}{\figurename}%
1074 \renewcommand*{\Freffnname}{Footnote}%
1075 \renewcommand*{\Frefonname}{On}%
1076 \renewcommand*{\Frefpgname}{\pagename}%
1077 \renewcommand*{\Frefsecname}{Section}%
1078 \renewcommand*{\Frefseename}{See}%
1079 \renewcommand*{\Freftabname}{\tablename}%
1080 % \end{macrocode}
1081 % \end{macro}
1082 % \begin{macro}{\Fref...shortname}
1083 % These macros are used for cross-references placed in the margin.
1084 % In marginal notes compact information is crucial due to the
1085 % limited space, so abbreviated versions of the strings are used.
1086 % For my general opinion about abbreviations see above.
1087 % \begin{macrocode}
1088 \renewcommand*{\Freffigshortname}{Fig.}%
1089 \renewcommand*{\Frefpgshortname}{P.}%
1090 \renewcommand*{\Freftabshortname}{Tab.}%
1091 % \end{macrocode}
1092 % \end{macro}
1093 % \begin{macro}{\fref...name}
1094 % Now the lower-case versions of the language dependent strings
1095 % (starting with a lower-case \source{s}) are declared. As these
1096 % macros are generated automatically by use of the
1097 % \cmd{\MakeLowercase} command, there is no need to customize them,
1098 % except you want to use for example \stringdef{Table} at the start
1099 % of a sentence and \stringdef{tabular} within a sentence.
1100 % Inconsistencies like this should of course be avoided.
1101 % \begin{macrocode}
1102 \renewcommand*{\frefchapname}{%
1103 \MakeLowercase{\Frefchapname}%
1104 }%
1105 \renewcommand*{\frefenumname}{%
1106 \MakeLowercase{\Frefenumname}%
1107 }%
1108 \renewcommand*{\frefeqname}{%
1109 \MakeLowercase{\Frefeqname}%
1110 }%
1111 \renewcommand*{\freffigname}{%
1112 \MakeLowercase{\Freffigname}%
1113 }%
1114 \renewcommand*{\freffnname}{%
1115 \MakeLowercase{\Freffnname}%
1116 }%
1117 \renewcommand*{\frefonname}{%
1118 \MakeLowercase{\Frefonname}%
1119 }%
1120 \renewcommand*{\frefpgname}{%
1121 \MakeLowercase{\Frefpgname}%
1122 }%
1123 \renewcommand*{\frefsecname}{%
1124 \MakeLowercase{\Frefsecname}%
1125 }%
1126 \renewcommand*{\frefseename}{%
1127 \MakeLowercase{\Frefseename}%
1128 }%
1129 \renewcommand*{\freftabname}{%
1130 \MakeLowercase{\Freftabname}%
1131 }%
1132 \renewcommand*{\freffigshortname}{%
1133 \MakeLowercase{\Freffigshortname}%
1134 }%
1135 \renewcommand*{\frefpgshortname}{%
1136 \MakeLowercase{\Frefpgshortname}%
1137 }%
1138 \renewcommand*{\freftabshortname}{%
1139 \MakeLowercase{\Freftabshortname}%
1140 }%
1141 % \end{macrocode}
1142 % \end{macro}
1143 % The closing brace of the second argument of \cmd{\fancyrefaddto}:
1144 % \begin{macrocode}
1145 }%
1146 % \end{macrocode}
1147 % If \cmd{\captionsenglish} is defined (\file{babel.sty} or
1148 % \file{german.sty} are used), the language is switched to
1149 % \option{english}. In either case the \package{varioref} package
1150 % will be called with the option \option{english} to provide
1151 % english strings like \sampleoutput{on the following page}, see
1152 % \file{varioref.dvi}.
1153 % \begin{macrocode}
1154 \@ifundefined{captionsenglish}{%
1155 }{%
1156 \selectlanguage{english}%
1157 }%
1158 \PassOptionsToPackage{\CurrentOption}{varioref}%
1159 % \end{macrocode}
1160 % The closing brace of the \option{english} option:
1161 % \begin{macrocode}
1162 }%
1163 % \end{macrocode}
1164 % \DescribeMacro{german}
1165 % The definition of the german strings is more simple. Except for
1166 % \cmd{\Frefonname} and \cmd{\Frefseename} the lower-case versions
1167 % of the macros are identical with the upper-case version. Damn,
1168 % my mother tongue seems to be a rather simple language. \winkey
1169 %
1170 % A check for the existence of \cmd{\captionsgerman} should not be
1171 % necessary as in almost all cases german \LaTeX nicians use either
1172 % \file{babel.sty} or \file{german.sty}, but one never
1173 % knows~\ldots{} The language is switched and the
1174 % \package{varioref} package is prepared accordingly.
1175 % \begin{macrocode}
1176 \DeclareOption{german}{%
1177 \fancyrefaddcaptions{german}{%
1178 \providecommand*{\chaptername}{Kapitel}%
1179 \providecommand*{\figurename}{Abbildung}%
1180 \providecommand*{\pagename}{Seite}%
1181 \providecommand*{\tablename}{Tabelle}%
1182 \renewcommand*{\Frefchapname}{\chaptername}%
1183 \renewcommand*{\Frefenumname}{Punkt}%
1184 \renewcommand*{\Frefeqname}{Gleichung}%
1185 \renewcommand*{\Freffigname}{\figurename}%
1186 \renewcommand*{\Freffigshortname}{Abb.}%
1187 \renewcommand*{\Freffnname}{Fu\ss note}%
1188 \renewcommand*{\Frefonname}{Auf}%
1189 \renewcommand*{\Frefpgname}{\pagename}%
1190 \renewcommand*{\Frefpgshortname}{S.}%
1191 \renewcommand*{\Frefsecname}{Abschnitt}%
1192 \renewcommand*{\Frefseename}{Siehe}%
1193 \renewcommand*{\Freftabname}{\tablename}%
1194 \renewcommand*{\Freftabshortname}{Tab.}%
1195 \renewcommand*{\frefchapname}{\Frefchapname}%
1196 \renewcommand*{\frefenumname}{\Frefenumname}%
1197 \renewcommand*{\frefeqname}{\Frefeqname}%
1198 \renewcommand*{\freffigname}{\Freffigname}%
1199 \renewcommand*{\freffigshortname}{\Freffigshortname}%
1200 \renewcommand*{\freffnname}{\Freffnname}%
1201 \renewcommand*{\frefonname}{%
1202 \MakeLowercase{\Frefonname}%
1203 }%
1204 \renewcommand*{\frefpgname}{\Frefpgname}%
1205 \renewcommand*{\frefpgshortname}{\Frefpgshortname}%
1206 \renewcommand*{\frefsecname}{\Frefsecname}%
1207 \renewcommand*{\frefseename}{%
1208 \MakeLowercase{\Frefseename}%
1209 }%
1210 \renewcommand*{\freftabname}{\Freftabname}%
1211 \renewcommand*{\freftabshortname}{\Freftabshortname}%
1212 }%
1213 \@ifundefined{captionsgerman}{%
1214 }{%
1215 \selectlanguage{german}%
1216 }%
1217 \PassOptionsToPackage{\CurrentOption}{varioref}%
1218 }%
1219 % \end{macrocode}
1220 % \DescribeMacro{loose}
1221 % This option sets up loose spacing between string and counter like
1222 % \sampleoutput{Figure~1}. This spacing is recommended, because
1223 % \file{varioref.sty} is using it also (on a hard-coded base), and
1224 % so inconsistencies can be avoided. Do not take things too
1225 % seriously, the inter-word spacing varies quite a bit from line to
1226 % line. Even a trained eye will not always be able to distinguish
1227 % between \socalled{tight} and \socalled{loose} spacing. Compared
1228 % with favourite \ac{WYTYSYDG}\footnote{What You Thought You Saw
1229 % You Didn't Get.} word processors the spacing will be tight in
1230 % either case. \winkey
1231 % \begin{macrocode}
1232 \DeclareOption{loose}{%
1233 \newcommand*{\fancyrefdefaultspacing}{%
1234 \fancyrefloosespacing
1235 }%
1236 }%
1237 % \end{macrocode}
1238 % \DescribeMacro{margin}
1239 % This option is an example for a application of
1240 % \cmd{\fancyrefhook}. It places all cross-references into the
1241 % margin, typesetting them in \cmd{\footnotesize} and
1242 % \cmd{\raggedright}. For details see the definition of the
1243 % \format{margin} format \vpageref{sec:margin}.
1244 %
1245 % Do \emph{not} use the \option{margin} option in combination with
1246 % those \format{margin} formats. As this would need nested
1247 % \cmd{\marginpar} commands, you will get \error{Float(s) lost.}
1248 % error messages.
1249 %
1250 % Also, you should use abbreviated formats in combination with the
1251 % \option{margin} option, because there is not enough space for a
1252 % message like \sampleoutput{Figure~1 on the following page} out
1253 % there.
1254 %
1255 % I would recommend the usage of marginal cross-references only for
1256 % floats. The according formats are already defined, so take this
1257 % options as an example for what is possible.
1258 % \begin{macrocode}
1259 \DeclareOption{margin}{%
1260 \renewcommand{\fancyrefhook}[1]{%
1261 \mbox{}%
1262 \marginpar{%
1263 \raggedright\hspace{0pt}\footnotesize
1264 \ensuremath{\m@th\rightarrow}~#1%
1265 }%
1266 }%
1267 }%
1268 % \end{macrocode}
1269 % \DescribeMacro{paren}
1270 % Another example for an application of \cmd{\fancyrefhook}. It
1271 % simply puts parentheses around every cross-reference. This does
1272 % not make much sense, if you intend to use marginal notes for
1273 % cross-referencing purposes: If you combine this option with the
1274 % |margin| option, the last specified option \socalled{wins}. If
1275 % you use the \format{margin} formats defined later, you will get
1276 % parentheses around marginal notes, which is ugly.
1277 % \begin{macrocode}
1278 \DeclareOption{paren}{%
1279 \renewcommand*{\fancyrefhook}[1]{(#1)}%
1280 }%
1281 % \end{macrocode}
1282 % \DescribeMacro{plain}
1283 % If this package option is given, only the plain counter of the
1284 % referenced object will be used, no page number will be printed at
1285 % all.
1286 % \begin{macrocode}
1287 \DeclareOption{plain}{%
1288 \renewcommand*{\fancyrefdefaultformat}{plain}%
1289 }%
1290 % \end{macrocode}
1291 % \DescribeMacro{tight}
1292 % This option may be useful, if you prefer tight spacing between
1293 % string and counter. According to most textbooks on typography
1294 % this is the recommended spacing between parts of abbreviations
1295 % like \sampleoutput{i.\,e.} or \sampleoutput{Fig.\,1}.
1296 % \begin{macrocode}
1297 \DeclareOption{tight}{%
1298 \newcommand*{\fancyrefdefaultspacing}{%
1299 \fancyreftightspacing
1300 }%
1301 }%
1302 % \end{macrocode}
1303 % \DescribeMacro{vario}
1304 % If this package option is given, all cross-referencing commands
1305 % will use the \format{vario} format with variable output of the
1306 % page number, like with \file{varioref.sty}. This is the default.
1307 % \begin{macrocode}
1308 \DeclareOption{vario}{%
1309 \renewcommand*{\fancyrefdefaultformat}{vario}%
1310 }%
1311 % \end{macrocode}
1312 % Other local options will be passed to the \package{varioref}
1313 % package after causing an error message. If you use e.\,g.\
1314 % \option{danish} as a \emph{global} option (see
1315 % \file{clsguide.dvi}), you will get \emph{english}
1316 % \package{fancyref} strings without a warning or an error, hence
1317 % be careful. This is \emph{not} the fault of the
1318 % \package{fancyref} package, but a feature of the \LaTeXe{} option
1319 % handler. You \emph{really} should load the package according to
1320 % \fref{sec:loading}.
1321 % \begin{macrocode}
1322 \DeclareOption*{%
1323 \PackageError{fancyref}{%
1324 Unknown option ``\CurrentOption''%
1325 }{%
1326 The option ``\CurrentOption'' was not declared in
1327 package ``fancyref'',\MessageBreak
1328 perhaps you have only misspelled its name.\MessageBreak
1329 Currently only the languages ``english'' and
1330 ``german'' are defined.\MessageBreak
1331 Try typing <return> to proceed. Most likely your
1332 output will be wrong,\MessageBreak
1333 e. g. ``Figure'' instead of ``Abbildung''.%
1334 }%
1335 \PassOptionsToPackage{\CurrentOption}{varioref}%
1336 }%
1337 % \end{macrocode}
1338 %
1339 %
1340 % \subsubsection{Option Processing}
1341 %
1342 % If no options are specified, english strings for
1343 % cross-referencing, loose spacing between string and counter, and
1344 % variable output of the page numbers will be used by default.
1345 % Otherwise the options are processed in the order given by the
1346 % calling command.
1347 % \begin{macrocode}
1348 \ExecuteOptions{english,loose,vario}%
1349 \ProcessOptions*%
1350 % \end{macrocode}
1351 %
1352 %
1353 % \subsubsection{Loading Files}
1354 %
1355 % This package uses a nice feature of the \package{varioref}
1356 % package to generate variable output depending on the difference
1357 % between the page number on which the cross-reference occurs and
1358 % the page number of the referenced object. \file{varioref.sty} is
1359 % therefore required.
1360 % \begin{macrocode}
1361 \RequirePackage{varioref}%
1362 % \end{macrocode}
1363 %
1364 %
1365 % \subsubsection{Defining Commands}
1366 %
1367 % \begin{macro}{\...labelprefix}
1368 % Most users distinguish between labels for figures and tables to
1369 % avoid a mix-up. This is usually done by prefixing the labels
1370 % with \prefix{fig} or \prefix{tab}. These definitions declare the
1371 % defaults for this classifying part.
1372 % \begin{macrocode}
1373 \newcommand*{\fancyrefchaplabelprefix}{chap}%
1374 \newcommand*{\fancyrefenumlabelprefix}{enum}%
1375 \newcommand*{\fancyrefeqlabelprefix}{eq}%
1376 \newcommand*{\fancyreffiglabelprefix}{fig}%
1377 \newcommand*{\fancyreffnlabelprefix}{fn}%
1378 \newcommand*{\fancyrefseclabelprefix}{sec}%
1379 \newcommand*{\fancyreftablabelprefix}{tab}%
1380 % \end{macrocode}
1381 % \end{macro}
1382 % To enable user changes of these prefixes it is necessary to do
1383 % some list processing.\footnote{Credits go to \person{Carsten
1384 % Heinz} and \person{Heiko Oberdiek} for providing and optimizing
1385 % this code. I did not understand a single token in the beginning.
1386 % \winkey} There is one command list for each prefix. It contains
1387 % a number of macros that will rename the formatting commands
1388 % defined for this prefix. Initially, the package defines the
1389 % \cmd{\@fancyref@ren} command as empty, by means of
1390 % \cmd{\newcommand*}. In this way, even with the \cmd{\def} command
1391 % other macros cannot be overwritten by accident.\footnote{Credits
1392 % go to \person{Bernd Raichle} for this nice little trick, which is
1393 % used throughout this package.}
1394 % \begin{macro}{\@...append@ren}
1395 % The first argument of the following command is one of those
1396 % command lists, the second argument is a \package{fancyref}
1397 % format. A macro renaming the corresponding formatting command
1398 % will be appended to the command list.
1399 % \begin{macrocode}
1400 \newcommand*{\@fancyref@ren}{\@empty}%
1401 \newcommand*{\@fancyref@append@ren}[2]{%
1402 \ifx\relax#1%
1403 \def#1{\@fancyref@ren{#2}}%
1404 \else
1405 \expandafter\def\expandafter#1%
1406 \expandafter{#1\@fancyref@ren{#2}}%
1407 \fi
1408 }%
1409 % \end{macrocode}
1410 % \end{macro}
1411 % \begin{macro}{\@...check@prefix}
1412 % This command does most of the work, when a prefix is to be
1413 % renamed. First, the old, saved prefix for the corresponding
1414 % object type is recalled.
1415 % \begin{macrocode}
1416 \newcommand*{\@fancyref@check@prefix}[1]{%
1417 \expandafter\let\expandafter\@fancyref@old@prefix
1418 \csname @fancyref@saved@prefix\string#1\endcsname
1419 % \end{macrocode}
1420 % The old prefix is compared with the prefix given by the
1421 % argument.
1422 % \begin{macrocode}
1423 \ifx\@fancyref@old@prefix#1%
1424 % \end{macrocode}
1425 % If the prefixes are different, the renaming macros are set up.
1426 % Their only argument will be a \package{fancyref} format.
1427 % \begin{macrocode}
1428 \else
1429 \def\@fancyref@ren##1{%
1430 % \end{macrocode}
1431 % The prefixing part of the name will be changed, if the renaming
1432 % macros are called with the corresponding argument.
1433 %
1434 % More precisely, the definition of the old formatting command is
1435 % copied to a new command including the new prefix in its name.
1436 % \begin{macrocode}
1437 \expandafter
1438 \let\csname fr@##1@#1\expandafter\endcsname
1439 \csname fr@##1@\@fancyref@old@prefix\endcsname
1440 % \end{macrocode}
1441 % Then the old command is deleted.
1442 % \begin{macrocode}
1443 \expandafter
1444 \let\csname fr@##1@\@fancyref@old@prefix\endcsname
1445 \@undefined
1446 }%
1447 % \end{macrocode}
1448 % Now the command list containing the renaming macros for the given
1449 % prefix is executed.
1450 % \begin{macrocode}
1451 \csname @fr@ren@list\string#1\endcsname
1452 % \end{macrocode}
1453 % The procedure is repeated for the upper-case formatting
1454 % commands.
1455 % \begin{macrocode}
1456 \def\@fancyref@ren##1{%
1457 \expandafter
1458 \let\csname Fr@##1@#1\expandafter\endcsname
1459 \csname Fr@##1@\@fancyref@old@prefix\endcsname
1460 \expandafter
1461 \let\csname Fr@##1@\@fancyref@old@prefix\endcsname
1462 \@undefined
1463 }%
1464 \csname @Fr@ren@list\string#1\endcsname
1465 % \end{macrocode}
1466 % Finally the new prefix for the corresponding object type is
1467 % saved.
1468 % \begin{macrocode}
1469 \expandafter\let
1470 \csname @fancyref@saved@prefix\string#1\endcsname#1%
1471 \fi
1472 }%
1473 % \end{macrocode}
1474 % \end{macro}
1475 % \begin{macro}{\...changeprefix}
1476 % This user command changes the default prefix for an object type
1477 % (the first argument) to a new string (the second argument). Then
1478 % the renaming of the formatting commands is done.
1479 % \begin{macrocode}
1480 \newcommand*{\fancyrefchangeprefix}[2]{%
1481 \renewcommand*{#1}{#2}%
1482 \@fancyref@check@prefix{#1}%
1483 }%
1484 % \end{macrocode}
1485 % \end{macro}
1486 % \begin{macro}{\frefformat}
1487 % This macro is used to define new formats for the typesetting of
1488 % cross-references. It takes three arguments, the first is the
1489 % name of the declared format, the second is the prefix macro used
1490 % for this format (e.\,g.\ \cmd{\fancyreffiglabelprefix} for
1491 % cross-references to figures) and the third describes the output
1492 % generated by the cross-reference.
1493 %
1494 % Within the third argument |#1| will be replaced by the counter of
1495 % the referenced object (i.\,e.\ the output of a \cmd{\ref}
1496 % command), |#2| will be replaced by the page number (i.\,e.\ the
1497 % output of a \cmd{\pageref} command) and |#3| will be replaced by
1498 % the output of a \cmd{\vpageref} command.
1499 % \begin{macrocode}
1500 \newcommand{\frefformat}[2]{%
1501 % \end{macrocode}
1502 % It is checked if the prefix has changed and the already existing
1503 % formatting commands are renamed.
1504 % \begin{macrocode}
1505 \@fancyref@check@prefix{#2}%
1506 % \end{macrocode}
1507 % Then the \package{fancyref} format given in the first argument is
1508 % appended to the command list for the prefix given in the second
1509 % argument.
1510 % \begin{macrocode}
1511 \expandafter\@fancyref@append@ren
1512 \csname @fr@ren@list\string#2\endcsname{#1}%
1513 % \end{macrocode}
1514 % Finally the formatting command is defined.
1515 % \begin{macrocode}
1516 \@namedef{fr@#1@#2}##1##2##3%
1517 }%
1518 % \end{macrocode}
1519 % \end{macro}
1520 % \begin{macro}{\Frefformat}
1521 % The definition of the command for declaring \package{fancyref}
1522 % formats used at the beginning of a sentence is almost the same,
1523 % the only difference is that upper-case commands like
1524 % \cmd{\Fr@sample@ex} are used internally. This enables usage of
1525 % \stringdef{figure} within a sentence and \stringdef{Figure} at
1526 % the beginning of a sentence.
1527 % \begin{macrocode}
1528 \newcommand{\Frefformat}[2]{%
1529 \@fancyref@check@prefix{#2}%
1530 \expandafter\@fancyref@append@ren
1531 \csname @Fr@ren@list\string#2\endcsname{#1}%
1532 \@namedef{Fr@#1@#2}##1##2##3%
1533 }%
1534 % \end{macrocode}
1535 % \end{macro}
1536 %
1537 %
1538 % \paragraph{Format Definition.\label{sec:fancyrefformats}}
1539 %
1540 % Now it is time for the definition of the \package{fancyref}
1541 % formats. Generally the \format{vario} formats use the features
1542 % of the \package{varioref} package, whereas the \format{plain}
1543 % formats provide the name of the referenced object and its
1544 % counter, but no page number.
1545 %
1546 % Of course the various macros for spacing, classifying prefixes
1547 % and names of the referenced object are used. This will ensure
1548 % that the default formats also work after redefining e.\,g.\
1549 % \cmd{\chaptername} to \stringdef{Fool} and
1550 % \cmd{\fancyrefchaplabelprefix} to \stringdef{moron}.
1551 % Cross-references generated by |\fref{moron:bar}| will then come
1552 % out correctly as \sampleoutput{fool~1}.
1553 % \begin{macrocode}
1554 \frefformat{vario}{\fancyrefchaplabelprefix}{%
1555 \frefchapname\fancyrefdefaultspacing#1#3%
1556 }%
1557 \frefformat{plain}{\fancyrefchaplabelprefix}{%
1558 \frefchapname\fancyrefdefaultspacing#1%
1559 }%
1560 \frefformat{vario}{\fancyrefenumlabelprefix}{%
1561 \frefenumname\fancyrefdefaultspacing#1#3%
1562 }%
1563 \frefformat{plain}{\fancyrefenumlabelprefix}{%
1564 \frefenumname\fancyrefdefaultspacing#1%
1565 }%
1566 % \end{macrocode}
1567 % The formats for the cross-refernces to equations are more
1568 % complex, because I wanted to support the \cmd{\tagform@} command
1569 % of the \package{amsmath} package \cite{AMS:1996}:
1570 %\begin{verbatim}
1571 % \makeatletter
1572 % \renewcommand{\tagform@}[1]{\textup{[#1]}}
1573 % \makeatother
1574 %\end{verbatim}
1575 % will make both the equation numbers and the cross-references
1576 % generated e.\,g.\ by |\fref{eq:bar}| come out as
1577 % \sampleoutput{[1]}. Even within a formula a cross-referenced
1578 % equation number will \emph{not} be typeset in italics.
1579 % \begin{macrocode}
1580 \@ifundefined{tagform@}{%
1581 \frefformat{vario}{\fancyrefeqlabelprefix}{%
1582 \frefeqname\fancyrefdefaultspacing\textup{(#1)}#3%
1583 }%
1584 \frefformat{plain}{\fancyrefeqlabelprefix}{%
1585 \frefeqname\fancyrefdefaultspacing\textup{(#1)}%
1586 }%
1587 }{%
1588 \frefformat{vario}{\fancyrefeqlabelprefix}{%
1589 \frefeqname\fancyrefdefaultspacing
1590 \textup{\tagform@{#1}}#3%
1591 }%
1592 \frefformat{plain}{\fancyrefeqlabelprefix}{%
1593 \frefeqname\fancyrefdefaultspacing
1594 \textup{\tagform@{#1}}%
1595 }%
1596 }%
1597 % \end{macrocode}
1598 %
1599 % \label{sec:margin}
1600 % For figures and tables an additional \package{fancyref} format
1601 % called \format{margin} is provided to put cross-references into
1602 % the margin.
1603 %
1604 % |\mbox{}| will fix an alignment problem, if the \cmd{\marginpar}
1605 % command occurs prior to the first word of a paragraph, see
1606 % \cite[p.~75]{Goossens:1994}. |\hspace{0pt}| enables hyphenation
1607 % of the very first word of the \cmd{\marginpar} command.
1608 %
1609 % Marginal notes are typeset in a smaller font and
1610 % \cmd{\raggedright}. The \cmd{\rightarrow} is typeset in math
1611 % mode without the horizontal space usually added by
1612 % \cmd{\mathsurround}.
1613 %
1614 % In marginal notes tight spacing is appropriate, because due to
1615 % the limited space in the margins abbreviated strings are used.
1616 % \begin{macrocode}
1617 \frefformat{margin}{\fancyreffiglabelprefix}{%
1618 \mbox{}\marginpar{%
1619 \raggedright\hspace{0pt}\footnotesize
1620 \ensuremath{\m@th\rightarrow}~%
1621 \Freffigshortname\fancyreftightspacing#1,
1622 \frefpgshortname\fancyreftightspacing#2%
1623 }%
1624 }%
1625 % \end{macrocode}
1626 % The \format{main} format should be used for that cross-reference
1627 % which explains the referenced object in detail. Scientific
1628 % papers usually are browsed very quickly, perhaps the reader stops
1629 % at a figure or a table and begins to search for the explanation
1630 % of this float. Hence it is very helpful to typeset this main
1631 % cross-reference in bold face and to provide the full information
1632 % including the page number (with support of the \package{varioref}
1633 % package). These \format{main} formats are defined only for
1634 % floats, i.\,e.\ figures or tables, because for other,
1635 % non-floating objects the \socalled{main} cross-reference usually
1636 % can be found very near to the object.
1637 % \begin{macrocode}
1638 \frefformat{main}{\fancyreffiglabelprefix}{%
1639 \textbf{\freffigname\fancyrefdefaultspacing#1}#3%
1640 }%
1641 % \end{macrocode}
1642 % The rest of the format definitions should now be straight
1643 % forward.
1644 % \begin{macrocode}
1645 \frefformat{vario}{\fancyreffiglabelprefix}{%
1646 \freffigname\fancyrefdefaultspacing#1#3%
1647 }%
1648 \frefformat{plain}{\fancyreffiglabelprefix}{%
1649 \freffigname\fancyrefdefaultspacing#1%
1650 }%
1651 \frefformat{vario}{\fancyreffnlabelprefix}{%
1652 \freffnname\fancyrefdefaultspacing#1#3%
1653 }%
1654 \frefformat{plain}{\fancyreffnlabelprefix}{%
1655 \freffnname\fancyrefdefaultspacing#1%
1656 }%
1657 \frefformat{vario}{\fancyrefseclabelprefix}{%
1658 \frefsecname\fancyrefdefaultspacing#1#3%
1659 }%
1660 \frefformat{plain}{\fancyrefseclabelprefix}{%
1661 \frefsecname\fancyrefdefaultspacing#1%
1662 }%
1663 \frefformat{margin}{\fancyreftablabelprefix}{%
1664 \mbox{}\marginpar{%
1665 \raggedright\hspace{0pt}\footnotesize
1666 \ensuremath{\m@th\rightarrow}~%
1667 \Freftabshortname\fancyreftightspacing#1,
1668 \frefpgshortname\fancyreftightspacing#2%
1669 }%
1670 }%
1671 \frefformat{main}{\fancyreftablabelprefix}{%
1672 \textbf{\freftabname\fancyrefdefaultspacing#1}#3%
1673 }%
1674 \frefformat{vario}{\fancyreftablabelprefix}{%
1675 \freftabname\fancyrefdefaultspacing#1#3%
1676 }%
1677 \frefformat{plain}{\fancyreftablabelprefix}{%
1678 \freftabname\fancyrefdefaultspacing#1%
1679 }%
1680 % \end{macrocode}
1681 % Now it is time for the upper-case versions of the format
1682 % definitions.
1683 % \begin{macrocode}
1684 \Frefformat{vario}{\fancyrefchaplabelprefix}{%
1685 \Frefchapname\fancyrefdefaultspacing#1#3%
1686 }%
1687 \Frefformat{plain}{\fancyrefchaplabelprefix}{%
1688 \Frefchapname\fancyrefdefaultspacing#1%
1689 }%
1690 \Frefformat{vario}{\fancyrefenumlabelprefix}{%
1691 \Frefenumname\fancyrefdefaultspacing#1#3%
1692 }%
1693 \Frefformat{plain}{\fancyrefenumlabelprefix}{%
1694 \Frefenumname\fancyrefdefaultspacing#1%
1695 }%
1696 \@ifundefined{tagform@}{%
1697 \Frefformat{vario}{\fancyrefeqlabelprefix}{%
1698 \Frefeqname\fancyrefdefaultspacing\textup{(#1)}#3%
1699 }%
1700 \Frefformat{plain}{\fancyrefeqlabelprefix}{%
1701 \Frefeqname\fancyrefdefaultspacing\textup{(#1)}%
1702 }%
1703 }{%
1704 \Frefformat{vario}{\fancyrefeqlabelprefix}{%
1705 \Frefeqname\fancyrefdefaultspacing
1706 \textup{\tagform@{#1}}#3%
1707 }%
1708 \Frefformat{plain}{\fancyrefeqlabelprefix}{%
1709 \Frefeqname\fancyrefdefaultspacing
1710 \textup{\tagform@{#1}}%
1711 }%
1712 }%
1713 \Frefformat{margin}{\fancyreffiglabelprefix}{%
1714 \mbox{}\marginpar{%
1715 \raggedright\hspace{0pt}\footnotesize
1716 \ensuremath{\m@th\rightarrow}~%
1717 \Freffigshortname\fancyreftightspacing#1,
1718 \frefpgshortname\fancyreftightspacing#2%
1719 }%
1720 }%
1721 \Frefformat{main}{\fancyreffiglabelprefix}{%
1722 \textbf{\Freffigname\fancyrefdefaultspacing#1}#3%
1723 }%
1724 \Frefformat{vario}{\fancyreffiglabelprefix}{%
1725 \Freffigname\fancyrefdefaultspacing#1#3%
1726 }%
1727 \Frefformat{plain}{\fancyreffiglabelprefix}{%
1728 \Freffigname\fancyrefdefaultspacing#1%
1729 }%
1730 \Frefformat{vario}{\fancyreffnlabelprefix}{%
1731 \Freffnname\fancyrefdefaultspacing#1#3%
1732 }%
1733 \Frefformat{plain}{\fancyreffnlabelprefix}{%
1734 \Freffnname\fancyrefdefaultspacing#1%
1735 }%
1736 \Frefformat{vario}{\fancyrefseclabelprefix}{%
1737 \Frefsecname\fancyrefdefaultspacing#1#3%
1738 }%
1739 \Frefformat{plain}{\fancyrefseclabelprefix}{%
1740 \Frefsecname\fancyrefdefaultspacing#1%
1741 }%
1742 \Frefformat{margin}{\fancyreftablabelprefix}{%
1743 \mbox{}\marginpar{%
1744 \raggedright\hspace{0pt}\footnotesize
1745 \ensuremath{\m@th\rightarrow}~%
1746 \Freftabshortname\fancyreftightspacing#1,
1747 \frefpgshortname\fancyreftightspacing#2%
1748 }%
1749 }%
1750 \Frefformat{main}{\fancyreftablabelprefix}{%
1751 \textbf{\Freftabname\fancyrefdefaultspacing#1}#3%
1752 }%
1753 \Frefformat{vario}{\fancyreftablabelprefix}{%
1754 \Freftabname\fancyrefdefaultspacing#1#3%
1755 }%
1756 \Frefformat{plain}{\fancyreftablabelprefix}{%
1757 \Freftabname\fancyrefdefaultspacing#1%
1758 }%
1759 % \end{macrocode}
1760 % \ldots~much tedious work!
1761 % \begin{macro}{\fancyrefargdelim}
1762 % \label{sec:delim}
1763 % The following definition sets up the default for the delimiting
1764 % character between the \socalled{classifying} part and the
1765 % \socalled{labeling} part of a label, e.\,g.\ in
1766 % \labelname{fig:foo} the colon is used as a delimitor. This can
1767 % be customized, but most users will stick to the conventional
1768 % \delimitor{:}.
1769 % \begin{macrocode}
1770 \newcommand*{\fancyrefargdelim}{:}%
1771 % \end{macrocode}
1772 % \end{macro}
1773 % The following code saves the backslash char in a token register,
1774 % so it can be used in \cmd{\PackageError}
1775 % messages.\footnote{Credits go to \person{Bernd Raichle} for this
1776 % dirty trick.} Sorry, I do not understand the code due to its
1777 % \cmd{\catcode} and grouping hacking. Still much to learn~\ldots
1778 % \begin{macrocode}
1779 \begingroup \catcode`\|=0 |catcode`|\=12
1780 |toks0={|endgroup
1781 |def|backslashchar{\}}
1782 |the|toks0 \relax
1783 % \end{macrocode}
1784 % \begin{macro}{\@...page@ref}
1785 % This macro is a hacked version of the \cmd{\vpageref} command
1786 % from the \package{varioref} package, which removes a space that
1787 % is superfluous for my purpose.
1788 % \begin{macrocode}
1789 \newcommand*{\@fancyref@page@ref}{\@ifnextchar[%]
1790 \@vpageref{\@vpageref[\unskip]}%
1791 }%
1792 % \end{macrocode}
1793 % \end{macro}
1794 % \begin{macro}{\@f@ref}
1795 % This macro now does the real work. It tests if the specified
1796 % format for the given classifying prefix exists. If it does, the
1797 % formatting command is called with three arguments: The counter of
1798 % the referenced object (\cmd{\ref}), the page number of the
1799 % referenced object (\cmd{\pageref}) and the page number resulting
1800 % from a \cmd{\vpageref}. The output of the formatting command
1801 % will be passed as an argument to the \cmd{\fancyrefhook} command
1802 % (\frefseename~\frefpgname~\pageref{sec:fancyrefhook}). If the
1803 % formatting command does not exist, a package error occurs.
1804 % \begin{macrocode}
1805 \newcommand*{\@f@ref}[4]{%
1806 \@ifundefined{#1r@#2@#3}{%
1807 \PackageError{fancyref}{%
1808 \backslashchar#1ref\space format ``#2''
1809 undefined\MessageBreak
1810 for label type ``#3''%
1811 }{%
1812 The format ``#2'' was not defined for the label type
1813 ``#3''\MessageBreak
1814 and the \backslashchar#1ref\space command. Perhaps
1815 you have only misspelled its name.\MessageBreak
1816 Otherwise you will have to define it with
1817 \protect\new#1refformat\MessageBreak
1818 prior to using it.%
1819 }%
1820 }{%
1821 \fancyrefhook{%
1822 \@nameuse{#1r@#2@#3}%
1823 {\ref{#3\fancyrefargdelim#4}}%
1824 {\pageref{#3\fancyrefargdelim#4}}%
1825 {\@fancyref@page@ref{#3\fancyrefargdelim#4}}%
1826 }%
1827 }%
1828 }%
1829 % \end{macrocode}
1830 % \end{macro}
1831 % \begin{macro}{\fref}
1832 % This macro is the front-end for the user. Its first, optional
1833 % argument is the format of the cross-reference, the second,
1834 % mandatory argument is the label of the cross-referenced object.
1835 % If no optional argument is provided, \cmd{\fancyrefdefaultformat}
1836 % will be used as a format.
1837 %
1838 % The second argument is then split at the delimiting character
1839 % (\cmd{\fancyrefargdelim},
1840 % \frefseename~\frefpgname~\pageref{sec:delim}) into a classifying
1841 % prefix and the labeling part. I am sorry that I do not
1842 % understand the \cmd{\@fref} command completely. But it works
1843 % really well,\footnote{Credits go to \person{David Carlisle} who
1844 % once again send me the cut-and-paste solution for my problems.}
1845 % and passes four arguments to the \cmd{\@f@ref} command:
1846 % Lower-case flag, format, classifying prefix and labeling part.
1847 % \begin{macrocode}
1848 \newcommand*{\@fref}{\@empty}%
1849 \newcommand*{\fref}[2][\fancyrefdefaultformat]{%
1850 \edef\@fref{%
1851 \def\noexpand\@fref
1852 ####1\fancyrefargdelim####2\noexpand\@fref{%
1853 \noexpand\@f@ref{f}{#1}{####1}{####2}%
1854 }%
1855 }%
1856 \@fref
1857 \@fref#2\@fref
1858 }%
1859 % \end{macrocode}
1860 % \end{macro}
1861 % \begin{macro}{\Fref}
1862 % This macro works exactly the same way as \cmd{\Fref}. It should
1863 % be used at the beginning of a sentence and hence passes an
1864 % upper-case \source{S} to the \cmd{\@f@ref} command.
1865 % \person{Stefan Ulrich}\footnote{He will easily notice that his
1866 % name was typeset without his additions to the \package{soul}
1867 % package \cite{Franz:1998}. \winkey} told me kindly that it is
1868 % very difficult to implement a reliable heuristic to check for the
1869 % start of a sentence. So I decided to leave this as an exercise
1870 % for the reader. \winkey
1871 % \begin{macrocode}
1872 \newcommand*{\@Fref}{\@empty}%
1873 \newcommand*{\Fref}[2][\fancyrefdefaultformat]{%
1874 \edef\@Fref{%
1875 \def\noexpand\@Fref
1876 ####1\fancyrefargdelim####2\noexpand\@Fref{%
1877 \noexpand\@f@ref{F}{#1}{####1}{####2}%
1878 }%
1879 }%
1880 \@Fref
1881 \@Fref#2\@Fref
1882 }%
1883 %</package>
1884 % \end{macrocode}
1885 % \end{macro}
1886 % \Finale
1887 % \iffalse
1888 %<*testfile>
1889 \documentclass[12pt,a4paper]{ltxdoc}
1890 %
1891 \usepackage{fancyref}
1892 \fancyrefaddcaptions{english}{%
1893 \newcommand*{\Frefthmname}{Theorem}%
1894 \newcommand*{\frefthmname}{\MakeLowercase{\Frefthmname}}%
1895 }%
1896 %
1897 \newcommand*{\booktitle}[1]{``#1''}
1898 \newcommand*{\format}[1]{\texttt{#1}}
1899 \newcommand*{\labelname}[1]{\texttt{#1}}
1900 \newcommand*{\option}[1]{\texttt{#1}}
1901 \newcommand*{\package}[1]{\texttt{#1}}
1902 \newcommand*{\person}[1]{\textsc{#1}}
1903 \newcommand*{\prefix}[1]{\texttt{#1}}
1904 \newcommand*{\stringdef}[1]{``#1''}
1905 %
1906 \newtheorem{theorem}{Theorem}
1907 %
1908 \begin{document}
1909 %
1910 Let us start with a famous equation:
1911 \begin{equation}
1912 \label{eq:pythagoras}
1913 a^2 + b^2 = c^2
1914 \end{equation}
1915 \Fref{eq:pythagoras} has been proven by \person{Pythagoras}. And this
1916 cross-reference was made with |\Fref{eq:pythagoras}|. Note that I
1917 really wrote:
1918 \begin{verbatim}
1919 \Fref{eq:pythagoras} has ...
1920 \end{verbatim}
1921 I did not use:
1922 \begin{verbatim}
1923 Equation~(\Fref{eq:pythagoras}) has ...
1924 \end{verbatim}
1925
1926 See the next page for further features of the \package{fancyref}
1927 package, I need this page break for demonstration purposes.
1928
1929 \clearpage
1930 The cross-reference works also in the middle of a sentence:
1931 \person{Pythagoras} has proven \fref{eq:pythagoras}. And this
1932 cross-reference was made with |\fref{eq:pythagoras}|. You can see the
1933 fancy output from the \package{varioref} package.
1934
1935 Oh, you do not like this package and want normal \cmd{\ref} output
1936 instead? No problem, just redefine the default format:
1937 \renewcommand*{\fancyrefdefaultformat}{plain}
1938 \begin{verbatim}
1939 \renewcommand*{\fancyrefdefaultformat}{plain}
1940 \end{verbatim}
1941 Now the cross-reference looks like this: \Fref{eq:pythagoras}. There
1942 is also a package option called \option{plain} for this purpose.
1943
1944 Oh, you do not like \stringdef{Equation} and want \stringdef{Eq.}
1945 instead? No problem, just redefine the string:
1946 \renewcommand*{\Frefeqname}{Eq.}
1947 \begin{verbatim}
1948 \renewcommand*{\Frefeqname}{Eq.}
1949 \end{verbatim}
1950 \Fref{eq:pythagoras} and \fref{eq:pythagoras} will be the result,
1951 respectively. Note that there is no need to redefine
1952 \cmd{\frefeqname} to \stringdef{eq.}. The \package{fancyref} package
1953 will do this automatically for you. But of course you can use
1954 \stringdef{eqn.} instead, if you really want to.
1955
1956 Oh, you are not using the colon as a delimitor but rather the dash? No
1957 problem, just redefine the character:
1958 \renewcommand*{\fancyrefargdelim}{-}
1959 \begin{verbatim}
1960 \renewcommand*{\fancyrefargdelim}{-}
1961 \end{verbatim}
1962 The new test equation with label \labelname{eq-trivial} will be:
1963 \begin{equation}
1964 \label{eq-trivial}
1965 a = a
1966 \end{equation}
1967 The cross-reference |\fref{eq-trivial}| will give \fref{eq-trivial} as
1968 output, as expected.
1969
1970 All that stuff may be nice, but you are using \prefix{eqn} instead of
1971 \prefix{eq}? No problem, just redefine the prefix:
1972 \fancyrefchangeprefix{\fancyrefeqlabelprefix}{eqn}
1973 \begin{verbatim}
1974 \fancyrefchangeprefix{\fancyrefeqlabelprefix}{eqn}
1975 \end{verbatim}
1976 We need a new, fantastic test equation with label
1977 \labelname{eqn-fantastic}:
1978 \begin{equation}
1979 \label{eqn-fantastic}
1980 b = b
1981 \end{equation}
1982 The cross-reference |\fref{eqn-fantastic}| will give
1983 \fref{eqn-fantastic} as output, as expected.
1984
1985 Maybe the spacing between \stringdef{eq.} and ``3'' is too generous,
1986 let us tighten things a bit, with
1987 \renewcommand*{\fancyrefdefaultspacing}{\fancyreftightspacing}
1988 \begin{verbatim}
1989 \renewcommand*{\fancyrefdefaultspacing}{%
1990 \fancyreftightspacing
1991 }
1992 \end{verbatim}
1993 the spacing looks like \fref{eqn-fantastic}. If you think this is
1994 better, just use the \option{tight} option of this package.
1995 \fancyrefchangeprefix{\fancyrefeqlabelprefix}{eq}
1996
1997 Perhaps you want parentheses around the cross-reference? No problem,
1998 just redefine the appropriate hook:
1999 \renewcommand*{\fancyrefhook}[1]{(#1)}
2000 \begin{verbatim}
2001 \renewcommand*{\fancyrefhook}[1]{(#1)}
2002 \end{verbatim}
2003 The result from |\fref{eq-trivial}| is \fref{eq-trivial}. In fact
2004 this could have been obtained easier, as I provided an package option
2005 just for this purpose:
2006 \begin{verbatim}
2007 \usepackage[paren]{fancyref}
2008 \end{verbatim}
2009
2010 Now let us try something really cool. What about introducing a new
2011 type of objects, e.\,g.\ theorems, with \prefix{thm} prefixed, new
2012 strings like \stringdef{Theorem} added and the cross-reference in huge
2013 italics? Also, as you have read in that bargain textbook on
2014 typography (\booktitle{cAN U rEaD It} by \person{John Badmountain}),
2015 cross-references to theorems should be typeset as footnotes. No
2016 problem: First, we need a new prefix:
2017 \newcommand*{\fancyrefthmlabelprefix}{thm}
2018 \begin{verbatim}
2019 \newcommand*{\fancyrefthmlabelprefix}{thm}
2020 \end{verbatim}
2021 Then we declare a new \package{fancyref} format called \format{foot}:
2022 \frefformat{foot}{\fancyrefthmlabelprefix}{%
2023 \unskip\footnote{%
2024 \huge\itshape\Frefthmname\fancyrefdefaultspacing#1#3%
2025 }%
2026 }
2027 \Frefformat{foot}{\fancyrefthmlabelprefix}{%
2028 \unskip\footnote{%
2029 \huge\itshape\Frefthmname\fancyrefdefaultspacing#1#3%
2030 }%
2031 }
2032 \begin{verbatim}
2033 \frefformat{foot}{\fancyrefthmlabelprefix}{%
2034 \unskip\footnote{%
2035 \huge\itshape\Frefthmname\fancyrefdefaultspacing#1#3%
2036 }%
2037 }
2038 \Frefformat{foot}{\fancyrefthmlabelprefix}{%
2039 \unskip\footnote{%
2040 \huge\itshape\Frefthmname\fancyrefdefaultspacing#1#3%
2041 }%
2042 }
2043 \end{verbatim}
2044 The strings have to be setup in the preamble of the document, I did
2045 this already, because I knew it would be necessary. The code I used
2046 was:
2047 \begin{verbatim}
2048 \fancyrefaddcaptions{english}{%
2049 \newcommand*{\Frefthmname}{Theorem}%
2050 \newcommand*{\frefthmname}{%
2051 \MakeLowercase{\Frefthmname}%
2052 }%
2053 }%
2054 \end{verbatim}
2055 And finally this is the test theorem:
2056 \begin{theorem}[Murphy]
2057 \label{thm-murphy}
2058 If something \emph{can} go wrong, it \emph{will} go wrong.
2059 \end{theorem}
2060 Now let us try it. |\Fref[foot]{thm-murphy}| comes out
2061 as \Fref[foot]{thm-murphy}. Oops, the hook is still at work, I will
2062 just reset it to its default value:
2063 \renewcommand*{\fancyrefhook}[1]{#1}%
2064 \begin{verbatim}
2065 \renewcommand*{\fancyrefhook}[1]{#1}
2066 \end{verbatim}
2067 And now? \Fref[foot]{thm-murphy} Gotcha!
2068 %
2069 \end{document}
2070 %</testfile>
2071 % \fi
2072 \endinput