aboutsummaryrefslogtreecommitdiffhomepage
path: root/org/texinfo.org
blob: 93a63f685cb4cc25b853db2871debc2a4ff49513 (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
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
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
-*- mode: org -*-
#+TITLE:       sisu texinfo
#+DESCRIPTION: documents - structuring, various output representations & search
#+FILETAGS:    :sisu:texinfo:
:wqa
#+AUTHOR:      Ralph Amissah
#+EMAIL:       [[mailto:ralph.amissah@gmail.com][ralph.amissah@gmail.com]]
#+COPYRIGHT:   Copyright (C) 2015 - 2021 Ralph Amissah
#+LANGUAGE:    en
#+STARTUP:     content hideblocks hidestars noindent entitiespretty
#+OPTIONS:     H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil _:nil -:t f:t *:t <:t
#+PROPERTY:    header-args  :exports code
#+PROPERTY:    header-args+ :noweb yes
#+PROPERTY:    header-args+ :eval no
#+PROPERTY:    header-args+ :results no
#+PROPERTY:    header-args+ :cache no
#+PROPERTY:    header-args+ :padline no
#+PROPERTY:    header-args+ :mkdirp yes

* texinfo.rb

#+BEGIN_SRC ruby  :tangle "../lib/sisu/texinfo.rb"
<<sisu_document_header>>
module SiSU_TexInfo
  require_relative 'html'                               # html.rb
  require_relative 'dp'                                 # dp.rb
    include SiSU_Param
  #include Stamp ... needed removed arbitrarily 2005w05/1 (warnings about undefined flags)
  require_relative 'texinfo_format'                     # texinfo_format.rb
  include SiSU_TexInfoFormat
  @tex_file=[]
  @@tabular="{tabular}"
  @@table_pagebreak_counter,@@tex_endnote_call_counter,@@tex_table_flag,@@tex_counter,@@tex_column,@@tex_columns,@@counting=0,0,0,0,0,0,0
  @@column_instruct,@@tex_line_mode,@@tex_word_mode,@@start_table,@@line_mode='','','','',''
  @@n,@@copyright,@@tableheader=nil,nil,nil
  @@tex_col_w=[]
  @@tex_pattern_margin_number="\\\\marginpar.+?\s+"
  class Source
    include SiSU_Param
    include SiSU_TexInfo
    def initialize(opt)
      @opt=opt
      @md=SiSU_Param::Parameters.new(@opt).get
      @env=SiSU_Env::InfoEnv.new(@opt.fns)
    end
    def directories
      begin
        case @opt.fns
        when /\.(?:-|ssm\.)?sst$/
          Dir.mkdir(@env.path.output) unless FileTest.directory?("#{@env.path.output}")
          Dir.mkdir(@env.processing_path.texi) unless FileTest.directory?(@env.processing_path.texi)
        end
      rescue
        SiSU_Screen::Ansi.new(opt,$!,$@).rescue do
          __LINE__.to_s + ':' + __FILE__
        end
      ensure
      end
    end
    def read
      begin
        song
      ensure
        Dir.chdir(@opt.f_pth[:pth])
      end
    end
    def song
      begin
        tool=(@opt.act[:verbose][:set]==:on \
        || @opt.act[:verbose_plus][:set]==:on \
        || @opt.act[:maintenance][:set]==:on) \
        ? "cd #{@md.file.output_path.texinfo.dir} && #{@env.program.texinfo} #{@md.file.base_filename.info}; cd -"
        : "[#{@opt.f_pth[:lng_is]}] #{@opt.fno}"
        (@opt.act[:verbose][:set]==:on \
        || @opt.act[:verbose_plus][:set]==:on \
        || @opt.act[:maintenance][:set]==:on) \
        && ! @opt.act[:quiet][:set]==:on \
        ? SiSU_Screen::Ansi.new(
            @opt.act[:color_state][:set],
            'TexInfo',
            tool
          ).green_hi_blue
        : SiSU_Screen::Ansi.new(
            @opt.act[:color_state][:set],
            'TexInfo',
            tool
          ).green_title_hi
        @md=SiSU_Param::Parameters.new(@opt).get
        directories
        @marshalfile=SiSU_Env::InfoFile.new(@opt.fns).marshal.ao_content
        if FileTest.file?(@marshalfile)==true
          File.open(@marshalfile) { |f| @@tuned_file=Marshal.load(f)}
          #tell.meta_verse_skipped if @opt.selections.str =~/[vVM]/
        else
          tex_array=IO.readlines(@opt.fns,'')
          SiSU_Metaverse.songsheet(tex_array)
        end
        tex_array=@@tuned_file
        TeXinfoMake.new(@md,tex_array).songsheet
        tex_array=''
      rescue; STDERR.puts SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],$!,$@).rescue
      ensure
      end
    end
  end
  class TeXinfoMake
    include SiSU_Param
    include SiSU_TexInfoFormat
    @@tex_1='(?:.+?)+~' #?? debug
    @@tabular="{tabular}"
    @@tex_pattern_margin_number="\\\\marginpar.+?\s+"
    def initialize(md,data)
      @md,@data=md,data
      @env=SiSU_Env::InfoEnv.new(@md.fns)
      @f=SiSU_Env::FileOp.new(@md)
    end
    def songsheet
      begin
        data=@data
        data=pre(data)
        data=endnote(data)
        data,head=markup(data)
        objs_txt=tail(data)
        doc_txt=[head,objs_txt]
        output(doc_txt)
        makeinfo #KEEP reinstate when fixed #%
        place_info
      rescue; STDERR.puts SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],$!,$@).rescue
      ensure
      end
    end
    def pre(data)
      data_new=[]
      data.each do |dob|
        # DEBUG 2003w16 this is a kludge, because i could not get parameters
        # from param, Sort out ... revert to more elegant solution
        if dob.is =='table'
          @@flag['tables']='y' # KLUDGE get from param
        end
        dob.obj=dob.obj.gsub(/<:p[bn]>/,'').
          gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,'\1(\2 [linked to:] \3)').
          gsub(/(^|#{Mx[:gl_c]}|\s)\{(.+?)\}((?:https?|file):\/\/\S+)/,'\1(\2 [linked to:] \3)')
        do_mono=SiSU_TexInfoFormat::Texinfo.new(@md,dob)
        dob.obj=do_mono.spec_char(dob.obj)
        data_new << dob
      end
      data_new
    end
    def endnote(data)
      data_new=[]
      data.each do |dob|
        if dob.of==:para \
        || dob.of==:block
          dob.obj=dob.obj.gsub(/\s*#{Mx[:en_a_o]}(?:\d+)\s+(.+?)#{Mx[:en_a_c]}/m,' @footnote{ \1} ').
            gsub(/\s*#{Mx[:en_a_o]}(\*+)\s+(.+?)#{Mx[:en_a_c]}/m,' @footnote{ \1} ')
        end
        data_new << dob
      end
      data_new
    end
    def poem
      data,data_new=@data,[]
      @tex_file=[]
      @@counting=0
      data.each do |dob|
        if dob.is ==:code
          @@flag['code']=true
          @@counting=1
        end
        if dob.is ==:verse
          @@flag['poem']=1
        end
        if @@flag['code']
          if @@flag['code'] \
          && (dob.obj =~ /#{Mx[:gr_o]}code[-_](?:end|close)#{Mx[:gr_c]}/) #watch change not tested 200501 #fix
            @@flag['code']=false
          end
          if @@flag['code'] \
          && (dob.obj =~ /\S/)
            sub_array=dob.obj.dup
            @@line_mode=sub_array.scan(/.+/)
            Tune.code_lines(@@line_mode)
            dob.obj=@@line_mode.join
          end
        elsif @@flag['poem']==1
          if @@flag['poem']==1 \
          && (dob.obj =~ /#{Mx[:gr_o]}verse[-_](?:end|close)#{Mx[:gr_c]}/) #watch change not tested 200501 #fix
            @@flag['poem']=0
          end
          if @@flag['poem']==1 \
          && (dob.obj =~ /\S/)
            sub_array=dob.obj.dup
            @@line_mode=sub_array.scan(/.+/)
            Tune.code_lines(@@line_mode)
            dob.obj=@@line_mode.join
          end
        end
        @tex_file << dob.obj
        data_new << dob
      end
      data_new
    end
    def code_lines
      data,data_new=@data,[]
      data.each do |line|
        if (line =~ /\S/) \
        && (line !~ /#{Mx[:gr_o]}(code|verse).+/) #fix
          line=if @@flag['code']
            line.gsub(/^\s*(.+)/m,"\\noindent \\marginpar\[left-text\]{\\begin{tiny}#{@@counting}\\end{tiny}}\\1\\")
            @@counting+=1 if @@flag['code']
          else line.gsub(/(.+)/m,'\noindent\1')
          end
        end
        data_new << line
      end
    end
    def tables
      data,data_new=@data,[]
      @tex_file=[]
      @@tableheader=0
      data.each do |dob|
        if dob.obj =~ /#{Mx[:tc_p]}|#{Mx[:gr_o]}T/ui #fix
          do_mono=SiSU_TexInfoFormat::Texinfo.new(@md,dob)
          dob.obj=do_mono.longtable # using longtable latex package
        end
        @tex_file << dob.obj
        data_new << dob
      end
      data_new
    end
    def markup(data)
      data_new=[]
      @tex_file=[]
      @row_break='\\\\\\'
      @break_page="#{@row_break}\n#{@row_break} \n"
      @tex_file << SiSU_TexInfoFormat::Texinfo.new(@md).head
      mono=SiSU_TexInfoFormat::Texinfo.new(@md)
      @tex_file << mono.topnode(@md.title.full)
      texinfo_menu=[]
      n_menu,n_submenu=0,0
      @submenu,@subsubmenu={},{}
      data.each do |dob|
        if dob.is ==:heading \
        && (dob.ln.to_s =~ /^[0-3]$/)
          toc=SiSU_TexInfoFormat::Texinfo.new(@md,dob)
          texinfo_menu << toc.menu
        elsif dob.is ==:heading \
        && (dob.ln.to_s =~ /^[4-6]$/)
          toc=SiSU_TexInfoFormat::Texinfo.new(@md,dob)
          texinfo_menu << toc.menu
          case dob.ln
          when 4
            n_menu+=1
            @submenu[n_menu]=[]
          when 5
            n_submenu+=1
            @subsubmenu[n_menu]=[]
            @submenu[n_menu] << toc.menu
          when 6
            n_submenu+=1
            @subsubmenu[n_submenu]=[]
            @subsubmenu[n_submenu] << toc.menu
          end
        else
          dob.obj=dob.obj.gsub(/\s*(?:<:?br>|<br \/>)\s*/,"\n\n")
        end
        data_new << dob
      end
      data=data_new
      texinfo_menu=texinfo_menu.compact
      texinfo_menu << "* Dublin Core::"
      @tex_file << texinfo_menu
      @tex_file << "* Index::\n" +
        "@end menu\n\n" +
        "@c %% 5\n\n"
      n_menu,n_submenu=0,0
      @@do_submenu,@@do_subsubmenu=1,1
      data_new=[]
      data.each do |dob|
        unless defined? dob.ln and dob.ln == (5..6)
          mono=SiSU_TexInfoFormat::Texinfo.new(@md,dob)
        end
        if dob.is==:heading
          case dob.ln
          when 0 then dob=mono.level0
          when 1 then dob=mono.level1
          when 2 then dob=mono.level2
          when 3 then dob=mono.level3
          when 4;
            @@n4_txt=dob.obj
            dob=mono.level4
            n_menu+=1
            @@do_submenu,@@do_subsubmenu=1,1
          when 5;
            n_submenu+=1
            @@do_subsubmenu=1
            @@n5_txt=dob.obj
            if @@do_submenu==1
              menu=SiSU_TexInfoFormat::TeXinfoTxt.new(@md,dob,@submenu[n_menu])
              dob.obj="#{menu.submenu}#{SiSU_TexInfoFormat::Texinfo.new(@md,dob,@@n4_txt).level5.obj}"
              @@do_submenu=0
            else dob.obj="#{SiSU_TexInfoFormat::Texinfo.new(@md,dob,@@n4_txt).level5.obj}"
            end
          when 6;
            if @@do_submenu==1
              menu=SiSU_TexInfoFormat::TeXinfoTxt.new(@md,dob,@submenu[n_menu])
              dob.obj="#{menu.submenu}#{SiSU_TexInfoFormat::Texinfo.new(@md,dob,@@n5_txt).level6.obj}"
              dob.obj="#{menu.subsubmenu}#{mono.level6.obj}"
              @@do_subsubmenu=0
            else dob.obj="#{SiSU_TexInfoFormat::Texinfo.new(@md,dob,@@n5_txt).level6.obj}"
            end
          end
        else
          if dob.obj !~/\S/
            dob.obj=nil
          else
            if dob.is==:para \
            && (dob.obj !~/#{Dx[:ocn_o]}#{dob.ocn}#{Dx[:ocn_c]}/)
              dob.obj=dob.ocn.is_a?(Fixnum) \
              ? "#{dob.obj} #{Dx[:ocn_o]}#{dob.ocn}#{Dx[:ocn_c]}\n\n" : "#{dob.obj}\n\n"
            end
          end
        end
        #%case with endnotes
        dob.obj=dob.obj.gsub(/\s*[0-8]\\+(\S+)?\s+/,' ') if dob.obj
        data_new << dob
      end
      [data_new, @tex_file]
    end
    def number_titles
      data,data_new=@data,[]
      @tex_file=[]
      data.each do |dob|
        if (@md.markup =~ /num_top/i) \
        && (dob.obj !~ /#{Rx[:meta]}/)
          if (dob.obj =~ /^[1-6]\\+(?:~\S+)?\s*<!h-.+?-!>/) \
          && (dob.obj !~ /<:\d-endnotes>/)
            header=dob.obj[/<!h-(.+?)-!>/m, 1].gsub(/-/m,'.')
            dob.obj=dob.obj.gsub(/^(?:[1-6]\\+(?:~\S+)|<:([12356]|4-.+?-)>)\s*<!h-.+?-!>/,
              "\\1 #{header} ")
          end
        elsif dob.obj=~ /<!h!>|<!h\d!>|<!h.+?!>|<!!h.+?!>/
          if dob.obj=~ /<!h-.+?-!>/
            dob.obj=dob.obj.gsub(/<!h-(.+?)-!>/,'\1 ')
          end
        end
        @tex_file << dob.obj
      end
      data_new << dob
    end
    def tail(data)
      tex=SiSU_TexInfoFormat::Texinfo.new(@md)
      objs_txt=[]
      data.each do |dob|
        if dob.obj \
        && (dob.is !=:structure \
        && dob.is !=:comment)
           objs_txt << dob.obj if dob.obj
        end
      end
      objs_txt << tex.dublincore << tex.tail
      objs_txt
    end
    def output(data)
      filename_texinfo=%{#{@env.processing_path.texi}/#{@md.fnb}.texinfo}
      file_texinfo=File.new(filename_texinfo,'w+')
      puts filename_texinfo if @md.opt.act[:maintenance][:set]==:on
      data.each {|s| (file_texinfo.puts s,"\n") if s}
      file_texinfo.close
    end
    def makeinfo
      if @md.fns =~/\.(?:-|ssm\.)?sst$/
        m=/(.+?)\.((?:-|ssm\.)?sst)$/.match(@md.fns)
        fnb,sfx=m[1],m[2]
        pwd=Dir.pwd
        case sfx
        when /(?:-|ssm\.)?sst$/
          @env=SiSU_Env::InfoEnv.new(@md.fns,@md.opt.selections.str)
          Dir.chdir(@env.processing_path.texi)
          texinfo=SiSU_Env::SystemCall.new("#{fnb}.texinfo")
          texinfo.makeinfo
        end
        Dir.chdir(pwd)
      end
      def place_info
        unless FileTest.directory?(@f.output_path.texinfo.dir)
          FileUtils::mkdir_p(@f.output_path.texinfo.dir)
        end
        info_src=%{#{@env.processing_path.texi}/#{@md.fnb}.info}
        Dir.glob("#{info_src}*").sort.each do |f|
          FileUtils::cp(f, File.dirname(@f.place_file.info.dir)) # bug should provide dir without need to extract it!
        end
      end
    end
  end
end
__END__
#+END_SRC

* texinfo_format.rb

#+BEGIN_SRC ruby  :tangle "../lib/sisu/texinfo_format.rb"
<<sisu_document_header>>
module SiSU_TexInfoFormat
  @@table_pg_break_counter=1
  require_relative 'dp'                                 # dp.rb
    include SiSU_Param
  class Texinfo
    @@tex_1='\\\\~' #?? debug
    @@tabular="{tabular}"
    @@tex_pattern_margin_number="\\\\marginpar.+?\s+"
    def initialize(md,dob=nil,up='')
      @md,@dob,@up=md,dob,up
      if dob.is_a?(Hash)
        p dob.class
        p caller
      elsif dob.is_a?(String)
        p dob.class
        p caller
      end
    end
    def head
      t=Time.now
      year=t.year
      title=spec_char(@md.title.full)
      title=title.gsub(/<(br|p|i)>|<\/\s*(br|p|i)>|<(br|p)\s*\/>/," #{Tex[:backslash]*2} ").
        gsub(/\$/,"\\$").
        gsub(/[,]\s*/,' - ')
      if @md.title.sub
        subtitle=spec_char(@md.title.sub)
        subtitle=subtitle.gsub(/<(br|p|i)>|<\/\s*(br|p|i)>|<(br|p)\s*\/>/," #{Tex[:backslash]*2} ").
          gsub(/\$/,"\\$").
          gsub(/[,]\s*/,' - ')
        subtitle="\n@subtitle #{subtitle}\n"
      end
      subtitle ||=''
      author=@md.author if @md.author
      author ||=''
      author=author.gsub(/[\*]/,'') #if author
      #SiSU_Env::InfoVersion.instance.get_version
      head =<<WOK
\\input texinfo   @c -*-texinfo-*-
@comment %**start of header
@setfilename #{@md.fnb}.info
@settitle #{title}
@syncodeindex pg cp
@comment %**end of header
@c %% 2
@copying
SiSU texinfo of #{title}

Copyright @copyright{} #{year} #{author}.

@quotation
Copyright #{author}, generated by ``SiSU''
@end quotation
@end copying

@dircategory SiSU Texinfo
@direntry
,* sisu: SiSU texinfo file.
@end direntry
WOK
      if @md.title.sub
        titlepage=<<WOK
@c %% 3
@titlepage
@title #{title} #{subtitle}
@author #{author}
@page
@vskip 0pt plus 1filll
@insertcopying
@end titlepage
@contents
WOK
      else
        titlepage=<<WOK
@c %% 3
@titlepage
@title #{title}
@author #{author}
@page
@vskip 0pt plus 1filll
@insertcopying
@end titlepage

@contents
WOK
      end
      "#{head}#{titlepage}"
    end
    def topnode(txt)
      txt=spec_char(txt)
      txt=txt.gsub(/<(br|p|i)>|<\/\s*(br|p|i)>|<(br|p)\s*\/>/," #{Tex[:backslash]*2} ").
        gsub(/\$/,"\\$").
        gsub(/[,]\s*/,' - ')
      "@c %% 4\n" +
        "@ifnottex\n" +
        "@node Top\n" +
        "@top #{txt}\n\n" +
        "@insertcopying\n" +
        "@end ifnottex\n\n" +
        "@menu\n"
    end
    def dublincore
      if defined? @md.title.full \
      and @md.title.full=~/\S+/
        full_title=spec_char(@md.title.full)
      end
      if defined? @md.creator.author \
      and @md.creator.author=~/\S+/
        author=spec_char(@md.creator.author)
      end
      if defined? @md.publisher \
      and @md.publisher=~/\S+/
        publisher=spec_char(@md.publisher)
      end
      if defined? @md.creator.contributor \
      and @md.creator.contributor=~/\S+/
        contributor=spec_char(@md.contributor)
      end
      if defined? @md.date.published \
      and @md.date.published=~/\S+/
        date=spec_char(@md.date.published)
      end
      if defined? @md.date.created \
      and @md.date.created=~/\S+/
        date_created=spec_char(@md.date.created)
      end
      if defined? @md.date.issued \
      and @md.date.issued=~/\S+/
        date_issued=spec_char(@md.date.issued)
      end
      if defined? @md.date.available \
      and @md.date.available=~/\S+/
        date_available=spec_char(@md.date.available)
      end
      if defined? @md.date.valid \
      and @md.date.valid=~/\S+/
        date_valid=spec_char(@md.date.valid)
      end
      if defined? @md.date.modified \
      and @md.date.modified=~/\S+/
        date_modified=spec_char(@md.date.modified)
      end
      if defined? @md.classify.subject \
      and @md.classify.subject=~/\S+/
        subject=spec_char(@md.classify.subject)
      end
      if defined? @md.notes.description \
      and @md.notes.description=~/\S+/
        description=spec_char(@md.description)
      end
      if defined? @md.notes.coverage \
      and @md.notes.coverage=~/\S+/
        coverage=spec_char(@md.notes.coverage)
      end
      if defined? @md.notes.relation \
      and @md.notes.relation=~/\S+/
        relation=spec_char(@md.notes.relation)
      end
      #type=spec_char(@md.type) if @md.type                                   #dc
      if defined? @md.notes.format \
      and @md.notes.format=~/\S+/
        format=spec_char(@md.notes.format)
      end
      #if defined? @md.identifier.sisupod \
      #and @md.identifier.sisupod=~/\S+/
      #  identifier=spec_char(@md.identifier.sisupod)
      #end
      if defined? @md.original.source \
      and @md.original.source=~/\S+/
        source=spec_char(@md.original.source)
      end
      if defined? @md.title.language \
      and @md.title.language=~/\S+/
        language=spec_char(@md.title.language)
      end
      if defined? @md.rights.all \
      and @md.rights.all=~/\S+/
        rights=spec_char(@md.rights.all)
      end
      rights=spec_char(@md.rights.all)
      full_title="Title: #{full_title}\n\n" if full_title                           #dc
      author="Author: #{author}\n\n" if author                                      #dc
      subject="Subject: #{subject}\n\n" if subject                                  #dc
      description="Description: #{description}\n\n" if description                  #dc
      publisher="Publisher: #{publisher}\n\n" if publisher                          #dc
      contributor="Contributor: #{contributor}\n\n" if contributor                  #dc
      date="Date: #{date}\n\n" if date                                              #dc
      date_created="Date Created: #{date_created}\n\n" if date_created              #dc
      date_issued="Date Issued: #{date_issued}\n\n" if date_issued                  #dc
      date_available="Date Available: #{date_available}\n\n" if date_available      #dc
      date_valid="Date Valid: #{date_valid}\n\n" if date_valid                      #dc
      date_modified="Date Modified: #{date_modified}\n\n" if date_modified          #dc
      format="Format: #{format}\n\n" if format                                      #dc
      identifier="Identifier: #{identifier}\n\n" if identifier #watch               #dc
      source="Source: #{source}\n\n" if source                                      #dc
      language="Language: #{language}\n\n" if language                              #dc
      relation="Relation: #{relation}\n\n" if relation                              #dc
      coverage="Coverage: #{coverage}\n\n" if coverage                              #dc
      rights="Rights: #{rights}\n\n" if rights                                      #dc
      <<WOK
@node Dublin Core
@unnumbered Dublin Core
@cindex chapter, Dublin Core

#{full_title}#{author}#{subject}#{description}#{publisher}#{contributor}#{date}#{date_created}#{date_issued}#{date_available}#{date_valid}#{date_modified}#{format}#{identifier}#{source}#{language}#{relation}#{coverage}#{rights}

WOK
    end
    def tail
      <<WOK
@c %% 6
@node Index
@unnumbered Index
@printindex cp

@bye
WOK
    end
    def clean(dob)
      if dob.is==:heading \
      and dob.obj !~/#{Dx[:ocn_o]}#{dob.ocn}#{Dx[:ocn_c]}/
        dob.obj=dob.ocn.is_a?(Fixnum) \
        ? "#{dob.obj} #{Dx[:ocn_o]}#{dob.ocn}#{Dx[:ocn_c]}" : dob.obj
      end
      dob.obj=dob.obj.gsub(/\n/m,' ').
        gsub(/,\s+/,' - ').
        strip
      dob
    end
    def menu
      dob=clean(@dob)
      m=dob.obj.gsub(/[:,]\s*/,' - ').
        gsub(/@footnote\{.+?\}\s+/,'')
      m="* #{m}::"
    end
    def level_common
      dob=clean(@dob)
      nd=dob.obj.gsub(/@footnote\{.+?\}\s+/,'').
        gsub(/: \s*/,' - ')
      dob.obj="@node #{nd}\n@unnumbered #{nd}\n@cindex chapter, #{nd}\n\n"
      dob
    end
    def level_sub(up)
      dob=clean(@dob)
      nd=dob.obj.gsub(/@footnote\{.+?\}\s+/,'').
        gsub(/: \s*/,' - ')
      dob.obj="@node #{nd}, #{up}\n@comment node-name, up\n@unnumbered #{nd}\n@cindex chapter, #{nd}\n\n"
      dob
    end
    def level0
      level_common
    end
    def level1
      level_common
    end
    def level2
      level_common
    end
    def level3
      level_common
    end
    def level4
      level_common
    end
    def level5
      level_sub(@up)
    end
    def level6
      level_sub(@up)
    end
    def spec_char(txt) # special characters
      txt=txt.gsub(/#{Mx[:br_eof]}/i,'').
        gsub(/#{Mx[:gl_o]}#169#{Mx[:gl_c]}/,'(c)').
        gsub(/#{Mx[:gl_o]}#(?:lt|060)#{Mx[:gl_c]}/,'<').gsub(/#{Mx[:gl_o]}(gt|#062)#{Mx[:gl_c]}/,'>').
        gsub(/#{Mx[:gl_o]}#123#{Mx[:gl_c]}/,'{').gsub(/#{Mx[:gl_o]}#125#{Mx[:gl_c]}/,'}').
        gsub(/#{Mx[:gl_o]}#(?:126|152)#{Mx[:gl_c]}/i,'~').
        gsub(/#{Mx[:gl_o]}#033#{Mx[:gl_c]}/,'!').
        gsub(/#{Mx[:gl_o]}#035#{Mx[:gl_c]}/,'#').
        gsub(/#{Mx[:gl_o]}#042#{Mx[:gl_c]}/,'*').
        gsub(/#{Mx[:gl_o]}#047#{Mx[:gl_c]}/,'/').
        gsub(/#{Mx[:gl_o]}#095#{Mx[:gl_c]}/,'_').
        gsub(/#{Mx[:gl_o]}#092#{Mx[:gl_c]}/,'\\').
        gsub(/(?:#{Mx[:br_line]}|#{Mx[:br_nl]})\s*/,"\n\n").                                   # watch
        gsub(/<sup><font face=symbol>&atild;<\/font><\/sup>/,' ').
        #gsub(/\\/,'\\backslash ').
        gsub(/<:pb>/,'\\newpage').
        gsub(/\\backslash copyright/,'\\copyright ').
        gsub(/\^/,'\\wedge ').
        gsub(/(\$)/,"\\$").
        gsub(/\~/,'\\~').
        gsub(/#{Mx[:url_o]}(https?:\S+?)#{Mx[:url_c]}/,'<\1>').
        gsub(/#{Mx[:url_o]}_(https?:\S+?)#{Mx[:url_c]}/,'\1').
        gsub(/§/i,'\S').
        gsub(/£/i,'\pounds').
        gsub(/å/,'\aa').gsub(/Å/,'\AA').
        gsub(/æ/,'\ae').gsub(/Æ/,'\AE').
        gsub(/ø/,'\o').gsub(/Ø/,'\O').
        gsub(/<a href=".+?">/i,' ').
        gsub(/<\/a>/i,' ').
        gsub(/<!>/i,' ').
        gsub(/#{Mx[:br_paragrph]}/i,''). #watch
        gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/,'*\1*').
        gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/,'/\1/').
        gsub(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/,'_\1_').
        gsub(/#{Mx[:fa_subscript_o]}(.+?)#{Mx[:fa_subscript_c]}/,'[\1]').
        gsub(/#{Mx[:fa_superscript_o]}(.+?)#{Mx[:fa_superscript_c]}/,'^\1^').
        gsub(/#{Mx[:fa_insert_o]}(.+?)#{Mx[:fa_insert_c]}/,'+\1+').
        gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,'"\1"').
        gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/,'-\1-').
        gsub(/@/i,'@@').
        gsub(/\{/,'@{').gsub(/\}/,'@}').
        gsub(/(?:&nbsp;|#{Mx[:nbsp]})+/,' ').        # ~ character for hardspace
        gsub(/&(\S+?);/,' ').
        gsub(/&/,'<=and>').
        gsub(/(\s+&\s+)/,' and ').
        gsub(/(\&)/,"\\&").
        gsub(/"(.+?)"/,"`\\1'").                                        # open & close "
        gsub(/\s+"/," `").                                              # open "
        gsub(/^([1-6-]\\+(?:~\S+)?|<.+?>)?\s*"/,'\1`').       # open "
        gsub(/"(\s|\.|,|:|;)/,"'\\1").                                  # close "
        gsub(/"([1-6-]\\+(?:~\S+)?|<.+?>)?\s*$/,"'\\1").       # close "
        gsub(/"(\.|,)/,"'").                                            # close "
        gsub(/\s+'/," `").                                              # open '
        gsub(/^([1-6-]\\+(?:~\S+)?|<.+?>)?\s*'/,'\1`').       # open '
        gsub(/(<font.*?>|<\/font>)/,'')
    end
    def longtable
      @end_table="\\end{longtable}"
      @row_break='\\\\\\'
      if @dob[/#{Mx[:gr_o]}Th?#{Mx[:tc_p]}\s+c(\d+);(.+?)#{Mx[:gr_c]}/ui] #CHECK !> closure #fix
        no_of_cols,cols_width=$1,$2
        @@tableheader=1 if @dob =~ /#{Mx[:gr_o]}Th/i #fix
        @w=cols_width.split(/;\s+/)
        @@number_of_cols=no_of_cols
        @colW=[]
        @colW << '{'
        @w.each  do |x|
          col_w=x.gsub(/.+/,'l\|') #unless x.nil?
          @colW << "#{col_w}" if col_w
        end
        @colW << '}'
        @colW=@colW.join
        @@start_table="\\setlength{\\LTleft}{0pt}\n\\setlength{\\LTright}{\\fill}\n" +
          "\\begin{longtable}[hb]#{@colW}\n"
        @dob.obj=@dob.obj.gsub(/#{Mx[:gr_o]}Th?#{Mx[:tc_p]}\s+c\d+?;.+#{Mx[:gr_c]}/u,"#{@@start_table}") #fix
      end
      if @dob =~/#{Mx[:gr_o]}TZ#{Mx[:gr_c]}/ #fix
        @dob.obj=@dob.obj.gsub(/#{Mx[:gr_o]}TZ#{Mx[:gr_c]}/," #{@end_table}") #fix
      end
      @dob.obj=@dob.obj.gsub(/#{Mx[:tc_o]}#{Mx[:tc_p]}/u,'')
      if @@tableheader==1
        if @dob =~/#{Mx[:tc_p]}\d+?#{Mx[:tc_p]}(.+?)(?:#{Mx[:tc_p]}|!)/u
          tablefoot=para[/\<!f(.+?)!\>/,1]
          @dob.obj=@dob.obj.gsub(/\<!f(.+?)!\>/,'').
            gsub(/#{Mx[:tc_p]}\d+?#{Mx[:tc_p]}(.+?)(?:#{Mx[:tc_p]}|!)/u,
              "{\\begin{tiny} {\\bfseries \\1}\\end{tiny}}&").
            gsub(/&>\s*$/,
              " #{@row_break} \\hline\\endhead #{@row_break}")
          @dob="#{@dob} \\multicolumn{#{@@number_of_cols}}{l}{\\tiny #{tablefoot}} \\\\ \\hline\n\\endfoot\n\\hline\n" if tablefoot
          @@tableheader=0
          @@number_of_cols=0
        end
      else
        if @dob =~/#{Mx[:tc_p]}\d+?#{Mx[:tc_p]}(.+?)(?:#{Mx[:tc_p]}|!)/u
          @dob.obj=@dob.obj.gsub(/#{Mx[:tc_p]}\d+?#{Mx[:tc_p]}(.+?)(?:#{Mx[:tc_p]}|!)/u,"\\begin{tiny}\\1\\end{tiny}&").
            gsub(/&>\s*$/," #{@row_break}")
        end
      end
      @dob
    end
    def scopedtable
      # some features related to headers have been incorporated in longtable
      # that are not included yet here, so until synced is broken on some
      # input files, work needs to be done if is to work as before
      @end_table="\\end{tabular}"
      @row_break='\\\\\\\\'
      @break_page="#{@row_break}\n#{@row_break} \n"
      if @dob[/#{Mx[:gr_o]}Th?#{Mx[:tc_p]}\s+c(\d+);(.+?)#{Mx[:gr_c]}/ui] #fix
        cols_width=$2
        @w=cols_width.split(/;\s+/)
        @colW=[]
        @w.each  do |x|
          col_w=((x.to_i*12)/100.00).to_s #unless x.nil?
          @colW << "p{#{col_w}cm}" if col_w
        end
        @@start_table="\\begin{tabular}{#{@colW}}\n"
        @dob.obj=@dob.obj.gsub(/#{Mx[:gr_o]}Th?#{Mx[:tc_p]}\s+c\d+?;.+#{Mx[:gr_c]}/u,"#{@@start_table}") #fix
      end
      if @dob =~/#{Mx[:gr_o]}TZ#{Mx[:gr_c]}/ #fix
        @dob.obj=@dob.obj.gsub(/#{Mx[:gr_o]}TZ#{Mx[:gr_c]}/,"#{@end_table}") #fix
        @@table_pg_break_counter=1
      end
      if @dob =~/#{Mx[:tc_o]}#{Mx[:tc_p]}/u
        if @@table_pg_break_counter==28 # taken from 34 ideal for portrait to 28 which suits landscape
          @dob =
            "\n\n#{@end_table} \n" +
            "#{@break_page}" +
            "#{@@start_table}\n"
          @@table_pg_break_counter=1
        else
          @dob.obj=@dob.obj.gsub(/#{Mx[:tc_o]}#{Mx[:tc_p]}/u,'')
          @@table_pg_break_counter+=1
          @dob.obj=@dob.obj.gsub(/\<!f(.+?)!\>/,'')
        end
      end
      if @dob =~/#{Mx[:tc_p]}\d+?#{Mx[:tc_p]}(.+?)(?:#{Mx[:tc_p]}|!)/u
        @dob.obj=@dob.obj.gsub(/#{Mx[:tc_p]}\d+?#{Mx[:tc_p]}(.+?)(?:#{Mx[:tc_p]}|!)/u,"\\begin{tiny}\\1\\end{tiny}&").
          gsub(/&>\s*$/,"#{@row_break}")
      end
      @dob
    end
    def graphics
      dir=SiSU_Env::InfoEnv.new(@md.fns)
      @dob.obj=@dob.obj.gsub(/<::\s+(\S+?)\s+>/i, #watch
        "\\includegraphics*[width=11pt]{#{dir.path.image_source_include}/c_\\1.png}")
    end
    def image
      dir=SiSU_Env::InfoEnv.new(@md.fns)
      width="100"
      width=@dob[/<:image.+?width=``(\d+)''.+?>/im,1]
      width=width.to_i*0.4
      @dob.obj=@dob.obj.gsub(/<:image\s+((?:https?|file|ftp)\S+)\s+(\S+)\s+.+\s+?>/i,
          "\\href{\\1}{\\includegraphics*[width=#{width}pt]{#{dir.path.image_source_include}/\\2}}").
        gsub(/<:image\s+(\S+)\s+.+\s+?>/i,
          "\\includegraphics*[width=#{width}pt]{#{dir.path.image_source_include}/\\1}")
    end
    def png
      # very messy clean up ! - work area, testing
      z=@dob[/\\\{(.+?)\}(?:image|png)/,1] # match operator for z \\ fragile !
      image=z.scan(/\S+/)[0] #image,w,x,y=z.scan(/\S+/)
      image=image.gsub(/\\/,'')
      @dob.obj=@dob.obj.gsub(/\\\{\S+\.(png|jpg|gif).+?\}(image|png)/,"<image #{image} not available>")  # fragile match operator\\ fragile !
    end
    def http
      # very messy clean up ! - work area, testing
      z=@dob[/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/,1] # match operator for z \\ fragile !
      url=@dob[/((?:https?|file|ftp):\S+)/im,1]
      if @dob =~/\.(png|jpg|gif)/
        image=z.scan(/\S+/)[0] #image,w,x,y=z.scan(/\S+/)
        image=image.gsub(/\\/,'')
        width=200
        width=z[/w=(\d+)/im,1] if z =~/w=(\d+)/
        width=width.to_i*0.8
        width=400 if width > 400
        c=z[/``(.+?)''/im,1]
        caption="{\\\\\\\ \n\\begin{scriptsize}#{c}\\end{scriptsize}&}" if c
      end
      if image
        dir=SiSU_Env::InfoEnv.new(@md.fns)
        @dob.obj=@dob.obj.gsub(/#{Mx[:lnk_o]}\S+\.(png|jpg|gif).+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/, # fragile match operator\\ fragile !
          "\n\\href{#{url}}{\\includegraphics*[width=#{width}pt]{#{dir.path.image_source_include}/#{image}}}#{caption}")
      else
        link=z[/(.+?)\\/im,1]
        @dob.obj=@dob.obj.gsub(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+#{Mx[:url_c]}/,"\n\\noindent\\href{#{url}}{#{link}}")  # fragile match operator\\ fragile !
      end
    end
  end
  class TeXinfoTxt
    def initialize(md,dob,txt)
      @md,@dob,@txt=md,dob,txt
    end
    def clean(dob,txt)
      if dob.is==:heading \
      and txt !~/#{Dx[:ocn_o]}#{dob.ocn}#{Dx[:ocn_c]}/
        txt=dob.ocn.is_a?(Fixnum) \
        ? "#{dob.obj} #{Dx[:ocn_o]}#{dob.ocn}#{Dx[:ocn_c]}" : dob.obj
      end
      txt.strip
    end
    def submenu
      txt=@txt.join("\n")
      txt=clean(@dob,txt)
      txt="@menu\n#{txt}\n@end menu\n\n"
      txt=txt.gsub(/.+/m,"#{txt}")
    end
    def subsubmenu
      txt=@txt.join("\n")
      txt=clean(@dob,txt)
      txt="@menu\n#{txt}\n@end menu\n\n"
      txt=txt.gsub(/.+/m,"#{txt}")
    end
  end
end
__END__
watch title, might need full_title
#+END_SRC

* document header

#+NAME: sisu_document_header
#+BEGIN_SRC text
#encoding: utf-8
=begin
- Name: SiSU

  - Description: documents, structuring, processing, publishing, search
    texinfo

  - Author: Ralph Amissah
    <ralph.amissah@gmail.com>

  - Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
    2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2019,
    2020, 2021, Ralph Amissah,
    All Rights Reserved.

  - License: GPL 3 or later:

    SiSU, a framework for document structuring, publishing and search

    Copyright (C) Ralph Amissah

    This program is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by the Free
    Software Foundation, either version 3 of the License, or (at your option)
    any later version.

    This program is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
    more details.

    You should have received a copy of the GNU General Public License along with
    this program. If not, see <http://www.gnu.org/licenses/>.

    If you have Internet connection, the latest version of the GPL should be
    available at these locations:
    <http://www.fsf.org/licensing/licenses/gpl.html>
    <http://www.gnu.org/licenses/gpl.html>

    <http://www.sisudoc.org/sisu/en/manifest/gpl.fsf.html>

  - SiSU uses:
    - Standard SiSU markup syntax,
    - Standard SiSU meta-markup syntax, and the
    - Standard SiSU object citation numbering and system

  - Homepages:
    <http://www.sisudoc.org>

  - Git
    <https://git.sisudoc.org/projects/>
    <https://git.sisudoc.org/projects/?p=software/sisu.git;a=summary>
    <https://git.sisudoc.org/projects/?p=markup/sisu-markup-samples.git;a=summary>
=end
#+END_SRC