summaryrefslogtreecommitdiff
path: root/Master/tlpkg/dviout/HYPERTEX/keyin.sty
blob: 2fdda1e9ef452fcf6d4745902b9a51155b87c59a (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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
%  This is a LaTeX style file for  dviout special `input (Ver.3.16.1 and after)
%                                 Ver.0.5
%                      Written by hoda, misc, SHIMA
%                             February 25, 2006
%
% \usepackage[<Options>]{keyin}
%
% Options: Ktrue(*)    \K{<string>\K} is valid
%          Kfalse      \K{<string>\K} is not valid (interpreted as <string>)
%          Kfalseall   Same as Kfalse but \Ktrue does not work
%          Kmeaning(*) Use \K{<string>\K} in Kmeaning-mode (see below)
%          Kverb       Use \K{<string>\K} in Kverb-mode    (see below)
%                       (*)--default
%          keyin(*)	   \keyin is valid
%          nokeyin     \keyin is invalid
%
%
% \keyin{<string1>}{<string2>}
%   <string1>: The string to be copied to Clipboard when the hot spot is 
%            clicked.
%              Two hexadecimal characters (0,1,...,9,A,...,F,a,...,f) following
%            one space character are translated into one character with the 
%            corresponding code.
%              Two adjacent space characters are translated into one space 
%            character.
%              If the top character is "." and two hexadecimal characters 
%            followed after it, they are translated into one character with 
%            the code.
%              If the top two characters are "..", they are translated into 
%            ".".
%   <string2>: Hot spot in the dvi file.
%
%   This command is interpreted as
%
%     \special{html:<a href="dviout:`in <string1>}<string2>%
%     \special{htmt:</a>}
%
%   Example:
%     \keyin{\begin{equation} 0d 0a\end{equation}}{Environment Equation}
%
% \verbkeyin{<string1>}{<string2>}
%     This is similar to keyin{<string1>}{<string2>} but there is no 
%   translation.
%
%   CAUTION:
%     If \(verb)keyin is used outside any other macro, <string1> can contain
%   any character provided that the balance of "{" and "}" is kept and
%   <string1> is never expanded.  But if it is used in some macro, 
%   <string1> will be expanded in the usual way.
%
%
% \K{<string>\K}
%     This is similar to \keyin{<string>}{<string>} but the translations 
%   mentioned above are ignored.  
%     This is useful when one is writing a source file of TeX with complex 
%   formulas or equations.  For example, use
%
%     \usepackage{keyin}
%
%   when the corresponding source file is edited.  In the final version use
%
%     \usepackage[Kfalse]{keyin}
%
%   or change \K{ and \K} into spaces by an Editor.  
%     The function of \K{<string>\K} is also switched on and off by \Ktrue 
%   and \Kfalse in the document area.
%     \K{<string>\K} has two different modes: `Kmeaning', `Kverb'. These modes
%   are changed by \Kmeaning and \Kverb.
%
%   Kmeaning-mode:
%     Adjusted form of <string> is copied to Clipboard.  \K{, \K} in comment
%   area are ignored. \K{<string>\K} can be used inside any other macro.
%
%   Kverb-mode:
%     CR/LF/SPACE/TAB in <string> is copied verbatim to Clipboard.
%     \K} in comment area are counted and extra \K} are ignored.
%   For example, if the source is
%
%     \K{ \K{ x \K} % y \K} z
%
%   then the string to be copied is " \K{ x \K} % y ".
%     \K{<string>\K} CAN NOT BE USED inside any other macro.
%                    
%    (eg.) AMSLaTeX environment: equation, aligned, gathered -> OK
%                                align, multline, gather,... -> not OK
%
%
% \begin{prototype}<string>\end{prototype}
%     This is almost the same as {\K{<string>\K}} in Kverb-mode but it ignores
%   comment area.  \end{prototype} can not be replaced by \end {prototype} nor
%   \end{ prototype } etc..
%
%
% \Ksetext{<ext>}
%     \K{<string>\K} in Kverb-mode and `prototype' environment use an extra
%   output file. \Ksetext{<ext>} set the extension of this file (<ext>=`key' 
%   by default).
%
%
%
\newif\if@K@command
\newif\if@K@falseall
\newif\if@K@verb
\newif\if@K@keyin
\DeclareOption{Kfalseall}{\@K@falsealltrue\@K@commandfalse}
\DeclareOption{Kfalse}{\@K@commandfalse}
\DeclareOption{Ktrue}{\@K@commandtrue}
\DeclareOption{Kverb}{\@K@verbtrue}
\DeclareOption{Kmeaning}{\@K@verbfalse}
\DeclareOption{keyin}{\@K@keyintrue}
\DeclareOption{nokeyin}{\@K@keyinfalse}
%
\ExecuteOptions{Ktrue,Kmeaning,keyin}
\ProcessOptions\relax
\def\Kfalse{\global\@K@commandfalse}
\def\Ktrue{\if@K@falseall\else\global\@K@commandtrue\fi}
\def\Kmeaning{\global\let\K=\m@K}
\def\Kverb{\global\let\K=\v@K}
%
\def\K@ext{key}
\def\Ksetext#1{\gdef\K@ext{#1}}
\newwrite\@key@file
%
% definition of `\keyin', `\verbkeyin' ------------------------
{%
 \@makeother\^^M%
 \@makeother\^^J%
 \gdef\@dosrtn{^^M^^J}% return of DOS
 \gdef\K@otherM{^^M}%
}
{
 \catcode`\^^M=\active%
 \gdef\@ctivate@rtn{%
  \@makeother\^^I% tab
  \catcode`\^^M=\active%
  \def^^M{\@dosrtn}%
 }%
 \gdef\re@l@rtn{%
  \def^^M{\K@otherM}%
  \newlinechar=\endlinechar%
 }%
}
% \keyin
\def\keyin{\leavevmode\begingroup\@sanitize%
 \@ctivate@rtn\@keyin}
