ALDT (Arnulf's LaTeX Documentation Tool)

Check-in [71697a16e2]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:removed unused code
Timelines: family | ancestors | trunk
Files: files | file ages | folders
SHA1:71697a16e2e746e33fbc62f538e9f6b3e8aa2edf
User & Date: arnulf 2012-09-01 19:03:49
Context
2012-09-01
19:03
removed unused code Leaf check-in: 71697a16e2 user: arnulf tags: trunk
18:46
fixes and new code check-in: b040be3522 user: arnulf tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to latex_cmds.tcl.

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
# *
# * Released under same BSD license as Tcl.
# * (Tcl BSD license found at <http://www.tcl.tk/software/tcltk/license.html>)
# *
# * Copyright 2012 Arnulf P. Wiedemann
#=====================================================

if {0} {
set latex_cmds_info [list \
  [list \\+ [list] [list latex]] \
  [list \\= [list] [list latex]] \
  [list \\| [list] [list latex]] \
  [list \\< [list] [list latex]] \
  [list \\> [list] [list latex]] \
  [list "\\\(" [list] [list latex]] \
  [list "\\\)" [list] [list latex]] \
  [list "\\\{" [list] [list latex]] \
  [list "\\\}" [list] [list latex]] \
  [list "\\ " [list] [list latex]] \
  [list "\\@" [list] [list latex]] \
  [list \\abovedisplayskip [list m] [list]] \
  [list \\abovedisplayshortskip [list m] [list]] \
  [list \\acute[list  m] [list]] \
  [list \\addcontentsline [list m m m] [list]] \
  [list \\addcounter [list m] [list]] \
  [list \\address [list m] [list]] \
  [list \\addtocontents [list m m] [list]] \
  [list \\addtocounter [list m m] [list]] \
  [list \\addtolength [list m m] [list]] \
  [list \\addvspace [list m] [list]] \
  [list \\Alph [list m] [list]] \
  [list \\alph [list m] [list]] \
  [list \\and [list ] [list]] \
  [list \\arabic [list m] [list]] \
  [list \\arraycolsep [list m] [list]] \
  [list \\arrayrulewidth [list m] [list]] \
  [list \\arraystretch [list m] [list]] \
  [list \\author [list m] [list]] \
  [list \\bar [list m] [list]] \
  [list \\baselineskip [list m] [list]] \
  [list \\begin [list x] [list latex]] \
  [list \\baselinestretch [list m] [list]] \
  [list \\belowdisplayskip [list m] [list]] \
  [list \\bf [list ] [list]] \
  [list \\bibitem [list o m t] [list]] \
  [list \\bigskip [list ] [list]] \
  [list \\bigskipamount [list m] [list]] \
  [list \\boldmath [list] [list]] \
  [list \\bottomfraction [list m] [list]] \
  [list \\bottomnumber [list m] [list]] \
  [list \\breve [list m] [list]] \
  [list \\cal [list] [list]] \
  [list \\caption [list o m] [list]] \
  [list \\cc [list m] [list]] \
  [list \\centering [list] [list]] \
  [list \\centerline [list m] [list]] \
  [list \\chapter [list o m] [list]] \
  [list \\chapter* [list m] [list]] \
  [list \\check [list m] [list]] \
  [list \\circle [list m] [list]] \
  [list \\cite [list o m] [list]] \
  [list \\cleardoublepage [list] [list]] \
  [list \\clearpage [list] [list]] \
  [list \\cline [list m] [list]] \
  [list \\closing [list m] [list]] \
  [list \\columnsep [list m] [list]] \
  [list \\columnseprule [list m] [list]] \
  [list \\dashbox [list m m o m] [list]] \
  [list \\date [list m] [list]] \
  [list \\dblfloatpagefraction [list m] [list]] \
  [list \\dblfloatsep [list m] [list]] \
  [list \\dbltextfloatsep [list m] [list]] \
  [list \\dbltopfraction [list m] [list]] \
  [list \\dbltopnumber [list m] [list]] \
  [list \\ddot [list m] [list]] \
  [list \\discretionary [list m m m] [list]] \
  [list \\displaystyle [list] [list]] \
  [list \\documentclass [list o m] [list latex]] \
  [list \\documentstyle [list o m] [list]] \
  [list \\dot [list m] [list]] \
  [list \\dotfill [list] [list]] \
  [list \\doublerulesep [list m] [list]] \
  [list \\em [list] [list]] \
  [list \\emph [list m] [list latex]] \
  [list \\encl [list m] [list]] \
  [list \\end [list m] [list]] \
  [list \\evensidemargin [list m] [list]] \
  [list \\extracolsep [list m] [list]] \
  [list \\fbox [list m] [list]] \
  [list \\fboxrule [list m] [list]] \
  [list \\fboxsep [list m] [list]] \
  [list \\fill [list] [list]] \
  [list \\floatpagefraction [list m] [list]] \
  [list \\floatsep [list m] [list]] \
  [list \\flushbottom [list] [list]] \
  [list \\fnsymbol [list m] [list]] \
  [list \\footheight [list m] [list]] \
  [list \\footnote [list o m] [list latex]] \
  [list \\footnotemark [list o] [list]] \
  [list \\footnotesep [list m] [list]] \
  [list \\footnotesize [list] [list]] \
  [list \\footnotetext [list o m] [list]] \
  [list \\footskip [list m] [list]] \
  [list \\frac [list m m] [list]] \
  [list \\frame [list m] [list]] \
  [list \\framebox [list o o m] [list]] \
  [list \\frenchspacing [list] [list]] \
  [list \\fussy [list m] [list]] \
  [list \\grave [list m] [list]] \
  [list \\hat [list m] [list]] \
  [list \\headheight [list m] [list]] \
  [list \\headsep [list m] [list]] \
  [list \\hfill [list] [list]] \
  [list \\hline [list] [list]] \
  [list \\hoffset [list m] [list]] \
  [list \\hrulefill [list] [list]] \
  [list \\hspace [list m] [list]] \
  [list \\Huge [list m] [list]] \
  [list \\huge [list m] [list]] \
  [list \\imath [list m] [list]] \
  [list \\include [list m] [list]] \
  [list \\includeonly [list m] [list]] \
  [list \\indent [list] [list]] \
  [list \\input [list m] [list]] \
  [list \\intextsep [list m] [list]] \
  [list \\it [list] [list]] \
  [list \\item [list o] [list]] \
  [list \\itemsep [list m] [list]] \
  [list \\jmath [list] [list]] \
  [list \\jot [list m] [list]] \
  [list \\kill [list] [list]] \
  [list \\label [list m] [list]] \
  [list \\LARGE [list] [list]] \
  [list \\Large [list] [list]] \
  [list \\large [list] [list]] \
  [list \\LaTeX [list] [list]] \
  [list \\line [list p2 m] [list]] \
  [list \\linebreak [list o] [list]] \
  [list \\linethickness [list m] [list]] \
  [list \\listoffigures [list] [list]] \
  [list \\listoftables [list] [list]] \
  [list \\makebox [list o o m] [list]] \
  [list \\maketitle [list] [list]] \
  [list \\marginpar [list o m] [list]] \
  [list \\marginparpush [list m] [list]] \
  [list \\marginparsep [list m] [list]] \
  [list \\marginparwidth [list m] [list]] \
  [list \\markboth [list m m] [list]] \
  [list \\markright [list m] [list]] \
  [list \\mathindent [list m] [list]] \
  [list \\mbox [list m] [list latex]] \
  [list \\medskip [list] [list]] \
  [list \\medskipamount [list m] [list]] \
  [list \\multicolumn [list m m m] [list]] \
  [list \\multiput [list p2 p2 m] [list]] \
  [list \\name [list m] [list]] \
  [list \\newcommand [list m o m] [list]] \
  [list \\newcounter [list m o] [list]] \
  [list \\newenvironment [list m o m m] [list]] \
  [list \\newfont [list m m] [list]] \
  [list \\newlength [list m] [list]] \
  [list \\newline [list] [list]] \
  [list \\newpage [list m] [list]] \
  [list \\newsavebox [list] [list]] \
  [list \\newtheorem [list m o m o] [list]] \
  [list \\noindent [list] [list]] \
  [list \\nolinebreak [list o] [list]] \
  [list \\nonfrenchspacing [list] [list]] \
  [list \\nonumber [list] [list]] \
  [list \\nopagebreak [list o] [list]] \
  [list \\normalmarginpar [list] [list]] \
  [list \\normalsize [list] [list]] \
  [list \\numberline [list m m] [list]] \
  [list \\oddsidemargin [list m] [list]] \
  [list \\onecolumn [list] [list]] \
  [list \\opening [list m] [list]] \
  [list \\oval [list p2 o] [list]] \
  [list \\overbrace [list m] [list]] \
  [list \\overline [list m] [list]] \
  [list \\pagebreak [list o] [list]] \
  [list \\pagenumbering [list m] [list]] \
  [list \\pageref [list m] [list]] \
  [list \\pagestyle [list m] [list]] \
  [list \\par [list] [list]] \
  [list \\paragraph [list o m] [list]] \
  [list \\paragraph* [list m] [list]] \
  [list \\parbox [list o m m] [list]] \
  [list \\parindent [list m] [list]] \
  [list \\parsep [list m] [list]] \
  [list \\parskip [list m] [list]] \
  [list \\part [list o m] [list]] \
  [list \\poptabs [list] [list]] \
  [list \\protect [list m] [list]] \
  [list \\ps [list m] [list]] \
  [list \\pushtabs [list] [list]] \
  [list \\put [list p2 m] [list]] \
  [list \\raggedbottom [list] [list]] \
  [list \\raggedleft [list] [list]] \
  [list \\raggedright [list] [list]] \
  [list \\raisebox [list m o o m] [list]] \
  [list \\ref [list m] [list]] \
  [list \\refstepcounter [list m] [list]] \
  [list \\renewcommand [list m o m] [list]] \
  [list \\renewenvironment [list m o m m] [list]] \
  [list \\reversemarginpar [list] [list]] \
  [list \\rm [list] [list]] \
  [list \\Roman [list m] [list]] \
  [list \\roman [list m] [list]] \
  [list \\rule [list o m m] [list]] \
  [list \\samepage [list] [list]] \
  [list \\savebox [list m o o m] [list]] \
  [list \\sbox [list m m] [list]] \
  [list \\sc [list] [list]] \
  [list \\scriptscriptstyle [list] [list]] \
  [list \\scriptsize [list] [list]] \
  [list \\scriptstyle [list] [list]] \
  [list \\section [list o m] [list]] \
  [list \\setcounter [list m m] [list]] \
  [list \\setlanguage [list m] [list]] \
  [list \\setlength [list m m] [list]] \
  [list \\settowidth [list m m] [list]] \
  [list \\sf [list] [list]] \
  [list \\shortstack [list o m] [list]] \
  [list \\signature [list m] [list]] \
  [list \\sl [list] [list]] \
  [list \\sloppy [list] [list]] \
  [list \\small [list] [list]] \
  [list \\smallskip [list] [list]] \
  [list \\smallskipamount [list m] [list]] \
  [list \\sqrt [list o m] [list]] \
  [list \\stackrel [list m m] [list]] \
  [list \\stepcounter [list m] [list]] \
  [list \\subparagraph [list o m] [list]] \
  [list \\subsection [list o m] [list]] \
  [list \\subsubsection [list o m] [list]] \
  [list \\symbol [list m] [list]] \
  [list \\tabbingsep [list m] [list]] \
  [list \\tabcolsep [list m] [list]] \
  [list \\tableofcontents [list] [list]] \
  [list \\TeX [list] [list]] \
  [list \\textfraction [list m] [list]] \
  [list \\textfloatsep [list m] [list]] \
  [list \\textheight [list m] [list]] \
  [list \\textstyle [list] [list]] \
  [list \\textwidth [list m] [list]] \
  [list \\thanks [list m] [list]] \
  [list \\thicklines [list m] [list]] \
  [list \\thinlines [list m] [list]] \
  [list \\thispagestyle [list m] [list]] \
  [list \\tilde [list m] [list]] \
  [list \\tiny [list] [list]] \
  [list \\title [list m] [list]] \
  [list \\today [list] [list latex]] \
  [list \\topfraction [list m] [list]] \
  [list \\topmargin [list m] [list]] \
  [list \\topnumber [list m] [list]] \
  [list \\topsep [list m] [list]] \
  [list \\topskip [list m] [list]] \
  [list \\totalnumber [list m] [list]] \
  [list \\tt [list] [list]] \
  [list \\twocolumn [list] [list]] \
  [list \\typein [list o m] [list]] \
  [list \\typeout [list m] [list]] \
  [list \\unboldmath [list] [list]] \
  [list \\underbrace [list m] [list]] \
  [list \\underline [list m] [list]] \
  [list \\unitlength [list m] [list]] \
  [list \\usebox [list m] [list]] \
  [list \\value [list m] [list]] \
  [list \\vec [list m] [list]] \
  [list \\vector [list p2 m] [list]] \
  [list \\verb [list m] [list]] \
  [list \\verb* [list m] [list]] \
  [list \\vfill [list] [list]] \
  [list \\vline [list] [list]] \
  [list \\voffset [list m] [list]] \
  [list \\vspace [list m] [list]] \
  [list \\vspace* [list m] [list]] \
  [list \\widehat [list m] [list]] \
  [list \\widetilde [list m] [list]] \
]

set latex_environment_cmds_info [list \
  [list \\abstract [list] [list]] \
  [list \\appendix [list] [list]] \
  [list \\array [list] [list]] \
  [list \\center [list] [list]] \
  [list \\description [list] [list]] \
  [list \\displaymath [list] [list]] \
  [list \\document [list m] [list latex]] \
  [list \\enumerate [list] [list]] \
  [list \\eqnarray [list] [list]] \
  [list \\equation [list] [list]] \
  [list \\figure [list] [list]] \
  [list \\flushleft [list] [list]] \
  [list \\flushright [list] [list]] \
  [list \\fussypar [list] [list]] \
  [list \\itemize [list] [list]] \
  [list \\letter [list] [list]] \
  [list \\math [list] [list]] \
  [list \\minipage [list] [list]] \
  [list \\picture [list] [list]] \
  [list \\quotation [list] [list]] \
  [list \\quote [list] [list]] \
  [list \\samepage [list] [list]] \
  [list \\sloppypar [list] [list]] \
  [list \\tabbing [list] [list]] \
  [list \\table [list] [list]] \
  [list \\tabular [list] [list]] \
  [list \\thebibliography [list] [list]] \
  [list \\titlepage [list] [list]] \
  [list \\verbatim [list] [list]] \
  [list \\verbatim* [list] [list]] \
  [list \\verse [list] [list]] \
]
}







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
8
9
10
11
12
13
14





















































































































































































































































































































# *
# * Released under same BSD license as Tcl.
# * (Tcl BSD license found at <http://www.tcl.tk/software/tcltk/license.html>)
# *
# * Copyright 2012 Arnulf P. Wiedemann
#=====================================================






















































































































































































































































































































Changes to latex_parse.tcl.

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
source ./latex_cmds.tcl

global gState
global gCmds
global gPackages
global gCurr


if {0} {
proc parseMandatoryArg {} {
  global gCurr gState

  set argStr ""
  set LC "{"
  set RC "}"
  set hadLC false
  set hadRC false
  if {! ("[lindex $gCurr(lst) $gCurr(idx)]" eq $LC)} {
    # no start of mandatory arg found
    set gState(error) true
    set gState(errorMsg) "line #$gCurr(numLines) command: [lindex $gCurr(command) end] missing mandatory argument: #[expr {$gCurr(numMandatoryArgs) + 1}]"
    return false
  }
  while {true} {
    if {$gCurr(idx) >= $gCurr(lgth)} {
      set gState(error) true
      set gState(errorMsg) "reached eof in parsing of mandatory argument"
      return false
    }
    set ch [lindex $gCurr(lst) $gCurr(idx)]
    switch $ch {
    "{" {
      if {$hadLC} {
        set gState(error) true
        set gState(errorMsg) "more than one $$LC!"
        return false
      } else {
        set hadLC true
        incr gCurr(idx)
      }
      }
    "}" {
      if {!$hadLC} {
        set gState(error) true
        set gState(errorMsg) "need $LC before $RC!"
        return false
      } else {
        if {!$hadLC} {
          set gState(error) true
          set gState(errorMsg) "more than one $RC!"
          return false
        } else {
          set hadRC true
          incr gCurr(idx)
          lappend gCurr(args) $argStr
          break
        }
      }
      }
    default {
      append argStr $ch
      incr gCurr(idx)
      }
    }
  }
  return true
}

proc parseOptionalArg {} {
  global gCurr gState

  set argStr ""
  set LB "\["
  set RB "\]"
  if {! ("[lindex $gCurr(lst) $gCurr(idx)]" eq $LB)} {
    # no optional arg found
    lappend gCurr(args) $argStr
    return true
  }
  incr gCurr(idx)
  set hadLB true
  set hadRB false
  while {true} {
    if {$gCurr(idx) >= $gCurr(lgth)} {
      set gState(error) true
      set gState(errorMsg) "reached eof in parsing optional argument"
      return false
    }
    set ch [lindex $gCurr(lst) $gCurr(idx)]
    switch $ch {
    "\[" {
      if {$hadLB} {
        set gState(error) true
        set gState(errorMsg) "more than one $$LB!"
        return false
      } else {
        set hadLB true
        incr gCurr(idx)
      }
      }
    "\]" {
      if {!$hadLB} {
        set gState(error) true
        set gState(errorMsg) "need $LB before $RB!"
        return false
      } else {
        if {!$hadLB} {
          set gState(error) true
          set gState(errorMsg) "more than one $RB!"
          return false
        } else {
          set hadRB true
          incr gCurr(idx)
          lappend gCurr(args) $argStr
          break
        }
      }
      }
    default {
      append argStr $ch
      incr gCurr(idx)
      }
    }
  }
  return true
}

proc parseEnvironmentArg {} {
  global gCurr gState

puts "BEG0!$gCurr(args)!$gCurr(idx)!$gCurr(lst)!"
  if {! [parseMandatoryArg]} {
    return false
  }
puts "BEG1!$gCurr(args)!$gCurr(idx)!$gCurr(lst)!"
  set argStr ""
  incr gCurr(idx)
  set beginStart $gCurr(begin)
  incr gCurr(begin)
  while {true} {
#puts "BEG2!$gCurr(args)!$gCurr(idx)!$gCurr(lgth)!$gCurr(lst)!"
    if {$gCurr(idx) >= $gCurr(lgth)} {
puts "NEXTLINE!"
      if {![nextLine]} {
        set gState(error) true
        set gState(errorMsg) "reached eof in parsing environment argument"
        return false
      }
puts "BEG2a!$gCurr(args)!$gCurr(idx)!$gCurr(lgth)!$gCurr(lst)!"
    }
#puts "BEG3!$gCurr(args)!$gCurr(idx)!$gCurr(lst)!"
    set ch [lindex $gCurr(lst) $gCurr(idx)]
#puts "BEG4!$ch!$gCurr(args)!$gCurr(idx)!$gCurr(lst)!$ch!$gCurr(lgth)!"
    switch $ch {
    "\\" {
      if {([expr {$gCurr(idx) + 3}] < $gCurr(lgth)) && ((($gCurr(idx) > 0) && ([lindex $gCurr(lst) [expr {$gCurr(idx) - 1}]] ne "\\")) || ($gCurr(idx) == 0))} {
        if {([lindex $gCurr(lst) [expr {$gCurr(idx) + 1}]] eq "e") 
          && ([lindex $gCurr(lst) [expr {$gCurr(idx) + 2}]] eq "n") 
          && ([lindex $gCurr(lst) [expr {$gCurr(idx) + 3}]] eq "d") } {
          set saveIdx $gCurr(idx)
          incr gCurr(idx) 4
          lappend gCurr(args) $argStr
          if {! [parseMandatoryArg]} {
            return false
          }
          if {[lindex $gCurr(args) 0] ne [lindex $gCurr(args) end]} {
            set gCur(idx) $saveIdx)
	    append argStr "\\end\{[lindex $gCurr(args) end]\}"
	    set gCurr(args) [lrange $gCurr(args) 0 end-1]
	  } else {
            incr gCurr(begin) -1
            if {$gCurr(begin) == 0} {
              # have a complete environment block
              if {($gCurr(begin) == $beginStart) && ([lindex $gCurr(args) 0] ne [lindex $gCurr(args) end])} {
                set gState(error) true
                set gState(errorMsg) "\\begin: missing closing \\end\{[lindex $gCurr(args) 0]\}"
                return false
              }
	      set gCurr(args) [lrange $gCurr(args) 0 end-1]
              return true
            }
          }
        } else {
          append argStr $ch
          incr gCurr(idx)
	}
      } else {
        append argStr $ch
        incr gCurr(idx)
      }
      }
    default {
      append argStr $ch
      incr gCurr(idx)
      }
    }
  }
  # not reached
  return true
}
}

