summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/smartref/byname.sty
blob: 648be4939d4ff664d378d5affdc1ce841f3b95fc (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
\def\fileversion{v1.1}
\def\filedate{2001/07/12}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Giuseppe Bilotta
%
% Phone +39-095-338103
%
% Email: bourbaki@bigfoot.com
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% This package is distributed under the terms
% of the LaTeX Project Public License
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Please read the readme.txt file for details
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{byname}[\filedate\space\fileversion\space Increase
reference capability (reference by name)]
%
\newcommand*{\byn@melabel}[2]{%
    \def\@currnamelabel{{#1}{#2}}}

\let\bns@vesect=\@sect

\def\@sect#1#2#3#4#5#6[#7]#8{%
    \bns@vesect{#1}{#2}{#3}{#4}{#5}{#6}[#7]{#8}%
    \byn@melabel{#7}{#8}}

\let\bns@vechap=\@chapter
\def\@chapter[#1]#2{%
    \bns@vechap[#1]{#2}%
    \byn@melabel{#1}{#2}}

% Hack label: also write the NameRef data ...
\def\newnamelabel{\@newl@bel {name}}
%save previous \label
\AtBeginDocument{\let\nr@ldlabel=\label
\renewcommand*{\label}[1]{\nr@ldlabel{#1}%
    \@bsphack%
    \protected@write\@auxout{}%
        {\string\newnamelabel{#1}{\@currnamelabel}}%
    \@esphack}}
% Reference by name
%
\@ifpackageloaded{hyperref}{%
   \newcommand*{\byname}[1]{%
       \expandafter\real@setref\csname name@#1\endcsname\@secondoftwo{#1}%
       }
   \newcommand*{\byshortname}[1]{%
       \expandafter\real@setref\csname name@#1\endcsname\@firstoftwo{#1}%
       }
   }{
   \newcommand*{\byname}[1]{%
       \expandafter\@setref\csname name@#1\endcsname\@secondoftwo{#1}%
       }
   \newcommand*{\byshortname}[1]{%
       \expandafter\@setref\csname name@#1\endcsname\@firstoftwo{#1}%
       }
   }
\endinput