class SiSU_TeX_Pdf::FormatTextObject

Attributes

dir[RW]
orientation[RW]
string[RW]
string1[RW]
tex[RW]
url[RW]

Public Class Methods

new(md,dob=nil) click to toggle source
# File lib/sisu/texpdf_format.rb, line 91
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::GetInit.new.tex
  @env ||=SiSU_Env::InfoEnv.new(@md.fns)
  @tex2pdf=@@tex3pdf ||=SiSU_Env::SystemCall.new.tex2pdf_engine
  @make ||=SiSU_Env::ProcessingSettings.new(@md)
end

Public Instance Methods

bullet() click to toggle source
# File lib/sisu/texpdf_format.rb, line 469
def bullet
  blt=if @dob.indent
    indent=case @dob.indent
    when /1/ then '0em'
    when /2/ then '1.0em'
    when /3/ then '2.0em'
    when /4/ then '3.0em'
    when /5/ then '4.0em'
    when /6/ then '5.0em'
    when /7/ then '6.0em'
    when /8/ then '7.0em'
    when /9/ then '8.0em'
    else      '-1.0em'
    end
    "\\begin{Bullet}{#{indent}}$\\txtbullet$\\hspace{\\enspace}#{@dob.tmp}\\end{Bullet}"
  else
    "\\begin{Bullet}{-5mm}$\\txtbullet$\\hspace{\\enspace}#{@dob.tmp}\\end{Bullet}"
  end
  blt
