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
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
|
#!/usr/bin/env ruby
#encoding: ASCII-8BIT
banner = ['TeXExec', 'version 6.2.1', '1997-2009', 'PRAGMA ADE/POD']
$: << File.expand_path(File.dirname($0)) ; $: << File.join($:.last,'lib') ; $:.uniq!
require 'fileutils'
# require 'ftools' # needed ?
require 'base/switch'
require 'base/logger'
require 'base/variables'
require 'base/system'
require 'base/state' # needed ?
require 'base/file' # needed ?
require 'base/tex'
require 'base/texutil'
require 'base/kpse'
class Commands
include CommandBase
def make
if job = TEX.new(logger) then
prepare(job)
# bonus, overloads language switch !
job.setvariable('language','all') if @commandline.option('all')
if @commandline.arguments.length > 0 then
if @commandline.arguments.first == 'all' then
job.setvariable('texformats',job.defaulttexformats)
job.setvariable('mpsformats',job.defaultmpsformats)
else
job.setvariable('texformats',@commandline.arguments)
job.setvariable('mpsformats',@commandline.arguments)
end
end
job.makeformats
job.inspect && Kpse.inspect if @commandline.option('verbose')
seterror if job.error?
end
end
def check
if job = TEX.new(logger) then
job.checkcontext
job.inspect && Kpse.inspect if @commandline.option('verbose')
end
end
def main
if @commandline.arguments.length>0 then
process
else
help
end
end
def process
if job = TEX.new(logger) then
job.setvariable('files',@commandline.arguments)
prepare(job)
job.processtex
job.inspect && Kpse.inspect if @commandline.option('verbose')
seterror if job.error?
end
end
def mptex
if job = TEX.new(logger) then
job.setvariable('files',@commandline.arguments)
prepare(job)
job.processmptex
job.inspect && Kpse.inspect if @commandline.option('verbose')
seterror if job.error?
end
end
def mpxtex
if job = TEX.new(logger) then
job.setvariable('files',@commandline.arguments)
prepare(job)
job.processmpxtex
job.inspect && Kpse.inspect if @commandline.option('verbose')
seterror if job.error?
end
end
def mpgraphic
if job = TEX.new(logger) then
job.setvariable('files',@commandline.arguments)
prepare(job)
job.processmpgraphic
job.inspect && Kpse.inspect if @commandline.option('verbose')
seterror if job.error?
end
end
def mpstatic
if job = TEX.new(logger) then
job.setvariable('filename',@commandline.arguments.first)
prepare(job)
job.processmpstatic
job.inspect && Kpse.inspect if @commandline.option('verbose')
seterror if job.error?
end
end
# hard coded goodies # to be redone as s-ctx-.. with vars passed as such
def listing
if job = TEX.new(logger) then
prepare(job)
job.cleanuptemprunfiles
files = if @commandline.option('sort') then @commandline.arguments.sort else @commandline.arguments end
if files.length > 0 then
if f = File.open(job.tempfilename('tex'),'w') then
backspace = @commandline.checkedoption('backspace', '1.5cm')
topspace = @commandline.checkedoption('topspace', '1.5cm')
pretty = @commandline.option('pretty')
f << "% interface=english\n"
f << "\\setupbodyfont[11pt,tt]\n"
f << "\\setuplayout\n"
f << " [topspace=#{topspace},backspace=#{backspace},\n"
f << " header=0cm,footer=1.5cm,\n"
f << " width=middle,height=middle]\n"
f << "\\setuptyping[lines=yes]\n"
f << "\\setuptyping[option=color]\n" if pretty
f << "\\starttext\n";
files.each do |filename|
report("list file: #{filename}")
cleanname = cleantexfilename(filename).downcase
f << "\\page\n"
f << "\\setupfootertexts[\\tttf #{cleanname}][\\tttf \\pagenumber]\n"
f << "\\typefile{#{filename}}\n"
end
f << "\\stoptext\n"
f.close
job.setvariable('interface','english')
job.setvariable('simplerun',true)
# job.setvariable('nooptionfile',true)
job.setvariable('files',[job.tempfilename])
job.processtex
else
report('no files to list')
end
else
report('no files to list')
end
job.cleanuptemprunfiles
end
end
def figures
# we replaced "texutil --figures ..."
if job = TEX.new(logger) then
prepare(job)
job.cleanuptemprunfiles
fast = @commandline.option('fast')
files = if @commandline.option('sort') then @commandline.arguments.sort else @commandline.arguments end
if fast or (files.length > 0) then
if f = File.open(job.tempfilename('tex'),'w') then
files.delete("texexec.pdf")
# Kpse.runscript('rlxtools', ['--identify','--collect'], files.join(' ')) unless fast
system("texmfstart rlxtools --identify --collect #{files.join(' ')}")
figures = @commandline.checkedoption('method', 'a').downcase
paperoffset = @commandline.checkedoption('paperoffset', '0pt')
backspace = @commandline.checkedoption('backspace', '1.5cm')
topspace = @commandline.checkedoption('topspace', '1.5cm')
boxtype = @commandline.checkedoption('boxtype','')
f << "% format=english\n";
f << "\\usemodule[res-20]\n"
f << "\\setuplayout\n";
f << " [topspace=#{topspace},backspace=#{backspace},\n"
f << " header=1.5cm,footer=0pt,\n";
f << " width=middle,height=middle]\n";
if @commandline.option('fullscreen') then
f << "\\setupinteraction\n";
f << " [state=start]\n";
f << "\\setupinteractionscreen\n";
f << " [option=max]\n";
end
boxtype += "box" unless boxtype.empty? || (boxtype =~ /box$/io)
f << "\\starttext\n";
f << "\\showexternalfigures[alternative=#{figures},offset=#{paperoffset},size=#{boxtype}]\n";
f << "\\stoptext\n";
f.close
job.setvariable('interface','english')
job.setvariable('simplerun',true)
job.setvariable('files',[job.tempfilename])
job.processtex
# File.silentdelete('rlxtools.rli') unless job.getvariable('keep')
else
report('no figures to show')
end
else
report('no figures to show')
end
job.cleanuptemprunfiles
end
end
def modules
if job = TEX.new(logger) then
prepare(job)
job.cleanuptemprunfiles
files = if @commandline.option('sort') then @commandline.arguments.sort else @commandline.arguments end
msuffixes = ['tex','mkii','mkiv','mp','pl','pm','rb']
if files.length > 0 then
files.each do |fname|
fnames = Array.new
if FileTest.file?(fname) then
fnames << fname
else
msuffixes.each do |fsuffix|
fnames << File.suffixed(fname,fsuffix)
end
end
fnames.each do |ffname|
if msuffixes.include?(File.splitname(ffname)[1]) && FileTest.file?(ffname) then
if mod = File.open(job.tempfilename('tex'),'w') then
if File.suffix(ffname) =~ /^(mkii|mkiv)$/o then
markfile = $1
else
markfile = nil
end
# Kpse.runscript('ctxtools',['--document'],ffname)
system("texmfstart ctxtools --document #{ffname}")
if ted = File.silentopen(File.suffixed(ffname,'ted')) then
firstline = ted.gets
if firstline =~ /interface=/o then
mod << firstline
else
mod << "% interface=en\n"
end
ted.close
else
mod << "% interface=en\n"
end
mod << "\\usemodule[mod-01]\n"
mod << "\\def\\ModuleNumber{1}\n"
mod << "\\starttext\n"
# todo: global file too
mod << "\\readlocfile{#{File.suffixed(ffname,'ted')}}{}{}\n"
mod << "\\stoptext\n"
mod.close
job.setvariable('interface','english') # redundant
# job.setvariable('simplerun',true)
# job.setvariable('nooptionfile',true)
job.setvariable('files',[job.tempfilename])
result = File.unsuffixed(File.basename(ffname))
if markfile then
result = result+'-'+markfile
end
job.setvariable('result',result)
job.processtex
# ["dvi", "pdf","ps"].each do |s|
# File.silentrename(job.tempfilename(s),File.suffixed(ffname,s));
# end
end
end
end
end
else
report('no modules to process')
end
job.cleanuptemprunfiles
end
end
def pdfsplit
if job = TEX.new(logger) then
prepare(job)
job.cleanuptemprunfiles
filename = File.expand_path(@commandline.arguments.first)
if FileTest.file?(filename) then
basename = filename.sub(/\..*?$/,'')
tempfile = File.suffixed(job.tempfilename,'tex')
if basename != filename then
info = `pdfinfo #{filename}`
if info =~ /Pages:\s*(\d+)/ then
nofpages = $1.to_i
result = @commandline.checkedoption('result','texexec')
nofpages.times do |i|
if f = File.open(tempfile,"w") then
n = i + 1
report("extracting page #{n}")
f << "\\starttext\\startTEXpage\n"
f << "\\externalfigure[#{filename}][object=no,page=#{n}]\n"
f << "\\stopTEXpage\\stoptext\n"
f.close
job.setvariable('result',"#{result}-#{n}")
job.setvariable('interface','english') # redundant
job.setvariable('simplerun',true)
job.setvariable('purge',true)
job.setvariable('files',[tempfile])
job.processtex
end
end
end
end
end
job.cleanuptemprunfiles
end
end
def arrangeoutput
if job = TEX.new(logger) then
prepare(job)
job.cleanuptemprunfiles
files = if @commandline.option('sort') then @commandline.arguments.sort else @commandline.arguments end
if files.length > 0 then
if f = File.open(job.tempfilename('tex'),'w') then
emptypages = @commandline.checkedoption('addempty', '')
paperoffset = @commandline.checkedoption('paperoffset', '0cm')
textwidth = @commandline.checkedoption('textwidth', '0cm')
backspace = @commandline.checkedoption('backspace', '0cm')
topspace = @commandline.checkedoption('topspace', '0cm')
f << "\\definepapersize\n"
f << " [offset=#{paperoffset}]\n"
f << "\\setuplayout\n"
f << " [backspace=#{backspace},\n"
f << " topspace=#{topspace},\n"
f << " marking=on,\n" if @commandline.option('marking')
f << " width=middle,\n"
f << " height=middle,\n"
f << " location=middle,\n"
f << " header=0pt,\n"
f << " footer=0pt]\n"
unless @commandline.option('noduplex') then
f << "\\setuppagenumbering\n"
f << " [alternative=doublesided]\n"
end
f << "\\starttext\n"
files.each do |filename|
report("arranging file #{filename}")
f << "\\insertpages\n"
f << " [#{filename}]\n"
f << " [#{emptypages}]\n" unless emptypages.empty?
f << " [width=#{textwidth}]\n"
end
f << "\\stoptext\n"
f.close
job.setvariable('interface','english')
job.setvariable('simplerun',true)
job.setvariable('arrange',true)
# job.setvariable('nooptionfile',true)
job.setvariable('files',[job.tempfilename])
job.processtex
else
report('no files to arrange')
end
else
report('no files to arrange')
end
job.cleanuptemprunfiles
end
end
def selectoutput
if job = TEX.new(logger) then
prepare(job)
job.cleanuptemprunfiles
files = if @commandline.option('sort') then @commandline.arguments.sort else @commandline.arguments end
if files.length > 0 then
if f = File.open(job.tempfilename('tex'),'w') then
selection = @commandline.checkedoption('selection', '')
paperoffset = @commandline.checkedoption('paperoffset', '0cm')
textwidth = @commandline.checkedoption('textwidth', '0cm')
backspace = @commandline.checkedoption('backspace', '0cm')
topspace = @commandline.checkedoption('topspace', '0cm')
paperformat = @commandline.checkedoption('paperformat', 'A4*A4').split(/[\*x]/o)
from, to = paperformat[0] || 'A4', paperformat[1] || paperformat[0] || 'A4'
if from == 'fit' or to == 'fit' then
f << "\\getfiguredimensions[#{files.first}]\n"
if from == 'fit' then
f << "\\expanded{\\definepapersize[from-fit][width=\\figurewidth,height=\\figureheight]}\n"
from = 'from-fit'
end
if to == 'fit' then
f << "\\expanded{\\definepapersize[to-fit][width=\\figurewidth,height=\\figureheight]}\n"
to = 'to-fit'
end
end
job.setvariable('paperformat','') # else overloaded later on
f << "\\setuppapersize[#{from}][#{to}]\n"
f << "\\definepapersize\n";
f << " [offset=#{paperoffset}]\n";
f << "\\setuplayout\n";
f << " [backspace=#{backspace},\n";
f << " topspace=#{topspace},\n";
f << " marking=on,\n" if @commandline.option('marking')
f << " width=middle,\n";
f << " height=middle,\n";
f << " location=middle,\n";
f << " header=0pt,\n";
f << " footer=0pt]\n";
f << "\\setupexternalfigures\n";
f << " [directory=]\n";
f << "\\starttext\n";
unless selection.empty? then
f << "\\filterpages\n"
f << " [#{files.first}][#{selection}][width=#{textwidth}]\n"
end
f << "\\stoptext\n"
f.close
job.setvariable('interface','english')
job.setvariable('simplerun',true)
# job.setvariable('nooptionfile',true)
job.setvariable('files',[job.tempfilename])
job.processtex
else
report('no files to selectt')
end
else
report('no files to select')
end
job.cleanuptemprunfiles
end
end
def copyoutput
copyortrim(false,'copy')
end
def trimoutput
copyortrim(true,'trim')
end
def copyortrim(trim=false,what='unknown')
if job = TEX.new(logger) then
prepare(job)
job.cleanuptemprunfiles
files = if @commandline.option('sort') then @commandline.arguments.sort else @commandline.arguments end
if files.length > 0 then
if f = File.open(job.tempfilename('tex'),'w') then
scale = @commandline.checkedoption('scale')
begin
scale = (scale.to_f * 1000.0).to_i if scale.to_i < 10
rescue
scale = 1000
end
scale = scale.to_i
paperoffset = @commandline.checkedoption('paperoffset', '0cm')
f << "\\starttext\n"
files.each do |filename|
result = @commandline.checkedoption('result','texexec')
begin
if (filename !~ /^texexec/io) && (filename !~ /^#{result}/) then
report("copying file: #{filename}")
f << "\\getfiguredimensions\n"
f << " [#{filename}]\n"
f << " [scale=#{scale},\n"
f << " page=1,\n"
f << " size=trimbox\n" if trim
f << "]\n"
f << "\\definepapersize\n"
f << " [copy]\n"
f << " [width=\\figurewidth,\n"
f << " height=\\figureheight]\n"
f << "\\setuppapersize\n"
f << " [copy][copy]\n"
f << "\\setuplayout\n"
f << " [page]\n"
f << "\\setupexternalfigures\n"
f << " [directory=]\n"
f << "\\copypages\n"
f << " [#{filename}]\n"
f << " [scale=#{scale},\n"
f << " marking=on,\n" if @commandline.option('markings')
f << " size=trimbox,\n" if trim
f << " offset=#{paperoffset}]\n"
end
rescue
report("wrong specification")
end
end
f << "\\stoptext\n"
f.close
job.setvariable('interface','english')
job.setvariable('simplerun',true)
# job.setvariable('nooptionfile',true)
job.setvariable('files',[job.tempfilename])
job.processtex
else
report("no files to #{what}")
end
else
report("no files to #{what}")
end
job.cleanuptemprunfiles
end
end
# todo: make this styles
def combineoutput
if job = TEX.new(logger) then
prepare(job)
job.cleanuptemprunfiles
files = if @commandline.option('sort') then @commandline.arguments.sort else @commandline.arguments end
if files.length > 0 then
if f = File.open(job.tempfilename('tex'),'w') then
paperoffset = @commandline.checkedoption('paperoffset', '0cm')
combination = @commandline.checkedoption('combination','2*2').split(/[\*x]/o)
paperformat = @commandline.checkedoption('paperformat', 'A4*A4').split(/[\*x]/o)
bannerheight = @commandline.checkedoption('bannerheight', '')
pdftitle = @commandline.checkedoption('pdftitle', '')
nx, ny = combination[0] || '2', combination[1] || combination[0] || '2'
from, to = paperformat[0] || 'A4', paperformat[1] || paperformat[0] || 'A4'
f << "\\setuppapersize[#{from}][#{to}]\n"
f << "\\setuplayout\n"
f << " [topspace=#{paperoffset},backspace=#{paperoffset},\n"
f << " header=0pt,footer=0pt,\n"
f << " width=middle,height=middle]\n"
if bannerheight.empty? then
f << "\\setuplayout[footer=1cm]\n"
else
f << "\\definelayer[page][width=\\paperwidth,height=\\paperheight]\n"
f << "\\setupbackgrounds[page][background=page]\n"
end
if @commandline.option('nobanner') then
f << "\\setuplayout[footer=0cm]\n"
f << "\\setupbackgrounds[page][background=]\n"
end
f << "\\setupexternalfigures[directory=]\n"
if not pdftitle.empty? then
f << "\\setupinteraction[state=start,title={#{pdftitle}}]\n"
end
f << "\\starttext\n"
files.each do |filename|
result = @commandline.checkedoption('result','texexec')
if (filename !~ /^texexec/io) && (filename !~ /^#{result}/) then
report("combination file: #{filename}")
cleanname = cleantexfilename(filename).downcase
bannerstring = "\\tttf #{cleanname}\\quad\\quad\\currentdate\\quad\\quad\\pagenumber"
if bannerheight.empty? then
f << "\\setupfootertexts\n"
f << " [#{bannerstring}]\n"
else
# for the moment we lack a better hook
f << "\\setuptexttexts\n"
f << " [{\\setlayerframed[page][preset=middlebottom][frame=off,height=#{bannerheight}]{#{bannerstring}}}]\n"
end
f << "\\combinepages[#{filename}][nx=#{nx},ny=#{ny}]\n"
f << "\\page\n"
end
end
f << "\\stoptext\n"
f.close
job.setvariable('interface','english')
job.setvariable('simplerun',true)
# job.setvariable('nooptionfile',true)
job.setvariable('files',[job.tempfilename])
job.processtex
else
report('no files to list')
end
else
report('no files to list')
end
job.cleanuptemprunfiles
end
end
private
def prepare(job)
job.booleanvars.each do |k|
job.setvariable(k,@commandline.option(k))
end
job.stringvars.each do |k|
job.setvariable(k,@commandline.option(k)) unless @commandline.option(k).empty?
end
job.standardvars.each do |k|
job.setvariable(k,@commandline.option(k)) unless @commandline.option(k).empty?
end
job.knownvars.each do |k|
job.setvariable(k,@commandline.option(k)) unless @commandline.option(k).empty?
end
job.setvariable('given.backend',job.getvariable('backend'))
if (str = @commandline.option('engine')) && ! str.standard? && ! str.empty? then
job.setvariable('texengine',str)
elsif @commandline.oneof('pdfetex','pdftex','pdf') then
job.setvariable('texengine','pdftex')
elsif @commandline.oneof('xetex','xtx') then
job.setvariable('texengine','xetex')
elsif @commandline.oneof('aleph') then
job.setvariable('texengine','aleph')
elsif @commandline.oneof('petex') then
job.setvariable('texengine','petex')
else
job.setvariable('texengine','standard')
end
if (str = @commandline.option('backend')) && ! str.standard? && ! str.empty? then
job.setvariable('backend',str)
elsif @commandline.oneof('pdfetex','pdftex','pdf') then
job.setvariable('backend','pdftex')
elsif @commandline.oneof('dvipdfmx','dvipdfm','dpx','dpm') then
job.setvariable('backend','dvipdfmx')
elsif @commandline.oneof('xetex','xtx') then
job.setvariable('backend','xetex')
elsif @commandline.oneof('aleph') then
job.setvariable('backend','dvipdfmx')
elsif @commandline.oneof('petex') then
job.setvariable('backend','dvipdfmx')
elsif @commandline.oneof('dvips','ps') then
job.setvariable('backend','dvips')
elsif @commandline.oneof('xdv') then
job.setvariable('backend','xdv')
else
case job.getvariable('texengine')
when 'pdfetex' then job.setvariable('backend','pdftex')
when 'pdftex' then job.setvariable('backend','pdftex')
when 'xetex' then job.setvariable('backend','xetex')
when 'petex' then job.setvariable('backend','dvipdfmx')
when 'aleph' then job.setvariable('backend','dvipdfmx')
else
job.setvariable('backend','standard')
end
end
if (str = @commandline.option('engine')) && ! str.standard? && ! str.empty? then
job.setvariable('mpsengine',@commandline.option('engine'))
else
job.setvariable('mpsengine','standard')
end
end
def cleantexfilename(filename)
filename.gsub(/([\$\_\#])/) do "\\$1" end.gsub(/([\~])/) do "\\string$1" end
end
end
# we will make this pluggable, i.e. load plugins from base/tex that
# extend the class and may even add switches
#
# commandline.load_plugins('base/tex')
#
# maybe it's too slow so for a while keep the --pdf* in here
logger = Logger.new(banner.shift)
commandline = CommandLine.new
commandline.registeraction('make', 'make formats')
commandline.registeraction('check', 'check versions')
commandline.registeraction('process', 'process file')
commandline.registeraction('mptex', 'process mp file')
commandline.registeraction('mpxtex', 'process mpx file')
commandline.registeraction('mpgraphic', 'process mp file to stand-alone graphics')
commandline.registeraction('mpstatic', 'process mp/ctx file to stand-alone graphics')
commandline.registeraction('listing', 'list of file content')
commandline.registeraction('figures', 'generate overview of figures')
commandline.registeraction('modules', 'generate module documentation')
commandline.registeraction('pdfarrange', 'impose pages (booklets)')
commandline.registeraction('pdfselect', 'select pages from file(s)')
commandline.registeraction('pdfcopy', 'copy pages from file(s)')
commandline.registeraction('pdftrim', 'trim pages from file(s)')
commandline.registeraction('pdfcombine', 'combine multiple pages')
commandline.registeraction('pdfsplit', 'split file in pages')
# compatibility switch
class Commands
include CommandBase
alias pdfarrange :arrangeoutput
alias pdfselect :selectoutput
alias pdfcopy :copyoutput
alias pdftrim :trimoutput
alias pdfcombine :combineoutput
end
# so far for compatibility, will move to tex
extrastringvars = [
'pages', 'background', 'backspace', 'topspace', 'boxtype', 'tempdir','bannerheight',
'printformat', 'method', 'scale', 'selection',
'combination', 'textwidth', 'addempty', 'logfile',
'startline', 'endline', 'startcolumn', 'endcolumn', 'scale'
]
extrabooleanvars = [
'centerpage', 'noduplex', 'color', 'pretty',
'fullscreen', 'screensaver', 'markings'
]
if job = TEX.new(logger) then
job.setextrastringvars(extrastringvars)
job.setextrabooleanvars(extrabooleanvars)
job.booleanvars.each do |k|
commandline.registerflag(k)
end
job.stringvars.each do |k|
commandline.registervalue(k,'')
end
job.standardvars.each do |k|
commandline.registervalue(k,'standard')
end
job.knownvars.each do |k|
commandline.registervalue(k,'')
end
end
class Commands
alias saved_help help
def wrap_help(title, vars)
report("")
report(title)
report("")
r, n = '', 0
vars.sort.each do |s|
if n == 5 then
report(r)
r, n = '', 1
else
n += 1
end
r << ' ' + s.to_s
end
report(r) unless r.empty?
end
def help
saved_help
if @commandline.option('all') then
if job = TEX.new(logger) then
wrap_help("boolean switches:", job.allbooleanvars)
wrap_help("string switches:", job.allstringvars)
end
else
report('')
report('--help --all shows all switches')
end
end
end
# todo: register flags -> first one true
commandline.registerflag('pdf')
commandline.registerflag('pdftex')
commandline.registerflag('pdfetex')
commandline.registerflag('dvipdfmx')
commandline.registerflag('dvipdfm')
commandline.registerflag('dpx')
commandline.registerflag('dpm')
commandline.registerflag('dvips')
commandline.registerflag('ps')
commandline.registerflag('xetex')
commandline.registerflag('xtx')
commandline.registerflag('xdv')
commandline.registerflag('aleph')
commandline.registerflag('petex')
commandline.registerflag('all')
commandline.registerflag('fast')
commandline.registerflag('sort')
# generic
commandline.registeraction('help')
commandline.registeraction('version')
commandline.registerflag('verbose')
commandline.expand
Commands.new(commandline,logger,banner).execute(commandline.action || 'main') # or just execute()
|