# coding: utf-8 =begin * Name: SiSU * Description: a framework for document structuring, publishing and search * Author: Ralph Amissah * Copyright: (C) 1997 - 2010, 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 . If you have Internet connection, the latest version of the GPL should be available at these locations: * SiSU uses: * Standard SiSU markup syntax, * Standard SiSU meta-markup syntax, and the * Standard SiSU object citation numbering and system * Hompages: * Download: * Ralph Amissah ** Description: LaTeX formatting template, unicode utf-8 version, used for pdf =end module SiSU_TeX_Pdf @@table_pg_break_counter=1 include SiSU_Viz class Bare_urls def initialize(md,dob=nil) @md,@dob=md,dob @brace_url=SiSU_Viz::Skin.new.url_decoration end def bare_urls @dob.tmp.gsub!(/(^|[^\\])_/m,'\1\_') #watch may not work @dob.tmp.gsub!(/(^|[^#{Mx[:lnk_c]}])#{Mx[:url_o]}_?(?:\\?_)?(\S+?)#{Mx[:url_c]}/m, "\\1#{@brace_url.tex_open}\\begin{scriptsize}\\url{\\2}\\end{scriptsize}#{@brace_url.tex_close}") @dob end def bare_urls_in_code @dob.tmp.gsub!(/(^|[^\\])_/m,'\1\_') #watch may not work @dob.tmp.gsub!(/(http:\/\/\S+?)([{]|[.,;)\]]?(?: |$))/m, '\begin{scriptsize}\url{\1}\end{scriptsize}\2') @dob end end class Format_text_object require 'iconv' require "#{SiSU_lib}/defaults" # defaults.rb attr_accessor :string,:string1,:orientation,:url,:dir,:tex @@sys=SiSU_Env::System_call.new @@tex_pattern_margin_number=/\\begin\{tiny\}\\hspace\{0mm\}\\end\{tiny\}\{\\marginpar.+?\}\}\}/ @@tableheader={ 'a4' => { :p => 0, :l => 0 }, 'a5' => { :p => 0, :l => 0 }, 'b5' => { :p => 0, :l => 0 }, 'letter' => { :p => 0, :l => 0 }, 'legal' => { :p => 0, :l => 0 } } @@sys=SiSU_Env::System_call.new def initialize(md,dob=nil) @md,@dob=md,dob if defined? @md.image \ and @md.image =~/center/ @center_begin,@center_end='\begin{center}','\end{center}' else @center_begin,@center_end='','' end @start_table='' @tx=SiSU_Env::Get_init.instance.tex @brace_rel=SiSU_Viz::Skin.new.rel_decoration @env ||=SiSU_Env::Info_env.new(@md.fns) @tex2pdf=@@tex3pdf ||=SiSU_Env::System_call.new.tex2pdf_engine end def ocn_display(dob) "\\begin{tiny}\\hspace{0mm}\\end{tiny}{\\marginpar{\\begin{tiny}\\hspace{0mm}\\hypertarget{#{dob.ocn}}{#{dob.ocn}}\\end{tiny}}}" #ocn object citation numbering end def longtable_landscape end_table='\end{longtable}' row_break='\\\\\\' txt=if @dob.is=='table' tw=case @dob.tmp[:paper_size] when /a4/i; @tx.a4.landscape.w #European default, SiSU default when /letter/i; @tx.letter.landscape.w #U.S. default when /legal/i; @tx.legal.landscape.w #U.S. alternative when /book|b5/i; @tx.b5.landscape.w #book default - larger when /a5/i; @tx.a5.landscape.w else @tx.a4.landscape.w #default currently A4 end textwidth=(tw.to_i/2) - 24 colW=[] colW << '{' @dob.widths.each do |x| x=(x.to_i * textwidth)/100 col_w=x.to_s # x.gsub(/.+/,'l\|') #unless x.nil? colW << "p{#{col_w}mm}" if col_w end colW << '}' colW=colW.join start_table="\n\\setlength{\\LTleft}{0pt}\n\\setlength{\\LTright}{\\fill}\n" + "\\begin{tiny}\n\\begin{longtable}#{colW}\n" rows=@dob.obj.split(/#{Mx[:br_nl]}/) if @dob.head_ #result imperfect, check on rows[0].gsub!(/(^|.+?)(?:#{Mx[:tc_p]}|$)/u,'\bfseries \1&') rows[0].gsub!(/&\s*$/," #{row_break} \\hline\\endhead #{row_break}") end rows.each do |r| r.gsub!(/#{Mx[:tc_p]}|$/,'&') r.gsub!(/$/," #{row_break}\n") unless r =~/#{row_break*2}$/ if r=~/\/ # not tested table footer if any tablefoot=$1 r.gsub!(/\/,'') r="#{r} \\multicolumn{#{@dob.cols}}{l}{\\tiny #{tablefoot}} \\\\ \\hline\n\\endfoot\n\\hline\n" end end table=rows.join #@dob[:dal].obj=rows.join ocn_display(@dob) + start_table + table + " #{end_table}\n\\end{tiny}" else '' end end def longtable_portrait end_table='\end{longtable}' row_break='\\\\\\' txt=if @dob.is=='table' tw=case @dob.tmp[:paper_size] when /a4/i; @tx.a4.portrait.w #European default, SiSU default when /letter/i; @tx.letter.portrait.w #U.S. default when /legal/i; @tx.legal.portrait.w #U.S. alternative when /book|b5/i; @tx.b5.portrait.w #book default - larger when /a5/i; @tx.a5.portrait.w else @tx.a4.portrait.w #default currently A4 end textwidth=tw.to_i - 20 colW=[] colW << '{' @dob.widths.each do |x| x=(x.to_i * textwidth)/100 #x=(x.to_i/100.0 * 160) col_w=x.to_s # x.gsub(/.+/,'l\|') #unless x.nil? colW << "p{#{col_w}mm}" if col_w end colW << '}' colW=colW.join start_table="\n\\setlength{\\LTleft}{0pt}\n\\setlength{\\LTright}{\\fill}\n" + "\\begin{tiny}\n\\begin{longtable}#{colW}\n" rows=@dob.obj.split(/#{Mx[:br_nl]}/) if @dob.head_ rows[0].gsub!(/(^|.+?)(?:#{Mx[:tc_p]}|$)/u,'\bfseries \1&') rows[0].gsub!(/&\s*$/," #{row_break} \\hline\\endhead #{row_break}") end rows.each do |r| r.gsub!(/#{Mx[:tc_p]}|$/u,'&') r.gsub!(/$/," #{row_break}\n") unless r =~/#{row_break*2}$/ if r=~/\/ # not tested table footer if any tablefoot=$1 r.gsub!(/\/,'') r="#{r} \\multicolumn{#{@dob.cols}}{l}{\\tiny #{tablefoot}} \\\\ \\hline\n\\endfoot\n\\hline\n" end end table=rows.join #@dob[:dal].obj=rows.join ocn_display(@dob) + start_table + table + " #{end_table}\n\\end{tiny}" else '' end end def heading_major dob=@dob title=@md.title.full dob.tmp.strip! if dob.tmp dob.tmp.gsub!(/(?:\\begin\{bfseries\}|\\begin\{itshape\})(.+?)(?:\\end\{bfseries\}|\\end\{itshape\})/m,'\1') cont_ln=dob.tmp.dup cont_ln.gsub!(@@tex_pattern_margin_number,'') if dob.tmp =~/\\[Ff]ootnote/ #and dob =~/^[1-6]#{Tex[:tilde]}/ # removing footnotes from headings! cont_ln.gsub!(/\s*\\footnote\[\d+\]\{%\n .+? \}\s*/,' ') cont_ln.gsub!(/\s*\\Footnote[A]\{[*+]+\d*\}\{%\n .+? \}\s*/,' ') end dob.tmp.gsub!(/^(.*)\n?$/m, "\\part*{\\1} \\addcontentsline{toc}{section}{#{cont_ln}} \\markboth{#{title}}\n") dob end def level4 dob=@dob dob.tmp.strip! if dob.tmp dob.tmp.gsub!(/(?:\\begin\{bfseries\}|\\begin\{itshape\})(.+?)(?:\\end\{bfseries\}|\\end\{itshape\})/m,'\1') cont_ln=dob.tmp.dup cont_ln.gsub!(@@tex_pattern_margin_number,'') cont_ln.gsub!(/#{Tex[:backslash]*2}/,"#{Tex[:backslash]*4}") # added w42 cont_ln.gsub!(/\\footnote\[\d+\]\{%.+?\\end\{scriptsize\}\s*\}/m,'') #arbitrary bugfix, revisit should not be necessary, eg. wta.1994 2004w22 cont_ln.gsub!(/\\Footnote[A]\{[*+]+\d*\}\{%.+?\\end\{scriptsize\}\s*\}/m,'') #arbitrary bugfix, revisit should not be necessary, eg. wta.1994 2004w22 title=@md.title.full if dob.name =~/endnotes/ dob.tmp.gsub!(/.+/m,'') end if dob.tmp =~/\\footnote/ #and dob =~/^[1-6]#{Tex[:tilde]}/ # removing footnotes from headings! cont_ln.gsub!(/\s*\\footnote\[\d+\]\{%\n .+? \}\s*/,' ') cont_ln.gsub!(/\s*\\Footnote[A]\{[*+]+\d*\}\{%\n .+? \}\s*/,' ') end dob.tmp.gsub!(/^(.*)?\n?$/m,"\\subsubsection*{\\1} \\addcontentsline{toc}{subsection}{#{cont_ln}} \\markright{#{title}}") dob end def level5 dob=@dob # there is a problem here with creation of headers does not do what you would want it to header starts with a * and is not in bold work on \\@txt*, same for next section 2002w46 dob.tmp.strip! if dob.tmp dob.tmp.gsub!(/(?:\\begin\{bfseries\}|\\begin\{itshape\})(.+?)(?:\\end\{bfseries\}|\\end\{itshape\})/m,'\1') cont_ln=dob.tmp.dup cont_ln.gsub!(@@tex_pattern_margin_number,'') cont_ln.gsub!(/\\footnote\[\d+\]\{%.+?\\end\{scriptsize\}\s*\}/m,'') #arbitrary bugfix, revisit should not be necessary, eg. wta.1994 2004w22 cont_ln.gsub!(/\\Footnote[A]\{[*+]+\d*\}\{%.+?\\end\{scriptsize\}\s*\}/m,'') #arbitrary bugfix, revisit should not be necessary, eg. wta.1994 2004w22 cont_ln.gsub!(/\\\&/,' and ') #revisit: tmp bugfix 200507, substitutes & with 'and' in toc, needed e.g. for AT&T, see ffa if dob.tmp =~/\\footnote/ #and dob =~/^[1-6]#{Tex[:tilde]}/ # removing footnotes from headings! cont_ln.gsub!(/\s*\\footnote\[\d+\]\{%\n .+? \}\s*/,' ') cont_ln.gsub!(/\s*\\Footnote[A]\{[*+]+\d*\}\{%\n .+? \}\s*/,' ') end dob.tmp.gsub!(/^(.*)?\n?$/m, "\\subsubsection*{\\1} \\addcontentsline{toc}{subsubsection}{#{cont_ln} \\\\ }") dob end def level6 dob=@dob # there is a problem here with creation of headers does not do what you would want it to header starts with a * and is not in bold work on \\sub@txt*, same for previous section 2002w46 dob.tmp.strip! if dob.tmp dob.tmp.gsub!(/(?:\\begin\{bfseries\}|\\begin\{itshape\})(.+?)(?:\\end\{bfseries\}|\\end\{itshape\})/m,'\1') cont_ln=dob.tmp.dup cont_ln.gsub!(@@tex_pattern_margin_number,'') cont_ln.gsub!(/\\footnote\[\d+\]\{%.+?\\end\{scriptsize\}\s*\}/m,'') #arbitrary bugfix, revisit should not be necessary, eg. wta.1994 2004w22 cont_ln.gsub!(/\\Footnote[A]\{[*+]+\d*\}\{%.+?\\end\{scriptsize\}\s*\}/m,'') #arbitrary bugfix, revisit should not be necessary, eg. wta.1994 2004w22 if dob.tmp =~/\\footnote/ #and dob =~/^[1-6]#{Tex[:tilde]}/ # removing footnotes from headings! cont_ln.gsub!(/\s*\\footnote\[\d+\]\{%\n .+? \}\s*/,' ') cont_ln.gsub!(/\s*\\Footnote[A]\{[*+]+\d*\}\{%\n .+? \}\s*/,' ') end dob.tmp.gsub!(/^(.*)?\n?$/m, '\subsubsection*{\1}') dob end def indent indent=case @dob.indent when /1/; '0mm' when /2/; '10mm' when /3/; '20mm' when /4/; '30mm' when /5/; '40mm' when /6/; '50mm' when /7/; '60mm' when /8/; '70mm' when /9/; '80mm' end "\\begin{ParagraphIndent}{#{indent}}#{@dob.tmp} \\end{ParagraphIndent}}" #"\\begin{ParagraphIndent}{#{indent}}#{@dob.tmp}\\end{ParagraphIndent}}" end def symbol_graphic dir=SiSU_Env::Info_env.new(@md.fns) image='c_' + /<:=\s*(\S+?)\s*>/m.match(@txt).captures.join + '.png' #watch if FileTest.file?("#{dir.path.image_source_tex}/#{image}") @txt.gsub!(/<:=\s*(\S+?)\s*>/, "\\includegraphics*[width=11pt]{#{dir.path.image_source_tex}/c_\\1.png}") else SiSU_Screen::Ansi.new(@md.cmd,"ERROR - image:",%{"#{image}" missing},"search path: #{dir.path.image_source_tex}").error2 unless @md.cmd =~/q/ @txt.gsub!(/#{Mx[:lnk_o]}\S+\.(png|jpg|gif).+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/,'') # fragile match operator\\ fragile ! end end def image dir=SiSU_Env::Info_env.new(@md.fns) image,m=/#{Mx[:lnk_o]}\s*(\S+)\s+.+?width=``(\d+)''.+?#{Mx[:lnk_c]}/m.match(@txt).captures width=m[1] || '100' width=width.to_i*0.4 image_source=if @md.fns =~/\.(?:ssm\.)?sst$/ \ and FileTest.file?("#{dir.path.image_source_local_tex}/#{image}") dir.path.image_source_local_tex elsif @md.fns =~/\.-ss[tm]$/ \ and FileTest.file?("#{dir.path.image_source_remote_tex}/#{image}") dir.path.image_source_remote_tex elsif FileTest.file?("#{dir.path.image_source_tex}/#{image}") dir.path.image_source_tex else SiSU_Screen::Ansi.new(@md.cmd,"ERROR - image:",%{"#{image}" missing},"search locations: #{dir.path.image_source_local_tex},#{dir.path.image_source_remote_tex} and #{dir.path.image_source_tex}").error2 unless @md.cmd =~/q/ nil end if image_source #CHECK @txt.gsub!(/#{Mx[:lnk_o]}\s*(\S+)\s+.+?#{Mx[:lnk_c]}/, @center_begin + "\\includegraphics*[width=#{width}pt]{#{image_source}/\\1}" + @center_end ) else @txt.gsub!(/#{Mx[:lnk_o]}\s*(\S+)\s+.+?#{Mx[:lnk_c]}/,'\1}') end end def png(ps='') #fc missing image check dir=SiSU_Env::Info_env.new(@md.fns) # messy clean up z=@txt[/#{Mx[:lnk_o]}(\S.+?)#{Mx[:lnk_c]}(?:image|png)/,1].strip if @txt =~ /#{Mx[:lnk_o]}\S.+?#{Mx[:lnk_c]}(?:image|png)/ # match operator for z \\ fragile ! if z #debug 2004w14 image=z[/(\S+?\.(?:png|jpg|gif)\b)/m] image.gsub!(/\\/,'') width=if z =~ /\d+x\d*/ w=(z[/(\d+)x\d*/,1]).to_i w*0.8 else '100' #revisit, is bug for small images/icons end width='380' if width.to_i > 380 c=z[/``(.+?)''/m] end hsp="\n{\\color{mywhite} .}&~\n" # ~ character for hardspace caption="{\\\\\\\ \n\\begin{scriptsize}#{hsp*3}#{c}\\end{scriptsize}&}" if c image_source=if @md.fns =~/\.(?:ssm\.)?sst$/ \ and FileTest.file?("#{dir.path.image_source_local_tex}/#{image}") dir.path.image_source_local_tex elsif @md.fns =~/\.-ss[tm]$/ \ and FileTest.file?("#{dir.path.image_source_remote_tex}/#{image}") dir.path.image_source_remote_tex elsif FileTest.file?("#{dir.path.image_source_tex}/#{image}") dir.path.image_source_tex else unless image.nil? \ or image.length < 2 SiSU_Screen::Ansi.new(@md.cmd,"ERROR - image:",%{"#{image}" missing},"search locations: #{dir.path.image_source_local_tex},#{dir.path.image_source_remote_tex} and #{dir.path.image_source_tex}").error2 unless @md.cmd =~/q/ end nil end if image_source @txt.gsub!(/#{Mx[:lnk_o]}\S+\.(png|jpg|gif).+?#{Mx[:lnk_c]}(image|png)/, # fragile match operator\\ fragile ! "#{@center_begin}\n\\includegraphics*[width=#{width}pt]{#{image_source}/#{image}}#{caption}#{@center_end}") else @txt.gsub!(/#{Mx[:lnk_o]}\S+\.(png|jpg|gif).+?#{Mx[:lnk_c]}(image|png)/,'') end end def url_str_internal(str,idx=nil) map_nametags=SiSU_Particulars::Combined_singleton.instance.get_map_nametags(@md).nametags_map #p map_nametags url_generic_rgx=/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/m url_relative_rgx=/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:rel_o]}\.\.\/\S+?#{Mx[:rel_c]}/m url_internal_rgx=/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:rel_o]}#?\S+?#{Mx[:rel_c]}/m while str =~/#{Mx[:lnk_o]}([^#{Mx[:lnk_o]}#{Mx[:lnk_c]}]+)#{Mx[:lnk_c]}#{Mx[:rel_o]}(\.\.\/\S+?)#{Mx[:rel_c]}/m link,url=$1,$2 link,url=link.strip,url.strip link.gsub!(/&/,"#{Xx[:protect]}&") url.gsub!(/^(\.\.\/)/,"#{@env.url.root}/") str.sub!(/#{Mx[:lnk_o]}[^#{Mx[:lnk_o]}#{Mx[:lnk_c]}]+#{Mx[:lnk_c]}#{Mx[:rel_o]}\.\.\/\S+?#{Mx[:rel_c]}/m,"#{@brace_rel.tex_open}\\href{#{url}}{#{link}}#{@brace_rel.tex_close}") end while str =~/#{Mx[:lnk_o]}([^#{Mx[:lnk_o]}#{Mx[:lnk_c]}]+)#{Mx[:lnk_c]}#{Mx[:rel_o]}#?(\S+?)#{Mx[:rel_c]}/m link,url=$1,$2 link,url=link.strip,url.strip link.gsub!(/&/,"#{Xx[:protect]}&") ocn_lnk=(url=~/^\d+$/ ? url : (map_nametags[url][:ocn])) if not ocn_lnk.empty? idx \ ? (str.sub!(url_internal_rgx,"\\hyperlink{#{ocn_lnk}}{#{link}}")) \ : (str.sub!(url_internal_rgx,"#{@brace_rel.tex_open}\\hyperlink{#{ocn_lnk}}{#{link}}#{@brace_rel.tex_close}")) else puts %{name tag: "#{url}" not found} str.sub!(url_internal_rgx,"#{link}") end #[keep] code that follows uses nametags directly, currently nametags converted to their ocn, related code: |texpdf.rb|@|hypertargets| #idx \ #? (str.sub!(url_internal_rgx,"\\hyperlink{#{url}}{#{link}}")) \ #: (str.sub!(url_internal_rgx,"#{@brace_rel.tex_open}\\hyperlink{#{url}}{#{link}}#{@brace_rel.tex_close}")) end str.gsub!(/#{Xx[:protect]}/,'') str end def url_str(str) url_generic_rgx=/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/m while str =~url_generic_rgx if str=~url_generic_rgx regx_url=%r/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/m z,url=regx_url.match(str).captures if str =~regx_url url=url.strip link=z.strip link.gsub!(/&/,"#{Xx[:protect]}&") str.sub!(url_generic_rgx,"#{@brace_rel.tex_open}\\href{#{url}}{#{link}}#{@brace_rel.tex_close}") str.gsub!(/#{Xx[:protect]}/,'') str else str end str end str end def url_with_txt(dob) url_generic_rgx=/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/m while dob.tmp =~url_generic_rgx if dob.tmp=~url_generic_rgx if dob.tmp =~/#{Mx[:lnk_o]}(?:.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/m regx_url=%r/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/m punctuate=/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/m.match(dob.tmp).captures.join else regx_url=%r/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/m punctuate='' end z,url=regx_url.match(dob.tmp).captures if dob.tmp =~regx_url url=url.strip link=z.strip link.gsub!(/&/,"#{Xx[:protect]}&") dob.tmp.sub!(url_generic_rgx,"#{@brace_rel.tex_open}\\href{#{url}}{#{link}}#{@brace_rel.tex_close}#{punctuate}") dob.tmp.gsub!(/#{Xx[:protect]}/,'') dob else dob end dob end dob end def urls_txt_and_images dob=@dob dir=SiSU_Env::Info_env.new(@md.fns) @dm={ 'a4'=> @tx.a4.landscape.img_px, 'letter'=> @tx.letter.landscape.img_px, 'legal'=> @tx.legal.landscape.img_px, 'b5'=> @tx.b5.landscape.img_px, 'a5'=> @tx.a5.landscape.img_px } images_hash={ } generic_rgx=/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image\b)/m url_generic_rgx=/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/m url_bare_rgx=/#{Mx[:url_o]}\S+?#{Mx[:url_c]}/m url_image_rgx=/#{Mx[:lnk_o]}[a-zA-Z0-9_\\-]+\.(?:png|jpg|gif).+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/m image_rgx=/#{Mx[:lnk_o]}[a-zA-Z0-9_\\-]+\.(?:png|jpg|gif).+?#{Mx[:lnk_c]}image/m @md.papersize_array.each do |ps| images_hash[ps] = dob.tmp while images_hash[ps] =~generic_rgx if dob.tmp =~url_generic_rgx \ and dob.tmp !~/\.(?:png|jpg|gif)|#{Mx[:lnk_c]}image\b/m dob=url_with_txt(dob) elsif images_hash[ps]=~generic_rgx if dob.tmp=~url_generic_rgx if images_hash[ps] =~/#{Mx[:lnk_o]}(?:.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/m regx_url=%r/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/m punctuate=/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/m.match(images_hash[ps]).captures.join else regx_url=%r/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/m punctuate='' end z,url=regx_url.match(images_hash[ps]).captures if images_hash[ps] =~regx_url url=url.strip else if images_hash[ps] =~/#{Mx[:lnk_o]}(?:.+?)#{Mx[:lnk_c]}image\.[^'"\s]+?(?:[;.,]?(?:\s|$)|(?:\s|$))/m regx_url=%r/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}image\.[^'"\s]+?(?:[;.,]?(?:\s|$)|(?:\s|$))/m punctuate=/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}image\.[^'"\s]+?([;.,]?(?:\s|$))/m.match(images_hash[ps]).captures.join else regx_url=%r/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}image/m punctuate='' end z=regx_url.match(images_hash[ps])[1] if images_hash[ps] =~regx_url url='' end if images_hash[ps] =~/#{Mx[:lnk_o]}\s*\S+\.?(?:png|jpg|gif)/m \ and images_hash[ps]=~/\s+\d+x\d+(\s+|\s*#{Mx[:lnk_c]})/m image,x,y=z.scan(/\S+/) image.gsub!(/\\/,'') w=((z =~/(\d+)x\d*/) ? z[/(\d+)x\d*/,1] : 200) width={} width['a4'] = ((w.to_i > @dm['a4']) ? @dm['a4'] : w) width['letter'] = ((w.to_i > @dm['letter']) ? @dm['letter'] : w) width['legal'] = ((w.to_i > @dm['legal']) ? @dm['legal'] : w) width['a5'] = ((w.to_i > @dm['a5']) ? @dm['a5'] : w) width['b5'] = ((w.to_i > @dm['b5']) ? @dm['b5'] : w) c=z[/``(.+?)''/m,1] hsp="\n{\\color{mywhite} .}&~\n" # ~ character for hardspace caption=(c ? "{\\\\\ \n\\begin{scriptsize}#{hsp*3}#{c}\\end{scriptsize}&}" : '') elsif images_hash[ps] =~/#{Mx[:lnk_o]}\s*(\S+\.?\.(?:png|jpg|gif))/m SiSU_Screen::Ansi.new(@md.cmd,%{document built without image: "#{$1}" as image dimensions not provided (either image not found or neither imagemagick nor graphicsmagick is installed)?\n}).print_grey #unless @opt.cmd =~/q/ images_hash[ps].gsub!(/#{Mx[:lnk_o]}\s*(\S+\.?\.(?:png|jpg|gif))/,'[image]') end if image #most images fc etc. #% clean up ! if @md.fns =~/\.(?:ssm\.)?sst$/ \ and FileTest.file?("#{dir.path.image_source_local_tex}/#{image}") case images_hash[ps] when url_image_rgx images_hash[ps].sub!(url_image_rgx, "#{@center_begin}\\\n\\href{#{url}}{\\includegraphics*[width=#{width[ps]}pt]{#{dir.path.image_source_local_tex}/#{image}}}#{caption} #{@center_end}") when image_rgx images_hash[ps].sub!(image_rgx, "#{@center_begin}\\\n\\includegraphics*[width=#{width[ps]}pt]{#{dir.path.image_source_local_tex}/#{image}}#{caption} #{@center_end}") end images_hash[ps] elsif @md.fns =~/\.-ss[tm]$/ \ and FileTest.file?("#{dir.path.image_source_remote_tex}/#{image}") case images_hash[ps] when url_image_rgx images_hash[ps].sub!(url_image_rgx, "#{@center_begin}\\\n\\href{#{url}}{\\includegraphics*[width=#{width[ps]}pt]{#{dir.path.image_source_remote_tex}/#{image}}}#{caption}#{@center_end}") when image_rgx images_hash[ps].sub!(image_rgx, "#{@center_begin}\\\n\\includegraphics*[width=#{width[ps]}pt]{#{dir.path.image_source_remote_tex}/#{image}}#{caption}#{@center_end}") end images_hash[ps] elsif FileTest.file?("#{dir.path.image_source_tex}/#{image}") case images_hash[ps] when url_image_rgx images_hash[ps].sub!(url_image_rgx, "#{@center_begin}\\\n\\href{#{url}}\n{\\includegraphics*[width=#{width[ps]}pt]{#{dir.path.image_source_tex}/#{image}}}#{caption}#{@center_end}") when image_rgx images_hash[ps].sub!(image_rgx, "#{@center_begin}\\\n\\includegraphics*[width=#{width[ps]}pt]{#{dir.path.image_source_tex}/#{image}}#{caption}#{@center_end}") end images_hash[ps] else SiSU_Screen::Ansi.new(@md.cmd,"ERROR - image:",%{"#{image}" missing},"search locations: #{dir.path.image_source_local_tex},#{dir.path.image_source_remote_tex} and #{dir.path.image_source_tex}").error2 unless @md.cmd =~/q/ if images_hash[ps] =~url_image_rgx \ or images_hash[ps] =~image_rgx images_hash[ps]='' end images_hash[ps] end else link=z.strip #[/(.+?)\\/m,1] images_hash[ps]="\\href{#{url}}{#{link}}#{punctuate}" if images_hash[ps] =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/ images_hash[ps] end else images_hash[ps] end images_hash[ps] #=ocn_display(dob) + images_hash[ps] end #while loop images_hash end images_hash use_images_hash={} images_hash.each do |k,t| use_images_hash[k]={ :l =>t, :p =>t} end dob.tmp=use_images_hash dob end def title title=SiSU_TeX_Pdf::Special_characters.new(@md,@md.title.full).special_characters_safe "\n\\title{#{title}}" end def title_landscape title end def title_portrait title end end class Format_head def initialize(md,t_o) @md,@t_o=md,t_o if t_o.class==Hash @txt =t_o[:txt] || nil @subtitle=t_o[:subtitle] || nil @ps=t_o[:paper_size] || nil @ocn=t_o[:ocn] || nil @layout=t_o[:orientation] || nil else p t_o.class p caller end @tx=SiSU_Env::Get_init.instance.tex @brace_url=SiSU_Viz::Skin.new.url_decoration @tex2pdf=@@tex3pdf ||=SiSU_Env::System_call.new.tex2pdf_engine @ps=@txt if @txt=~/(?:a4|letter|legal|book|a5|b5)/i end def language @lang=if @md.language[:code] case @md.language[:code] when 'en'; 'english' when 'us'; 'USenglish' # depreciated, see iso-639-2 when 'fr'; 'french' when 'de'; 'ngerman' when 'it'; 'italian' when 'es'; 'spanish' when 'pt'; 'portuges' #when 'br'; 'brazilian' # depreciated, see iso-639-2 when 'sv'; 'swedish' when 'da'; 'danish' when 'fi'; 'finnish' when 'no'; 'norske,nynorsk' when 'is'; 'icelandic' when 'nl'; 'dutch' when 'et'; 'estonian' when 'hu'; 'magyar' when 'pl'; 'polish' when 'ro'; 'romanian' when 'ru'; 'russian' when 'gl'; 'greek' when 'uk'; 'ukrainian' when 'tr'; 'turkish' when 'sk'; 'slovak' when 'sl'; 'slovenian' when 'hr'; 'croatian' when 'cs'; 'czech' when 'bg'; 'bulgarian' else 'english' end else 'english' end end def tex_head_lang #babel 18n language lang=if @lang =~/^(?:en)$/; @lang else "#{@lang},english" end end def tex_head_encode case @tex2pdf when /xe/ <') w.gsub!(/[#{Mx[:br_line]}#{Mx[:br_paragraph]}]/,' \newline ') #watch w.gsub!(/#{Mx[:gl_o]}#(?:126|152)#{Mx[:gl_c]}/,'<=tilde>') #126 usual w.gsub!(/\\?\||#{Mx[:gl_o]}#124#{Mx[:gl_c]}/,'<=pipe>') #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!(/&(?:nbsp);|#{Mx[:nbsp]}/,'<=hardspace>') unless is=='code' # < SiSU special character also LaTeX str.gsub!(/&(?:lt|#060);/,'<=lt>') # < SiSU special character also LaTeX str.gsub!(/#{Mx[:gl_o]}#(?:gt|062)#{Mx[:gl_c]}/,'<=gt>') # > SiSU special character also LaTeX str.gsub!(/#{Mx[:gl_o]}#123#{Mx[:gl_c]}/,'<=curlyopen>') # { SiSU special character also LaTeX str.gsub!(/#{Mx[:gl_o]}#125#{Mx[:gl_c]}/,'<=curlyclose>') # } SiSU special character also LaTeX str.gsub!(/#{Mx[:gl_o]}#(?:126|152)#{Mx[:gl_c]}/,'<=tilde>') # ~ 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!(/#{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]}/,'<=amp>') #unless @txt=~/<:code>/ # / SiSU special character also LaTeX str.gsub!(/#{Mx[:gl_o]}#047#{Mx[:gl_c]}/,'<=slash>') # / SiSU special character also LaTeX str.gsub!(/#{Mx[:gl_o]}#092#{Mx[:gl_c]}/,'<=backslash>') # \ SiSU special character also LaTeX str.gsub!(/#{Mx[:gl_o]}#095#{Mx[:gl_c]}/,'<=underscore>') # _ 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]}|\^/,'<=caret>') # ^ SiSU not really special sisu character but done, also LaTeX str.gsub!(/\#/,'<=hash>') ##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_2(str,is='') str.gsub!(/#{Mx[:gl_o]}#156#{Mx[:gl_c]}/,'\oe ') str.gsub!(/\$/,'\$') str.gsub!(/\#/,'\#') str.gsub!(/\%/,'\%') str.gsub!(/\~/,'\~') #revist, should not be necessary to mark remaining tildes if str !~/^\s*#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}image\s/ str.gsub!(/_/,'\_') end str.gsub!(/\{/,'\{') str.gsub!(/\}/,'\}') if is=='code' str.gsub!(/&/,'{\\\&}') str.gsub!(/\\~(\\\{)/,'{$\tilde$}\1') str.gsub!(/(\\\})\\~/,'\1{$\tilde$}') str.gsub!(/\\~(\[)/,'{$\tilde$}\1') str.gsub!(/(\])\\~/,'\1{$\tilde$}') str.gsub!(/<=tilde>/,'{$\tilde$}') str.gsub!(/<=pipe>/,'{\textbar}') str.gsub!(/<=caret>/,'{\^{~}}') str.gsub!(/<=hash>/,'{\#}') else str.gsub!(/ |#{Mx[:nbsp]}/,'~') # ~ character for hardspace str.gsub!(/&/,'<=amp>') end str.gsub!(/&\S+?;/,' ') str.gsub!(/§/u,'\S') #latex: space between next character not preserved? #str.gsub!(/§ /,'\S ') str.gsub!(/£/u,'\pounds') str.gsub!(//,' ') str.gsub!(/<\/a>/,' ') str.gsub!(/((?:^|\s)#{Mx[:lnk_c]})#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, '\1\begin{scriptsize}\url{\2}\end{scriptsize}\3') #special case \{ e.g. \}http://url str.gsub!(/#{Mx[:url_o]}\\_(\S+?)#{Mx[:url_c]}/, '\begin{scriptsize}\url{\1}\end{scriptsize}') #special case \{ e.g. \}http://url str.gsub!(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/, '\begin{scriptsize}\\url{\1}\end{scriptsize}') #specially escaped url no decoration unless is=='code' str.gsub!(/(^|#{Mx[:gl_c]}|\s)((?:https?|file|ftp):\/\/\S+?\.[^'"\s]+?)([;.,]?(?=\s|$))/, "\\1#{@brace_url.tex_open}\\begin{scriptsize}\\url{\\2}\\end{scriptsize}#{@brace_url.tex_close}\\3") #url matching with decoration positive lookahead, sequence issue with { linked }http://url cannot use \b at start else #code-block: angle brackets special characters, note _ already escaped str.gsub!(/\\_/m,'{\UseTextSymbol{OML}{>}}') end str.gsub!(/<:ee>/,'') str.gsub!(//,' ') #proposed change, insert, but may be redundant str.gsub!(/<(br|p)>|<\/\s*(br|p)>|<(br|p)\s*\/>/," #{Tex[:backslash]*2} ") # Work Area str.gsub!(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/,'\begin{bfseries}\1 \end{bfseries}') str.gsub!(/(.+?)<\/h\d+>/,'\begin{bfseries}\1 \end{bfseries}') str.gsub!(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/,'\emph{\1}') str.gsub!(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/,'\uline{\1}') # ulem str.gsub!(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,"``\\1''") # quote #CHECK str.gsub!(/#{Mx[:fa_insert_o]}(.+?)#{Mx[:fa_insert_c]}/,'\uline{\1}') # ulem str.gsub!(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/,'\sout{\1}') # ulem str.gsub!(/#{Mx[:fa_superscript_o]}(.+?)#{Mx[:fa_superscript_c]}/,"\$^{\\textrm{\\1}}\$") str.gsub!(/#{Mx[:fa_subscript_o]}(.+?)#{Mx[:fa_subscript_c]}/,"\$_{\\textrm{\\1}}\$") unless is=='code' str.gsub!(/"(.+?)"/,'“\1”') # quote marks / quotations open & close " need condition exclude for code str.gsub!(/\s+"/,' “') # open " str.gsub!(/^(#{Mx[:lv_o]}[1-6-]:\S*?#{Mx[:lv_c]}|<.+?>)?\s*"/,'\1“') #fix Mx[:lv_o] # open " str.gsub!(/"(\s|\.|,|:|;)/,'”\1') # close " str.gsub!(/"(#{Mx[:lv_o]}[1-6-]:\S*?#{Mx[:lv_c]}|<.+?>)?\s*$/,'”\1') #fix Mx[:lv_o] # close " str.gsub!(/"(\.|,)/,'”') # close " str.gsub!(/\s+'/,' `') # open ' str.gsub!(/^(#{Mx[:lv_o]}[1-6-]:\S*?#{Mx[:lv_c]}|<.+?>)?\s*'/,'\1`') #fix Mx[:lv_o] # open ' end str.gsub!(/(|<\/font>)/,'') str.gsub!(/\s*#{Mx[:fa_superscript_o]}(\S+?)#{Mx[:fa_superscript_c]}/,'^\1') str end def xetex_special_characters_3(str) str.gsub!(/])/,'\1') # clean up, incredibly messy :-( footnote indents, problems if match exists in ordinary paragraphs? check! Work Area 200501 a bit tricky as must be able to match multiple times, and to clean remainder str.gsub!(/([^<][^b][^r]\s+)\/>/,'\1') # clean up, incredibly messy :-( footnote indents, problems if match exists in ordinary paragraphs? check! Work Area 200501 a bit tricky as must be able to match multiple times, and to clean remainder #problem sequence (another kludge) -> str.gsub!(/<=lt>/m,'{\UseTextSymbol{OML}{<}}') str.gsub!(/<=gt>/m,'{\UseTextSymbol{OML}{>}}') str.gsub!(/<=underscore>/,'\_') while str =~/(http:\/\/\S+?)(?:<=tilde>\S+)+/ #tilde in urls \href treated differently from text #FIX str.gsub!(/(http:\/\/\S+?)(?:<=tilde>(\S+))+/,'\1~\2') end str.gsub!(/<=tilde>/,'{$\tilde$}') str.gsub!(/<=pipe>/,'{\textbar}') str.gsub!(/<=caret>/,'{\^{~}}') str.gsub!(/<=exclaim>/,'\Verbatim{!}') str.gsub!(/(http:\/\/\S+?)(?:(?:<=hash>)(\S+))+/,'\1#\2') #hash in urls \href treated differently from text #FIX str.gsub!(/<=hash>/,'{\#}') str.gsub!(/<=hardspace>/,'{~}') #changed ... 2005 while str =~/(http:\/\/\S+?)(?:<=amp>\S+)+/ #amp in urls \href treated differently from text #FIX str.gsub!(/(http:\/\/\S+?)(?:<=amp>(\S+))+/,'\1&\2') end str.gsub!(/<=amp>/,'{\\\&}') #changed ... 2005 str.gsub!(/<=slash>/,'{/}') str.gsub!(/<=backslash>/,'{\textbackslash}') str.gsub!(/<=copymark>\s*(.+)/, '^\copyright \textnormal{\1} \2') # watch likely to be problematic str end def special_characters_curly(str) str.gsub!(/<=curlyopen>/,'\{') str.gsub!(/<=curlyclose>/,'\}') str end def special_characters_code_fix(str) str.gsub!(/<=hardspace>/,'{~}') str.gsub!(/<=pipe>/,'{\textbar}') str.gsub!(/<=tilde>/,'{$\tilde$}') str end def special_characters_unsafe_1(str) #depreciated, make obsolete # some substitutions are sequence sensitive, rearrange with care. str.gsub!(/\\backslash (copyright|clearpage|newpage)/,"\\\\\\1") #kludge bad solution, find out where tail is sent through specChar ! str end def special_characters #special characters - some substitutions are sequence sensitive, rearrange with care. str,is=@txt,@is str=xetex_special_characters_1(str,is) unless str.nil? str=special_characters_unsafe_1(str) unless str.nil? #xetex_special_characters_unsafe_1(@txt) str=xetex_special_characters_2(str,is) unless str.nil? #issues with xetex str=xetex_special_characters_3(str) unless str.nil? @txt=str end def special_word_break_points str=@txt str.gsub!(/([_,.;:\/|=])/,'\1\-') #str.gsub!(/([_,.;:|=])/,'\1\-') @txt=str end def special_number_break_points str=@txt str=str.gsub(/([0-9a-f]{8})/i,'\1\-') @txt=str end def special_characters_safe #special characters - some substitutions are sequence sensitive, rearrange with care. str,is=@txt,@is str=xetex_special_characters_1(str,is) unless str.nil? str=xetex_special_characters_2(str,is) unless str.nil? # remove this to start with, causes issues @txt=str end end class Use_TeX attr_accessor :url,:txt,:date def initialize(md) @md=md @vz=SiSU_Env::Get_init.instance.skin @date=SiSU_Env::Info_date.new # #{@date.year} @copymark='{\\begin{footnotesize}\\raisebox{1ex}{\\copyright}\\end{footnotesize}}' @brace_url=SiSU_Viz::Skin.new.url_decoration end def skip "\n\\vspace*{\\smallskipamount} \n" end def paraskip_normal '\setlength{\parskip}{1ex plus0.5ex minus0.2ex}' end def paraskip_small '\setlength{\parskip}{0.5ex plus0.2ex minus0.1ex}' end def paraskip_tiny '\setlength{\parskip}{0.1ex plus0.1ex minus0.1ex}' end def skip_small "\\smallskip{}" end def skip_small_vspace "\n\\vspace*{\\smallskipamount} \n" end def skip_small_footnote end def skip_medium "\n\\medskip{}\n\n" end def skip_dummy "\n" end def header "\\lhead[ ]{ }\n" + "\\chead[ \\fancyplain{} \\bfseries \\footnotesize \\leftmark ]{ \\fancyplain{} \\bfseries \\footnotesize \\rightmark }\n" + "\\rhead[ ]{ }\n" end def footer base_prog_txt=if @md.base_program case @md.base_program when /kdissert/i; " \\\\ \\href{http://freehackers.org/~tnagy/kdissert/}{Kdissert}" else '' end else '' end "\\lfoot[\\textrm{\\thepage}]{\\tiny \\href{#{@vz.url_sisu}}{#{@vz.txt_signature}}#{base_prog_txt}}\n" + "\\cfoot[\\href{#{@vz.url_home}}{#{@vz.url_txt}}]{\\href{#{@vz.url_home}}{#{@vz.url_txt}}}\n" + "\\rfoot[\\tiny \\href{#{@vz.url_sisu}}{#{@vz.txt_signature}}]{\\textrm{\\thepage}}\n" end def site "\\href{#{@vz.url_home}}{#{@vz.url_txt}}" end def sitename #owners site, eg freeculture, free.for.all, gutenberg etc. "\\href{#{@vz.url_home}}{#{@vz.txt_home}}" end def owner_chapter "Contact Details for Original Promulgating Authority" end #BOOK standard dimensions - 229x156 def newpage(orientation) case orientation when /landscape/ # using longtable latex package <