end
hang() click to toggle source
# File lib/sisu/texpdf_format.rb, line 320
def hang
  case @dob.indent
  when /0/
    case @dob.hang
    when /0/ then indent,hang='0mm', '0mm'
    when /1/ then indent,hang='0mm','10mm'
    when /2/ then indent,hang='0mm','20mm'
    when /3/ then indent,hang='0mm','30mm'
    when /4/ then indent,hang='0mm','40mm'
    when /5/ then indent,hang='0mm','50mm'
    when /6/ then indent,hang='0mm','60mm'
    when /7/ then indent,hang='0mm','70mm'
    when /8/ then indent,hang='0mm','80mm'
    when /9/ then indent,hang='0mm','90mm'
    end
  when /1/
    case @dob.hang
    when /0/ then indent,hang='10mm','-10mm'
    when /1/ then indent,hang='10mm',  '0mm'
    when /2/ then indent,hang='10mm', '10mm'
    when /3/ then indent,hang='10mm', '20mm'
    when /4/ then indent,hang='10mm', '30mm'
    when /5/ then indent,hang='10mm', '40mm'
    when /6/ then indent,hang='10mm', '50mm'
    when /7/ then indent,hang='10mm', '60mm'
    when /8/ then indent,hang='10mm', '70mm'
    when /9/ then indent,hang='10mm', '80mm'
    end
  when /2/
    case @dob.hang
    when /0/ then indent,hang='20mm','-20mm'
    when /1/ then indent,hang='20mm','-10mm'
    when /2/ then indent,hang='20mm',  '0mm'
    when /3/ then indent,hang='20mm', '10mm'
    when /4/ then indent,hang='20mm', '20mm'
    when /5/ then indent,hang='20mm', '30mm'
    when /6/ then indent,hang='20mm', '40mm'
    when /7/ then indent,hang='20mm', '50mm'
    when /8/ then indent,hang='20mm', '60mm'
    when /9/ then indent,hang='20mm', '70mm'
    end
  when /3/
    case @dob.hang
    when /0/ then indent,hang='30mm','-30mm'
    when /1/ then indent,hang='30mm','-20mm'
    when /2/ then indent,hang='30mm','-10mm'
    when /3/ then indent,hang='30mm',  '0mm'
    when /4/ then indent,hang='30mm', '10mm'
    when /5/ then indent,hang='30mm', '20mm'
    when /6/ then indent,hang='30mm', '30mm'
    when /7/ then indent,hang='30mm', '40mm'
    when /8/ then indent,hang='30mm', '50mm'
    when /9/ then indent,hang='30mm', '60mm'
    end
  when /4/
    case @dob.hang
    when /0/ then indent,hang='40mm','-40mm'
    when /1/ then indent,hang='40mm','-30mm'
    when /2/ then indent,hang='40mm','-20mm'
    when /3/ then indent,hang='40mm','-10mm'
    when /4/ then indent,hang='40mm',  '0mm'
    when /5/ then indent,hang='40mm', '10mm'
    when /6/ then indent,hang='40mm', '20mm'
    when /7/ then indent,hang='40mm', '30mm'
    when /8/ then indent,hang='40mm', '40mm'
    when /9/ then indent,hang='40mm', '50mm'
    end
  when /5/
    case @dob.hang
    when /0/ then indent,hang='50mm','-50mm'
    when /1/ then indent,hang='50mm','-40mm'
    when /2/ then indent,hang='50mm','-30mm'
    when /3/ then indent,hang='50mm','-20mm'
    when /4/ then indent,hang='50mm','-10mm'
    when /5/ then indent,hang='50mm',  '0mm'
    when /6/ then indent,hang='50mm', '10mm'
    when /7/ then indent,hang='50mm', '20mm'
    when /8/ then indent,hang='50mm', '30mm'
    when /9/ then indent,hang='50mm', '40mm'
    end
  when /6/
    case @dob.hang
    when /0/ then indent,hang='60mm','-60mm'
    when /1/ then indent,hang='60mm','-50mm'
    when /2/ then indent,hang='60mm','-40mm'
    when /3/ then indent,hang='60mm','-30mm'
    when /4/ then indent,hang='60mm','-20mm'
    when /5/ then indent,hang='60mm','-10mm'
    when /6/ then indent,hang='60mm',  '0mm'
    when /7/ then indent,hang='60mm', '10mm'
    when /8/ then indent,hang='60mm', '20mm'
    when /9/ then indent,hang='60mm', '30mm'
    end
  when /7/
    case @dob.hang
    when /0/ then indent,hang='70mm','-70mm'
    when /1/ then indent,hang='70mm','-60mm'
    when /2/ then indent,hang='70mm','-50mm'
    when /3/ then indent,hang='70mm','-40mm'
    when /4/ then indent,hang='70mm','-30mm'
    when /5/ then indent,hang='70mm','-20mm'
    when /6/ then indent,hang='70mm','-10mm'
    when /7/ then indent,hang='70mm',  '0mm'
    when /8/ then indent,hang='70mm', '10mm'
    when /9/ then indent,hang='70mm', '20mm'
    end
  when /8/
    case @dob.hang
    when /0/ then indent,hang='80mm','-80mm'
    when /1/ then indent,hang='80mm','-70mm'
    when /2/ then indent,hang='80mm','-60mm'
    when /3/ then indent,hang='80mm','-50mm'
    when /4/ then indent,hang='80mm','-40mm'
    when /5/ then indent,hang='80mm','-30mm'
    when /6/ then indent,hang='80mm','-20mm'
    when /7/ then indent,hang='80mm','-10mm'
    when /8/ then indent,hang='80mm',  '0mm'
    when /9/ then indent,hang='80mm', '10mm'
    end
  when /9/
    case @dob.hang
    when /0/ then indent,hang='90mm','-90mm'
    when /1/ then indent,hang='90mm','-80mm'
    when /2/ then indent,hang='90mm','-70mm'
    when /3/ then indent,hang='90mm','-60mm'
    when /4/ then indent,hang='90mm','-50mm'
    when /5/ then indent,hang='90mm','-40mm'
    when /6/ then indent,hang='90mm','-30mm'
    when /7/ then indent,hang='90mm','-20mm'
    when /8/ then indent,hang='90mm','-10mm'
    when /9/ then indent,hang='90mm',  '0mm'
    end
  end
  "\\begin{ParagraphHang}{#{indent}}{#{hang}}#{@dob.tmp} \\end{ParagraphHang}}"
end
heading_dev_null(dob) click to toggle source
# File lib/sisu/texpdf_format.rb, line 252
def heading_dev_null(dob)
  dob.tmp,dob.obj='',''
  dob
end
heading_level_1() click to toggle source
# File lib/sisu/texpdf_format.rb, line 304
def heading_level_1
  if not @dob.use_ == :dummy
    heading_sublevels(@dob)
  else
    heading_dev_null(@dob)
  end
end
heading_level_2() click to toggle source
# File lib/sisu/texpdf_format.rb, line 311
def heading_level_2
  heading_sublevels(@dob)
end
heading_level_3() click to toggle source
# File lib/sisu/texpdf_format.rb, line 314
def heading_level_3
  heading_sublevels(@dob)
end
heading_level_4() click to toggle source
# File lib/sisu/texpdf_format.rb, line 317
def heading_level_4
  heading_sublevels(@dob)
