From 595970ff23c8474ce7832473a98c1e4d55543c78 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Thu, 8 Dec 2011 21:17:27 -0500 Subject: v3: texpdf, codeblocks, use listings package (for grey box) * (internally retain possibility to use boites package) --- lib/sisu/v3/texpdf.rb | 196 +++++++++++++++++++++++++++++++------------ lib/sisu/v3/texpdf_format.rb | 125 ++++++++++++++++++++++----- 2 files changed, 244 insertions(+), 77 deletions(-) (limited to 'lib') 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 + <') + w.gsub!(/[\\]?~/,'~') + w.gsub!(/[#{Mx[:br_line]}#{Mx[:br_paragraph]}]/,"\n") #watch + w.gsub!(/#{Mx[:gl_o]}#(?:126|152)#{Mx[:gl_c]}/,'~') #126 usual + w.gsub!(/\\?\||#{Mx[:gl_o]}#124#{Mx[:gl_c]}/,'|') #unless is=='code' #unless w=~/<~\d+;(?:[ohmu]|[0-6]:)\d+;\w\d+>/ # | SiSU not really special sisu character but done, also LaTeX + para_array << w + end + str=para_array.join(' ') + str=str.strip unless is=='code' + str + else '' + end + str.gsub(/\s*#{Mx[:mk_o]}:name#\S+?#{Mx[:mk_c]}\s*/,' ') + str.gsub!(/.+?<-#>/,'') + str.gsub!(/#{Mx[:br_eof]}/,'') + str.gsub!(/#{Mx[:br_endnotes]}/,'') + #problem sequence -> + str.gsub!(/&(?:lt|#060);/,'<') # < SiSU special character also LaTeX + str.gsub!(/#{Mx[:gl_o]}#(?:gt|062)#{Mx[:gl_c]}/,'>') # > SiSU special character also LaTeX + str.gsub!(/#{Mx[:gl_o]}#123#{Mx[:gl_c]}/,'{') # { SiSU special character also LaTeX + str.gsub!(/#{Mx[:gl_o]}#125#{Mx[:gl_c]}/,'}') # } SiSU special character also LaTeX + str.gsub!(/#{Mx[:gl_o]}#(?:126|152)#{Mx[:gl_c]}/,'~') # ~ SiSU special character also LaTeX + str.gsub!(/#{Mx[:gl_o]}#035#{Mx[:gl_c]}/,'#') # # SiSU special character also LaTeX + str.gsub!(/#{Mx[:gl_o]}#033#{Mx[:gl_c]}/,'!') # ! SiSU not really special sisu character but done, also LaTeX + #str.gsub!(/(^|\s)\*\s/,'\1\asterisk ') # * should you wish to escape astrisk e.g. describing \*{bold}* + str.gsub!(/#{Mx[:gl_o]}#042#{Mx[:gl_c]}/,'*') # * should you wish to escape astrisk e.g. describing \*{bold}* + str.gsub!(/#{Mx[:gl_o]}#045#{Mx[:gl_c]}/,'-') # - SiSU special character also LaTeX + str.gsub!(/#{Mx[:gl_o]}#043#{Mx[:gl_c]}/,'+') # + SiSU special character also LaTeX + str.gsub!(/#{Mx[:gl_o]}#044#{Mx[:gl_c]}/,',') # + SiSU special character also LaTeX + str.gsub!(/#{Mx[:gl_o]}#038#{Mx[:gl_c]}/,'&') #unless @txt=~/<:code>/ # / SiSU special character also LaTeX + str.gsub!(/#{Mx[:gl_o]}#047#{Mx[:gl_c]}/,'/') # / SiSU special character also LaTeX + str.gsub!(/#{Mx[:gl_o]}#092#{Mx[:gl_c]}/,'\\') # \ SiSU special character also LaTeX + str.gsub!(/#{Mx[:gl_o]}#095#{Mx[:gl_c]}/,'_') # _ SiSU special character also LaTeX + str.gsub!(/#{Mx[:gl_o]}#124#{Mx[:gl_c]}/,'|') # | SiSU not really special sisu character but done, also LaTeX + str.gsub!(/#{Mx[:gl_o]}#058#{Mx[:gl_c]}/,':') # : SiSU not really special sisu character but done, also LaTeX + str.gsub!(/#{Mx[:gl_o]}#094#{Mx[:gl_c]}|\^/,'^') # ^ SiSU not really special sisu character but done, also LaTeX + ##watch placement, problem sequence ^ + str.gsub!(/&atild;<\/font><\/sup>/,' ') + str.gsub!(/\\copy(right|mark)?/,'<=copymark>') # ok problem with superscript + str + end def xetex_special_characters_1(str,is='') # ~ ^ $ & % _ { } #LaTeX special characters - KEEP list #str=Iconv.conv('ISO-8859-1', 'UTF-8', @txt) # `require': iconv will be deprecated in the future, use String#encode instead. word=str.scan(/\S+|\n/) #unless line =~/^(?:@\S|%+\s)/ @@ -1326,6 +1400,11 @@ WOK str=xetex_special_characters_2(str,is) unless str.nil? # remove this to start with, causes issues @txt=str end + def characters_code_listings #special characters - some substitutions are sequence sensitive, rearrange with care. + str,is=@txt,@is + str=xetex_code_listings(str,is) unless str.nil? + @txt=str + end def special_characters_code str=@txt str.gsub!(/ \\\\([ #{Mx[:br_nl]}]+|$)/,' \textbackslash\textbackslash\hardspace\1') @@ -1369,7 +1448,7 @@ WOK end def header "\\lhead[ ]{ }\n" + - "\\chead[ \\fancyplain{} \\bfseries \\footnotesize \\leftmark ]{ \\fancyplain{} \\bfseries \\footnotesize \\rightmark }\n" + + "\\chead[ \\fancyplain{} \\bfseries \\footnotesize \\leftmark ]{ \\fancyplain{} \\bfseries \\footnotesize \\rightmark }\n" + "\\rhead[ ]{ }\n" end def footer @@ -1500,13 +1579,13 @@ WOK \"Support Open Standards and Software Libré for the Information Technology Infrastructure\" RA\\subsubsection*{Information on this document copy #{site}} \\addcontentsline{toc}{subsection}{Information on this document copy} {\\begin{footnotesize} -\\\\ Generated by \\href{http://www.jus.uio.no/sisu/}{SiSU} found at \\href{http://www.jus.uio.no/sisu/}{www.jus.uio.no/sisu} \\begin{tiny}[ #{v[:project]} #{v[:version]} #{v[:date_stamp]} ]\\end{tiny} \\href{http://www.sisudoc.org}{www.sisudoc.org}. SiSU is software for document structuring, publishing and search (using SiSU: object citation numbering, markup, meta-markup, and system) Copyright #{@copymark} 1997, current #{@date.year_static} Ralph Amissah, All Rights Reserved. +\\\\ Generated by \\href{http://www.jus.uio.no/sisu/}{SiSU} found at \\href{http://www.jus.uio.no/sisu/}{www.jus.uio.no/sisu} \\begin{tiny}[ #{v[:project]} #{v[:version]} #{v[:date_stamp]} ]\\end{tiny} \\href{http://www.sisudoc.org}{www.sisudoc.org}. SiSU is software for document structuring, publishing and search (using SiSU: object citation numbering, markup, meta-markup, and system) Copyright #{@copymark} 1997, current #{@date.year_static} Ralph Amissah, All Rights Reserved. \\\\ SiSU is released under \\href{http://www.fsf.org/licenses/gpl.html}{GPL 3 } or later (\\href{http://www.fsf.org/licenses/gpl.html}{www.fsf.org/licenses/gpl.html}). {\\end{footnotesize} {\\begin{small} -\\\\ W3 since October 3 1993 \\href{http://www.jus.uio.no/sisu/}{#{sisu_ico}}SiSU 1997, current #{@date.year_static}. \\\\ #{sitename} presentations at \\begin{scriptsize}#{site}\\end{scriptsize} \\\\ \\\\ #{@md.title.full} \\textbf{pdf} versions can be found at: \\\\ +\\\\ W3 since October 3 1993 \\href{http://www.jus.uio.no/sisu/}{#{sisu_ico}}SiSU 1997, current #{@date.year_static}. \\\\ #{sitename} presentations at \\begin{scriptsize}#{site}\\end{scriptsize} \\\\ \\\\ #{@md.title.full} \\textbf{pdf} versions can be found at: \\\\ {\\end{small} -\\\\ #{@brace_url.tex_open}\\begin{scriptsize}\\url{#{@vz.url_root_http}/#{url}/#{@md.fn[:pdf_p]}}\\end{scriptsize}#{@brace_url.tex_close} \\\\ -#{@brace_url.tex_open}\\begin{scriptsize}\\url{#{@vz.url_root_http}/#{url}/#{@md.fn[:pdf_l]}}\\end{scriptsize}#{@brace_url.tex_close} \\\\ +\\\\ #{@brace_url.tex_open}\\begin{scriptsize}\\url{#{@vz.url_root_http}/#{url}/#{@md.fn[:pdf_p]}}\\end{scriptsize}#{@brace_url.tex_close} \\\\ +#{@brace_url.tex_open}\\begin{scriptsize}\\url{#{@vz.url_root_http}/#{url}/#{@md.fn[:pdf_l]}}\\end{scriptsize}#{@brace_url.tex_close} \\\\ \\\\\n#{@md.title.full} \\textbf{html} versions may be found at: \\\\ #{@brace_url.tex_open}\\begin{scriptsize}\\url{#{@vz.url_root_http}/#{url}/#{@md.fn[:toc]}}\\end{scriptsize}#{@brace_url.tex_close} or \\\\ #{@brace_url.tex_open}\\begin{scriptsize}\\url{#{@vz.url_root_http}/#{url}/#{@md.fn[:doc]}}\\end{scriptsize}#{@brace_url.tex_close} -- cgit v1.2.3