| 1 |
%% |
| 2 |
%% This is file `freftest.tex', |
| 3 |
%% generated with the docstrip utility. |
| 4 |
%% |
| 5 |
%% The original source files were: |
| 6 |
%% |
| 7 |
%% fancyref.dtx (with options: `testfile') |
| 8 |
%% |
| 9 |
%% LaTeX package for fancy cross-referencing. |
| 10 |
%% |
| 11 |
%% Copyright (C) 1999 Axel Reichert |
| 12 |
%% See the files README and COPYING. |
| 13 |
%% |
| 14 |
%% \CharacterTable |
| 15 |
%% {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 |
| 16 |
%% 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 |
| 17 |
%% Digits \0\1\2\3\4\5\6\7\8\9 |
| 18 |
%% Exclamation \! Double quote \" Hash (number) \# |
| 19 |
%% Dollar \$ Percent \% Ampersand \& |
| 20 |
%% Acute accent \' Left paren \( Right paren \) |
| 21 |
%% Asterisk \* Plus \+ Comma \, |
| 22 |
%% Minus \- Point \. Solidus \/ |
| 23 |
%% Colon \: Semicolon \; Less than \< |
| 24 |
%% Equals \= Greater than \> Question mark \? |
| 25 |
%% Commercial at \@ Left bracket \[ Backslash \\ |
| 26 |
%% Right bracket \] Circumflex \^ Underscore \_ |
| 27 |
%% Grave accent \` Left brace \{ Vertical bar \| |
| 28 |
%% Right brace \} Tilde \~} |
| 29 |
\documentclass[12pt,a4paper]{ltxdoc} |
| 30 |
\usepackage{fancyref} |
| 31 |
\fancyrefaddcaptions{english}{% |
| 32 |
\newcommand*{\Frefthmname}{Theorem}% |
| 33 |
\newcommand*{\frefthmname}{\MakeLowercase{\Frefthmname}}% |
| 34 |
}% |
| 35 |
\newcommand*{\booktitle}[1]{``#1''} |
| 36 |
\newcommand*{\format}[1]{\texttt{#1}} |
| 37 |
\newcommand*{\labelname}[1]{\texttt{#1}} |
| 38 |
\newcommand*{\option}[1]{\texttt{#1}} |
| 39 |
\newcommand*{\package}[1]{\texttt{#1}} |
| 40 |
\newcommand*{\person}[1]{\textsc{#1}} |
| 41 |
\newcommand*{\prefix}[1]{\texttt{#1}} |
| 42 |
\newcommand*{\stringdef}[1]{``#1''} |
| 43 |
\newtheorem{theorem}{Theorem} |
| 44 |
\begin{document} |
| 45 |
Let us start with a famous equation: |
| 46 |
\begin{equation} |
| 47 |
\label{eq:pythagoras} |
| 48 |
a^2 + b^2 = c^2 |
| 49 |
\end{equation} |
| 50 |
\Fref{eq:pythagoras} has been proven by \person{Pythagoras}. And this |
| 51 |
cross-reference was made with |\Fref{eq:pythagoras}|. Note that I |
| 52 |
really wrote: |
| 53 |
\begin{verbatim} |
| 54 |
\Fref{eq:pythagoras} has ... |
| 55 |
\end{verbatim} |
| 56 |
I did not use: |
| 57 |
\begin{verbatim} |
| 58 |
Equation~(\Fref{eq:pythagoras}) has ... |
| 59 |
\end{verbatim} |
| 60 |
|
| 61 |
See the next page for further features of the \package{fancyref} |
| 62 |
package, I need this page break for demonstration purposes. |
| 63 |
|
| 64 |
\clearpage |
| 65 |
The cross-reference works also in the middle of a sentence: |
| 66 |
\person{Pythagoras} has proven \fref{eq:pythagoras}. And this |
| 67 |
cross-reference was made with |\fref{eq:pythagoras}|. You can see the |
| 68 |
fancy output from the \package{varioref} package. |
| 69 |
|
| 70 |
Oh, you do not like this package and want normal \cmd{\ref} output |
| 71 |
instead? No problem, just redefine the default format: |
| 72 |
\renewcommand*{\fancyrefdefaultformat}{plain} |
| 73 |
\begin{verbatim} |
| 74 |
\renewcommand*{\fancyrefdefaultformat}{plain} |
| 75 |
\end{verbatim} |
| 76 |
Now the cross-reference looks like this: \Fref{eq:pythagoras}. There |
| 77 |
is also a package option called \option{plain} for this purpose. |
| 78 |
|
| 79 |
Oh, you do not like \stringdef{Equation} and want \stringdef{Eq.} |
| 80 |
instead? No problem, just redefine the string: |
| 81 |
\renewcommand*{\Frefeqname}{Eq.} |
| 82 |
\begin{verbatim} |
| 83 |
\renewcommand*{\Frefeqname}{Eq.} |
| 84 |
\end{verbatim} |
| 85 |
\Fref{eq:pythagoras} and \fref{eq:pythagoras} will be the result, |
| 86 |
respectively. Note that there is no need to redefine |
| 87 |
\cmd{\frefeqname} to \stringdef{eq.}. The \package{fancyref} package |
| 88 |
will do this automatically for you. But of course you can use |
| 89 |
\stringdef{eqn.} instead, if you really want to. |
| 90 |
|
| 91 |
Oh, you are not using the colon as a delimitor but rather the dash? No |
| 92 |
problem, just redefine the character: |
| 93 |
\renewcommand*{\fancyrefargdelim}{-} |
| 94 |
\begin{verbatim} |
| 95 |
\renewcommand*{\fancyrefargdelim}{-} |
| 96 |
\end{verbatim} |
| 97 |
The new test equation with label \labelname{eq-trivial} will be: |
| 98 |
\begin{equation} |
| 99 |
\label{eq-trivial} |
| 100 |
a = a |
| 101 |
\end{equation} |
| 102 |
The cross-reference |\fref{eq-trivial}| will give \fref{eq-trivial} as |
| 103 |
output, as expected. |
| 104 |
|
| 105 |
All that stuff may be nice, but you are using \prefix{eqn} instead of |
| 106 |
\prefix{eq}? No problem, just redefine the prefix: |
| 107 |
\fancyrefchangeprefix{\fancyrefeqlabelprefix}{eqn} |
| 108 |
\begin{verbatim} |
| 109 |
\fancyrefchangeprefix{\fancyrefeqlabelprefix}{eqn} |
| 110 |
\end{verbatim} |
| 111 |
We need a new, fantastic test equation with label |
| 112 |
\labelname{eqn-fantastic}: |
| 113 |
\begin{equation} |
| 114 |
\label{eqn-fantastic} |
| 115 |
b = b |
| 116 |
\end{equation} |
| 117 |
The cross-reference |\fref{eqn-fantastic}| will give |
| 118 |
\fref{eqn-fantastic} as output, as expected. |
| 119 |
|
| 120 |
Maybe the spacing between \stringdef{eq.} and ``3'' is too generous, |
| 121 |
let us tighten things a bit, with |
| 122 |
\renewcommand*{\fancyrefdefaultspacing}{\fancyreftightspacing} |
| 123 |
\begin{verbatim} |
| 124 |
\renewcommand*{\fancyrefdefaultspacing}{% |
| 125 |
\fancyreftightspacing |
| 126 |
} |
| 127 |
\end{verbatim} |
| 128 |
the spacing looks like \fref{eqn-fantastic}. If you think this is |
| 129 |
better, just use the \option{tight} option of this package. |
| 130 |
\fancyrefchangeprefix{\fancyrefeqlabelprefix}{eq} |
| 131 |
|
| 132 |
Perhaps you want parentheses around the cross-reference? No problem, |
| 133 |
just redefine the appropriate hook: |
| 134 |
\renewcommand*{\fancyrefhook}[1]{(#1)} |
| 135 |
\begin{verbatim} |
| 136 |
\renewcommand*{\fancyrefhook}[1]{(#1)} |
| 137 |
\end{verbatim} |
| 138 |
The result from |\fref{eq-trivial}| is \fref{eq-trivial}. In fact |
| 139 |
this could have been obtained easier, as I provided an package option |
| 140 |
just for this purpose: |
| 141 |
\begin{verbatim} |
| 142 |
\usepackage[paren]{fancyref} |
| 143 |
\end{verbatim} |
| 144 |
|
| 145 |
Now let us try something really cool. What about introducing a new |
| 146 |
type of objects, e.\,g.\ theorems, with \prefix{thm} prefixed, new |
| 147 |
strings like \stringdef{Theorem} added and the cross-reference in huge |
| 148 |
italics? Also, as you have read in that bargain textbook on |
| 149 |
typography (\booktitle{cAN U rEaD It} by \person{John Badmountain}), |
| 150 |
cross-references to theorems should be typeset as footnotes. No |
| 151 |
problem: First, we need a new prefix: |
| 152 |
\newcommand*{\fancyrefthmlabelprefix}{thm} |
| 153 |
\begin{verbatim} |
| 154 |
\newcommand*{\fancyrefthmlabelprefix}{thm} |
| 155 |
\end{verbatim} |
| 156 |
Then we declare a new \package{fancyref} format called \format{foot}: |
| 157 |
\frefformat{foot}{\fancyrefthmlabelprefix}{% |
| 158 |
\unskip\footnote{% |
| 159 |
\huge\itshape\Frefthmname\fancyrefdefaultspacing#1#3% |
| 160 |
}% |
| 161 |
} |
| 162 |
\Frefformat{foot}{\fancyrefthmlabelprefix}{% |
| 163 |
\unskip\footnote{% |
| 164 |
\huge\itshape\Frefthmname\fancyrefdefaultspacing#1#3% |
| 165 |
}% |
| 166 |
} |
| 167 |
\begin{verbatim} |
| 168 |
\frefformat{foot}{\fancyrefthmlabelprefix}{% |
| 169 |
\unskip\footnote{% |
| 170 |
\huge\itshape\Frefthmname\fancyrefdefaultspacing#1#3% |
| 171 |
}% |
| 172 |
} |
| 173 |
\Frefformat{foot}{\fancyrefthmlabelprefix}{% |
| 174 |
\unskip\footnote{% |
| 175 |
\huge\itshape\Frefthmname\fancyrefdefaultspacing#1#3% |
| 176 |
}% |
| 177 |
} |
| 178 |
\end{verbatim} |
| 179 |
The strings have to be setup in the preamble of the document, I did |
| 180 |
this already, because I knew it would be necessary. The code I used |
| 181 |
was: |
| 182 |
\begin{verbatim} |
| 183 |
\fancyrefaddcaptions{english}{% |
| 184 |
\newcommand*{\Frefthmname}{Theorem}% |
| 185 |
\newcommand*{\frefthmname}{% |
| 186 |
\MakeLowercase{\Frefthmname}% |
| 187 |
}% |
| 188 |
}% |
| 189 |
\end{verbatim} |
| 190 |
And finally this is the test theorem: |
| 191 |
\begin{theorem}[Murphy] |
| 192 |
\label{thm-murphy} |
| 193 |
If something \emph{can} go wrong, it \emph{will} go wrong. |
| 194 |
\end{theorem} |
| 195 |
Now let us try it. |\Fref[foot]{thm-murphy}| comes out |
| 196 |
as \Fref[foot]{thm-murphy}. Oops, the hook is still at work, I will |
| 197 |
just reset it to its default value: |
| 198 |
\renewcommand*{\fancyrefhook}[1]{#1}% |
| 199 |
\begin{verbatim} |
| 200 |
\renewcommand*{\fancyrefhook}[1]{#1} |
| 201 |
\end{verbatim} |
| 202 |
And now? \Fref[foot]{thm-murphy} Gotcha! |
| 203 |
\end{document} |
| 204 |
\endinput |
| 205 |
%% |
| 206 |
%% End of file `freftest.tex'. |