summaryrefslogtreecommitdiff
path: root/web/noweb/src/icon/totex.icn
blob: 353f695656ebe160ac507f3e85279c241797f7c2 (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
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
#line 5 "totex.nw"
# Copyright 1991 by Norman Ramsey.  All rights reserved.
# See file COPYRIGHT for more information.
#line 11 "totex.nw"
procedure rcsinfo () 
  return "$Id: totex.nw,v 1.21 2008/10/06 01:03:05 nr Exp nr $" ||
         "$Name: v2_12 $"
end
global headercomment, realwrite
procedure main(args)
  local delay, name
  
#line 46 "totex.nw"
text := 1
#line 135 "totex.nw"
useitemstab := table()
#line 149 "totex.nw"
defns := table("")
#line 336 "totex.nw"
TeXspecials := '\\{}$&#^_ ~%'
#line 19 "totex.nw"
  delay := !args == "-delay"
  noindex := !args == "-noindex"
  if !args == "-no-gen-comment" then &null
  else {realwrite := write; write := firstwrite}
  while inputline := read() do inputline ? {
    
#line 82 "totex.nw"
if ="@text " then 	{ text +:= *(line := tab(0))
                          writes(if \quoting then 
#line 88 "totex.nw"
if /noindex & \lastindexref then 
  "\\nwlinkedidentq{" || TeXliteral(line) || "}{" || lastindexref || "}"
else 
  TeXliteral(line)
#line 84 "totex.nw"
                                 else if \code then 
#line 93 "totex.nw"
if /noindex & \lastindexref then 
  "\\nwlinkedidentc{" ||   escape(line, '{}\\') || "}{" || lastindexref || "}"
else 
  escape(line, '{}\\')

#line 85 "totex.nw"
                                 else line)
                          lastindexref := &null                                  } else
#line 99 "totex.nw"
if ="@nl" & pos(0) then { if /code then {
#line 115 "totex.nw"
if text = 0 then writes("\\nwdocspar")
text := 1
#line 99 "totex.nw"
                                                                                }
                          if \quoting then writes("\\nwnewline")
			  
#line 201 "totex.nw"
if \pendinguses | \pendingprev | \pendingnext then {
  writes("\\nwstartdeflinemarkup")
  
#line 208 "totex.nw"
if \pendinguses then {
  dumpitems(useitems, "nwusesondefline")
}
if \pendingprev | \pendingnext then {
  writes("\\nwprevnextdefs{", \pendingprev | "\\relax", "}{", 
                              \pendingnext | "\\relax", "}")
}
#line 204 "totex.nw"
  writes("\\nwenddeflinemarkup")
  pendinguses := pendingprev := pendingnext := &null
}
#line 102 "totex.nw"
                          write()                                                } else
#line 71 "totex.nw"
if ="@begin code " then	{ code := 1     ; writes("\\nwbegincode{", tab(0), "}")
                          
#line 177 "totex.nw"
every defitems | useitems := []
notused := &null
#line 72 "totex.nw"
                                                                                 } else
if ="@end code "   then { 
#line 184 "totex.nw"
dumpitems(defitems, "nwalsodefined")
dumpitems(useitems, "nwused")
writes("\\nwnotused{", \notused, "}")
#line 177 "totex.nw"
every defitems | useitems := []
notused := &null
#line 74 "totex.nw"
                          code := &null ; writes("\\nwendcode{}")
                          lastdefnlabel := pendingprev := pendingnext := &null   } else
#line 122 "totex.nw"
if ="@defn " then 	{ writes("\\sublabel{", \lastxreflabel, "}")
			  writes("\\nwmargintag{", label2tag(\lastxreflabel), "}")
                          writes("\\moddef{", convquotes(thischunk := tab(0)), 
                                 ("~" || label2tag(\lastxrefref)) | "",
                                 "}\\", defns[thischunk], "endmoddef")
			  useitems := \useitemstab[thischunk]
			  pendinguses := 1
			  lastdefnlabel := lastxreflabel
			  
#line 216 "totex.nw"
every lastxreflabel | lastxrefref := &null
#line 131 "totex.nw"
                          defns[thischunk] := "plus"                           } else
#line 77 "totex.nw"
if ="@begin docs " then	{ if \delay & match(0) then 
#line 110 "totex.nw"
&null
#line 77 "totex.nw"
                                                                                   
                          else {text := 0; writes("\\nwbegindocs{",tab(0),"}")}  } else
if ="@end docs " then  	{ if \delay & match(0) then 
#line 112 "totex.nw"
{ writes("\\nwfilename{", filename, "}"); delay := &null }
#line 79 "totex.nw"
                                                                                
			  else writes("\\nwenddocs{}")                           } else
#line 137 "totex.nw"
if ="@use " then 	{ writes("\\LA{}", convquotes(name := tab(0)), 
                                 ("~" || label2tag(\lastxrefref)) | "",
                                 "\\RA{}")
			  
#line 216 "totex.nw"
every lastxreflabel | lastxrefref := &null
#line 140 "totex.nw"
                                                            } else
#line 175 "totex.nw"
if ="@xref "               then { 
#line 189 "totex.nw"
if ="label "               then { lastxreflabel := tab(0)			} else
if ="ref "                 then { lastxrefref   := tab(0)			} else
if ="begindefs"   & pos(0) then {                            		        } else
if ="defitem "             then { put(defitems, tab(0)) 		        } else
if ="enddefs"     & pos(0) then {              				        } else
if ="beginuses"   & pos(0) then { useitems := []                		} else
if ="useitem "             then { put(useitems, tab(0))	          		} else
if ="enduses"     & pos(0) then { useitemstab[thischunk] := useitems	        } else
if ="notused "             then { notused := tab(0)                             } else
if ="nextdef "             then { pendingnext := tab(0)                         } else
if ="prevdef "             then { pendingprev := tab(0)                         } else
#line 294 "totex.nw"
if ="beginchunks" & pos(0) then { 						  } else
if ="chunkbegin "          then { label := tab(upto(' ')); =" "
                                  writes("\\nwixlogsorted{c}{{", convquotes(tab(0)),
                                      "}{", label, "}{")		          } else
if ="chunkuse "            then { writes("\\nwixu{", tab(0), "}")		  } else
if ="chunkdefn "           then { writes("\\nwixd{", tab(0), "}")		  } else
if ="chunkend"    & pos(0) then { write("}}%")				          } else
if ="endchunks"   & pos(0) then {     					          } else
#line 175 "totex.nw"
                                                  
#line 218 "totex.nw"
warn_unknown("xref " || tab(upto(' \t') | 0))
#line 175 "totex.nw"
                                                                                } else
#line 232 "totex.nw"
if ="@index "               then { 
#line 240 "totex.nw"
if ="nl" & pos(0)          then        { write(if \code then "\\eatline" else "%")}else
if =("defn "|"localdefn ") then 
#line 244 "totex.nw"
/noindex &
#line 241 "totex.nw"
                                       { 
#line 253 "totex.nw"
writes("\\nosublabel{", \lastxreflabel, "}")
writes("\\nwindexdefn{\\nwixident{", TeXliteral(name := tab(0)), "}}{", indexlabel(name), "}{",
	\lastxrefref, "}")
#line 216 "totex.nw"
every lastxreflabel | lastxrefref := &null
#line 241 "totex.nw"
                                                                                 } else
if ="use "                 then 
#line 244 "totex.nw"
/noindex &
#line 242 "totex.nw"
                                       { 
#line 261 "totex.nw"
if /code & /quoting then {
  writes("\\protect\\nosublabel{", \lastxreflabel, "}")
  writes("\\protect\\nwindexuse{\\nwixident{", TeXliteral(name := tab(0)), "}}{", 
                indexlabel(name), "}{", \lastxrefref, "}")
}
lastindexref := lastxrefref
#line 216 "totex.nw"
every lastxreflabel | lastxrefref := &null
#line 242 "totex.nw"
                                                                                 } else
#line 272 "totex.nw"
if ="begindefs" & pos(0) then 
#line 244 "totex.nw"
/noindex &
#line 272 "totex.nw"
                                     { 
#line 184 "totex.nw"
dumpitems(defitems, "nwalsodefined")
dumpitems(useitems, "nwused")
writes("\\nwnotused{", \notused, "}")
#line 177 "totex.nw"
every defitems | useitems := []
notused := &null
#line 273 "totex.nw"
                                       writes("\\nwidentdefs{")                   } else
if ="isused "            then 
#line 244 "totex.nw"
/noindex &
#line 274 "totex.nw"
                                     { "handled by latex"                         } else
if ="defitem "           then 
#line 244 "totex.nw"
/noindex &
#line 275 "totex.nw"
                                     { i := tab(0); 
#line 284 "totex.nw"
writes("\\\\{{\\nwixident{", TeXliteral(i), "}}{", indexlabel(i), "}}") 
#line 275 "totex.nw"
                                                                                  } else
if ="enddefs"   & pos(0) then 
#line 244 "totex.nw"
/noindex &
#line 276 "totex.nw"
                                     { writes("}")                                } else
if ="beginuses" & pos(0) then 
#line 244 "totex.nw"
/noindex &
#line 277 "totex.nw"
                                     { 
#line 184 "totex.nw"
dumpitems(defitems, "nwalsodefined")
dumpitems(useitems, "nwused")
writes("\\nwnotused{", \notused, "}")
#line 177 "totex.nw"
every defitems | useitems := []
notused := &null
#line 278 "totex.nw"
                                       writes("\\nwidentuses{"); ulist := []      } else
if ="isdefined "         then 
#line 244 "totex.nw"
/noindex &
#line 279 "totex.nw"
                                     { "latex finds the definitions"              } else
if ="useitem "           then 
#line 244 "totex.nw"
/noindex &
#line 280 "totex.nw"
                                     { i := tab(0); 
#line 284 "totex.nw"
writes("\\\\{{\\nwixident{", TeXliteral(i), "}}{", indexlabel(i), "}}") 
#line 280 "totex.nw"
                                                                                
                                        put(ulist, i);                            } else
if ="enduses"   & pos(0) then 
#line 244 "totex.nw"
/noindex &
#line 282 "totex.nw"
                                     { writes("}"); 
#line 286 "totex.nw"
every i := !ulist do 
  writes("\\nwindexuse{\\nwixident{", TeXliteral(i), "}}{", indexlabel(i), "}{", \lastdefnlabel, "}")
#line 282 "totex.nw"
                                                                                  } else
#line 303 "totex.nw"
if ="beginindex"  & pos(0) then 
#line 244 "totex.nw"
/noindex &
#line 303 "totex.nw"
                                       { 					  } else
if ="entrybegin "          then 
#line 244 "totex.nw"
/noindex &
#line 304 "totex.nw"
                                       { label := tab(upto(' ')); =" "; name := tab(0)
										 write("\\nwixlogsorted{i}{{\\nwixident{", TeXliteral(name),
										 "}}{", indexlabel(name), "}}%")	          } else
if ="entryuse "            then 
#line 244 "totex.nw"
/noindex &
#line 307 "totex.nw"
                                       { "handled by latex"	                  } else
if ="entrydefn "           then 
#line 244 "totex.nw"
/noindex &
#line 308 "totex.nw"
                                       { "handled by latex"                       } else
if ="entryend"    & pos(0) then 
#line 244 "totex.nw"
/noindex &
#line 309 "totex.nw"
                                       {                                          } else
if ="endindex"    & pos(0) then 
#line 244 "totex.nw"
/noindex &
#line 310 "totex.nw"
                                       {                                          } else
#line 232 "totex.nw"
                                                    
#line 234 "totex.nw"
warn_unknown("index " || tab(upto(' \t') | 0))
#line 232 "totex.nw"
                                                                                  } else
#line 153 "totex.nw"
if ="@quote"    & pos(0)      then { quoting := 1     ; writes("{\\Tt{}")        } else
if ="@endquote" & pos(0)      then { quoting := &null ; writes("\\nwendquote}")  } else
if ="@file "                  then { filename := tab(0); 
#line 216 "totex.nw"
every lastxreflabel | lastxrefref := &null
#line 156 "totex.nw"
                                     \delay | writes("\\nwfilename{", filename, "}")
										 } else
if ="@line "                  then {                                             } else
if ="@literal "               then { writes(tab(0))                              } else
if ="@header latex "          then { 
#line 165 "totex.nw"
writes("\\documentclass{article}\\usepackage{noweb}\\pagestyle{noweb}\\noweboptions{", tab(0),
       "}\\begin{document}")
#line 160 "totex.nw"
                                                              		         } else
if ="@header tex "            then { writes("\\input nwmac ")		         } else
if ="@trailer latex" & pos(0) then { write("\\end{document}")		         } else
if ="@trailer tex"   & pos(0) then { write("\\bye")			         } else
#line 61 "totex.nw"
if ="@fatal " then {				# follows last else
 #  write(&errout, "Noweb error in stage ", tab(upto(' ')), ":", tab(0))
  exit(1)
} else if ="@" then 
  warn_unknown(1(tab(upto(' ')|0), pos(0) | move(1)))
else
  write(&errout, "Botched line in noweb pipeline: ", tab(0))
#line 25 "totex.nw"
  }
  write()
end
#line 142 "totex.nw"
procedure label2tag(label)
  return "{\\nwtagstyle{}\\subpageref{" || label || "}}"
end
#line 220 "totex.nw"
procedure dumpitems(items, cs)
  if *\items > 0 then {
    writes("\\", cs, "{")
    every writes("\\\\{", !items, "}")
    writes("}")
    return
  } else
    fail
end
#line 316 "totex.nw"
procedure firstwrite(L[])
  write := realwrite
  put(L,
      "% ===> this file was generated automatically by noweave --- better not edit it")
  return write!L
end
#line 325 "totex.nw"
procedure escape(line, chars, prefix)
  /prefix := "\\"
  line ? {
    s := ""
    while s ||:= tab(upto(chars)) do s ||:= prefix || move(1)
    return s || tab(0)
  }
end
#line 334 "totex.nw"
global TeXspecials
#line 357 "totex.nw"
procedure TeXliteral(arg)
  static nospace, code
  initial { codes := ["\\", "nwbackslash",
                      "{", "nwlbrace",
					  "}", "nwrbrace",
					  "$", "$",
					  "&", "&",
					  "#", "#",
					  "^", "char94", 
                                          "_", "_",
					  "%", "%",
					  "~", "char126"]
            code := table()
            while (c := get(codes), n := get(codes)) do code[c] := string(n)
            if c := !TeXspecials & c ~== " " & not member(code, c) then
	      fatal("internal error, character-code mismatch, report a bug!")
          }
  s := ""
  arg ? {
    while s ||:= tab(upto(TeXspecials)) do {
      c := move(1)
      if member(code, c) then
        s ||:= "{\\" || code[c] || "}"
      else
        s ||:= "\\" || c
    }
    return s || tab(0)
  }
end
#line 390 "totex.nw"
procedure convquotes(s)
  r := ""
  s ? {
    while r ||:= tab(find("[[")) do {
      ="[[" | fatal("impossible missing [[")
      r ||:= "\\code{}" || TeXliteral(tab(find("]]")))
      r ||:= tab(many(']')-2)
      ="]]" | fatal("impossible missing ]]")
      r ||:= "\\edoc{}"
    }
    return r || tab(0)
  }
end
#line 404 "totex.nw"
procedure warn_unknown(tag)
  static warned
  initial warned := set()
  if not member(warned, tag) then {
    write(&errout, "Warning: unrecognized escape @", tag, " ", tab(0))
    insert(warned, tag)
  }
  return
end
#line 416 "totex.nw"
procedure indexlabel(ident)
  static badset, trans
  initial {
    
#line 430 "totex.nw"
trans := table()
trans[" "] := "sp"      # space
trans["#"] := "has"     # hash
trans["$"] := "do"      # dollar
trans["%"] := "pe"      # percent
trans["&"] := "am"      # ampersand
trans[","] := "com"     # commad
trans[":"] := "col"     # colon
trans["\\"] := "bs"      # backslash
trans["^"] := "hat"     # hat
trans["_"] := "un"      # underscore
trans["{"] := "lb"      # left brace
trans["}"] := "rb"      # right brace
trans["~"] := "ti"      # tilde
#line 420 "totex.nw"
    badset := ''
    every badset ++:= key(trans)
  }
  ident ? {
    s := ""
    while s ||:= tab(upto(badset)) do s ||:= ":" || trans[move(1)]
    return s || tab(0)
  }
end
#line 445 "totex.nw"
procedure fatal(L[])
  write!([&errout, "noweb error in tohtml: "] ||| L)
  exit(1)
end