proc parseLine {line} {
  global gState gCmds gCurr

#puts "parseLine!$line!"
  if {!$gState(inCommand)} {
    set curr_buffer [list]
    set gCurr(numMandatoryArgs) 0
    while {true} {
      set ch [lindex $gCurr(lst) $gCurr(idx)]
      switch $ch {
      "\\" {
        set gCurr(args) [list]
        set cmdName $ch
        incr gCurr(idx)
        while {true && ($gCurr(idx) < $gCurr(lgth))} {
          set ch [lindex $gCurr(lst) $gCurr(idx)]
          if {![string is alpha $ch]} {
            break
          } 
          append cmdName $ch
          incr gCurr(idx)
        }
        if {[info exists gCmds($cmdName)]} {
puts "cmd!$cmdName!$gCmds($cmdName)!"
          # push command to execute
          lappend gCurr(command) $cmdName
          set gCurr(args) [list]
          # parse parameters for command
          foreach paramType $gCmds($cmdName) {
            switch $paramType {
            m {
              if {![parseMandatoryArg]} {
                return false
              }
              incr gCurr(numMandatoryArgs)
              }
            o {
              if {![parseOptionalArg]} {
                return false
              }
              }
            x {
              if {![parseEnvironmentArg]} {
                return false
              }
              }
            }
          }
          uplevel 0 [list $cmdName {*}$gCurr(args)]
          # pop off executed command
          set gCurr(command) [lrange $gCurr(command) 0 end-1]
        } else {
          set gState(error) true
          set gState(errorMsg) "no such cmd: $cmdName!"
          return false
        }
        }
      "%" {
        set $gCurr(idx) $gCurr(lgth)
        break
        }
      "#" -
      "$" -
      "&" -
      "~" -
      "^" {
        incr gCurr(idx)
        set ch [lindex $gCurr(lst) $gCurr(idx)]
        # need code here to handle !!
        }
      default {
        incr gCurr(idx)
        set ch [lindex $gCurr(lst) $gCurr(idx)]
        }
      }
      if {$gCurr(idx) >= $gCurr(lgth)} {
        break
      }
    }
  } else {
  }
  return true
}

