summaryrefslogtreecommitdiff
path: root/support/hypertex/tanmoy/hyperbasics.old.tex
blob: e49f9ecdc9f6a129f06a400ff9a9069ebdb345b1 (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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                         %
% This file is written by Tanmoy Bhattacharya <tanmoy@qcd.lanl.gov> and   %
% is in the public domain for what it is worth. It is an interface to the %
% xhdvi hypertext dvi previewer written by                                %
% Arthur Smith <asmith@bigsky.chem.washington.edu> and available from     %
% ftp://snorri.cpac.washington.edu/pub/hypertex/xhdvi.tar.Z               %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                         %
% Only \hyperdef, \hyperref and \hyperREF are user callable.              %
% Usage: \hyperdef\TeXcs{category}{name}{text}                            %
% Usage: \hyperREF{url}{text}                                             %
% Usage: \hyperref{filename}{category}{name}{text}                        %
%   or   \hyperref\TeXcs{text}                                            %
%             where \TeXcs has been defined by a hyperdef.                %
%                                                                         %
%        Note: The token following \hyperref is expanded completely first.%
%              Really perverse forms like                                 %
%                \csname perverse\endcsname                               %
%              will give an error                                         %
%                                                                         %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The following might be useful to other macros interfacing in.           %
% Usage: \hyper@nchor{name="#myname" href="#refer"}{text}                 %
% Usage: \hyperlink{target_name}{text}                                    %
% Usage: \hypertarget{myname}{text}                                       %
% In cases where there is a possibility of premature expansion use        %
%     \hyper@\hyperpr@ref instead of \hyperref                            %
% and \hyper@\hyperpr@def instead of \hyperdef                            %
% These macros increase enormously in size when expanded, but the expanded%
% token sequence always ends in \hyperpr@ref and \hyperpr@def respectively%
% Macro writers might want to make use of the macro \hyperv@rsion         %
% which is undefined in version 0 and is the version number otherwise     %
% \hyper@nique is exactly like \hyperdef except no special are written    %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Save the current catcode of @ and redefine @ to be a letter
%
\expandafter\edef\csname hypers@fe\endcsname{\catcode
                                             `\noexpand@=\the\catcode`\@}%
\catcode`\@=11
%
% Check if the file is already included
%
\ifx\hyperd@ne\hyper@ndefined
 \global\let\hyperd@ne=\relax
\else
 \errhelp{hyperbasics.tex needs to be included only once outside
          of any {...} or \begingroup...\endgroup. You have tried to
          include it more than once. If the previous include was indeed
          outside any groupings, continue and all will be well.}%
 \errmessage{Input this file only once!}%
 \endinput
\fi
%
% Version number
%
\def\hyperv@rsion{3}%
%
% Check and input a previous .hrf file if it exists
%
\newread\hyperf@le
\def\hyperf@lename{\jobname.hrf}%
\immediate\openin\hyperf@le\hyperf@lename\relax
\ifeof\hyperf@le\relax
 \immediate\closein\hyperf@le\relax
\else
 \immediate\closein\hyperf@le\relax
 \input \hyperf@lename
\fi
%
% Open a new .hrf file
%
\newwrite\hyperf@le
\immediate\openout\hyperf@le\hyperf@lename
%%%%
% MAIN SECTION
%%%%
%
% define a token register
%
\newtoks\hypert@ks
%
% Define a convenient macro to hold the character #
%
\edef\hypert@mp{\catcode`\noexpand\#=\the\catcode`\#}%
\catcode`\#=12
\def\hyperh@sh{#}%
\hypert@mp
\let\hypert@mp=\relax
\let\hyper@nd=\relax
\def\hyperstr@pquote"#1"#2\hyper@nd{\ifx\hyper@ndefined#2\hyper@ndefined#1\else
                                    \ifx\hyper@ndefined#1\hyper@ndefined
                                    \hyperstr@pquote#2"\hyper@nd\else
                                    #1\hyperstr@pquote"#2"\hyper@nd\fi\fi}%
%
\long\def\hyper@nchor#1#2{\edef\hyperm@cro{html:<A #1>}%
                          \special\expandafter{\hyperm@cro}%
                          {#2}\special{html:</A>}}%
%
\def\hyperlink#1{\edef\hypert@mp{#1}%
                 \hyper@nchor{href="\expandafter\hyperstr@pquote
                 \expandafter"\hypert@mp"\hyper@nd"}}%
%
\def\hypertarget#1{\edef\hypert@mp{#1}%
                   \hyper@nchor{name="\expandafter\hyperstr@pquote
                   \expandafter"\hypert@mp"\hyper@nd"}}%
%
\def\hyperref{\afterassignment\hyperr@f\let\hyperp@ram}
\def\hyperr@f{\ifx\hyperp@ram{\iffalse}\fi
               \expandafter\expandafter\expandafter\hyperr@@
               \expandafter{%
              \else
               \iffalse}\fi
               \ifx\hyperp@ram\hyper@ndefined
                 \message{Undefined reference}%
                 \def\hyperp@r@m{{}{undefined}{}}%
               \else
                 \edef\hyperp@r@m{\hyperp@ram}%
               \fi
               \expandafter\expandafter\expandafter\hyperr@@
               \expandafter\hyperp@r@m
              \fi}%
% refer to #1, \hyperh@sh#2.#3 or #1\hyperh@sh#2.#3
% depending on what is blank/nonblank
\def\hyperr@@#1#2#3{\ifx\hyper@ndefined#1\hyper@ndefined
                    \hypert@ks\expandafter{\hyperh@sh#2.#3}%
                    \else
                     \ifx\hyper@ndefined#2#3\hyper@ndefined
                      \hypert@ks{#1}%
                     \else
                      \def\hypert@mp{#1}%
                      \hypert@ks\expandafter\expandafter\expandafter
                      {\expandafter\hypert@mp\hyperh@sh#2.#3}%
                     \fi
                    \fi
                    \hyperlink{\the\hypert@ks}}%
%
\def\hyperREF#1{\hyperlink{#1}}%
%
\def\hyperdef#1#2#3{{\global\escapechar=`\\\relax
                     \edef\hypert@mp{\hyperstr@pquote"#2.#3"\hyper@nd}%
                     \expandafter\ifx\csname hyperd@\meaning\hypert@mp
                     \endcsname
                     \relax
                     \expandafter\gdef\csname hyperd@\meaning\hypert@mp
                     \endcsname{}%
                     \gdef#1{{}{\hyperstr@pquote"#2"\hyper@nd}%
                               {\hyperstr@pquote"#3"\hyper@nd}}%
                     \immediate\write\hyperf@le{\def\noexpand#1{#1}}%
                     \xdef\hypert@mp{\global\let\noexpand\hypert@mp=\relax
                                     \noexpand\hypertarget{\hypert@mp}}%
                     \global\hypert@ks={\hypert@mp}%
                     \else
                     \message\expandafter{'\hypert@mp' duplicate}%
                     \global\let\hypert@mp=\relax
                     \global\hypert@ks={\hyperdef{#1}{#2}{#3@}}%
                     \fi}\the\hypert@ks}%

\def\hyper@nique#1#2#3#4{\global\escapechar=`\\\relax
                     \edef\hypert@mp{\hyperstr@pquote"#2.#3"\hyper@nd}%
                     \expandafter\ifx\csname hyperd@\meaning\hypert@mp
                     \endcsname
                     \relax
                     \gdef#1{{}{\hyperstr@pquote"#2"\hyper@nd}%
                               {\hyperstr@pquote"#3"\hyper@nd}}%
                     \global\let\hypert@mp=\relax
                     #4%
                     \else
                     \global\let\hypert@mp=\relax
                     \hyper@nique{#1}{#2}{#3@}{#4}%
                     \fi
                     }%

%%% 
% protection macros
%%%
\def\hyper@@{\let\hyper@@@=\relax}%
\hyper@@
\def\hyper@{\relax\let\hyper@@@\noexpand\hyper@\noexpand}%
\def\hyperpr@ref{\hyper@@\hyperref}
\def\hyperpr@def{\hyper@@\hyperdef}

%
% Restore the catcode of @
%
\hypers@fe
\endinput
% A line after endinput to avoid both msdos gremlins and an incomplete
% last line