diff options
Diffstat (limited to 'lib/sisu/v0/texpdf.rb')
-rw-r--r-- | lib/sisu/v0/texpdf.rb | 406 |
1 files changed, 219 insertions, 187 deletions
diff --git a/lib/sisu/v0/texpdf.rb b/lib/sisu/v0/texpdf.rb index b22b462b..ead5752b 100644 --- a/lib/sisu/v0/texpdf.rb +++ b/lib/sisu/v0/texpdf.rb @@ -125,8 +125,8 @@ module SiSU_TeX #% needed needs to be reprogrammed !!! SiSU_Env::Info_skin.new(@md).select dal_array=SiSU_DAL::Source.new(@opt).get # dal file drawn here - SiSU_TeX::Source::LaTeX_create.new(dal_array,@md,'landscape').songsheet - SiSU_TeX::Source::LaTeX_create.new(dal_array,@md,'portrait').songsheet + SiSU_TeX::Source::LaTeX_create.new(dal_array,@md).songsheet + #SiSU_TeX::Source::LaTeX_create.new(dal_array,@md,'portrait').songsheet dal_array='' pwd=Dir.pwd SiSU_TeX::Source::LaTeX_to_pdf.new(@md).latexrun_selective @@ -234,14 +234,14 @@ module SiSU_TeX include SiSU_Param @@tex_backslash ||="\\\\" @@tilde='\\\\\\~' #?? debug crazy - @@tex_head_portrait,@@tex_head_landscape=nil,nil + @@tex_head={ :p => nil, :l => nil } @@flag_alt,@@flag_group,@@flag_code=false,false,false @@dp,@@prefix_b=nil,nil - def initialize(data,md,orientation) - @data,@md,@orientation=data,md,orientation + def initialize(data,md) + @data,@md=data,md @env=SiSU_Env::Info_env.new(@md.fns) @st={ :tex=>{} } - @tex=SiSU_TeX_Pdf::Use_TeX.new(@md,@orientation) + @tex=SiSU_TeX_Pdf::Use_TeX.new(@md) @vz=SiSU_Env::Get_init.instance.skin @dp=@@dp ||=SiSU_Env::Info_env.new.digest.pattern vz=SiSU_Env::Get_init.instance.skin @@ -256,7 +256,7 @@ module SiSU_TeX data=@data @@tex_footnote_array=[] @@rights=nil - tell=SiSU_Screen::Ansi.new(@md.cmd,"pdfTex #@orientation") + tell=SiSU_Screen::Ansi.new(@md.cmd,"pdfTex portrait & landscape") tell.txt_grey unless @md.cmd =~/q/ if @md.dc_rights use=@md.dc_rights.dup #dup is necessary, else contents of :rights changed @@ -286,7 +286,6 @@ module SiSU_TeX end data=number_paras(data,ocn) data=markup(data) - #data=markup(data).flatten #watch output(data) rescue; SiSU_Errors::Info_error.new($!,$@,@md.cmd,@md.fns).error ensure @@ -331,19 +330,25 @@ module SiSU_TeX end @tex_file end + def tables_hash(md,para) + para_p=para.dup #visit + do_mono_l=SiSU_TeX_Pdf::Format_text_object.new(md,para) + do_mono_p=SiSU_TeX_Pdf::Format_text_object.new(md,para_p) + block={ + :l => do_mono_l.longtable_landscape, + :p => do_mono_p.longtable_portrait + } + end def tables(data) + @@tableheader={ :p => 0, :l => 0 } @tex_file=[] - @@tableheader=0 data.each do |para| - if para =~/¡|<!T/ - do_mono=SiSU_TeX_Pdf::Format_text_object.new(@md,para) - case @orientation # using longtable latex package - when /landscape/; para=do_mono.longtable_landscape - when /portrait/; para=do_mono.longtable_portrait - end + @tex_file << if para =~/¡|<!T/ + tables_hash(@md,para) #Hash result + else para end - @tex_file << para end + @tex_file end def enclose(para,type='') para.strip! @@ -353,6 +358,98 @@ module SiSU_TeX else para end end + def markup_common(para) + tex_f=nil + mono=SiSU_TeX_Pdf::Format_text_object.new(@md,para) + if para =~/<:(?:code|alt|verse|group)>/ \ + or @@flag_alt + if para =~/<:(?:code|alt|verse|group)>/ + @lineone=case para + when /<:(?:alt|verse|group)>/; para + when /<:code>/; "#{@tex.paraskip_small} \\begin{scriptsize} " + para + else 'error' #should never occur + end + end + if para =~/<=curly/ #takes care of escaped curly braces, expand + do_mono=SiSU_TeX_Pdf::Format_text_object.new(@md,para) + para=do_mono.special_characters_curly(para) + end + regx=/<:((?:code|alt|verse|group)(?:-end)?)>/m + x=regx.match(para)[1] if para =~regx + x=$1 + para.gsub!(/\n<:(?:code|alt|verse|group)>\n/m,'') + para=enclose(para,'code') unless para =~/^$/ + if x =~/(?:alt|verse|group)/; @@flag_alt=true + if x =~/group/; @@flag_group=true + end + elsif x =~/code/; @@flag_alt,@@flag_code=true,true + elsif @@flag_alt; + if para =~ /\}(?:https?|file|ftp)/m + para=mono.http #(@orientation) + end + @group_collect << para #<< "\n\n" + end + if x =~/(?:code|alt|verse|group)-end/m + regx=/(\\+marginpar\{\\+begin\{tiny\}\d+\\+end\{tiny\}\})/ + y=if para =~regx + regx.match(para)[1] + else '' + end + para.gsub!(regx,'') + #@group_collect.each{ |x| x.gsub!(/(<:\S+>|<!.*?!>|<!>)/,' ') } + group_collect=[] + group_collect << '\begin{footnotesize} ' unless @@flag_code + @group_collect.each do |x| + x.gsub!(/(<:\S+>|<!.*?!>|<!>)/,' ') + x=x.split(/ \\\\ /) + group_collect << x + end + group_collect << ' \end{footnotesize} ' unless @@flag_code + @group_collect=group_collect.flatten + @lineone.gsub!(/(<:\S+>|<!.*?!>|<!>)/,' ') + #@group_collect.each{ |x| x.gsub!(/(.#{@@tilde}\S*\s*|<:\S+>|<!.*?!>|<!>)/,' ') } + #@lineone.gsub!(/(.#{@@tilde}\S*\s*|<:\S+>|<!.*?!>|<!>)/,' ') + insert=[] + if para =~/<:code-end>/m + insert << y + @lineone << @group_collect << ' \end{scriptsize}' << " #{@tex.paraskip_normal}" + else insert << y + @lineone << @group_collect + end + @@flag_alt,@@flag_group,@@flag_code=false,false,false + @group_collect=[] + para.gsub!(/(<:\S+>|<!.*?!>|<!>)/,' ') + #para.gsub!(/(.#{@@tilde}\S*\s*|<:\S+>|<!.*?!>|<!>)/,' ') + #@tex_file << insert.flatten + tex_f = insert.flatten + end + else + if para =~ /\}(?:https?|file|ftp)/ + para=mono.http #(@orientation) + end + case para + when /^1#{@@tilde}/; mono.level1 + when /^2#{@@tilde}/; mono.level2 + when /^3#{@@tilde}/; mono.level3 + when /^4#{@@tilde}/; mono.level4 + when /^5#{@@tilde}/; mono.level5 + when /^6#{@@tilde}/; mono.level6 + when /^<:i([1-9])>/; mono.indent($1) + when /<:=/; mono.symbol_graphic #watch + when /^\s*<:image\s+/; mono.image + when /\}image/; mono.png + else + para.strip! + para=enclose(para) unless para =~/^$/ + end + para.gsub!(/(\.#{@@tilde}\S*\s*|<:\S+>|<!.*?!>|<!>)/,' ') #% tread with care + #para.gsub!(/(.#{@@tilde}(?:\\~\S+)?\s*|<:\S+>|<!.*?!>|<!>)/,' ') #KEEP reference, problem escaping open curly braces \{ + if para =~/<=curly/ #takes care of escaped curly braces, expand + do_mono=SiSU_TeX_Pdf::Format_text_object.new(@md,para) + para=do_mono.special_characters_curly(para) + end + tex_f = para + end + tex_f + end def markup(data) @tex_file=[] md={} @@ -360,12 +457,10 @@ module SiSU_TeX home=@vz.txt_home.gsub(/<(br|p)>|<\/\s*(br|p)>|<(br|p)\s*\/>|\\\\/,' - ') #no line splitting in heading neither html nor latex title=@md.title.gsub(/<(br|p)>|<\/\s*(br|p)>|<(br|p)\s*\/>|\\\\/,' - ') #no line splitting in heading neither html nor latex subtitle=@md.subtitle.gsub(/<(br|p)>|<\/\s*(br|p)>|<(br|p)\s*\/>|\\\\/,' - ') if @md.subtitle #no line splitting in heading neither html nor latex - orient=SiSU_TeX_Pdf::Format_text_object.new(@md,@orientation,"#{home}: - #{title} #{subtitle}") #.new - if @orientation =~/portrait/ - @@tex_head_portrait=orient.document_head_with_orientation - elsif @orientation =~/landscape/ - @@tex_head_landscape=orient.document_head_with_orientation - end + orient_portrait=SiSU_TeX_Pdf::Format_text_object.new(@md,'portrait',"#{home}: - #{title} #{subtitle}") + orient_landscape=SiSU_TeX_Pdf::Format_text_object.new(@md,'landscape',"#{home}: - #{title} #{subtitle}") + @@tex_head[:p]=orient_portrait.document_head_with_orientation + @@tex_head[:l]=orient_landscape.document_head_with_orientation @tex_file <<<<WOK #{@tex.header}#{@tex.footer} \\tolerance=500 @@ -380,39 +475,25 @@ WOK #else '' #end @copymark='' #check and remove as now is superflous - if @orientation =~/landscape/ # using longtable latex package - @tex_file << SiSU_TeX_Pdf::Format_text_object.new(@md,@md.title,@md.subtitle).title_landscape - if @md.dc_creator - do_mono=SiSU_TeX_Pdf::Format_text_object.new(@md,@md.dc_creator) - creator=do_mono.special_characters - @tex_file << if @md.creator_home - <<WOK + x={} + x[:l]=SiSU_TeX_Pdf::Format_text_object.new(@md,@md.title,@md.subtitle).title_landscape + x[:p]=SiSU_TeX_Pdf::Format_text_object.new(@md,@md.title,@md.subtitle).title_portrait + @tex_file << x + x=nil + if @md.dc_creator + do_mono=SiSU_TeX_Pdf::Format_text_object.new(@md,@md.dc_creator) + creator=do_mono.special_characters + @tex_file << if @md.creator_home + <<WOK \\author{\\href{#{@md.creator_home}}{#@copymark \\textnormal{#{creator}}}} WOK - else "\n\\author{#@copymark \\textnormal{#{creator}}}" - end - end - @tex_file << unless @md.fnb =~/^mail\s*$/ - "\n\\date{\\begin{footnotesize} copy @ #{@tex.site} \\end{footnotesize} #{sisu_rc_footnote}}" - else "\\date" - end - else #portrait - @tex_file << SiSU_TeX_Pdf::Format_text_object.new(@md,@md.title,@md.subtitle).title_portrait - if @md.dc_creator - creator=@md.dc_creator - @tex_file << if @md.creator_home - <<WOK - -\\author{\\href{#{@md.creator_home}}{#@copymark \\textnormal{#{creator}}}} -WOK - else "\n\\author{#@copymark \\textnormal{#{creator}}}" - end - end - @tex_file << unless @md.fnb =~/^mail\s*$/; "\n\\date{\\begin{footnotesize} copy @ #{@tex.site} \\end{footnotesize} #{sisu_rc_footnote}}" - else "\\date" + else "\n\\author{#@copymark \\textnormal{#{creator}}}" end end + @tex_file << unless @md.fnb =~/^mail\s*$/; "\n\\date{\\begin{footnotesize} copy @ #{@tex.site} \\end{footnotesize} #{sisu_rc_footnote}}" + else "\\date" + end @tex_file <<<<WOK \\pagenumbering{roman}\\maketitle \\pagestyle{fancy} @@ -426,104 +507,38 @@ WOK else @tex.doc_no_sc_info end @tex_file << @tex.manifest_info - @tex_file << @tex.newpage - @tex_file <<<<WOK + x={} + x[:l] =<<WOK +#{@tex.newpage('landscape')} \\pagestyle{fancy} \\tableofcontents -#{@tex.newpage} +#{@tex.newpage('landscape')} \\pagenumbering{arabic} #{@tex.paraskip_normal} +#{@tex.newpage('landscape')} WOK - @tex_file << @tex.newpage + x[:p] =<<WOK +#{@tex.newpage('portrait')} +\\pagestyle{fancy} +\\tableofcontents +#{@tex.newpage('portrait')} +\\pagenumbering{arabic} +#{@tex.paraskip_normal} +#{@tex.newpage('portrait')} +WOK + @tex_file << x + x=nil @group_collect=[] data.each do |para| #% case follows with levels 1-6 indents & graphics - mono=SiSU_TeX_Pdf::Format_text_object.new(@md,para) - if para =~/<:(?:code|alt|verse|group)>/ \ - or @@flag_alt - if para =~/<:(?:code|alt|verse|group)>/ - @lineone=case para - when /<:(?:alt|verse|group)>/; para - when /<:code>/; "#{@tex.paraskip_small} \\begin{scriptsize} " + para - else 'error' #should never occur - end - end - if para =~/<=curly/ #takes care of escaped curly braces, expand - do_mono=SiSU_TeX_Pdf::Format_text_object.new(@md,para) - para=do_mono.special_characters_curly(para) - end - regx=/<:((?:code|alt|verse|group)(?:-end)?)>/m - x=regx.match(para)[1] if para =~regx - x=$1 - para.gsub!(/\n<:(?:code|alt|verse|group)>\n/m,'') - para=enclose(para,'code') unless para =~/^$/ - if x =~/(?:alt|verse|group)/; @@flag_alt=true - if x =~/group/; @@flag_group=true - end - elsif x =~/code/; @@flag_alt,@@flag_code=true,true - elsif @@flag_alt; - if para =~ /\}(?:https?|file|ftp)/m - para=mono.http(@orientation) - end - @group_collect << para #<< "\n\n" - end - if x =~/(?:code|alt|verse|group)-end/m - regx=/(\\+marginpar\{\\+begin\{tiny\}\d+\\+end\{tiny\}\})/ - y=if para =~regx - regx.match(para)[1] - else '' - end - para.gsub!(regx,'') - #@group_collect.each{ |x| x.gsub!(/(<:\S+>|<!.*?!>|<!>)/,' ') } - group_collect=[] - group_collect << '\begin{footnotesize} ' unless @@flag_code - @group_collect.each do |x| - x.gsub!(/(<:\S+>|<!.*?!>|<!>)/,' ') - x=x.split(/ \\\\ /) - group_collect << x - end - group_collect << ' \end{footnotesize} ' unless @@flag_code - @group_collect=group_collect.flatten - @lineone.gsub!(/(<:\S+>|<!.*?!>|<!>)/,' ') - #@group_collect.each{ |x| x.gsub!(/(.#{@@tilde}\S*\s*|<:\S+>|<!.*?!>|<!>)/,' ') } - #@lineone.gsub!(/(.#{@@tilde}\S*\s*|<:\S+>|<!.*?!>|<!>)/,' ') - insert=[] - if para =~/<:code-end>/m - insert << y + @lineone << @group_collect << ' \end{scriptsize}' << " #{@tex.paraskip_normal}" - else insert << y + @lineone << @group_collect - end - @@flag_alt,@@flag_group,@@flag_code=false,false,false - @group_collect=[] - para.gsub!(/(<:\S+>|<!.*?!>|<!>)/,' ') - #para.gsub!(/(.#{@@tilde}\S*\s*|<:\S+>|<!.*?!>|<!>)/,' ') - @tex_file << insert.flatten - end - else - if para =~ /\}(?:https?|file|ftp)/ - para=mono.http(@orientation) - end - case para - when /^1#{@@tilde}/; mono.level1 - when /^2#{@@tilde}/; mono.level2 - when /^3#{@@tilde}/; mono.level3 - when /^4#{@@tilde}/; mono.level4 - when /^5#{@@tilde}/; mono.level5 - when /^6#{@@tilde}/; mono.level6 - when /^<:i([1-9])>/; mono.indent($1) - when /<:=/; mono.symbol_graphic #watch - when /^\s*<:image\s+/; mono.image - when /\}image/; mono.png - else - para.strip! - para=enclose(para) unless para =~/^$/ - end - para.gsub!(/(\.#{@@tilde}\S*\s*|<:\S+>|<!.*?!>|<!>)/,' ') #% tread with care - #para.gsub!(/(.#{@@tilde}(?:\\~\S+)?\s*|<:\S+>|<!.*?!>|<!>)/,' ') #KEEP reference, problem escaping open curly braces \{ - if para =~/<=curly/ #takes care of escaped curly braces, expand - do_mono=SiSU_TeX_Pdf::Format_text_object.new(@md,para) - para=do_mono.special_characters_curly(para) - end - @tex_file << para + if para.class == String + para=markup_common(para) + elsif para.class == Hash + para={ + :p => markup_common(para[:p]), + :l => markup_common(para[:l]) + } end + @tex_file << para end @tex_file << "\n\\newpage\n" # was \\pagebreak\n @md.subtitle_tex=@md.subtitle.dup if @md.subtitle @@ -573,62 +588,79 @@ WOK end @tex_file << "\n\\end{document}" end + def number_paras_numbering(para,ocn) + if para =~/<\\~(\d+);(?:[oh]|[0-6]:)\d+;\w\d+><#@dp:#@dp>$/ \ + and para !~/\\end\{longtable\}|<EOF>/ #catch <!TZ!> + m=/(.+?)<\\~(\d+);(?:[oh]|[0-6]:)\d+;\w\d+><#@dp:#@dp>$/m + parablock=para[m,1] + paranum=if ocn; para[m,2] + else '' + end + do_duo=SiSU_TeX_Pdf::Format_text_object.new(@md,parablock,paranum) + para=do_duo.para_num if parablock + elsif para =~/^<~\d+;(?:[oh]|[0-6]:)\d+;\w\d+><#@dp:#@dp>$/ #2005 this is added for tables, rationalise + m=/<~(\d+);(?:[oh]|[0-6]:)\d+;\w\d+><#@dp:#@dp>$/m + paranum=para[m,1] + para.gsub!(/<~\d+;(?:[oh]|[0-6]:)\d+;\w\d+><#@dp:#@dp>/,'') + para="\\marginpar{\\begin{tiny}#{paranum}\\end{tiny}}" + para + elsif para =~/^<~\d+;(?:[oh]|[0-6]:)\d+;\w\d+>/ #extra 2005 this is added for tables, rationalise + m=/<~(\d+);[oh]\d+;\w\d+>/m + paranum=para[m,1] + para.gsub!(/<~\d+;(?:[oh]|[0-6]:)\d+;\w\d+>/,'') + para="\\marginpar{\\begin{tiny}#{paranum}\\end{tiny}}" + para + elsif para =~/\\end\{longtable\}/ #catch <!TZ!> + para.gsub!(/<\\~\d+>|<\\~(\d+);(?:[ohm]|[0-6]:)\d+;\w\d+><#@dp:#@dp>/,'') + para.gsub!(/<\\~\d+>|<\\~(\d+);(?:[ohm]|[0-6]:)\d+;\w\d+>/,'') #extra + end + para + end def number_paras(data,ocn) - @tex_file=[] + tex_file=[] data.each do |para| - if para =~/<\\~(\d+);(?:[oh]|[0-6]:)\d+;\w\d+><#@dp:#@dp>$/ \ - and para !~/\\end\{longtable\}|<EOF>/ #catch <!TZ!> - m=/(.+?)<\\~(\d+);(?:[oh]|[0-6]:)\d+;\w\d+><#@dp:#@dp>$/m - parablock=para[m,1] - paranum=if ocn; para[m,2] - else '' - end - do_duo=SiSU_TeX_Pdf::Format_text_object.new(@md,parablock,paranum) - para=do_duo.para_num if parablock - elsif para =~/^<~\d+;(?:[oh]|[0-6]:)\d+;\w\d+><#@dp:#@dp>$/ #2005 this is added for tables, rationalise - m=/<~(\d+);(?:[oh]|[0-6]:)\d+;\w\d+><#@dp:#@dp>$/m - paranum=para[m,1] - para.gsub!(/<~\d+;(?:[oh]|[0-6]:)\d+;\w\d+><#@dp:#@dp>/,'') - para="\\marginpar{\\begin{tiny}#{paranum}\\end{tiny}}" + para - #para="\\marginpar{\\begin{tiny}#{paranum}\\end{tiny}}" - #elsif para =~/<!T.+?!~\d+?>/ - elsif para =~/^<~\d+;(?:[oh]|[0-6]:)\d+;\w\d+>/ #extra 2005 this is added for tables, rationalise - m=/<~(\d+);[oh]\d+;\w\d+>/m - paranum=para[m,1] - para.gsub!(/<~\d+;(?:[oh]|[0-6]:)\d+;\w\d+>/,'') - para="\\marginpar{\\begin{tiny}#{paranum}\\end{tiny}}" + para - elsif para =~/\\end\{longtable\}/ #catch <!TZ!> - para.gsub!(/<\\~\d+>|<\\~(\d+);(?:[ohm]|[0-6]:)\d+;\w\d+><#@dp:#@dp>/,'') - para.gsub!(/<\\~\d+>|<\\~(\d+);(?:[ohm]|[0-6]:)\d+;\w\d+>/,'') #extra + para=if para.class == Hash \ + and (para[:p] and para[:l]) + para = { + :p => number_paras_numbering(para[:p],ocn), + :l => number_paras_numbering(para[:l],ocn) + } + else #elsif para.class == String + number_paras_numbering(para,ocn) end - @tex_file << para + tex_file << para end - @tex_file + tex_file end - def output(data) - data.flatten! - data.compact! + def output(array) + array.flatten! + array.compact! fns_l=@md.fns.gsub(/~/,'-') #this is a sorry fix, but necessary as it appears latex programs like not ~ - if @orientation =~/landscape/ - filename_tex_landscape=File.new("#{@env.path.tex}/#{fns_l}.landscape.tex",'w+') - filename_tex_landscape << @@tex_head_landscape - data.each do |para| - para.gsub!(/^\s+/,'') - filename_tex_landscape.puts para,"\n" if para !~/\A\s*\Z/ - end - filename_tex_landscape.close - @@tex_head_landscape=[] - elsif @orientation =~/portrait/ - filename_tex_portrait=File.new("#{@env.path.tex}/#{fns_l}.tex",'w+') - filename_tex_portrait << @@tex_head_portrait - data.each do |para| + filename_tex_landscape=File.new("#{@env.path.tex}/#{fns_l}.landscape.tex",'w+') + filename_tex_portrait=File.new("#{@env.path.tex}/#{fns_l}.tex",'w+') + filename_tex_portrait << @@tex_head[:p] + filename_tex_landscape << @@tex_head[:l] + array.each do |para| + case para + when String para.gsub!(/^\s+/,'') - filename_tex_portrait.puts para,"\n" if para !~/\A\s*\Z/ + if para !~/\A\s*\Z/ + filename_tex_portrait.puts para,"\n" + filename_tex_landscape.puts para,"\n" + end + when Hash + para[:p].gsub!(/^\s+/,'') + para[:l].gsub!(/^\s+/,'') + if para[:p] !~/\A\s*\Z/ + filename_tex_portrait.puts para[:p],"\n" + end + if para[:l] !~/\A\s*\Z/ + filename_tex_landscape.puts para[:l],"\n" + end end - filename_tex_portrait.close - @@tex_head_portrait=[] end - data=[] + filename_tex_portrait.close + filename_tex_landscape.close + @@tex_head={} #@@tex_head={ :p => nil, :l => nil } + array=[] end end end |