diff options
Diffstat (limited to 'lib/sisu/v3/texpdf.rb')
-rw-r--r-- | lib/sisu/v3/texpdf.rb | 196 |
1 files changed, 142 insertions, 54 deletions
diff --git a/lib/sisu/v3/texpdf.rb b/lib/sisu/v3/texpdf.rb index d36344cd..2b9e1087 100644 --- a/lib/sisu/v3/texpdf.rb +++ b/lib/sisu/v3/texpdf.rb @@ -294,6 +294,7 @@ module SiSU_TeX true else false end + @codeblock_box='listings' #alternative 'boites' end def songsheet begin @@ -352,7 +353,11 @@ module SiSU_TeX dob.tmp=SiSU_TeX_Pdf::Format_text_object.new(@md,dob.tmp).url_str_internal(dob.tmp) end elsif dob.is =='code' - dob.tmp=SiSU_TeX_Pdf::Special_characters.new(@md,dob.tmp).special_characters_code + dob.tmp=if @codeblock_box=='listings' + dob.tmp + else + SiSU_TeX_Pdf::Special_characters.new(@md,dob.tmp).special_characters_code + end elsif dob.is =='break' if dob.obj==Mx[:br_page]; dob.tmp='\newpage' elsif dob.obj==Mx[:br_page_new]; dob.tmp='\clearpage' @@ -408,6 +413,53 @@ module SiSU_TeX def enclose(dob) dob end + def box_boites(dob,ocn) + sp_char=SiSU_TeX_Pdf::Special_characters.new(@md,dob.tmp,dob.is) + dob.tmp=sp_char.special_characters_safe + dob.tmp.gsub!(/(#{Mx[:nbsp]})/m,'{\color{mywhite}\1}') + #dob.tmp.gsub!(/#{Mx[:nbsp]}/m,'{~}') # dob.tmp.gsub!(/#{Mx[:nbsp]}\s*/m,'{~}') + dob.tmp.gsub!(/#{Mx[:vline]}/m,'\vline') + dob.tmp.gsub!(/ \\( |#{Mx[:br_nl]})/,' {\textbackslash}\1') + dob.tmp.gsub!(/#{Mx[:br_nl]}\s*\Z/m,'') + dob.tmp.gsub!(/#{Mx[:br_nl]}{2}/,'\newline \\\\\\ ') + dob.tmp.gsub!(/#{Mx[:br_nl]}/,' \\\\\\ ') + dob.tmp.gsub!(/\n\n\n/m," \\newline\n\n") + ocn=SiSU_TeX_Pdf::Format_text_object.new(@md).ocn_display(dob) + dob.tmp = ocn \ + + @tex_ml.paraskip_small \ + + '\begin{Codeblock}' \ + + '\begin{codeblockboitebox} \hardspace \newline ' \ + + dob.tmp \ + + '\end{codeblockboitebox}' \ + + '\end{Codeblock}' \ + + "\n" \ + + @tex_ml.paraskip_normal + dob + end + def box_listings(dob,ocn) + sp_char=SiSU_TeX_Pdf::Special_characters.new(@md,dob.tmp,dob.is) + dob.tmp=sp_char.characters_code_listings + dob.tmp.gsub!(/^\s+/m,'') #bug, fix earlier, should be made unecessary + dob.tmp.gsub!(/#{Mx[:nbsp]}/m,' ') + dob.tmp.gsub!(/#{Mx[:vline]}/m,'|') + dob.tmp.gsub!(/#{Mx[:br_nl]}(?:\s?\n)?/m,"\n") + dob.tmp.gsub!(/\n\n\n/m," \n\n") + ocn=SiSU_TeX_Pdf::Format_text_object.new(@md).ocn_display(dob) + dob.tmp = ocn \ + + @tex_ml.paraskip_small \ + + '\begin{Codeblock}' \ + + "\n" \ + + '\begin{lstlisting} ' \ + + "\n" \ + + dob.tmp \ + + "\n" \ + + '\end{lstlisting} ' \ + + "\n" \ + + '\end{Codeblock}' \ + + "\n" \ + + @tex_ml.paraskip_normal + dob + end def markup_common(dob) tex_f=nil txt_obj={ dal: dob } @@ -430,7 +482,7 @@ module SiSU_TeX + '\\end{footnotesize}' \ + "\n" \ + @tex_ml.paraskip_normal - elsif dob.is=~/verse/ + elsif dob.is=~/verse/ ocn \ + @tex_ml.paraskip_tiny \ + "\n" \ @@ -444,26 +496,13 @@ module SiSU_TeX end dob when /code/ - sp_char=SiSU_TeX_Pdf::Special_characters.new(@md,dob.tmp,dob.is) - dob.tmp=sp_char.special_characters_safe - dob.tmp.gsub!(/(#{Mx[:nbsp]})/m,'{\color{mywhite}\1}') - #dob.tmp.gsub!(/#{Mx[:nbsp]}/m,'{~}') # dob.tmp.gsub!(/#{Mx[:nbsp]}\s*/m,'{~}') - dob.tmp.gsub!(/#{Mx[:vline]}/m,'\vline') - dob.tmp.gsub!(/ \\( |#{Mx[:br_nl]})/,' {\textbackslash}\1') - dob.tmp.gsub!(/#{Mx[:br_nl]}\s*\Z/m,'') - dob.tmp.gsub!(/#{Mx[:br_nl]}{2}/,'\newline \\\\\\ ') - dob.tmp.gsub!(/#{Mx[:br_nl]}/,' \\\\\\ ') - dob.tmp.gsub!(/\n\n\n/m," \\newline\n\n") - ocn=SiSU_TeX_Pdf::Format_text_object.new(@md).ocn_display(dob) - dob.tmp = ocn \ - + @tex_ml.paraskip_small \ - + '\begin{Codeblock}' \ - + '\begin{codeblockboitebox} \hardspace \newline ' \ - + dob.tmp \ - + '\end{codeblockboitebox}' \ - + '\end{Codeblock}' \ - + "\n" \ - + @tex_ml.paraskip_normal + dob=if @codeblock_box == 'listings' + box_listings(dob,ocn) + elsif @codeblock_box == 'boites' + box_boites(dob,ocn) + else + box_boites(dob,ocn) + end dob else 'error' #should never occur end @@ -533,7 +572,7 @@ module SiSU_TeX dob=enclose(dob) unless dob.tmp =~/^$/ end else - dob.tmp.strip! + dob.tmp.strip! unless dob.is=='code' dob=enclose(dob) unless dob.tmp =~/^$/ end if dob.class==String @@ -543,22 +582,83 @@ module SiSU_TeX dob end if dob.tmp =~/(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image\b)/m \ - and dob.is !='code' + && dob.is !='code' dob=SiSU_TeX_Pdf::Bare_urls.new(@md,dob).bare_urls tst=SiSU_TeX_Pdf::Format_text_object.new(@md,dob) dob=tst.urls_txt_and_images dob elsif dob.tmp =~/https?:\/\/\S+\b/m \ - and dob.is =='code' + && dob.is =='code' \ + && @codeblock_box !='listings' dob=SiSU_TeX_Pdf::Bare_urls.new(@md,dob).bare_urls_in_code dob end - if dob.class !=Hash and dob.tmp =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}image\b/ \ - and dob.is !='code' + if dob.class !=Hash \ + && dob.tmp =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}image\b/ \ + && dob.is !='code' tst=SiSU_TeX_Pdf::Format_text_object.new(@md,dob) end dob end + def tex_box_listings + <<WOK +\\definecolor{listinggray}{gray}{0.9} +\\definecolor{lbcolor}{rgb}{0.9,0.9,0.9} +\\lstset{ + backgroundcolor=\\color{lbcolor}, + tabsize=4, + rulecolor=, + language=, + basicstyle=\\scriptsize, + upquote=true, + aboveskip={1.5\\baselineskip}, + columns=fixed, + showstringspaces=false, + extendedchars=true, + breaklines=true, + prebreak = \\raisebox{0ex}[0ex][0ex]{\\ensuremath{\\hookleftarrow}}, + frame=single, + showtabs=false, + showspaces=false, + showstringspaces=false, + identifierstyle=\\ttfamily, + keywordstyle=\\color[rgb]{0,0,1}, + commentstyle=\\color[rgb]{0.133,0.545,0.133}, + stringstyle=\\color[rgb]{0.627,0.126,0.941}, +} +WOK + end + def tex_box_boites + <<WOK +\\def\\codeblockboitebox{% + \\def\\bkvz@before@breakbox{\\ifhmode\\par\\fi\\vskip\\breakboxskip\\relax}% + \\def\\bkvz@set@linewidth{\\advance\\linewidth -2\\fboxrule + \\advance\\linewidth -2\\fboxsep} % + \\def\\bk@line{\\hbox to \\linewidth{% + \\ifbkcount\\smash{\\llap{\\the\\bk@lcnt\\ }}\\fi + \\psframebox*[framesep=0pt,linewidth=0pt]{% + \\vrule\\@width\\fboxrule \\hskip\\fboxsep + \\box\\bk@bxa + \\hskip\\fboxsep \\vrule\\@width\\fboxrule + }% + }}% + %\\def\\bkvz@top{\\hrule\\@height\\fboxrule} + \\def\\bkvz@top{\\hrule height .6pt}% + \\def\\bkvz@bottom{\\hrule\\@height\\fboxrule}% + \\breakbox} +\\def\\endcodeblockboitebox{\\endbreakbox} +WOK + end + def tex_codeblock + codeblock_box=if @codeblock_box=='listings' + tex_box_listings + elsif @codeblock_box=='boites' + tex_box_boites + else + tex_box_boites + end + codeblock_box + end def markup(data) @tex_file=[] md={} @@ -569,8 +669,8 @@ module SiSU_TeX orient_portrait=SiSU_TeX_Pdf::Format_head.new(@md,txt_obj) txt_obj={ txt: "#{home}: - #{title}", paper_size: ps, orientation: 'landscape' } orient_landscape=SiSU_TeX_Pdf::Format_head.new(@md,txt_obj) - @@tex_head[ps][:p]=orient_portrait.document_head_with_orientation - @@tex_head[ps][:l]=orient_landscape.document_head_with_orientation + @@tex_head[ps][:p]=orient_portrait.document_head_with_orientation(@codeblock_box) + @@tex_head[ps][:l]=orient_landscape.document_head_with_orientation(@codeblock_box) end @tex_file <<<<WOK #{@tex_ml.header}#{@tex_ml.footer} @@ -598,24 +698,7 @@ module SiSU_TeX \\newcommand{\\slash}{{/}} \\newcommand{\\underscore}{\\_} \\newcommand{\\exclaim}{\\Verbatim{!}} -\\def\\codeblockboitebox{% - \\def\\bkvz@before@breakbox{\\ifhmode\\par\\fi\\vskip\\breakboxskip\\relax}% - \\def\\bkvz@set@linewidth{\\advance\\linewidth -2\\fboxrule - \\advance\\linewidth -2\\fboxsep} % - \\def\\bk@line{\\hbox to \\linewidth{% - \\ifbkcount\\smash{\\llap{\\the\\bk@lcnt\\ }}\\fi - \\psframebox*[framesep=0pt,linewidth=0pt]{% - \\vrule\\@width\\fboxrule \\hskip\\fboxsep - \\box\\bk@bxa - \\hskip\\fboxsep \\vrule\\@width\\fboxrule - }% - }}% - %\\def\\bkvz@top{\\hrule\\@height\\fboxrule} - \\def\\bkvz@top{\\hrule height .6pt}% - \\def\\bkvz@bottom{\\hrule\\@height\\fboxrule}% - \\breakbox} -\\def\\endcodeblockboitebox{\\endbreakbox} - +#{tex_codeblock} % (tilde hash amp affected by http) % \\sloppy \\begin{document} @@ -789,8 +872,10 @@ WOK ps,h,fn=o[:ps],o[:h],o[:filename] if h[ps] \ and (h[ps][:p] and h[ps][:l]) - h[ps][:p].gsub!(/(?:^[ ]+|[ ]+$)/m,'') if h[ps][:p] - h[ps][:l].gsub!(/(?:^[ ]+|[ ]+$)/m,'') if h[ps][:l] + h[ps][:p].gsub!(/[ ]+$/m,'') if h[ps][:p] + h[ps][:l].gsub!(/[ ]+$/m,'') if h[ps][:l] + #h[ps][:p].gsub!(/(?:^[ ]+|[ ]+$)/m,'') if h[ps][:p] + #h[ps][:l].gsub!(/(?:^[ ]+|[ ]+$)/m,'') if h[ps][:l] h[ps][:p].gsub!(/\n\n\n+/m,"\n\n") if h[ps][:p] h[ps][:l].gsub!(/\n\n\n+/m,"\n\n") if h[ps][:l] if h[ps][:p] !~/\A\s*\Z/ @@ -800,8 +885,10 @@ WOK fn[:landscape].puts h[ps][:l],"\n" end elsif (h[:p] and h[:l]) - h[:p].gsub!(/(?:^[ ]+|[ ]+$)/m,'') if h[:p] - h[:l].gsub!(/(?:^[ ]+|[ ]+$)/m,'') if h[:l] + h[:p].gsub!(/[ ]+$/m,'') if h[:p] + h[:l].gsub!(/[ ]+$/m,'') if h[:l] + #h[:p].gsub!(/(?:^[ ]+|[ ]+$)/m,'') if h[:p] + #h[:l].gsub!(/(?:^[ ]+|[ ]+$)/m,'') if h[:l] h[:p].gsub!(/\n\n\n+/m,"\n\n") if h[:p] h[:l].gsub!(/\n\n\n+/m,"\n\n") if h[:l] if h[:p] !~/\A\s*\Z/ @@ -827,7 +914,7 @@ WOK file[:landscape] << @@tex_head[ps][:l] array.each do |morph| if morph.class==String - morph.gsub!(/^\s+/,'') + #morph.gsub!(/^\s+/,'') if morph !~/\A\s*\Z/ file[:portrait].puts morph,"\n" file[:landscape].puts morph,"\n" @@ -835,9 +922,10 @@ WOK elsif morph.class.inspect =~ /SiSU_document_structure/ \ and morph.tmp \ and morph.tmp.class==String - unless morph.of=='block' + if morph.is !='code' \ + && morph.of !='block' morph.tmp.gsub!(/^\s+/,'') - else morph.tmp.gsub!(/^ +/,'') + else morph.tmp end if morph.tmp !~/\A\s*\Z/ \ or morph.is=='code' |