proc nextLine {} {
  global gState gCurr

  if {[gets stdin line] >= 0} {
    set gState(beginLine) true
    set gCurr(line) $line
    incr gCurr(numLines)
    set gCurr(idx) 0
    set gCurr(lst) [split $line ""]
    set gCurr(lgth) [llength $gCurr(lst)]
  }
  return true
}

::Parser::Token::Init
::Interp::Init
::LaTeX::CommandInfo::Init
set fname [lindex $argv 0]
set fd [open $fname r]
set str [read $fd]
close $fd
set script [$::Interp::string_obj_type newStringObj "$str" -1 "BASE_2"]
#puts "SCRIPT![$script toDebugString]!"
$::Interp::eval_statement evalObj $script

if {0} {
set parser [::Parser::Parse #auto]
$parser parserInit $str [string length $str] 1
while {true} {
  if {[$parser isEof]} {
    break
  }
  if {! [$parser parseScript]} {
    puts stderr "Error in parsing!"
    break
  }
puts "TOK![::Parser::Token::token2String [$parser getToken]]![$parser getText]!"
  set token [$parser getToken]
  if {$token == [::Parser::Token::string2Token "TOKEN_TAG_NAME"]} {
    set commandName [$parser getText]
puts "isCommand![::LaTeX::CommandInfo::isCommand $commandName]!"
    if {[info exists gCmds($commandName)]} {
puts "is correct tag_name![::Parser::Token::token2String $token]!$commandName!"
    } else {
       puts stderr "bad command name!$commandName!"
    }
  } else {
puts "token![::Parser::Token::token2String $token]!"
  }
}
}


if {0} {
set gState(inCommand) false
set gCurr(numLines) 0
set gCurr(command) [list]
set gCurr(begin) 0
while {[nextLine]} {
  if {![parseLine $gCurr(line)]} {
    puts stderr "$gState(errorMsg)"
    return false
  }
}
}
puts stderr "END"







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<











<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<

36
37
38
39
40
41
42





































































































































































































































































































43
44
45
46
47
48
49
50
51
52
53






54

































55
source ./latex_cmds.tcl

global gState
global gCmds
global gPackages
global gCurr






































































































































































































































































































::Parser::Token::Init
::Interp::Init
::LaTeX::CommandInfo::Init
set fname [lindex $argv 0]
set fd [open $fname r]
set str [read $fd]
close $fd
set script [$::Interp::string_obj_type newStringObj "$str" -1 "BASE_2"]
#puts "SCRIPT![$script toDebugString]!"
$::Interp::eval_statement evalObj $script









































puts stderr "END"