[641] | 1 | \def\fileversion{v1.9}
|
---|
| 2 | \def\filedate{2002/02/28}
|
---|
| 3 | % smartref.sty
|
---|
| 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
| 5 | %
|
---|
| 6 | % Giuseppe Bilotta
|
---|
| 7 | %
|
---|
| 8 | % Phone +39 095 338103
|
---|
| 9 | %
|
---|
| 10 | % Email: bourbaki@bigfoot.com
|
---|
| 11 | %
|
---|
| 12 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
| 13 | %
|
---|
| 14 | % This package is distributed under the terms
|
---|
| 15 | % of the LaTeX Project Public License
|
---|
| 16 | %
|
---|
| 17 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
| 18 | %
|
---|
| 19 | % Please read the readme.txt file for details
|
---|
| 20 | %
|
---|
| 21 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
| 22 | \NeedsTeXFormat{LaTeX2e}
|
---|
| 23 | \ProvidesPackage{smartref}[\filedate\space\fileversion\space Increase
|
---|
| 24 | reference capability (deep reference)]
|
---|
| 25 | %
|
---|
| 26 | \newcounter{@smartlistlen}
|
---|
| 27 | \newcounter{less@smartlist}
|
---|
| 28 | \setcounter{less@smartlist}{-2}
|
---|
| 29 | \newcommand*{\@increasesmartlist}{%
|
---|
| 30 | \addtocounter{@smartlistlen}{1}%
|
---|
| 31 | \addtocounter{less@smartlist}{1}}
|
---|
| 32 | \def\sm@rtreflist{{\@currentlabel}}
|
---|
| 33 | \@increasesmartlist
|
---|
| 34 | %
|
---|
| 35 | \newcommand*{\@getsmartreflist}[3]{%
|
---|
| 36 | \ifx#1%
|
---|
| 37 | \relax\protect\G@refundefinedtrue%
|
---|
| 38 | \@latex@warning {SmartReference `#2' on page %
|
---|
| 39 | \thepage \space undefined}%
|
---|
| 40 | \nfss@text{\reset@font \bfseries ??}%
|
---|
| 41 | \else%
|
---|
| 42 | \expandafter #2#1%
|
---|
| 43 | \fi}
|
---|
| 44 | \newcounter{@currsmartlistplace}
|
---|
| 45 | \newcommand*{\@getsmartref}[3]{%Paramaters are: #1: Where #2: Label, #3: place in list
|
---|
| 46 | \edef\@smartlistplace{#3}%
|
---|
| 47 | \setcounter{@currsmartlistplace}{0}%
|
---|
| 48 | \edef\@originalsmartlist{%
|
---|
| 49 | \expandafter\@getsmartreflist\csname sr@#2\endcsname{}{}}%
|
---|
| 50 | \edef\@currsmartlist{\@originalsmartlist}%
|
---|
| 51 | \loop%
|
---|
| 52 | \edef\@currsmartvalue{\expandafter\@car\@currsmartlist\@nil}%
|
---|
| 53 | \ifnum\the@currsmartlistplace=\theless@smartlist
|
---|
| 54 | \edef\@currsmartlist{\noexpand{\expandafter\@cdr\@currsmartlist\@nil\noexpand}}%
|
---|
| 55 | \else
|
---|
| 56 | \edef\@currsmartlist{\expandafter\@cdr\@currsmartlist\@nil}%
|
---|
| 57 | \fi
|
---|
| 58 | \ifnum\the@currsmartlistplace<\@smartlistplace%
|
---|
| 59 | \addtocounter{@currsmartlistplace}{1}%
|
---|
| 60 | \repeat
|
---|
| 61 | \edef#1{\@currsmartvalue}%
|
---|
| 62 | % \typeout{Got Smart Reference (place #3, value \@currsmartvalue)}%
|
---|
| 63 | }
|
---|
| 64 | % Hack label: also write the SmartRef data ...
|
---|
| 65 | \def\newsmartlabel{\@newl@bel {sr}}
|
---|
| 66 | %save previous \label
|
---|
| 67 | \AtBeginDocument{%
|
---|
| 68 | \let\sr@ldlabel=\label
|
---|
| 69 | \renewcommand*{\label}[1]{%
|
---|
| 70 | \sr@ldlabel{#1}%
|
---|
| 71 | \@bsphack%
|
---|
| 72 | \protected@write\@auxout{}%
|
---|
| 73 | {\string\newsmartlabel{#1}{\sm@rtreflist}}%
|
---|
| 74 | \@esphack}%
|
---|
| 75 | % This one is needed for those who use AMS-LaTeX, to ensure that
|
---|
| 76 | % smartref labelling system is used wih equations too (AMS-LaTeX
|
---|
| 77 | % uses its own labeling system for equations
|
---|
| 78 | \let\ltx@label=\label}
|
---|
| 79 | % Command to add new items to reflist:
|
---|
| 80 | %
|
---|
| 81 | \newtoks\sm@rtintern@ltok
|
---|
| 82 | \newcommand*{\addtoreflist}[1]{% Add item ...
|
---|
| 83 | \@ifundefined{c@#1}% Check if real counter;
|
---|
| 84 | {\@nocounterr{#1}}% If not, give error
|
---|
| 85 | {\@ifundefined{#1posinlist}{% If yes, check if already defined:
|
---|
| 86 | \sm@rtintern@ltok=\expandafter{\sm@rtreflist}% If not, define everything ...
|
---|
| 87 | \expandafter\edef\csname sm@rtreflist\endcsname{%
|
---|
| 88 | \the\sm@rtintern@ltok{\noexpand\csname the#1\endcsname}}% Add it ...
|
---|
| 89 | % Set position of counter in list:
|
---|
| 90 | \expandafter\edef\csname #1posinlist\endcsname{\the@smartlistlen}%
|
---|
| 91 | \@increasesmartlist%
|
---|
| 92 | % Define SmartCommands:
|
---|
| 93 | % Define command to get number of <name> for <label>; parameters:
|
---|
| 94 | % #1 is where the value goes, #2 is label name.
|
---|
| 95 | \typeout{Defining \csname sget#1val\endcsname ...}
|
---|
| 96 | % `smart get <name> value'
|
---|
| 97 | % Usage \sgetchapternum{\holder}{labelname}
|
---|
| 98 | \expandafter\def\csname sget#1val\endcsname##1##2{%
|
---|
| 99 | \@ifundefined{sr@##2}{%
|
---|
| 100 | \G@refundefinedtrue%
|
---|
| 101 | \@latex@warning{SmartReference `##2' on page \thepage \space undefined}%
|
---|
| 102 | \def##1{0}}%
|
---|
| 103 | {\expandafter\@getsmartref{##1}{##2}{\csname #1posinlist\endcsname}}%
|
---|
| 104 | }%
|
---|
| 105 | % Define command to check if number of <name> for <label> is different from current
|
---|
| 106 | % <name> value; parameters:
|
---|
| 107 | % #1 is label name.
|
---|
| 108 | \typeout{Defining \csname s#1ref\endcsname ...}
|
---|
| 109 | % `smart <name> \ref'
|
---|
| 110 | % Usage \schapterref{labelname}
|
---|
| 111 | % TODOs:
|
---|
| 112 | % - check for counters that get reset.
|
---|
| 113 | \expandafter\newif\csname if#1changed\endcsname % define if consctruct
|
---|
| 114 | \expandafter\def\csname is#1changed\endcsname##1{% checker for change
|
---|
| 115 | \csname sget#1val\endcsname{\sm@rtrefvalue}{##1}%
|
---|
| 116 | \edef\@currentrefvalue{\csname the#1\endcsname}%
|
---|
| 117 | \ifx\sm@rtrefvalue\@currentrefvalue%
|
---|
| 118 | \csname #1changedfalse\endcsname%
|
---|
| 119 | \else%
|
---|
| 120 | \csname #1changedtrue\endcsname%
|
---|
| 121 | \fi}%
|
---|
| 122 | \expandafter\def\csname s#1ref\endcsname##1{%
|
---|
| 123 | \csname is#1changed\endcsname{##1}%
|
---|
| 124 | \csname if#1changed\endcsname%
|
---|
| 125 | , \csname short#1name\endcsname~\csname #1ref\endcsname{##1}%
|
---|
| 126 | % , \csname short#1name\endcsname~\sm@rtrefvalue%
|
---|
| 127 | \else%
|
---|
| 128 | \relax%
|
---|
| 129 | \fi%
|
---|
| 130 | }%
|
---|
| 131 | % Define shorthand for \ref{labelname}\s<name>ref{labelname}; parameters:
|
---|
| 132 | % #1 is label name.
|
---|
| 133 | \typeout{Defining \csname sref#1ref\endcsname ...}
|
---|
| 134 | % Usage \srefchapterref{labelname}
|
---|
| 135 | % If HyperRef is used, let it use no-link refs
|
---|
| 136 | % TODO: define starred and unstarred version; maybe the same for the next.
|
---|
| 137 | \@ifpackageloaded{hyperref}{%
|
---|
| 138 | \expandafter\def\csname sref#1ref\endcsname##1{%
|
---|
| 139 | \@refstar{##1}\csname s#1ref\endcsname{##1}%
|
---|
| 140 | }
|
---|
| 141 | }{
|
---|
| 142 | \expandafter\def\csname sref#1ref\endcsname##1{%
|
---|
| 143 | \ref{##1}\csname s#1ref\endcsname{##1}%
|
---|
| 144 | }%
|
---|
| 145 | }%
|
---|
| 146 | % Define equivalent of \pageref; parameters:
|
---|
| 147 | % #1 is label name.
|
---|
| 148 | \typeout{Defining \csname #1ref\endcsname ...}
|
---|
| 149 | % Usage \chapterref{labelname}
|
---|
| 150 | \expandafter\def\csname #1ref\endcsname##1{%
|
---|
| 151 | \csname sget#1val\endcsname{\sm@rtrefv@lue}{##1}%
|
---|
| 152 | \sm@rtrefv@lue%
|
---|
| 153 | }%
|
---|
| 154 | }{}%
|
---|
| 155 | }%
|
---|
| 156 | }
|
---|
| 157 | %
|
---|
| 158 | \DeclareOption{page}{%
|
---|
| 159 | \AtBeginDocument{%
|
---|
| 160 | \addtoreflist{page}%
|
---|
| 161 | \providecommand*\shortpagename{pag.}%
|
---|
| 162 | }}
|
---|
| 163 | \DeclareOption{chapter}{%
|
---|
| 164 | \AtBeginDocument{%
|
---|
| 165 | \addtoreflist{chapter}%
|
---|
| 166 | \@ifundefined{smartref}{%
|
---|
| 167 | \newcommand*{\smartref}[1]{%
|
---|
| 168 | \srefchapterref{#1}%
|
---|
| 169 | }%
|
---|
| 170 | }{%
|
---|
| 171 | \let\nochapter@smartref=\smartref%
|
---|
| 172 | \renewcommand*{\smartref}[1]{%
|
---|
| 173 | \nochapter@smartref{#1}\schapterref{#1}}%
|
---|
| 174 | }
|
---|
| 175 | %\DeclareRobustCommand{\smartref}%
|
---|
| 176 | \@ifpackagewith{babel}{italian}{%
|
---|
| 177 | \providecommand*\shortchaptername{Cap.}}{%
|
---|
| 178 | \providecommand*\shortchaptername{Chap.}}
|
---|
| 179 | \typeout{Short chapter name defined: \shortchaptername}%
|
---|
| 180 | }}
|
---|
| 181 | \DeclareOption{part}{%
|
---|
| 182 | \AtBeginDocument{%
|
---|
| 183 | \addtoreflist{part}%
|
---|
| 184 | \@ifundefined{smartref}{%
|
---|
| 185 | \newcommand*{\smartref}[1]{%
|
---|
| 186 | \srefpartref{#1}%
|
---|
| 187 | }%
|
---|
| 188 | }{%
|
---|
| 189 | \let\nopart@smartref=\smartref%
|
---|
| 190 | \renewcommand*{\smartref}[1]{%
|
---|
| 191 | \nopart@smartref{#1}\spartref{#1}}%
|
---|
| 192 | }
|
---|
| 193 | %\DeclareRobustCommand{\smartref}%
|
---|
| 194 | \@ifpackagewith{babel}{italian}{%
|
---|
| 195 | \providecommand*\shortpartname{Parte}}{%
|
---|
| 196 | \providecommand*\shortpartname{Part}}%
|
---|
| 197 | \typeout{Short part name defined: \shortpartname}%
|
---|
| 198 | }}
|
---|
| 199 | \DeclareOption*{%
|
---|
| 200 | \PackageWarning{smartref}%
|
---|
| 201 | {Option `\CurrentOption' unknown!\MessageBreak%
|
---|
| 202 | Adding `\CurrentOption' as a reflevel}%
|
---|
| 203 | \expandafter\addtoreflist\expandafter{\CurrentOption}
|
---|
| 204 | }
|
---|
| 205 | \DeclareOption{byname}{\AtEndOfPackage{\usepackage{byname}}}
|
---|
| 206 | \ProcessOptions\relax
|
---|
| 207 | \endinput
|
---|