summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/fancyref/freftest.tex
blob: dba80fcef449f830cc172566c146dd645fb81277 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
%%
%% This is file `freftest.tex',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% fancyref.dtx  (with options: `testfile')
%% 
%% LaTeX package for fancy cross-referencing.
%% 
%% Copyright (C) 1999  Axel Reichert
%% See the files README and COPYING.
%% 
%% \CharacterTable
%%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}
\documentclass[12pt,a4paper]{ltxdoc}
\usepackage{fancyref}
\fancyrefaddcaptions{english}{%
  \newcommand*{\Frefthmname}{Theorem}%
  \newcommand*{\frefthmname}{\MakeLowercase{\Frefthmname}}%
}%
\newcommand*{\booktitle}[1]{``#1''}
\newcommand*{\format}[1]{\texttt{#1}}
\newcommand*{\labelname}[1]{\texttt{#1}}
\newcommand*{\option}[1]{\texttt{#1}}
\newcommand*{\package}[1]{\texttt{#1}}
\newcommand*{\person}[1]{\textsc{#1}}
\newcommand*{\prefix}[1]{\texttt{#1}}
\newcommand*{\stringdef}[1]{``#1''}
\newtheorem{theorem}{Theorem}
\begin{document}
Let us start with a famous equation:
\begin{equation}
  \label{eq:pythagoras}
  a^2 + b^2 = c^2
\end{equation}
\Fref{eq:pythagoras} has been proven by \person{Pythagoras}.  And this
cross-reference was made with |\Fref{eq:pythagoras}|.  Note that I
really wrote:
\begin{verbatim}
   \Fref{eq:pythagoras} has ...
\end{verbatim}
I did not use:
\begin{verbatim}
   Equation~(\Fref{eq:pythagoras}) has ...
\end{verbatim}

See the next page for further features of the \package{fancyref}
package, I need this page break for demonstration purposes.

\clearpage
The cross-reference works also in the middle of a sentence:
\person{Pythagoras} has proven \fref{eq:pythagoras}.  And this
cross-reference was made with |\fref{eq:pythagoras}|.  You can see the
fancy output from the \package{varioref} package.

Oh, you do not like this package and want normal \cmd{\ref} output
instead?  No problem, just redefine the default format:
\renewcommand*{\fancyrefdefaultformat}{plain}
\begin{verbatim}
   \renewcommand*{\fancyrefdefaultformat}{plain}
\end{verbatim}
Now the cross-reference looks like this:  \Fref{eq:pythagoras}.  There
is also a package option called \option{plain} for this purpose.

Oh, you do not like \stringdef{Equation} and want \stringdef{Eq.}
instead?  No problem, just redefine the string:
\renewcommand*{\Frefeqname}{Eq.}
\begin{verbatim}
   \renewcommand*{\Frefeqname}{Eq.}
\end{verbatim}
\Fref{eq:pythagoras} and \fref{eq:pythagoras} will be the result,
respectively.  Note that there is no need to redefine
\cmd{\frefeqname} to \stringdef{eq.}.  The \package{fancyref} package
will do this automatically for you.  But of course you can use
\stringdef{eqn.} instead, if you really want to.

Oh, you are not using the colon as a delimitor but rather the dash?  No
problem, just redefine the character:
\renewcommand*{\fancyrefargdelim}{-}
\begin{verbatim}
   \renewcommand*{\fancyrefargdelim}{-}
\end{verbatim}
The new test equation with label \labelname{eq-trivial} will be:
\begin{equation}
  \label{eq-trivial}
  a = a
\end{equation}
The cross-reference |\fref{eq-trivial}| will give \fref{eq-trivial} as
output, as expected.

All that stuff may be nice, but you are using \prefix{eqn} instead of
\prefix{eq}?  No problem, just redefine the prefix:
\fancyrefchangeprefix{\fancyrefeqlabelprefix}{eqn}
\begin{verbatim}
   \fancyrefchangeprefix{\fancyrefeqlabelprefix}{eqn}
\end{verbatim}
We need a new, fantastic test equation with label
\labelname{eqn-fantastic}:
\begin{equation}
  \label{eqn-fantastic}
  b = b
\end{equation}
The cross-reference |\fref{eqn-fantastic}| will give
\fref{eqn-fantastic} as output, as expected.

Maybe the spacing between \stringdef{eq.} and ``3'' is too generous,
let us tighten things a bit, with
\renewcommand*{\fancyrefdefaultspacing}{\fancyreftightspacing}
\begin{verbatim}
   \renewcommand*{\fancyrefdefaultspacing}{%
     \fancyreftightspacing
   }
\end{verbatim}
the spacing looks like \fref{eqn-fantastic}.  If you think this is
better, just use the \option{tight} option of this package.
\fancyrefchangeprefix{\fancyrefeqlabelprefix}{eq}

Perhaps you want parentheses around the cross-reference?  No problem,
just redefine the appropriate hook:
\renewcommand*{\fancyrefhook}[1]{(#1)}
\begin{verbatim}
   \renewcommand*{\fancyrefhook}[1]{(#1)}
\end{verbatim}
The result from |\fref{eq-trivial}| is \fref{eq-trivial}.  In fact
this could have been obtained easier, as I provided an package option
just for this purpose:
\begin{verbatim}
   \usepackage[paren]{fancyref}
\end{verbatim}

Now let us try something really cool.  What about introducing a new
type of objects, e.\,g.\ theorems, with \prefix{thm} prefixed, new
strings like \stringdef{Theorem} added and the cross-reference in huge
italics?  Also, as you have read in that bargain textbook on
typography (\booktitle{cAN U rEaD It} by \person{John Badmountain}),
cross-references to theorems should be typeset as footnotes.  No
problem:  First, we need a new prefix:
\newcommand*{\fancyrefthmlabelprefix}{thm}
\begin{verbatim}
   \newcommand*{\fancyrefthmlabelprefix}{thm}
\end{verbatim}
Then we declare a new \package{fancyref} format called \format{foot}:
\frefformat{foot}{\fancyrefthmlabelprefix}{%
  \unskip\footnote{%
    \huge\itshape\Frefthmname\fancyrefdefaultspacing#1#3%
  }%
}
\Frefformat{foot}{\fancyrefthmlabelprefix}{%
  \unskip\footnote{%
    \huge\itshape\Frefthmname\fancyrefdefaultspacing#1#3%
  }%
}
\begin{verbatim}
   \frefformat{foot}{\fancyrefthmlabelprefix}{%
     \unskip\footnote{%
       \huge\itshape\Frefthmname\fancyrefdefaultspacing#1#3%
     }%
   }
   \Frefformat{foot}{\fancyrefthmlabelprefix}{%
     \unskip\footnote{%
       \huge\itshape\Frefthmname\fancyrefdefaultspacing#1#3%
     }%
   }
\end{verbatim}
The strings have to be setup in the preamble of the document, I did
this already, because I knew it would be necessary.  The code I used
was:
\begin{verbatim}
   \fancyrefaddcaptions{english}{%
     \newcommand*{\Frefthmname}{Theorem}%
     \newcommand*{\frefthmname}{%
       \MakeLowercase{\Frefthmname}%
     }%
   }%
\end{verbatim}
And finally this is the test theorem:
\begin{theorem}[Murphy]
  \label{thm-murphy}
  If something \emph{can} go wrong, it \emph{will} go wrong.
\end{theorem}
Now let us try it.  |\Fref[foot]{thm-murphy}| comes out
as \Fref[foot]{thm-murphy}.  Oops, the hook is still at work, I will
just reset it to its default value:
\renewcommand*{\fancyrefhook}[1]{#1}%
\begin{verbatim}
   \renewcommand*{\fancyrefhook}[1]{#1}
\end{verbatim}
And now?  \Fref[foot]{thm-murphy} Gotcha!
\end{document}
\endinput
%%
%% End of file `freftest.tex'.