\if@K@keyin
\def\@keyin#1{\special{html:<a href="dviout:`in #1">}\endgroup\@@keyin}
\def\@@keyin#1{#1\special{html:</a>}}
\else
\def\@keyin#1{\endgroup\@@keyin}
\def\@@keyin#1{#1}
\fi
% \verbkeyin
\def\verbkeyin{\leavevmode\begingroup\@sanitize%
 \@ctivate@rtn\@verbkeyin}
\if@K@keyin
\def\@verbkeyin#1{\special{html:<a href="dviout:`input #1">}\endgroup\@@keyin}
\else
\def\@verbkeyin#1{\endgroup\@@keyin}
\fi
%
% ------------------------ internal tools ------------------------
%
% \K@aplyproctolist#1#2#3
%   #1:<proc>  #2:<list>  #3:<delim> 
% \Kexit: exit from the loop
\newif\if@K@exit
\def\Kexit{\global\@K@exittrue}
\def\K@aplyproctolist#1#2#3{%
 {%
  \def\aplyproctoitm##1#3##2\@nil{%
   #1{##1}%
   \if@K@exit%
    \def\nxt@todo{\global\@K@exitfalse}%
   \else%
    \def\rstlist{##2}%
    \ifx\rstlist\@empty%
     \let\nxt@todo=\relax%
    \else%
     \def\nxt@todo{\aplyproctoitm##2\@nil}%
    \fi%
   \fi%
   \nxt@todo%
  }%
  \global\@K@exitfalse%  
  \aplyproctoitm#2#3\@nil%
 }%
}%
%
% \K@warning
\def\K@warning#1{\typeout{<Warning by `keyin.sty'> at l.\the\inputlineno:}%
 \typeout{#1}}
%
% \K@chk@incmt
\newif\if@K@incmt
{
 \catcode`/=0
 /catcode`/\=12
 /global/def/K@bs@char{\}
 /catcode`/^^M=/active%
 /gdef/K@chk@incmt#1^^M#2/@nil{%
  /let/nxt@todoc=/relax%
  /def/rst@lin{#2}%
  /ifx/rst@lin/@empty%
   /if@K@incmt/else%
    /K@aplyproctolist/K@rmvesccmt{#1}{\\}%
   /fi%
  /else%
   /global/@K@incmtfalse%
   /def/nxt@todoc{/K@chk@incmt#2/@nil}%
  /fi%
  /nxt@todoc%
 }%
 /catcode`/*=14%
 /@makeother/%*
 /gdef/K@rmvesccmt#1{*
  /K@aplyproctolist/K@chkcmtchar{#1}{\%}*
  /if@K@incmt/Kexit/fi*
 }*
 /gdef/K@chkcmtchar#1{*
  /K@@chkcmtchar#1%/@nil*
 }*
 /gdef/K@@chkcmtchar#1%#2/@nil{*
  /def/rst@lin{#2}*
  /ifx/rst@lin/@empty/else*
   /global/@K@incmttrue/Kexit*
  /fi*
 }*
}
%
% \Kcmtchkr
\def\Kcmtchkr{%
 \K@warning{I misjudged this place would be in comment area!}%
}
%
% \K@wrtkeyfile
\def\K@wrtkeyfile#1{%
 \immediate\openout\@key@file=\jobname.\K@ext\relax%
 {%
  \re@l@rtn%
  \immediate\write\@key@file{#1}%
 }%
 \immediate\closeout\@key@file%
}%
% \K@execkeyblk
\def\K@execkeyblk{%
 \endgroup%
 \global\@K@topfalse%
 \input{\jobname.\K@ext}%
 \global\@K@toptrue%
 \special{html:</a>}%
}
%
{ % `%' of catcode 12
 \@makeother\%
 \gdef\K@cmt@char{%}
}
% `{', `}' -> catcode 12
\def\@other@enb{%
 \@makeother\{%
 \@makeother\}%
}
%
% definition of environment `prototype' ------------------------
\newif\if@K@top
\@K@toptrue
\newcounter{prot@depth}
%
\newenvironment{prototype}{%
 \leavevmode%
 \let\nxt@todo=\relax%
 \if@K@top%
  \if@K@command%
   \begingroup%
   \@sanitize\@ctivate@rtn\@other@enb%
   \setcounter{prot@depth}{1}%
   \global\@K@incmtfalse%
   \def\nxt@todo{\wrt@protostr{}}%
  \fi%
 \fi%
 \nxt@todo%
}{}
{
 \catcode`\[=1
 \catcode`\]=2
 \@makeother\{
 \@makeother\}
 \catcode`/=0%
 \catcode`/^^M=\active%
 /catcode`/\=12%
 % get the whole text before the corresponding `\end{prototype}'
 /gdef/wrt@protostr#1#2\end{prototype}[%
  /K@aplyproctolist/K@cnt@vldbgn[#2][\begin{prototype}]%
  /if@K@incmt%
   /def/nxt@todo[/wrt@protostr[#1#2\end{prototype}]]%
  /else%
   /addtocounter[prot@depth][-2]%
   /ifnum/value[prot@depth]=0%
    /special[html:<a href="dviout:`input #1#2">]%
    /K@wrtkeyfile[#1#2/K@cmt@char]%
    /K@execkeyblk%
    /def/nxt@todo[/end[prototype]]%
   /else%
    /def/nxt@todo[/wrt@protostr[#1#2\end{prototype}]]%
   /fi%
  /fi%
  /nxt@todo%
 ]%
 /gdef/K@cnt@vldbgn#1[%
  /K@chk@incmt#1^^M/@nil%
  /if@K@incmt/else%
   /stepcounter[prot@depth]%
  /fi%
 ]%
]
% definition of `\K{ ... \K}' ------------------------
%
% ------------ Kmeaning-mode ------------
\long\def\m@K#1{\m@@K#1\@nil}
\long\def\m@@K#1\K\@nil{%
 \if@K@command%
  \if@K@top%
   \leavevmode%
   \def\@keyin@temp{#1}%
   \@onelevel@sanitize\@keyin@temp%
   \special{html:<a href="dviout:`input \@keyin@temp">}%
   \global\@K@topfalse%
   #1%
   \global\@K@toptrue%
   \special{html:</a>}%
  \else%
   #1%
  \fi%
 \else%
  #1%
 \fi%
}
%
% ------------ Kverb-mode ------------
\newcounter{K@depth}
%
\outer\def\v@K{%
 \leavevmode%
 \begingroup%
 \@other@enb%
 \K@enb%
}
%
{
 \catcode`\[=1
 \catcode`\]=2
 \@other@enb%
 \catcode`/=0
 \catcode`/^^M=\active% 
 /catcode`/\=12%
 %
 /gdef/K@enb#1[%
  /def/nxt@todo[/endgroup]%
  /if {#1%
   /if@K@top%
    /if@K@command%
     /setcounter[K@depth][1]%
     /global/@K@incmtfalse%
     /@sanitize/@ctivate@rtn%
     /def/nxt@todo[/v@@K[]]%
    /fi%
   /fi%
  /else%
   /if }#1/else%
    /errmessage[\K must be followed by { or }]%
   /fi%
  /fi%
  /nxt@todo%
 ]%
 %
 /gdef/v@@K#1#2\K#3[%
   /K@chk@incmt#2^^M/@nil%
   /if }#3%
    /addtocounter[K@depth][-1]%
   	/ifnum/value[K@depth]=0%
     /special[html:<a href="dviout:`input #1#2">]%
     /if@K@incmt%
      /K@wrtkeyfile[#1#2/K@bs@char Kcmtchkr]%
      /def/nxt@todo[/K@skipaftr]%
     /else%
      /K@wrtkeyfile[#1#2/K@cmt@char]%
      /def/nxt@todo[/K@execkeyblk]%
   	 /fi%
   	/else%
     /def/nxt@todo[/v@@K[#1#2\K#3]]%
   	/fi% 
   /else%
    /def/nxt@todo[/v@@K[#1#2\K#3]]%
    /if@K@incmt%
     /ifcat /noexpand#3/noexpand^^M%
      /@K@incmtfalse%
     /fi%
    /else%
     /if {#3%
      /stepcounter[K@depth]%
     /else%
      /ifcat /noexpand#3a/else%
       /errmessage[\K must be followed by { or }]%
      /fi%
     /fi%
    /fi%
   /fi%
   /nxt@todo%
 ]%
 /gdef/K@skipaftr#1^^M[/K@execkeyblk]%
]
% 
\if@K@verb
 \Kverb
\else
 \Kmeaning
\fi