diff options
Diffstat (limited to 'lib/sisu/v0/texpdf_format.rb')
-rw-r--r-- | lib/sisu/v0/texpdf_format.rb | 86 |
1 files changed, 49 insertions, 37 deletions
diff --git a/lib/sisu/v0/texpdf_format.rb b/lib/sisu/v0/texpdf_format.rb index 0fa439f0..a3f2f7d2 100644 --- a/lib/sisu/v0/texpdf_format.rb +++ b/lib/sisu/v0/texpdf_format.rb @@ -375,12 +375,12 @@ para else tell=SiSU_Screen::Ansi.new(@md.cmd,"ERROR - image:",%{"#{image}" missing},"search path: #{dir.path.image_source_tex}") tell.error2 unless @md.cmd =~/q/ - @string.gsub!(/\{\S+\.(png|jpg|gif).+?\}(?:https?|file|ftp):\/\/\S+/,'') # fragile match operator\\ fragile ! + @string.gsub!(/#{Mx[:lnk_o]}\S+\.(png|jpg|gif).+?#{Mx[:lnk_c]}(?:https?|file|ftp):\/\/\S+/,'') # fragile match operator\\ fragile ! end end def image dir=SiSU_Env::Info_env.new(@md.fns) - image,m=/<:image\s+(\S+)\s+.+?width=``(\d+)''.+?>/m.match(@string).captures + image,m=/#{Mx[:lnk_o]}\s*(\S+)\s+.+?width=``(\d+)''.+?#{Mx[:lnk_c]}/m.match(@string).captures width=m[1] || '100' width=width.to_i*0.4 image_source=if @md.fns =~/\.(?:ssm\.)?sst$/ \ @@ -397,17 +397,17 @@ para nil end if image_source - @string.gsub!(/<:image\s+((?:https?|file|ftp)\S+)\s+(\S+)\s+.+\s+?>/, + @string.gsub!(/#{Mx[:lnk_o]}\s*((?:https?|file|ftp):\/\/\S+)\s+(\S+).+?#{Mx[:lnk_c]}/, @center_begin + "\\href{\\1}{\\includegraphics*[width=#{width}pt]{#{image_source}/\\2}}" + @center_end ) - @string.gsub!(/<:image\s+(\S+)\s+.+\s+?>/, + @string.gsub!(/#{Mx[:lnk_o]}\s*(\S+)\s+.+?#{Mx[:lnk_c]}/, @center_begin + "\\includegraphics*[width=#{width}pt]{#{image_source}/\\1}" + @center_end ) - else @string.gsub!(/<:image\s+(\S+)\s+.+\s+?>/,'\1}') + else @string.gsub!(/#{Mx[:lnk_o]}\s*(\S+)\s+.+?#{Mx[:lnk_c]}/,'\1}') end end def png #fc missing image check dir=SiSU_Env::Info_env.new(@md.fns) # messy clean up - z=@string[/\\\{(\S.+?)\}(?:image|png)/,1].strip if @string =~ /\\\{\S.+?\}(?:image|png)/ # match operator for z \\ fragile ! + z=@string[/#{Mx[:lnk_o]}(\S.+?)#{Mx[:lnk_c]}(?:image|png)/,1].strip if @string =~ /#{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!(/\\/,'') @@ -438,29 +438,28 @@ para nil end if image_source - @string.gsub!(/\\\{\S+\.(png|jpg|gif).+?\}(image|png)/, # fragile match operator\\ fragile ! + @string.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 - @string.gsub!(/\\\{\S+\.(png|jpg|gif).+?\}(image|png)/,'') # fragile match operator\\ fragile ! + else @string.gsub!(/#{Mx[:lnk_o]}\S+\.(png|jpg|gif).+?#{Mx[:lnk_c]}(image|png)/,'') end end def http_word_mode #(orientation='') # clean up ! - work area, testing dir=SiSU_Env::Info_env.new(@md.fns) @words=[] - @url_generic_rgx=/\\\{.+?\\?\}(?:https?|file|ftp):\S+/ + @url_generic_rgx=/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(?:https?|file|ftp):\/\/\S+/ @string.each do |word| @words << if word=~@url_generic_rgx - if word =~/\\\{(?:.+?)\\?\}(?:https?|file|ftp):\/\/\S+?\.[^'"><\s]+?(?:[;.,]?(?:\s|$)|(?:\s|$))/ - regx_url=%r/\\\{(.+?)\\?\}((?:https?|file|ftp):\/\/\S+?\.[^'"><\s]+?)(?:[;.,]?(?:\s|$)|(?:\s|$))/ - punctuate=/\\\{.+?\\?\}(?:https?|file|ftp):\/\/\S+?\.[^'"><\s]+?([;.,]?(?:\s|$))/.match(word).captures.join + if word =~/#{Mx[:lnk_o]}(?:.+?)#{Mx[:lnk_c]}(?:https?|file|ftp):\/\/\S+?\.[^'"><\s]+?(?:[;.,]?(?:\s|$)|(?:\s|$))/ + regx_url=%r/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}((?:https?|file|ftp):\/\/\S+?\.[^'"><\s]+?)(?:[;.,]?(?:\s|$)|(?:\s|$))/ + punctuate=/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(?:https?|file|ftp):\/\/\S+?\.[^'"><\s]+?([;.,]?(?:\s|$))/.match(word).captures.join else - regx_url=%r/\\\{(.+?)\\?\}((?:https?|file|ftp):\S+)/ + regx_url=%r/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}((?:https?|file|ftp):\S+)/ punctuate='' end z,url=regx_url.match(word).captures if word =~regx_url url=url.strip - if word =~/\{\s*\S+\.?(?:png|jpg|gif)/ \ + if word =~/#{Mx[:lnk_o]}\s*\S+\.?(?:png|jpg|gif)/ \ and word=~/\s+\d+x\d+\s+/ image,x,y=z.scan(/\S+/) image.gsub!(/\\/,'') @@ -486,37 +485,37 @@ para "{\\\\\ \n\\begin{scriptsize}#{hsp*3}#{c}\\end{scriptsize}&}" else '' end - elsif word =~/\{\s*(\S+\.?\.(?:png|jpg|gif))/ + elsif word =~/#{Mx[:lnk_o]}\s*(\S+\.?\.(?:png|jpg|gif))/ tell=SiSU_Screen::Ansi.new(@md.cmd,%{document built without image: "#{$1}" as image dimensions not provided (& librmagick-ruby is not installed)?\n}) tell.print_grey #unless @opt.cmd =~/q/ end word=if image #most images fc etc. #% clean up ! word=if @md.fns =~/\.(?:ssm\.)?sst$/ \ and FileTest.file?("#{dir.path.image_source_local_tex}/#{image}") - word=if word =~ /(\{[a-zA-Z0-9_\\]+\.(?:png|jpg|gif).+?\}(?:https?|file|ftp):\/\/\S+)/ + word=if word =~ /(#{Mx[:lnk_o]}[a-zA-Z0-9_\\]+\.(?:png|jpg|gif).+?#{Mx[:lnk_c]}(?:https?|file|ftp):\/\/\S+)/ "#@center_begin\\\n\\href{#{url}}{\\includegraphics*[width=#{width}pt]{#{dir.path.image_source_local_tex}/#{image}}}#{caption} #@center_end" end word elsif @md.fns =~/\.-ss[tm]$/ \ and FileTest.file?("#{dir.path.image_source_remote_tex}/#{image}") - word=if word =~ /(\{[a-zA-Z0-9_\\]+\.(?:png|jpg|gif).+?\}(?:https?|file|ftp):\/\/\S+)/ + word=if word =~ /(#{Mx[:lnk_o]}[a-zA-Z0-9_\\]+\.(?:png|jpg|gif).+?#{Mx[:lnk_c]}(?:https?|file|ftp):\/\/\S+)/ "#@center_begin\\\n\\href{#{url}}{\\includegraphics*[width=#{width}pt]{#{dir.path.image_source_remote_tex}/#{image}}}#{caption}#@center_end" end word elsif FileTest.file?("#{dir.path.image_source_tex}/#{image}") - word=if word =~/(\{[a-zA-Z0-9_\\]+\.(?:png|jpg|gif).+?\}(?:https?|file|ftp):\/\/\S+)/ + word=if word =~/(#{Mx[:lnk_o]}[a-zA-Z0-9_\\]+\.(?:png|jpg|gif).+?#{Mx[:lnk_c]}(?:https?|file|ftp):\/\/\S+)/ "#@center_begin\\\n\\href{#{url}}\n{\\includegraphics*[width=#{width}pt]{#{dir.path.image_source_tex}/#{image}}}#{caption}#@center_end" end word else tell=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}") tell.error2 unless @md.cmd =~/q/ - word='' if word =~ /\{\S+\.(png|jpg|gif).+?\}(?:https?|file|ftp):\/\/\S+/ + word='' if word =~ /#{Mx[:lnk_o]}\S+\.(png|jpg|gif).+?#{Mx[:lnk_c]}(?:https?|file|ftp):\/\/\S+/ word end else link=z.strip #[/(.+?)\\/m,1] - word="\\href{#{url}}{#{link}}#{punctuate}" if word =~/\\\{.+?\\\}(?:https?|file|ftp):\/\/\S+/ + word="\\href{#{url}}{#{link}}#{punctuate}" if word =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(?:https?|file|ftp):\/\/\S+/ word end else word @@ -526,7 +525,7 @@ para @words end def http - wm=@string.dup.scan(/\\\{.+?\\\}(?:(?:https?|file|ftp):\S+|image)|\w+\s*|./m) + wm=@string.dup.scan(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(?:(?:https?|file|ftp):\S+|image)|\w+\s*|./m) @string=SiSU_TeX_Pdf::Format_text_object.new(@md,wm,@ps).http_word_mode #GET PAPER SIZE AND USE IT end def title @@ -993,7 +992,7 @@ WOK string.gsub!(/\#/,'\#') string.gsub!(/\%/,'\%') string.gsub!(/\~/,'\~') #revist, should not be necessary to mark remaining tildes - if string !~/^\s*<:image|\}:image\s/ + if string !~/^\s*#{Mx[:lnk_o]}|#{Mx[:lnk_c]}image\s/ string.gsub!(/_/,'\_') end string.gsub!(/\{/,'\{') @@ -1013,11 +1012,15 @@ WOK string.gsub!(/&\S+?;/,' ') string.gsub!(/<a href=".+?">/,' ') string.gsub!(/<\/a>/,' ') - string.gsub!(/[^\}>_]((?:https?|file|ftp):\/\/\S+?)(<\/\S>)/,' \begin{scriptsize}\href{\1}{\1} \end{scriptsize}\2') #special case - string.gsub!(/((?:^|\s)[}])((?:https?|file|ftp):\/\/\S+?\.[^'"><\s]+?)([;.,]?(?:\s|$))/,'\1\begin{scriptsize}\\href{\2}{\2}\end{scriptsize}\3') #special case \{ e.g. \}http://url - string.gsub!(/\B(?:\\_|\\)((?:https?|file|ftp):\/\/\S+?\.[^'"><\s]+?)([;.,]?(?:\s|$))/,'\begin{scriptsize}\\href{\1}{\1}\end{scriptsize}\2') #specially escaped url no decoration + string.gsub!(/((?:^|\s)#{Mx[:lnk_c]})((?:https?|file|ftp):\/\/\S+?\.[^'"><\s]+?)([;.,]?(?:\s|$))/, + '\1\begin{scriptsize}\\href{\2}{\2}\end{scriptsize}\3') #special case \{ e.g. \}http://url + string.gsub!(/[^\}>_]((?:https?|file|ftp):\/\/\S+?)(<\/\S>)/, + ' \begin{scriptsize}\href{\1}{\1} \end{scriptsize}\2') #special case + string.gsub!(/\B(?:\\_|\\)((?:https?|file|ftp):\/\/\S+?\.[^'"><\s]+?)([;.,]?(?:\s|$))/, + '\begin{scriptsize}\\href{\1}{\1}\end{scriptsize}\2') #specially escaped url no decoration unless @@flag_code - string.gsub!(/(^|#{Mx[:gl_c]}|\s)((?:https?|file|ftp):\/\/\S+?\.[^'"><\s]+?)([;.,]?(?=\s|$))/,"\\1#{@url_brace.tex_open}\\begin{scriptsize}\\href{\\2}{\\2}\\end{scriptsize}#{@url_brace.tex_close}\\3") #url matching with decoration <url> positive lookahead, sequence issue with { linked }http://url cannot use \b at start + string.gsub!(/(^|#{Mx[:gl_c]}|\s)((?:https?|file|ftp):\/\/\S+?\.[^'"><\s]+?)([;.,]?(?=\s|$))/, + "\\1#{@url_brace.tex_open}\\begin{scriptsize}\\href{\\2}{\\2}\\end{scriptsize}#{@url_brace.tex_close}\\3") #url matching with decoration <url> positive lookahead, sequence issue with { linked }http://url cannot use \b at start else #code-block: angle brackets special characters, note _ already escaped string.gsub!(/\\_</,'{\UseTextSymbol{OML}{<}}') string.gsub!(/\\_>/,'{\UseTextSymbol{OML}{>}}') @@ -1025,7 +1028,8 @@ WOK string.gsub!(/<:ee>/,'') string.gsub!(/<!>/,' ') #proposed change, insert, but may be redundant - string.gsub!(/ \/>#{Mx[:pa_o]}:i[12]#{Mx[:pa_c]}(.+?)(?:\}~|<br)/,' \begin{ParagraphIndent}{0.01\columnwidth}\1\end{ParagraphIndent} ') # 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 + string.gsub!(/ \/>#{Mx[:pa_o]}:i[12]#{Mx[:pa_c]}(.+?)(?:\}~|<br)/, + ' \begin{ParagraphIndent}{0.01\columnwidth}\1\end{ParagraphIndent} ') # 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 string.gsub!(/<(br|p)>|<\/\s*(br|p)>|<(br|p)\s*\/>/," #{@@tex_backslash*2} ") # Work Area string.gsub!(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/,'\begin{bfseries}\1 \end{bfseries}') #string.gsub!(/<em>(.+?)<\/em>/,'\begin{bfseries}\1 \end{bfseries}') @@ -1049,7 +1053,8 @@ WOK string.gsub!(/\s+'/,' `') # open ' string.gsub!(/^(#{Mx[:lv_o]}[1-6-]:\S*?#{Mx[:lv_c]}|<.+?>)?\s*'/,'\1`') # open ' end - string.gsub!(/^(#{Mx[:pa_o]}:i[1-9]#{Mx[:pa_c]})?\s*#{Mx[:gl_bullet]}\s*/,'\1 \begin{math} \bullet \end{math}~~') #bullets - added 2004w17 watch \\_ + string.gsub!(/^(#{Mx[:pa_o]}:i[1-9]#{Mx[:pa_c]})?\s*#{Mx[:gl_bullet]}\s*/, + '\1 \begin{math} \bullet \end{math}~~') #bullets - added 2004w17 watch \\_ string.gsub!(/(<font.*?>|<\/font>)/,'') string.gsub!(/\s*#{Mx[:fa_superscript_o]}(\S+?)#{Mx[:fa_superscript_c]}/,'^\1') #string.gsub!(/\s*(?:#{Mx[:br_line]}|#{Mx[:br_paragraph]}|\n)\*/,' \\\\ ') @@ -1084,7 +1089,8 @@ WOK #string.gsub!(/<=asterisk>/,'{\ast}') #string.gsub!(/<=copymark>/,"^{\\copyright} ") # watch has been problematic #copymark='{\\begin{small}\\raisebox{1ex}{\\copyright}\\end{small}} ' - string.gsub!(/<=copymark>\s*(.+)?\s+(#{Mx[:id_o]}\\~\d+;\w(?:[0-6]:)?\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#@dp:#@dp#{Mx[:id_c]})/,"^\\copyright \\textnormal{\\1} \\2") # watch likely to be problematic + string.gsub!(/<=copymark>\s*(.+)?\s+(#{Mx[:id_o]}\\~\d+;\w(?:[0-6]:)?\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#@dp:#@dp#{Mx[:id_c]})/, + '^\copyright \textnormal{\1} \2') # watch likely to be problematic string end def xetex_special_characters_1(string) # ~ ^ $ & % _ { } #LaTeX special characters - KEEP list @@ -1153,7 +1159,7 @@ WOK string.gsub!(/\#/,'\#') string.gsub!(/\%/,'\%') string.gsub!(/\~/,'\~') #revist, should not be necessary to mark remaining tildes - if string !~/^\s*<:image|\}:image\s/ + if string !~/^\s*#{Mx[:lnk_o]}|#{Mx[:lnk_c]}image\s/ string.gsub!(/_/,'\_') end string.gsub!(/\{/,'\{') @@ -1173,11 +1179,15 @@ WOK string.gsub!(/&\S+?;/,' ') string.gsub!(/<a href=".+?">/,' ') string.gsub!(/<\/a>/,' ') - string.gsub!(/[^\}>_]((?:https?|file|ftp):\/\/\S+?)(<\/\S>)/,' \begin{scriptsize}\href{\1}{\1} \end{scriptsize}\2') #special case - string.gsub!(/((?:^|\s)[}])((?:https?|file|ftp):\/\/\S+?\.[^'"><\s]+?)([;.,]?(?:\s|$))/,'\1\begin{scriptsize}\\href{\2}{\2}\end{scriptsize}\3') #special case \{ e.g. \}http://url - string.gsub!(/\B(?:\\_|\\)((?:https?|file|ftp):\/\/\S+?\.[^'"><\s]+?)([;.,]?(?:\s|$))/,'\begin{scriptsize}\\href{\1}{\1}\end{scriptsize}\2') #specially escaped url no decoration + string.gsub!(/((?:^|\s)#{Mx[:lnk_c]})((?:https?|file|ftp):\/\/\S+?\.[^'"><\s]+?)([;.,]?(?:\s|$))/, + '\1\begin{scriptsize}\\href{\2}{\2}\end{scriptsize}\3') #special case \{ e.g. \}http://url + string.gsub!(/[^\}>_]((?:https?|file|ftp):\/\/\S+?)(<\/\S>)/, + ' \begin{scriptsize}\href{\1}{\1} \end{scriptsize}\2') #special case + string.gsub!(/\B(?:\\_|\\)((?:https?|file|ftp):\/\/\S+?\.[^'"><\s]+?)([;.,]?(?:\s|$))/, + '\begin{scriptsize}\\href{\1}{\1}\end{scriptsize}\2') #specially escaped url no decoration unless @@flag_code - string.gsub!(/(^|#{Mx[:gl_c]}|\s)((?:https?|file|ftp):\/\/\S+?\.[^'"><\s]+?)([;.,]?(?=\s|$))/,"\\1#{@url_brace.tex_open}\\begin{scriptsize}\\href{\\2}{\\2}\\end{scriptsize}#{@url_brace.tex_close}\\3") #url matching with decoration <url> positive lookahead, sequence issue with { linked }http://url cannot use \b at start + string.gsub!(/(^|#{Mx[:gl_c]}|\s)((?:https?|file|ftp):\/\/\S+?\.[^'"><\s]+?)([;.,]?(?=\s|$))/, + "\\1#{@url_brace.tex_open}\\begin{scriptsize}\\href{\\2}{\\2}\\end{scriptsize}#{@url_brace.tex_close}\\3") #url matching with decoration <url> positive lookahead, sequence issue with { linked }http://url cannot use \b at start else #code-block: angle brackets special characters, note _ already escaped string.gsub!(/\\_</,'{\UseTextSymbol{OML}{<}}') string.gsub!(/\\_>/,'{\UseTextSymbol{OML}{>}}') @@ -1185,7 +1195,8 @@ WOK string.gsub!(/<:ee>/,'') string.gsub!(/<!>/,' ') #proposed change, insert, but may be redundant - string.gsub!(/ \/>#{Mx[:pa_o]}:i[12]#{Mx[:pa_c]}(.+?)(?:\}~|<br)/,' \begin{ParagraphIndent}{0.01\columnwidth}\1\end{ParagraphIndent} ') # 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 + string.gsub!(/ \/>#{Mx[:pa_o]}:i[12]#{Mx[:pa_c]}(.+?)(?:\}~|<br)/, + ' \begin{ParagraphIndent}{0.01\columnwidth}\1\end{ParagraphIndent} ') # 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 string.gsub!(/<(br|p)>|<\/\s*(br|p)>|<(br|p)\s*\/>/," #{@@tex_backslash*2} ") # Work Area string.gsub!(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/,'\begin{bfseries}\1 \end{bfseries}') #string.gsub!(/<em>(.+?)<\/em>/,'\begin{bfseries}\1 \end{bfseries}') @@ -1249,7 +1260,8 @@ WOK #string.gsub!(/<=asterisk>/,'{\ast}') #string.gsub!(/<=copymark>/,"^{\\copyright} ") # watch has been problematic #copymark='{\\begin{small}\\raisebox{1ex}{\\copyright}\\end{small}} ' - string.gsub!(/<=copymark>\s*(.+)?\s+(#{Mx[:id_o]}\\~\d+;\w(?:[0-6]:)?\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#@dp:#@dp#{Mx[:id_c]})/,"^\\copyright \\textnormal{\\1} \\2") # watch likely to be problematic + string.gsub!(/<=copymark>\s*(.+)?\s+(#{Mx[:id_o]}\\~\d+;\w(?:[0-6]:)?\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#@dp:#@dp#{Mx[:id_c]})/, + '^\copyright \textnormal{\1} \2') # watch likely to be problematic string end def special_characters_curly(string) |