end
heading_sublevels(dob) click to toggle source
# File lib/sisu/texpdf_format.rb, line 256
    def heading_sublevels(dob)
      if dob.lv=='1'
        sect='section'
        tocadd=%{\\addcontentsline{toc}{section}}
        pre=''
        post=''
        headadd=%{\n\\markright{#{@md.title.full}}}
      elsif dob.lv=='2'
        sect='subsection'
        tocadd=%{\\addcontentsline{toc}{subsection}}
        pre=''
        post=" \\\\\n"
        headadd=''
      elsif dob.lv=='3'
        sect='subsubsection'
        tocadd=%{\\addcontentsline{toc}{subsubsection}}
        pre='' #pre='~~~~'
        post=" \\\\\n"
        headadd=''
      end
      dob.tmp=dob.tmp.strip if dob.tmp
      dob.tmp=dob.tmp.gsub(/\\begin\{(bfseries|itshape)\}(.+?)\\end\{\1\}/m,'\2').
        gsub(/#{Mx[:url_o]}|#{Mx[:url_c]}/,'')
      cont_ln=dob.tmp.dup
      cont_ln=cont_ln.gsub(/\\begin\{(monosp)\}(.+?)\\end\{\1\}/m,'\2').
        gsub(@@tex_pattern_margin_number,'').
        gsub(/#{Tex[:backslash]*2}/,"#{Tex[:backslash]*4}"). # added w42
        gsub(/\\footnote\[\d+\]\{%.+?\\end\{scriptsize\}\s*\}/m,''). #arbitrary bugfix, revisit should not be necessary, eg. wta.1994 2004w22
        gsub(/\\Footnote[A]\{[*+]+\d*\}\{%.+?\\end\{scriptsize\}\s*\}/m,'') #arbitrary bugfix, revisit should not be necessary, eg. wta.1994 2004w22
      if dob.name =~/endnotes/
        dob.tmp=dob.tmp.gsub(/.+/m,'')
      end
      cont_ln=remove_footnotes(cont_ln)
      cont_ln=cont_ln.gsub(/\{[\\]+(&)\}/,'\\1')
      dob.tmp=dob.tmp.gsub(/^(.*)?\n?$/m,
        "\\#{sect}*{\\1}
#{tocadd}{#{pre}#{cont_ln}#{post}}#{headadd}")
      dob
    end
indent() click to toggle source
# File lib/sisu/texpdf_format.rb, line 455
def indent
  indent=case @dob.indent
  when /1/ then '0mm'
  when /2/ then '10mm'
  when /3/ then '20mm'
  when /4/ then '30mm'
  when /5/ then '40mm'
  when /6/ then '50mm'
  when /7/ then '60mm'
  when /8/ then '70mm'
  when /9/ then '80mm'
  end
  "\\begin{ParagraphIndent}{#{indent}}#{@dob.tmp} \\end{ParagraphIndent}}"
end
longtable_landscape() click to toggle source
# File lib/sisu/texpdf_format.rb, line 123
def longtable_landscape
  end_table='\end{longtable}'
  row_break='\\\\\\'
  if @dob.is==:table
    tw=case @dob.tmp[:paper_size]
    when /a4/i      then @tx.a4.landscape.w     #European default, SiSU default
    when /letter/i  then @tx.letter.landscape.w #U.S. default
    when /legal/i   then @tx.legal.landscape.w  #U.S. alternative
    when /book|b5/i then @tx.b5.landscape.w     #book default - larger
    when /a5/i      then @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]=rows[0].gsub(/(^|.+?)(?:#{Mx[:tc_p]}|$)/u,'\bfseries \1&').
        gsub(/&\s*$/," #{row_break} \\hline\\endhead #{row_break}")
    end
    rows_new=[]
    rows.each do |r|
      r=table_special_characters(r)
      r=r.gsub(/$/," #{row_break}\n") unless r =~/#{row_break*2}$/
      if r=~/\<!f(.+?)!\>/ # not tested table footer if any
        tablefoot=$1
        r=r.gsub(/\<!f(.+?)!\>/,'')
        r="#{r} \\multicolumn{#{@dob.cols}}{l}{\\tiny #{tablefoot}} \\\\ \\hline\n\\endfoot\n\\hline\n"
      end
      rows_new << r
    end
    table=rows_new.join #@dob[:ao].obj=rows.join
    ocn_display(@dob) + start_table + table + " #{end_table}\n\\end{tiny}"
  else ''
  end
end
longtable_portrait() click to toggle source
# File lib/sisu/texpdf_format.rb, line 168
def longtable_portrait
  end_table='\end{longtable}'
  row_break='\\\\\\'
  if @dob.is==:table
    tw=case @dob.tmp[:paper_size]
    when /a4/i      then @tx.a4.portrait.w     #European default, SiSU default
    when /letter/i  then @tx.letter.portrait.w #U.S. default
    when /legal/i   then @tx.legal.portrait.w  #U.S. alternative
    when /book|b5/i then @tx.b5.portrait.w     #book default - larger
    when /a5/i      then @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]=rows[0].gsub(/(^|.+?)(?:#{Mx[:tc_p]}|$)/u,'\bfseries \1&').
        gsub(/&\s*$/," #{row_break} \\hline\\endhead #{row_break}")
    end
    rows_new=[]
    rows.each do |r|
      r=table_special_characters(r)
      r=r.gsub(/$/," #{row_break}\n") unless r =~/#{row_break*2}$/
      if r=~/\<!f(.+?)!\>/ # not tested table footer if any
        tablefoot=$1
        r=r.gsub(/\<!f(.+?)!\>/,'')
        r="#{r} \\multicolumn{#{@dob.cols}}{l}{\\tiny #{tablefoot}} \\\\ \\hline\n\\endfoot\n\\hline\n"
      end
      rows_new << r
    end
    table=rows_new.join #@dob[:ao].obj=rows.join
    ocn_display(@dob) + start_table + table + " #{end_table}\n\\end{tiny}"
  else ''
  end
end
ocn_display(dob) click to toggle source
# File lib/sisu/texpdf_format.rb, line 104
def ocn_display(dob)
  show_ocn=(@make.build.ocn?) \
  ? dob.ocn
  : ''
  "\\begin{tiny}\\hspace{0mm}\\end{tiny}{\\marginpar{\\begin{tiny}\\hspace{0mm}\\hypertarget{#{dob.ocn}}{#{show_ocn}}\\end{tiny}}}" #ocn object citation numbering
end
remove_footnotes(cont_ln) click to toggle source
# File lib/sisu/texpdf_format.rb, line 213
def remove_footnotes(cont_ln)
  cont_ln=if cont_ln =~/\\[Ff]ootnote/m
    cont_ln.gsub(/\s*\\[Ff]ootnote\[\d+\]\{%\s+.+?\}\s*/m,' ').
      gsub(/\s*\\[Ff]ootnote[A]\{[*+]+\d*\}\{%\S+.+?\}\s*/m,' ')
  else cont_ln
  end
end
section_heading_level(dob) click to toggle source
# File lib/sisu/texpdf_format.rb, line 236
    def section_heading_level(dob)
      dob.tmp=dob.tmp.strip if dob.tmp
      dob.tmp=dob.tmp.gsub(/\\begin\{(bfseries|itshape)\}(.+?)\\end\{\1\}/m,'\2').
        gsub(/#{Mx[:url_o]}|#{Mx[:url_c]}/,'')
      cont_ln=dob.tmp.dup
      cont_ln=cont_ln.gsub(/\\begin\{(monosp)\}(.+?)\\end\{\1\}/m,'\2').
        gsub(@@tex_pattern_margin_number,'')
      cont_ln=remove_footnotes(cont_ln)
      cont_ln=cont_ln.gsub(/\{[\\]+(&)\}/,'\\1')
      dob.tmp=dob.tmp.gsub(/^(.*)\n?$/m,
        "\\clearpage
\\part*{\\1}
\\addcontentsline{toc}{part}{#{cont_ln}}
\\markboth{#{@md.title.full}}\n")
      dob
    end
section_heading_level_B() click to toggle source
# File lib/sisu/texpdf_format.rb, line 295
def section_heading_level_B
  section_heading_level(@dob)
end
section_heading_level_C() click to toggle source
# File lib/sisu/texpdf_format.rb, line 298
def section_heading_level_C
  section_heading_level(@dob)
end
section_heading_level_D() click to toggle source
# File lib/sisu/texpdf_format.rb, line 301
def section_heading_level_D
  section_heading_level(@dob)
end
symbol_graphic() click to toggle source
# File lib/sisu/texpdf_format.rb, line 489
def symbol_graphic
  dir=SiSU_Env::InfoEnv.new(@md.fns)
  image='c_' + /<:=\s*(\S+?)\s*>/m.match(@txt).captures.join + '.png' #watch
  if FileTest.file?("#{dir.path.image_source_include}/#{image}")
    @txt.gsub!(/<:=\s*(\S+?)\s*>/,
      "\\includegraphics*[width=11pt]{#{dir.path.image_source_include}/c_\\1.png}")
  else
    SiSU_Screen::Ansi.new(
      @md.opt.act[:color_state][:set],
      "ERROR - image:",
      %{"#{image}" missing},
      "search path: #{dir.path.image_source_include}"
    ).error2 unless @md.opt.act[:quiet][:set]==:on
    @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
table_special_characters(r) click to toggle source
# File lib/sisu/texpdf_format.rb, line 110
def table_special_characters(r)
  r=r.gsub(/#{Mx[:tc_p]}/mu,'&').
    gsub(/#{Mx[:tc_c]}/m,'\\\\\\').
    gsub(/%/,'\%').
    gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/,'\begin{bfseries}\1 \end{bfseries}').
    gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/,'\emph{\1}').
    gsub(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/,'\uline{\1}'). # ulem
    gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,"``\\1''"). # quote #CHECK
    gsub(/#{Mx[:fa_insert_o]}(.+?)#{Mx[:fa_insert_c]}/,'\uline{\1}'). # ulem
    gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/,'\sout{\1}'). # ulem
    gsub(/#{Mx[:fa_superscript_o]}(.+?)#{Mx[:fa_superscript_c]}/,"\$^{\\textrm{\\1}}\$").
    gsub(/#{Mx[:fa_subscript_o]}(.+?)#{Mx[:fa_subscript_c]}/,"\$_{\\textrm{\\1}}\$")
end
title() click to toggle source
# File lib/sisu/texpdf_format.rb, line 730
def title
  title=SiSU_TeX_Pdf::SpecialCharacters.new(@md,@md.title.full).special_characters_safe
  "\n\\title{#{title}}"
end
title_landscape() click to toggle source
# File lib/sisu/texpdf_format.rb, line 734
def title_landscape
  title
end
title_level_A() click to toggle source
# File lib/sisu/texpdf_format.rb, line 220
    def title_level_A
      dob=@dob
      dob.tmp=dob.tmp.strip if dob.tmp
      dob.tmp=dob.tmp.gsub(/\\begin\{(bfseries|itshape)\}(.+?)\\end\{\1\}/m,'\2').
        gsub(/#{Mx[:url_o]}|#{Mx[:url_c]}/,'')
      cont_ln=dob.tmp.dup
      cont_ln=cont_ln.gsub(/\\begin\{(monosp)\}(.+?)\\end\{\1\}/m,'\2').
        gsub(@@tex_pattern_margin_number,'')
      cont_ln=remove_footnotes(cont_ln)
      cont_ln=cont_ln.gsub(/\{[\\]+(&)\}/,'\\1')
      titleset=''
      dob.tmp=dob.tmp.gsub(/^(.*)\n?$/m,
        "#{titleset}\\part*{\\1}
\\markboth{#{@md.title.full}}\n")
      dob
    end
title_portrait() click to toggle source
# File lib/sisu/texpdf_format.rb, line 737
def title_portrait
  title
end
url_str(str) click to toggle source
# File lib/sisu/texpdf_format.rb, line 542
def url_str(str)
  rgx_url_generic=/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/m
  while str =~rgx_url_generic
    if str=~rgx_url_generic
      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!(rgx_url_generic,"#{url_decoration.tex_open}\\href{#{url}}{#{link}}#{url_decoration.tex_close}")
      str=str.gsub(/#{Xx[:protect]}/,'')
      str
    else str
    end
    str
  end
  str
end
url_str_internal(str,idx=nil) click to toggle source
# File lib/sisu/texpdf_format.rb, line 505
def url_str_internal(str,idx=nil)
  map_nametags=SiSU_Particulars::CombinedSingleton.instance.get_map_nametags(@md).nametags_map #p map_nametags
  rgx_url_internal=/#{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="#{@env.url.root}/" + url
    str.sub!(/#{Mx[:lnk_o]}[^#{Mx[:lnk_o]}#{Mx[:lnk_c]}]+#{Mx[:lnk_c]}#{Mx[:rel_o]}:\S+?#{Mx[:rel_c]}/m,
      "#{url_decoration.tex_open}\\href{#{url}}{#{link}}#{url_decoration.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]}&")
    url.gsub!(/\\_/,'_')
    ocn_lnk=if map_nametags[url] \
    and map_nametags[url][:ocn]
      map_nametags[url][:ocn]
    else nil
    end
    ocn_lnk=(url=~/^\d+$/ ? url : ocn_lnk)
    if ocn_lnk and not ocn_lnk.empty?
      idx \
      ? (str.sub!(rgx_url_internal,"\\hyperlink{#{ocn_lnk}}{#{link}}"))
      : (str.sub!(rgx_url_internal,"#{url_decoration.tex_open}\\hyperlink{#{ocn_lnk}}{#{link}}#{url_decoration.tex_close}"))
    else
      puts %{name tag: "#{url}" not found}
      str.sub!(rgx_url_internal,"#{link}")
    end
    #[keep] code that follows uses nametags directly, currently nametags converted to their ocn, related code: |texpdf.rb|@|hypertargets|
    #idx \
    #? (str.sub!(rgx_url_internal,"\\hyperlink{#{url}}{#{link}}")) \
    #: (str.sub!(rgx_url_internal,"#{url_decoration.tex_open}\\hyperlink{#{url}}{#{link}}#{url_decoration.tex_close}"))
  end
  str=str.gsub(/#{Xx[:protect]}/,'')
end
url_with_txt(dob) click to toggle source
# File lib/sisu/texpdf_format.rb, line 560
def url_with_txt(dob)
  rgx_url_generic=/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/m
  while dob.tmp =~rgx_url_generic
    if dob.tmp=~rgx_url_generic
      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!(rgx_url_generic,"#{url_decoration.tex_open}\\href{#{url}}{#{link}}#{url_decoration.tex_close}#{punctuate}")
      dob.tmp.gsub!(/#{Xx[:protect]}/,'')
      #dob.tmp=dob.tmp.sub(rgx_url_generic,"#{url_decoration.tex_open}\\href{#{url}}{#{link}}#{url_decoration.tex_close}#{punctuate}").
      #  gsub(/#{Xx[:protect]}/,'')
      dob
    else dob
    end
    dob
  end
  dob
end
urls_txt_and_images() click to toggle source
# File lib/sisu/texpdf_format.rb, line 586
def urls_txt_and_images
  dob=@dob
  dir=SiSU_Env::InfoEnv.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
  rgx_url_generic=/#{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 =~rgx_url_generic \
      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=~rgx_url_generic
          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=z.scan(/\S+/)[0] #image,x,y=z.scan(/\S+/)
          image.gsub!(/\\/,'')
          w=((z =~/\s(\d+)x\d*/) ? z[/\s(\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.opt.act[:color_state][:set],
            %{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 @md.opt.act[:quiet][:set]==:on
          images_hash[ps].gsub!(/#{Mx[:lnk_o]}\s*(\S+\.?\.(?:png|jpg|gif))/,'[image]')
        end
        if image #most images fc etc. #% clean up !
          if FileTest.file?("#{dir.path.image_source_include}/#{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_include}/#{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_include}/#{image}}#{caption}#{@center_end}")
            end
            images_hash[ps]
          elsif @md.opt.f_pth[:pth] =~/\/\S+?\/sisupod\/\S+?\/sisupod\/doc/
            pt=/(\/\S+?\/sisupod\/\S+?\/sisupod)\/doc/.match(@md.opt.f_pth[:pth])[1]
            img_src=pt + '/image'
            if FileTest.file?("#{img_src}/#{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]{#{img_src}/#{image}}}#{caption} #{@center_end}")
              when image_rgx
                images_hash[ps].sub!(image_rgx,
                  "#{@center_begin}\\\n\\includegraphics*[width=#{width[ps]}pt]{#{img_src}/#{image}}#{caption} #{@center_end}")
              end
              images_hash[ps]
            end

          elsif @md.fns =~/\.(?:ssm\.)?sst$/ \
          and FileTest.file?("#{dir.path.image_source_include_local}/#{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_include_local}/#{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_include_local}/#{image}}#{caption} #{@center_end}")
            end
            images_hash[ps]
          elsif @md.fns =~/\.-ss[tm]$/ \
          and FileTest.file?("#{dir.path.image_source_include_remote}/#{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_include_remote}/#{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_include_remote}/#{image}}#{caption}#{@center_end}")
            end
            images_hash[ps]
          else
            SiSU_Screen::Ansi.new(
              @md.opt.act[:color_state][:set],
              "ERROR - image:",
              %{"#{image}" missing},
              "search locations: #{dir.path.image_source_include_local}, #{dir.path.image_source_include_remote} and #{dir.path.image_source_include}"
            ).error2 unless @md.opt.act[:quiet][:set]==:on
            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
  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