From d29a3e5469d8468084641c385ebf16948f7c2437 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Tue, 22 Jul 2008 20:00:59 -0400 Subject: sisu-0.68.0 proposed * middle layer document representation changed, (accounting for substantial patch) * texpdf multiple document sizes as specified in config * numerous small fixes [should on the whole be easier to maintain] --- lib/sisu/v0/texpdf.rb | 417 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 270 insertions(+), 147 deletions(-) (limited to 'lib/sisu/v0/texpdf.rb') diff --git a/lib/sisu/v0/texpdf.rb b/lib/sisu/v0/texpdf.rb index 1d37b588..8d951dfb 100644 --- a/lib/sisu/v0/texpdf.rb +++ b/lib/sisu/v0/texpdf.rb @@ -72,7 +72,7 @@ module SiSU_TeX @@tabular="{tabular}" @@column_instruct=@@squigle_close=@@tex_line_mode=@@tex_word_mode=@@line_mode='' @@tex_debug_counter=@@table_pagebreak_counter=@@tex_footnote_call_counter=@@tex_table_flag=@@tex_counter=@@tex_column=@@tex_columns=@@tex_columns=@@counting=0 - @@tex_pattern_margin_number="\\\\begin\\\{tiny\\\}~\\\\end\\\{tiny\\\}\\\{\\\\marginpar.+?\s+" + @@tex_pattern_margin_number=/\\\\begin\\\{tiny\\\}~\\\\end\\\{tiny\\\}\\\{\\\\marginpar.+?\s+/ #@@tex_pattern_margin_number="\\\\marginpar.+?\s+" @@n=@@tableheader=@@rights=nil @@date ||=SiSU_Env::Info_date.new @@ -116,12 +116,10 @@ module SiSU_TeX tell=SiSU_Screen::Ansi.new(@opt.cmd,@opt.fns,"#{@env.program.pdf_viewer} #{path}/#{@md.fnb}/#{@md.fn[:pdf_p]}") tell.flow if @opt.cmd =~/[MVv]/ @md=@particulars.md - my_make=SiSU_Env::Create_file.new(@opt.cmd,@opt.fns) + SiSU_Env::Create_file.new(@opt.cmd,@opt.fns) $flag=@md.cmd #introduced to pass 0 for no object citation numbers... to texpdf_format @dir_o="#{@env.path.output}/#{@opt.fnb}" directories - filename_index="#{@md.txt_path}/pdf" - newfilename=filename_index #% needed needs to be reprogrammed !!! SiSU_Env::Info_skin.new(@md).select dal_array=SiSU_DAL::Source.new(@opt).get # dal file drawn here @@ -160,33 +158,49 @@ module SiSU_TeX def initialize(md,env) @md,@env=md,env end - def latex_do(texfilename) + def latex_do(texfilename,papersize) @texfilename=texfilename @@n_lpdf=@@n_lpdf+1 - tell=SiSU_Screen::Ansi.new(@md.cmd,'portrait ->') + tell=SiSU_Screen::Ansi.new(@md.cmd,"#{papersize} portrait ->") tell.dark_grey_title_hi if @md.cmd =~/[MVv]/ tex_fn_base=@texfilename.gsub(/\.tex$/,'') cmd=SiSU_Env::System_call.new("#{tex_fn_base}.tex",'',@md.cmd) tell=SiSU_Screen::Ansi.new(@md.cmd) tell.grey_open unless @md.cmd =~/q/ - 2.times { |i| cmd.latex2pdf(@md) unless ("#{tex_fn_base}.tex" !~/\w+/) } + if "#{tex_fn_base}" =~/\w+/ \ + and "#{papersize}" =~/\w+/ + 2.times { |i| cmd.latex2pdf(@md,papersize) } + end tell.p_off unless @md.cmd =~/q/ - tell=SiSU_Screen::Ansi.new(@md.cmd,'landscape ->') + tell=SiSU_Screen::Ansi.new(@md.cmd,"#{papersize} landscape ->") tell.dark_grey_title_hi if @md.cmd =~/[MVv]/ cmd=SiSU_Env::System_call.new("#{tex_fn_base}.landscape.tex",'',@md.cmd) tell.grey_open - 2.times { |i| cmd.latex2pdf(@md) unless ("#{tex_fn_base}.landscape.tex" !~/\w+/) } + if "#{tex_fn_base}" =~/\w+/ \ + and "#{papersize}" =~/\w+/ + 2.times { |i| cmd.latex2pdf(@md,papersize) } + end tell.p_off unless @md.cmd =~/q/ pwd=Dir.pwd portrait_pdf="#{pwd}/#{tex_fn_base}.pdf" landscape_pdf="#{pwd}/#{tex_fn_base}.landscape.pdf" + case papersize + when /a4/; pdf_p=@md.fn[:pdf_p_a4]; pdf_l=@md.fn[:pdf_l_a4] + when /a5/; pdf_p=@md.fn[:pdf_p_a5]; pdf_l=@md.fn[:pdf_l_a5] + when /b5/; pdf_p=@md.fn[:pdf_p_b5]; pdf_l=@md.fn[:pdf_l_b5] + when /letter/; pdf_p=@md.fn[:pdf_p_letter]; pdf_l=@md.fn[:pdf_l_letter] + when /legal/; pdf_p=@md.fn[:pdf_p_legal]; pdf_l=@md.fn[:pdf_l_legal] + else pdf_p=@md.fn[:pdf_p_a4]; pdf_l=@md.fn[:pdf_l_a4] + end if FileTest.file?(portrait_pdf) - cp(portrait_pdf,"#@dir_sisu/#{@md.fnb}/#{@md.fn[:pdf_p]}") + cp(portrait_pdf,"#@dir_sisu/#{@md.fnb}/#{pdf_p}") rm(portrait_pdf) + else p "here #{__FILE__} #{__LINE__} NOT FOUND: #{portrait_pdf}" if @md.cmd.inspect =~/M/ end if FileTest.file?(landscape_pdf) - cp(landscape_pdf,"#@dir_sisu/#{@md.fnb}/#{@md.fn[:pdf_l]}") + cp(landscape_pdf,"#@dir_sisu/#{@md.fnb}/#{pdf_l}") rm(landscape_pdf) + else p "here #{__FILE__} #{__LINE__} NOT FOUND: #{landscape_pdf}" if @md.cmd.inspect =~/M/ end tell=SiSU_Screen::Ansi.new(@md.cmd,@@n_lpdf,'processed (SiSU LaTeX to pdf - using pdfetex aka. pdftex or pdflatex)') tell.generic_number unless @md.cmd =~/q/ @@ -198,25 +212,50 @@ module SiSU_TeX @tex_f_no=0 info={} if FileTest.file?(@env.source_file_with_path) - if @md.fns =~/\.(?:-|ssm\.)?sst$/ - @dirout=SiSU_Env::Info_env.new(@md.fns) - case @md.fns - when /\.(?:-|ssm\.)?sst$/ - if FileTest.directory?(@env.path.tex)==true - Dir.chdir(@env.path.tex) - @dir_sisu=@dirout.path.output - texfile=@md.fns.gsub(/$/,'.tex') - texfile=texfile.gsub(/~/,'-') - if File.exist?(texfile) \ - and File.size(texfile) > 0 - @tex_f_no+=1 - latex_do(texfile) - else - puts "\tzero file size #{@env.path.tex}/#{@md.fns}" + @md.papersize_array.each do |ps| + if @md.fns =~/\.(?:-|ssm\.)?sst$/ + @dirout=SiSU_Env::Info_env.new(@md.fns) + case @md.fns + when /\.(?:-|ssm\.)?sst$/ + if FileTest.directory?(@env.path.tex)==true + Dir.chdir(@env.path.tex) + @dir_sisu=@dirout.path.output + texfile=@md.fns.gsub(/$/,".#{ps}.tex") + texfile=texfile.gsub(/~/,'-') + if File.exist?(texfile) \ + and File.size(texfile) > 0 + @tex_f_no+=1 + latex_do(texfile,ps) + else + puts "\tzero file size #{@env.path.tex}/#{texfile}" + end end end end end + outputdir="#@dir_sisu/#{@md.fnb}" + case @md.papersize_array[0] #default pdf + when /a4/; pdf_p=@md.fn[:pdf_p_a4]; pdf_l=@md.fn[:pdf_l_a4] + when /a5/; pdf_p=@md.fn[:pdf_p_a5]; pdf_l=@md.fn[:pdf_l_a5] + when /b5/; pdf_p=@md.fn[:pdf_p_b5]; pdf_l=@md.fn[:pdf_l_b5] + when /letter/; pdf_p=@md.fn[:pdf_p_letter]; pdf_l=@md.fn[:pdf_l_letter] + when /legal/; pdf_p=@md.fn[:pdf_p_legal]; pdf_l=@md.fn[:pdf_l_legal] + else pdf_p=@md.fn[:pdf_p_a4]; pdf_l=@md.fn[:pdf_l_a4] + end + if FileTest.file?("#{outputdir}/#{pdf_p}") + system(" + cd #{outputdir} + rm portrait.pdf + ln -s #{pdf_p} portrait.pdf + ") + end + if FileTest.file?("#{outputdir}/#{pdf_l}") + system(" + cd #{outputdir} + rm landscape.pdf + ln -s #{pdf_l} landscape.pdf + ") + end else tell=SiSU_Screen::Ansi.new(@md.cmd,"FILE NOT FOUND: << #{@md.fns} >> - requested latex system processing skipped") tell.warn @@ -232,7 +271,14 @@ module SiSU_TeX #include SiSU_Param @@tex_backslash ||="\\\\" @@tilde='\\\\\\~' #?? debug crazy - @@tex_head={ :p => nil, :l => nil } + @@tex_head={ + 'a4'=>{:p => nil, :l => nil}, + 'a5'=>{:p => nil, :l => nil}, + 'b5'=>{:p => nil, :l => nil}, + 'letter'=>{:p => nil, :l => nil}, + 'legal'=>{:p => nil, :l => nil}, + 'book'=>{:p => nil, :l => nil} + } @@flag_alt,@@flag_group,@@flag_code=false,false,false @@dp,@@prefix_b=nil,nil def initialize(particulars) @@ -260,30 +306,30 @@ module SiSU_TeX tell.txt_grey unless @md.cmd =~/q/ if @md.dc_rights use=@md.dc_rights.dup #dup is necessary, else contents of :rights changed - do_mono=SiSU_TeX_Pdf::Format_text_object.new(@md,use) + sp_char=SiSU_TeX_Pdf::Special_characters.new(@md,use) copymark=if @md.creator_copymark; '{\\begin{small}\\raisebox{1ex}{\\copyright}\\end{small}} ' else '' end copymark='Copyright {\\begin{small}\\raisebox{1ex}{\\copyright}\\end{small}} ' - copyright=do_mono.special_characters_safe.gsub(/^\s*Copyright \(C\)/, copymark) + copyright=sp_char.special_characters_safe.gsub(/^\s*Copyright \(C\)/, copymark) @@rights||="\n #{@@tex_backslash*2}[3]\\ \\linebreak #{copyright}" end if @md.prefix_b - do_mono=SiSU_TeX_Pdf::Format_text_object.new(@md,@md.prefix_b) - prefix_b=do_mono.special_characters_safe + sp_char=SiSU_TeX_Pdf::Special_characters.new(@md,@md.prefix_b) + prefix_b=sp_char.special_characters_safe @@prefix_b="\n #{@@tex_backslash*2}[3]\\ \\linebreak \\ #{prefix_b}\n" unless @@prefix_b end data=pre(data) data=footnote(data) if @md.flag_tables - data=tables(data) + data=tables(data) end ocn=if @md.markup.inspect =~/no_ocn/ \ or @md.mod.inspect =~/--no-ocn/ \ or @skin_no_ocn false - else true - end + else true + end data=number_paras(data,ocn) data=markup(data) output(data) @@ -298,22 +344,22 @@ module SiSU_TeX # DEBUG 2003w16 this is a kludge, because i could not get parameters # from param, Sort out ... revert to more elegant solution # even more of a kludge as had to insert newlines where code is used not satisfactory, think about - para=if para =~/<:br>|\n/; para.split(/<:br>|\n/) + para=if para =~/#{Mx[:br_nl]}|\n/; para.split(/#{Mx[:br_nl]}|\n/) else para end if para.class == String - @md.flag_tables=true if para =~/\\\}\\~/m,"\\footnote[\\1]{%\n \\2} ") #removed space before \\footnote 2004w21, watch - para.gsub!(/\\~\[([*+]\d+)\s+(.+?)<#@dp>\]\\~/m,"\\FootnoteA{\\1}{%\n \\2} ") #work on asterisk footnotes - para.gsub!(/\\~\\\{([*+]+)\s+(.+?)<#@dp>\\\}\\~/m,"\\FootnoteA{\\1}{%\n \\2} ") #work on asterisk footnotes + if para =~/#{Mx[:en_a_o]}[\d*+]+\s|#{Mx[:en_b_o]}([*+]\d+)\s/ # note escape not necessary in front of ~ has implications for many other matches #debug note + para.gsub!(/#{Mx[:en_a_o]}(\d+)\s+(.+?)#{Mx[:id_o]}#@dp#{Mx[:id_c]}#{Mx[:en_a_c]}/m,"\\footnote[\\1]{%\n \\2} ") #removed space before \\footnote 2004w21, watch + para.gsub!(/#{Mx[:en_b_o]}([*+]\d+)\s+(.+?)#{Mx[:id_o]}#@dp#{Mx[:id_c]}#{Mx[:en_b_c]}/m,"\\FootnoteA{\\1}{%\n \\2} ") #work on asterisk footnotes + para.gsub!(/#{Mx[:en_a_o]}([*+]+)\s+(.+?)#{Mx[:id_o]}#@dp#{Mx[:id_c]}#{Mx[:en_a_c]}/m,"\\FootnoteA{\\1}{%\n \\2} ") #work on asterisk footnotes end @tex_file << para 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 - } + @block={} + @para=para + @md.papersize_array.each do |ps| + @@tableheader={ ps => { :p => 0, :l => 0 }} + para,para_p=@para.dup,@para.dup #visit + format_l=SiSU_TeX_Pdf::Format_text_object.new(md,para,ps) + format_p=SiSU_TeX_Pdf::Format_text_object.new(md,para_p,ps) + @block[ps]={ + :l => format_l.longtable_landscape, + :p => format_p.longtable_portrait + } + end + @block end def tables(data) - @@tableheader={ :p => 0, :l => 0 } @tex_file=[] data.each do |para| - @tex_file << if para =~/¡|/ \ + if para =~/#{Mx[:gr_o]}(?:code|alt|verse|group)#{Mx[:gr_c]}/ \ or @@flag_alt - if para =~/<:(?:code|alt|verse|group)>/ + if para =~/#{Mx[:gr_o]}(?:code|alt|verse|group)#{Mx[:gr_c]}/ @lineone=case para - when /<:(?:alt|verse|group)>/; para - when /<:code>/; "#{@tex.paraskip_small} \\begin{scriptsize} " + para + when /#{Mx[:gr_o]}(?:alt|verse|group)#{Mx[:gr_c]}/; para + when /#{Mx[:gr_o]}code#{Mx[:gr_c]}/; "#{@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) + sp_char=SiSU_TeX_Pdf::Special_characters.new(@md,para) + para=sp_char.special_characters_curly(para) end - regx=/<:((?:code|alt|verse|group)(?:-end)?)>/m + regx=/#{Mx[:gr_o]}((?:code|alt|verse|group)(?:-end)?)#{Mx[:gr_c]}/m + x=nil x=regx.match(para)[1] if para =~regx - x=$1 - para.gsub!(/\n<:(?:code|alt|verse|group)>\n/m,'') + para.gsub!(/\n#{Mx[:gr_o]}(?:code|alt|verse|group)#{Mx[:gr_c]}\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; + elsif @@flag_alt if para =~ /\}(?:https?|file|ftp)/m - para=mono.http #(@orientation) + para=SiSU_TeX_Pdf::Format_text_object.new(@md,para,'a4').http end @group_collect << para #<< "\n\n" end @@ -400,67 +451,84 @@ module SiSU_TeX group_collect=[] group_collect << '\begin{footnotesize} ' unless @@flag_code @group_collect.each do |x| - x.gsub!(/(<:\S+>||)/,' ') + x.gsub!(/(<:\S+>|#{Mx[:id_o]}.*?#{Mx[:id_c]}|#{Mx[:tc_o]}.*?#{Mx[:tc_c]}|#{Mx[:gr_o]}.*?#{Mx[:gr_c]}||)/,' ') #Mx fix x=x.split(/ \\\\ /) group_collect << x end group_collect << ' \end{footnotesize} ' unless @@flag_code @group_collect=group_collect.flatten - @lineone.gsub!(/(<:\S+>||)/,' ') + @lineone.gsub!(/(<:\S+>|#{Mx[:fa_o]}.*?#{Mx[:fa_c]}|#{Mx[:gr_o]}.*?#{Mx[:gr_c]}||)/,' ') #@group_collect.each{ |x| x.gsub!(/(.#{@@tilde}\S*\s*|<:\S+>||)/,' ') } - #@lineone.gsub!(/(.#{@@tilde}\S*\s*|<:\S+>||)/,' ') insert=[] - if para =~/<:code-end>/m + insert=if para =~/#{Mx[:gr_o]}code-end#{Mx[:gr_c]}/m insert << y + @lineone << @group_collect << ' \end{scriptsize}' << " #{@tex.paraskip_normal}" else insert << y + @lineone << @group_collect end + para.gsub!(/(<:\S+>|#{Mx[:fa_o]}.*?#{Mx[:fa_c]}|#{Mx[:gr_o]}.*?#{Mx[:gr_c]}||)/,' ') @@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 + tex_f=insert.flatten end + para=tex_f else - if para =~ /\}(?:https?|file|ftp)/ - para=mono.http #(@orientation) - end + #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 + when /^#{Mx[:lv_o_1]}/; mono.level1 + when /^#{Mx[:lv_o_2]}/; mono.level2 + when /^#{Mx[:lv_o_3]}/; mono.level3 + when /^#{Mx[:lv_o_4]}/; mono.level4 + when /^#{Mx[:lv_o_5]}/; mono.level5 + when /^#{Mx[:lv_o_6]}/; mono.level6 + when /^#{Mx[:pa_o]}:i([1-9])#{Mx[:pa_c]}/; 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!(/\s*(?:#{Mx[:br_line]}|#{Mx[:br_nl]})\s*/,' \\\\\\\\ ') #% tread with care + para.gsub!(/(\.#{@@tilde}\S*\s*|<:\S+>|#{Mx[:fa_o]}.*?#{Mx[:fa_c]}|#{Mx[:gr_o]}.*?#{Mx[:gr_c]}||)/,' ') #% 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) + sp_char=SiSU_TeX_Pdf::Special_characters.new(@md,para) + para=sp_char.special_characters_curly(para) + end + para + end + if para =~ /\}(?:https?|file|ftp)/ + para=if para !~/\.(?:png|jpg|gif)/ + SiSU_TeX_Pdf::Format_text_object.new(@md,para,'a4').http + else + @block={} + @md.papersize_array.each do |ps| + image=SiSU_TeX_Pdf::Format_text_object.new(@md,para,ps).http + @block[ps]={ + :l => image, + :p => image + } + end + @block end - tex_f = para end - tex_f + para end def markup(data) @tex_file=[] md={} #% document headers watch special characters in title & subtitle: glark "\{\{~(sub)?title.+?[$&%#_\{\}]" *.(lm|er)?? - 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_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 + home=@vz.txt_home.gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}|#{Mx[:br_paragraph]}|\\\\/,' - ') #no line splitting in heading neither html nor latex + title=@md.title.gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}|#{Mx[:br_paragraph]}|\\\\/,' - ') #no line splitting in heading neither html nor latex + subtitle=@md.subtitle.gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}|#{Mx[:br_paragraph]}|\\\\/,' - ') if @md.subtitle #no line splitting in heading neither html nor latex + @md.papersize_array.each do |ps| + orient_portrait=SiSU_TeX_Pdf::Format_head.new(@md,ps,'portrait',"#{home}: - #{title} #{subtitle}") + orient_landscape=SiSU_TeX_Pdf::Format_head.new(@md,ps,'landscape',"#{home}: - #{title} #{subtitle}") + @@tex_head[ps][:p]=orient_portrait.document_head_with_orientation + @@tex_head[ps][:l]=orient_landscape.document_head_with_orientation + end @tex_file <<< markup_common(para[:p]), - :l => markup_common(para[:l]) - } + if ( para['a4'] or para['a5'] or para['b5'] \ + or para['letter'] or para['legal']) + @md.papersize_array.each do |ps| + if para[ps] + if (para[ps][:p] and para[ps][:l]) + para[ps]={ + :p => markup_common(para[ps][:p]), + :l => markup_common(para[ps][:l]) + } + else p "here #{__FILE__} #{__LINE__}" if @md.cmd.inspect =~/M/ + end + end + end + elsif (para[:p] and para[:l]) + para = { + :p => markup_common(para[:p]), + :l => markup_common(para[:l]) + } + else p "here #{__FILE__} #{__LINE__}" if @md.cmd.inspect =~/M/ + end end @tex_file << para end @@ -553,7 +637,7 @@ WOK url=%<#{l[:url]}> url.gsub!(/(?:\\)*([$&~%_#}{^])/,"\\\\\\1") #latex special chars s_lnk=l[:say] - s_lnk.gsub!(/(
|
|

|

)/,'') + s_lnk.gsub!(/\s*(#{Mx[:br_line]}|#{Mx[:br_nl]}|#{Mx[:br_paragraph]})\s*/,' \\\\\\\\ ') s_lnk.gsub!(/(?:\\)*([$&~%_#}{^])/,"\\\\\\1") #latex special chars if url !~/^\.(\.)?\// s_lnk_url=%<\\begin{scriptsize}\\href{#{url}}{#{url}}\\end{scriptsize}> # note this bit of dereferencing magic @@ -589,77 +673,116 @@ WOK @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\}|/ #catch - m=/(.+?)<\\~(\d+);(?:[oh]|[0-6]:)\d+;\w\d+><#@dp:#@dp>$/m + if para =~/#{Mx[:id_o]}\\~(\d+);(?:[oh]|[0-6]:)\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#@dp:#@dp#{Mx[:id_c]}$/ \ + and para !~/\\end\{longtable\}|#{Mx[:br_eof]}/ #catch + m=/(.+?)#{Mx[:id_o]}\\~(\d+);(?:[oh]|[0-6]:)\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#@dp:#@dp#{Mx[:id_c]}$/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 + elsif para =~/^#{Mx[:id_o]}~\d+;(?:[oh]|[0-6]:)\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#@dp:#@dp#{Mx[:id_c]}$/ #2005 this is added for tables, rationalise + m=/#{Mx[:id_o]}~(\d+);(?:[oh]|[0-6]:)\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#@dp:#@dp#{Mx[:id_c]}$/m paranum=para[m,1] - para.gsub!(/<~\d+;(?:[oh]|[0-6]:)\d+;\w\d+><#@dp:#@dp>/,'') + para.gsub!(/#{Mx[:id_o]}~\d+;(?:[oh]|[0-6]:)\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#@dp:#@dp#{Mx[:id_c]}/,'') 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 + elsif para =~/^#{Mx[:id_o]}~\d+;(?:[oh]|[0-6]:)\d+;\w\d+#{Mx[:id_c]}/ #extra 2005 this is added for tables, rationalise + m=/#{Mx[:id_o]}~(\d+);[oh]\d+;\w\d+#{Mx[:id_c]}/m paranum=para[m,1] - para.gsub!(/<~\d+;(?:[oh]|[0-6]:)\d+;\w\d+>/,'') + para.gsub!(/#{Mx[:id_o]}~\d+;(?:[oh]|[0-6]:)\d+;\w\d+#{Mx[:id_c]}/,'') para="\\marginpar{\\begin{tiny}#{paranum}\\end{tiny}}" + para elsif para =~/\\end\{longtable\}/ #catch - para.gsub!(/<\\~\d+>|<\\~(\d+);(?:[ohm]|[0-6]:)\d+;\w\d+><#@dp:#@dp>/,'') - para.gsub!(/<\\~\d+>|<\\~(\d+);(?:[ohm]|[0-6]:)\d+;\w\d+>/,'') #extra + para.gsub!(/#{Mx[:id_o]}\\~\d+#{Mx[:id_c]}|#{Mx[:id_o]}\\~(\d+);(?:[ohm]|[0-6]:)\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#@dp:#@dp#{Mx[:id_c]}/,'') + para.gsub!(/#{Mx[:id_o]}\\~\d+#{Mx[:id_c]}|#{Mx[:id_o]}\\~(\d+);(?:[ohm]|[0-6]:)\d+;\w\d+#{Mx[:id_c]}/,'') #extra end para end def number_paras(data,ocn) tex_file=[] data.each do |para| - 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) - } + para=if para.class == Hash + if ( para['a4'] or para['a5'] or para['b5'] \ + or para['letter'] or para['legal']) + @para={} + @md.papersize_array.each do |ps| + if para[ps] + if (para[ps][:p] and para[ps][:l]) + @para[ps]={ + :p => number_paras_numbering(para[ps][:p],ocn), + :l => number_paras_numbering(para[ps][:l],ocn) + } + else p "here #{__FILE__} #{__LINE__}" if @md.cmd.inspect =~/M/ + end + end + end + elsif (para[:p] and para[:l]) + @para = { + :p => number_paras_numbering(para[:p],ocn), + :l => number_paras_numbering(para[:l],ocn) + } + else p "here #{__FILE__} #{__LINE__}" if @md.cmd.inspect =~/M/ + end else #elsif para.class == String - number_paras_numbering(para,ocn) + @para=number_paras_numbering(para,ocn) end - tex_file << para + tex_file << @para end tex_file end def output(array) array.flatten! array.compact! + @array=array fns_l=@md.fns.gsub(/~/,'-') #this is a sorry fix, but necessary as it appears latex programs like not ~ - 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+/,'') - 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" + @md.papersize_array.each do |ps| + filename_tex_landscape=File.new("#{@env.path.tex}/#{fns_l}.#{ps}.landscape.tex",'w+') + filename_tex_portrait=File.new("#{@env.path.tex}/#{fns_l}.#{ps}.tex",'w+') + filename_tex_portrait << @@tex_head[ps][:p] + filename_tex_landscape << @@tex_head[ps][:l] + array.each do |para| + case para + when String + para.gsub!(/^\s+/,'') + if para !~/\A\s*\Z/ + filename_tex_portrait.puts para,"\n" + filename_tex_landscape.puts para,"\n" + end + when Hash + if para[ps] and (para[ps][:p] and para[ps][:l]) + para[ps][:p].gsub!(/^\s+/,'') if para[ps][:p] + para[ps][:l].gsub!(/^\s+/,'') if para[ps][:l] + if para[ps][:p] !~/\A\s*\Z/ + filename_tex_portrait.puts para[ps][:p],"\n" + end + if para[ps][:l] !~/\A\s*\Z/ + filename_tex_landscape.puts para[ps][:l],"\n" + end + elsif (para[:p] and para[:l]) + para[:p].gsub!(/^\s+/,'') if para[:p] + para[:l].gsub!(/^\s+/,'') if para[:l] + 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 + else p "here #{__FILE__} #{__LINE__}" if @md.cmd.inspect =~/M/ + end end end + array=@array + filename_tex_portrait.close + filename_tex_landscape.close end - filename_tex_portrait.close - filename_tex_landscape.close - @@tex_head={} #@@tex_head={ :p => nil, :l => nil } + @@tex_head={ + 'a4'=>{:p => nil, :l => nil}, + 'a5'=>{:p => nil, :l => nil}, + 'b5'=>{:p => nil, :l => nil}, + 'letter'=>{:p => nil, :l => nil}, + 'legal'=>{:p => nil, :l => nil}, + 'book'=>{:p => nil, :l => nil} + } array=[] end end -- cgit v1.2.3