-
Notifications
You must be signed in to change notification settings - Fork 0
/
rulelinks.sty
61 lines (56 loc) · 2.14 KB
/
rulelinks.sty
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
%
% Hyperlinks in rule names:
%
% The first time a rule name is used is presumed to be the definition
% (probably in some figure with a bunch of rules).
%
% Subsequent uses will be hyperlinks to the definition site.
%
% TODO:
% Provide a way of using a rule name that doesn't establish that site
% as the definition.
%
\ProvidesPackage{rulelinks}[2015/06/09 - First release]
\RequirePackage{mathpartir}
%
% \newrulecommand{Rulename}{MyName}
%
% Note: don't put a backslash in Rulename.
%
\newcommand{\newrulecommand}[2]{%
\expandafter\newcommand\csname NoLink#1\endcsname{#2}%
\expandafter\newcommand\csname #1\endcsname{%
\ifcsname ZZRULE#1\endcsname%
% Already defined: Link to definition.
% "\expandafter...\endcsname" is what actually renders the rule,
% by invoking the \NoLink... version defined above.
\hyperlink{rule:#1}{\expandafter\csname NoLink#1\endcsname}%
%
\else%
% Not yet defined: Declare a hypertarget.
\hypertarget{rule:#1}{\expandafter\csname NoLink#1\endcsname}%
\expandafter\gdef\csname ZZRULE#1\endcsname{}% Declare a macro so we go to the "Already defined" branch for subsequent uses
\fi\xspace%
}
}
%
% \newrulecommandONE: for rule names that take one argument (like \SumIntro{k}).
%
% \newrulecommandONE{Rulename}{MyName#1}
%
\newcommand{\newrulecommandONE}[2]{%
\expandafter\newcommand\csname NoLink#1\endcsname[1]{#2}%
\expandafter\newcommand\csname #1\endcsname[1]{%
\ifcsname ZZRULE#1\endcsname%
% Already defined: Link to definition.
% "\expandafter...\endcsname" is what actually renders the rule,
% by invoking the \NoLink... version defined above.
\hyperlink{rule:#1}{\expandafter\csname NoLink#1\endcsname{##1}}%
%
\else%
% Not yet defined: Declare a hypertarget.
\hypertarget{rule:#1}{\expandafter\csname NoLink#1\endcsname{##1}}%
\expandafter\gdef\csname ZZRULE#1\endcsname{}% Declare a macro so we go to the "Already defined" branch for subsequent uses
\fi\xspace%
}
}