From 65477054fd798728bf186aa2938727ddddbe86a5 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Tue, 22 May 2007 02:06:46 +0100 Subject: Imported upstream version 0.52.7 --- lib/sisu/0.52/texpdf_format.rb | 1222 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1222 insertions(+) create mode 100644 lib/sisu/0.52/texpdf_format.rb (limited to 'lib/sisu/0.52/texpdf_format.rb') diff --git a/lib/sisu/0.52/texpdf_format.rb b/lib/sisu/0.52/texpdf_format.rb new file mode 100644 index 00000000..db18ce61 --- /dev/null +++ b/lib/sisu/0.52/texpdf_format.rb @@ -0,0 +1,1222 @@ +=begin + * Name: SiSU information Structuring Universe - Structured information, Serialized Units + * Author: Ralph Amissah + * http://www.jus.uio.no/sisu + * http://www.jus.uio.no/sisu/SiSU/download.html + + * Description: LaTeX formatting template, unicode utf-8 version, used for pdf + + * Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Ralph Amissah + + * License: GPL 2 or later + + Summary of GPL 2 + + 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 2 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, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + + If you have Internet connection, the latest version of the GPL should be + available at these locations: + http://www.fsf.org/licenses/gpl.html + http://www.gnu.org/copyleft/gpl.html + http://www.jus.uio.no/sisu/gpl2.fsf + + SiSU was first released to the public on January 4th 2005 + + SiSU uses: + + * Standard SiSU markup syntax, + * Standard SiSU meta-markup syntax, and the + * Standard SiSU object citation numbering and system + + © Ralph Amissah 1997, current 2007. + All Rights Reserved. + + * Ralph Amissah: ralph@amissah.com + ralph.amissah@gmail.com +=end +module SiSU_TeX_Pdf + @@table_pg_break_counter=1 + require SiSU_lib + '/param' + include SiSU_Param + include SiSU_Viz + class Use_TeX + attr_accessor :url,:txt,:date + def initialize(md,orientation='') + @md,@orientation=md,orientation + @vz=SiSU_Env::Get_init.instance.skin + @date=SiSU_Env::Info_date.new + @copymark='{\\begin{footnotesize}\\raisebox{1ex}{\\copyright}\\end{footnotesize}}' + 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 skip_small + #"\\smallskip{}" + end + def skip_small_vspace + "\n\\vspace*{\\smallskipamount} \n" + end + def skip_small_footnote + #"\n\\smallskip{}\n" + 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 + case @orientation + when /landscape/ # using longtable latex package +</] + no_of_cols,cols_width,ocn=$1,$2,$3 + tw=case @md.papersize + 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 + @@tableheader=1 if @string =~/\n\\setlength{\\LTleft}{0pt}\n\\setlength{\\LTright}{\\fill}\n" + + "\\begin{tiny}\n\\begin{longtable}#@colW\n" + @string.gsub!(//,@start_table) + end + if @string =~// + @string.gsub!(//," #@end_table\n\\end{tiny}") + end + @string.gsub!(//,1] + @string.gsub!(/\/,'') + @string.gsub!(/¡\d+?¡(.+?)(?:¡|!)/,'\bfseries \1&') + @string.gsub!(/&>\s*$/," #@row_break \\hline\\endhead #@row_break") + @string="#@string \\multicolumn{#{@@number_of_cols}}{l}{\\tiny #{tablefoot}} \\\\ \\hline\n\\endfoot\n\\hline\n" if tablefoot + @@tableheader,@@number_of_cols=0,0 + end + else + if @string =~/¡\d+?¡(.+?)(?:¡|!)/ + @string.gsub!(/¡\d+?¡(.+?)(?:¡|!)/,'\1&') + @string.gsub!(/&>\s*$/," #@row_break") + end + end + @string="<~#{ocn}>" + @string + end + def longtable_portrait + @end_table='\end{longtable}' + @row_break='\\\\\\' + if @string[//] + no_of_cols,cols_width,ocn=$1,$2,$3 + tw=case @md.papersize + 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 + @@tableheader=1 if @string =~/\n\\setlength{\\LTleft}{0pt}\n\\setlength{\\LTright}{\\fill}\n" + + "\\begin{tiny}\n\\begin{longtable}#@colW\n" + @string.gsub!(//,"#@start_table") + end + if @string =~// + @string.gsub!(//," #@end_table\n\\end{tiny}") + end + @string.gsub!(//,1] + @string.gsub!(/\/,'') + @string.gsub!(/¡\d+?¡(.+?)(?:¡|!)/,'\bfseries \1&') + @string.gsub!(/&>\s*$/," #@row_break \\hline\\endhead #@row_break") + @string="#@string \\multicolumn{#{@@number_of_cols}}{l}{\\tiny #{tablefoot}} \\\\ \\hline\n\\endfoot\n\\hline\n" if tablefoot + @@tableheader,@@number_of_cols=0,0 + end + else + if @string =~/¡\d+?¡(.+?)(?:¡|!)/ + @string.gsub!(/¡\d+?¡(.+?)(?:¡|!)/,'\1&') + @string.gsub!(/&>\s*$/," #@row_break") + end + end + @string="<~#{ocn}>" + @string + end + def scopedtable + # some features related to headers have been incorporated in longtable that are not included yet here, + # so until synced is broken on some input files, work needs to be done if is to work as before + @end_table="\\end{tabular}" + @row_break='\\\\\\\\' + @break_page="#@row_break\n#@row_break \n" + if @string[//] + no_of_cols, cols_width=$1,$2 + @w=cols_width.split(/;\s*/) + @colW=[] + @w.each do |x| + col_w=((x.to_i*12)/100.00).to_s #unless x.nil? + @colW << "p{#{col_w}cm}" if col_w + end + @start_table="\\begin{tabular}{#@colW}\n" + @string.gsub!(//,"#@start_table}") + end + if @string =~// + @string.gsub!(//,"#@end_table") + @@table_pg_break_counter=1 + end + if @string =~//,1] + @string.gsub!(/\/,'') + end + end + if @string =~/¡\d+?¡(.+?)(?:¡|!)/ + @string.gsub!(/¡\d+?¡(.+?)(?:¡|!)/,"\\1&") + @string.gsub!(/&>\s*$/,"#@row_break") + end + @string + end + def special_characters_1(para) + # ~ ^ $ & % _ { } #LaTeX special characters - KEEP list + #p @@utf_8.list + #@string=Iconv.conv('ISO-8859-1', 'UTF-8', @string) + word=@string.scan(/\S+|\n/) #unless line =~/^(?:0~\S|%+\s)/ + para_array=[] + if word + word.each do |w| # _ - / # | : ! ^ ~ + unless para =~/^(?:0~|%+ |') unless w=~/^[1-6]~|~\{|\}~|~\[|\]~|^\^~\s|~\^|\*~\S+|~#|\{t~|<~\d+;(?:[ohmu]|[0-6]:)\d+;\w\d+>/ + w.gsub!(/&#(?:126|152);/,'<=tilde>') #126 usual + #w.gsub!(/&#(?:126|152);/,'<=tilde>') unless w=~/https?:\/\/\S+/ #126 usual + w.gsub!(/\\?\|||/,'<=pipe>') #unless w=~/<~\d+;(?:[ohmu]|[0-6]:)\d+;\w\d+>/ # | SiSU not really special sisu character but done, also LaTeX + end + para_array << w + end + para=para_array.join(' ') + @string=para.strip + end + @string.gsub!(/<~\d+;(?:\w|[0-6]:)\d+;[umdv]\d+><#@dp:#@dp>/,'') + @string.gsub!(/.+?<-#>/,'') + @string.gsub!(//,'') + @string.gsub!(//,'') + #problem sequence -> + @string.gsub!(/&(?:nbsp);/,'<=hardspace>') # < SiSU special character also LaTeX + @string.gsub!(/&(?:lt|#060);/,'<=lt>') # < SiSU special character also LaTeX + @string.gsub!(/&(?:gt|#062);/,'<=gt>') # > SiSU special character also LaTeX + @string.gsub!(/{/,'<=curlyopen>') # { SiSU special character also LaTeX + @string.gsub!(/}/,'<=curlyclose>') # } SiSU special character also LaTeX + @string.gsub!(/&#(?:126|152);/,'<=tilde>') # ~ SiSU special character also LaTeX + @string.gsub!(/#/,'\#') # # SiSU special character also LaTeX + @string.gsub!(/!/,'!') # ! SiSU not really special sisu character but done, also LaTeX + @string.gsub!(/*/,'*') # * should you wish to escape astrisk e.g. describing \*{bold}* + @string.gsub!(/-/,'-') # - SiSU special character also LaTeX + @string.gsub!(/+/,'+') # + SiSU special character also LaTeX + @string.gsub!(/,/,',') # + SiSU special character also LaTeX + @string.gsub!(/&/,'<=amp>') #unless @string=~/<:code>/ # / SiSU special character also LaTeX + @string.gsub!(///,'<=slash>') # / SiSU special character also LaTeX + @string.gsub!(/\/,'<=backslash>') # \ SiSU special character also LaTeX + @string.gsub!(/_/,'<=underscore>') # _ SiSU special character also LaTeX + @string.gsub!(/|/,'|') # | SiSU not really special sisu character but done, also LaTeX + @string.gsub!(/:/,':') # : SiSU not really special sisu character but done, also LaTeX + @string.gsub!(/^/,'<=caret>') # ^ SiSU not really special sisu character but done, also LaTeX + @string.gsub!(/\#/,'<=hash>') + ##watch placement, problem sequence ^ + @string.gsub!(/&atild;<\/font><\/sup>/,' ') + @string.gsub!(/<:pb>/,'\newpage') + @string.gsub!(/<:pn>/,'\clearpage') + @string.gsub!(/\\copy(right|mark)?/,'<=copymark>') # ok problem with superscript + end + def special_characters_2(para) + @string.gsub!(/œ/,'\oe ') + @string.gsub!(/\$/,'\$') + @string.gsub!(/\#/,'\#') + @string.gsub!(/\%/,'\%') + @string.gsub!(/\~/,'\~') #revist, should not be necessary to mark remaining tildes + if @string !~/^\s*<:image|\}:image\s/ + @string.gsub!(/_/,'\_') + end + @string.gsub!(/\{/,'\{') + @string.gsub!(/\}/,'\}') + @string.gsub!(/ /,'~') # ~ character for hardspace + # sequence important must appear after removal of { and } + @string.gsub!(/&\S+?;/,'') #hmmm + # sequence imortant place before removal of & + if @string=~/<:code>/; @@flag_code=true + elsif @string=~/<:code-end>/; @@flag_code=false + end + if @@flag_code; @string.gsub!(/&/,'{\\\&}') + else @string.gsub!(/(\s+&\s+)/,' and ') + end + @string.gsub!(/§/,'\S') #latex: space between next character not preserved? #@string.gsub!(/§ /,'\S ') + @string.gsub!(/£/,'\pounds') + @string.gsub!(/&\S+?;/,' ') + @string.gsub!(//,' ') + @string.gsub!(/<\/a>/,' ') + if @string !~/^\s*<:image|\}image/ #watch carefully could introduce breaks ! removed \}http changed 0.1.1-4 200501 + if @string =~/(?:https?|ftp):\/\/\S+?<\/\S>/ #problems where have font attribute eg (change substitution sequence?) # [^\}>] added for escaped curly brace <=curlyclose> watch + @string.gsub!(/[^\}>]((?:https?|ftp):\/\/\S+?)(<\/\S>)/,' \begin{scriptsize}\href{\1}{ \1 } \end{scriptsize}\2') + else # regular urls !! http:// href + if @string=~/(?:https?|ftp):\/\/\S+?[,.]? / + @string.gsub!(/(?:^|[^\}>])((?:https?|ftp):\/\/\S+?)([,.])? /,' \begin{scriptsize}\href{\1}{ \1}\end{scriptsize}\2 ') + else @string.gsub!(/(?:^|[^\}>])((?:https?|ftp):\/\/\S+)/,' \begin{scriptsize}\href{ \1 }{\1} \end{scriptsize}') #should not be necessary, not checked + end + end + else #@string =~/\\~\\\{.+?\\\}\\~/ # \\~\\{1 + #@string.gsub!(/(?:\n)?(http:\/\/\S+)/," \\begin{scriptsize}\\href{\\1}{\\1} \\end{scriptsize}") #bug... + end + @string.gsub!(/<:ee>/,'') + @string.gsub!(//,' ') + #proposed change, insert, but may be redundant + @string.gsub!(/ \/><:i[12]>(.+?)(?:\}~||<\/\s*(br|p)>|<(br|p)\s*\/>/," #{@@tex_backslash*2} ") # Work Area + @string.gsub!(/(.+?)<\/b>/,'\begin{bfseries}\1 \end{bfseries}') + @string.gsub!(/(.+?)<\/em>/,'\begin{bfseries}\1 \end{bfseries}') + @string.gsub!(/<(bold|strong)>(.+?)<\/(bold|strong)>/,'\begin{bfseries}\1 \end{bfseries}') + @string.gsub!(/(.+?)<\/h\d+>/,'\begin{bfseries}\1 \end{bfseries}') + @string.gsub!(/(.+?)<\/i>/,'\emph{\1}') + @string.gsub!(/(.+?)<\/italic>/,'\emph{\1}') + @string.gsub!(/(.+?)<\/u>/,'\uline{\1}') # ulem + @string.gsub!(/(.+?)<\/ins>/,'\uline{\1}') # ulem + @string.gsub!(/(.+?)<\/del>/,'\sout{\1}') # ulem + @string.gsub!(/(.+?)<\/sub>/,"\$_{\\textrm{\\1}}\$") + @string.gsub!(/(.+?)<\/sup>/,"\$^{\\textrm{\\1}}\$") + unless @@flag_code + @string.gsub!(/"(.+?)"/,"``\\1''") # quote marks / quotations open & close " need condition exclude for code + @string.gsub!(/\s+"/,' ``') # open " + @string.gsub!(/^([1-6-]#{@@tilde}\S*|<.+?>)?\s*"/,'\1``') # open " + @string.gsub!(/"(\s|\.|,|:|;)/,"''\\1") # close " + @string.gsub!(/"([1-6-]#{@@tilde}\S*|<.+?>)?\s*$/,"''\\1") # close " + @string.gsub!(/"(\.|,)/,"''") # close " + @string.gsub!(/\s+'/,' `') # open ' + @string.gsub!(/^([1-6-]#{@@tilde}\S*|<.+?>)?\s*'/,'\1`') # open ' + end + @string.gsub!(/^(<:i[12]>)?\s*\\_\*\s*/,'\\1 \begin{math} \bullet \end{math}~~') #bullets - added 2004w17 watch \\_ + @string.gsub!(/(|<\/font>)/,'') + @string.gsub!(/\s*(\S+?)<\/sup>/,'^\1') + @string.gsub!(/(|<\/sup>)/,'') + @string + end + def special_characters_3(para) + @string.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 + @string.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) -> + @string.gsub!(/<=lt>/,'{\UseTextSymbol{OML}{<}}') + @string.gsub!(/<=gt>/,'{\UseTextSymbol{OML}{>}}') + #@string.gsub!(/<=lt>/,'\<') + #@string.gsub!(/<=gt>/,'\>') + @string.gsub!(/<=underscore>/,'\_') + @string.gsub!(/(\href\{http:\/\/\S+?)(?:(?:<=tilde>)(\S+))+\}/,'\1\~\2}') #tildes in urls \href treated differently from text + @string.gsub!(/<=tilde>/,'{\~~}') + @string.gsub!(/<=pipe>/,'{\textbar}') + @string.gsub!(/<=caret>/,'{\^{~}}') + #@string.gsub!(/<=caret>/,'\^{}') + @string.gsub!(/<=exclaim>/,'\Verbatim{!}') + @string.gsub!(/<=hash>/,'{\#}') + #@string.gsub!(/<=hash>/,'{\UseTextSymbol{OT1}{#}}') + #@string.gsub!(/<=slash>/,'{\slash}') + @string.gsub!(/<=hardspace>/,'{~}') #changed ... 2005 + @string.gsub!(/<=amp>/,'{\\\&}') #changed ... 2005 + #@string.gsub!(/<=amp>/,'{\UseTextSymbol{OT1}{&}}') + @string.gsub!(/<=slash>/,'{/}') + @string.gsub!(/<=backslash>/,'{\textbackslash}') + #@string.gsub!(/<=asterisk>/,'*') + #@string.gsub!(/<=exclaim>/,'!') + #@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+(<\\~\d+;\w(?:[0-6]:)?\d+;\w\d+><#@dp:#@dp>)/,"^\\copyright \\textnormal{\\1} \\2") # watch likely to be problematic + @string + end + def special_characters_curly(para) + @string.gsub!(/<=curlyopen>/,'\{') + @string.gsub!(/<=curlyclose>/,'\}') + @string + end + def special_characters_unsafe_1(para) #depreciated, make obsolete + # some substitutions are sequence sensitive, rearrange with care. + @string.gsub!(/\\backslash (copyright|clearpage|newpage)/,"\\\\\\1") #kludge bad solution, find out where tail is sent through specChar ! + end + def special_characters_unsafe_2(para) + end + def special_characters_unsafe_3(para) + end + def special_characters #special characters - some substitutions are sequence sensitive, rearrange with care. + special_characters_1(@string) + special_characters_unsafe_1(@string) + special_characters_2(@string) + special_characters_3(@string) + end + def special_characters_safe #special characters - some substitutions are sequence sensitive, rearrange with care. + special_characters_1(@string) + special_characters_2(@string) + #special_characters_3(@string) + end + def heading_major(para,lev) + title=@md.title + para.strip! if para + para.gsub!(/(?:\\begin\{bfseries\}|\\begin\{itshape\})(.+?)(?:\\end\{bfseries\}|\\end\{itshape\})/m,'\1') + cont_ln=para.dup + cont_ln.gsub!(/#{@@tex_pattern_margin_number}/,'') + cont_ln.gsub!(/#{lev}#{@@tilde}\s+/,'') + if para =~/\\[Ff]ootnote/ #and para =~/^[1-6]#{@@tilde}/ # removing footnotes from headings! + cont_ln.gsub!(/\s*\\footnote\[\d+\]\{%\n .+? \}\s*/,' ') + cont_ln.gsub!(/\s*\\Footnote[A]\{[*+]+\d*\}\{%\n .+? \}\s*/,' ') + end + para.gsub!(/(#{@md.lev}.*)\n?$/m,"\\part*{\\1} +\\addcontentsline{toc}{section}{#{cont_ln}} +\\markboth{#{title}}\n") if (para !~/#{lev}#{@@tilde}/) + para.gsub!(/^#{lev}#{@@tilde}\s*(.*)\n?$/m, + "\\part*{\\1} +\\addcontentsline{toc}{section}{#{cont_ln}} +\\markboth{#{title}}\n") + end + def level1 + heading_major(@string,1) + end + def level2 + heading_major(@string,2) + end + def level3 + heading_major(@string,3) + end + def level4 + @string.strip! if @string + @string.gsub!(/(?:\\begin\{bfseries\}|\\begin\{itshape\})(.+?)(?:\\end\{bfseries\}|\\end\{itshape\})/m,'\1') + cont_ln=@string.dup + cont_ln.gsub!(/#{@@tex_pattern_margin_number}/,'') + cont_ln.gsub!(/#{@@tex_backslash*2}/,"#{@@tex_backslash*4}") # added w42 + cont_ln.gsub!(/4#{@@tilde}\S+\s+/,'') + 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 + @string.gsub!(/#{@md.lv4}\s+(#{@md.lv4})/m,'\1') + if @string =~/4#{@@tilde}endnotes|<:4-endnotes>/ + # watch exclusion removes endnotes marker from pdf 2003w03 + @string.gsub!(/.+/m,'') + end + if @string =~/\\footnote/ #and para =~/^[1-6]#{@@tilde}/ # removing footnotes from headings! + cont_ln.gsub!(/\s*\\footnote\[\d+\]\{%\n .+? \}\s*/,' ') + cont_ln.gsub!(/\s*\\Footnote[A]\{[*+]+\d*\}\{%\n .+? \}\s*/,' ') + end + if @string !~/4#{@@tilde}/ + @string.gsub!(/(#{@md.lv4}.*)\n?$/m,"\\subsubsection*{\\1} +\\addcontentsline{toc}{subsection}{#{cont_ln}} +\\markright{#{title}}") + else + @string.gsub!(/^\s*4#{@@tilde}\S+\s*(.*)?\n?$/m,"\\subsubsection*{\\1} +\\addcontentsline{toc}{subsection}{#{cont_ln}} +\\markright{#{title}}") + end + @string.gsub!(/#{@md.lv4}\s*(.marginpar)/m,'\1') + end + def level5 + # 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 \\@string*, same for next section 2002w46 + @string.strip! if @string + @string.gsub!(/(?:\\begin\{bfseries\}|\\begin\{itshape\})(.+?)(?:\\end\{bfseries\}|\\end\{itshape\})/m,'\1') + cont_ln=@string.dup + cont_ln.gsub!(/#{@@tex_pattern_margin_number}/,'') + cont_ln.gsub!(/5#{@@tilde}\S*\s+/,'') + 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 + @string.gsub!(/#{@md.lv5}\s+(#{@md.lv5})/m,'\1') + if @string =~/\\footnote/ #and para =~/^[1-6]#{@@tilde}/ # removing footnotes from headings! + cont_ln.gsub!(/\s*\\footnote\[\d+\]\{%\n .+? \}\s*/,' ') + cont_ln.gsub!(/\s*\\Footnote[A]\{[*+]+\d*\}\{%\n .+? \}\s*/,' ') + end + if @string !~/5#{@@tilde}/ + @string.gsub!(/(#{@md.lv5}.*?)\n?$/m,"\\subsubsection*{\\1} +\\addcontentsline{toc}{subsubsection}{#{cont_ln} \\\\ +}") + else + @string.gsub!(/^\s*5#{@@tilde}\S*\s*(.*)?\n?$/m,"\\subsubsection*{\\1} +\\addcontentsline{toc}{subsubsection}{#{cont_ln} \\\\ +}") + end + @string.gsub!(/#{@md.lv5}\s*(.marginpar)/m,'\1') + end + def level6 + # 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@string*, same for previous section 2002w46 + @string.strip! if @string + @string.gsub!(/(?:\\begin\{bfseries\}|\\begin\{itshape\})(.+?)(?:\\end\{bfseries\}|\\end\{itshape\})/m,'\1') + cont_ln=@string.dup + cont_ln.gsub!(/#{@@tex_pattern_margin_number}/,'') + cont_ln.gsub!(/6#{@@tilde}\S*\s+/,'') + 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 + @string.gsub!(/#{@md.lv6}\s+(#{@md.lv6})/m,'\1') + if @string =~/\\footnote/ #and para =~/^[1-6]#{@@tilde}/ # removing footnotes from headings! + cont_ln.gsub!(/\s*\\footnote\[\d+\]\{%\n .+? \}\s*/,' ') + cont_ln.gsub!(/\s*\\Footnote[A]\{[*+]+\d*\}\{%\n .+? \}\s*/,' ') + end + @string.gsub!(/(#{@md.lv6}.*)\n?$/m, + "\\subsubsection*{\\1}") if (@string !~/6#{@@tilde}/) + @string.gsub!(/^\s*6#{@@tilde}\S*\s*(.*)?\n?$/m, + '\subsubsection*{\1}') + @string.gsub!(/#{@md.lv6}\s*(.marginpar)/m,'\1') + #end BUGWATCH + end + def indent1 + @string.gsub!(/<:i1>(.*)/m, + '\begin{ParagraphIndent}{0.01\columnwidth} \1 +\end{ParagraphIndent} +') + end + def indent2 + @string.gsub!(/<:i2>(.*)/m, + '\begin{ParagraphIndent}{0.02\columnwidth} \1 +\end{ParagraphIndent} +') + end + def symbol_graphic + dir=SiSU_Env::Info_env.new(@md.fns) + image='c_' + /<:=\s*(\S+?)\s*>/m.match(@string).captures.join + '.png' #watch + if FileTest.file?("#{dir.path.image_source_tex}/#{image}") + @string.gsub!(/<:=\s*(\S+?)\s*>/, + "\\includegraphics*[width=11pt]{#{dir.path.image_source_tex}/c_\\1.png}") + 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?|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 + width=m[1] || '100' + width=width.to_i*0.4 + image_source=if @md.fns =~/\._?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 + 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/ + nil + end + if image_source + @string.gsub!(/<:image\s+((?:https?|ftp)\S+)\s+(\S+)\s+.+\s+?>/, + @center_begin + "\\href{\\1}{\\includegraphics*[width=#{width}pt]{#{image_source}/\\2}}" + @center_end ) + @string.gsub!(/<:image\s+(\S+)\s+.+\s+?>/, + @center_begin + "\\includegraphics*[width=#{width}pt]{#{image_source}/\\1}" + @center_end ) + else @string.gsub!(/<:image\s+(\S+)\s+.+\s+?>/,'\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 ! + 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 + #caption="{\\\\\\\ \n\\begin{scriptsize}#{hsp*3}#{c[1]}\\end{scriptsize}&}" if c + image_source=if @md.fns =~/\._?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 + 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/ + end + nil + end + if image_source + @string.gsub!(/\\\{\S+\.(png|jpg|gif).+?\}(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 ! + end + end + def http_word_mode(orientation='') + # clean up ! - work area, testing + dir=SiSU_Env::Info_env.new(@md.fns) + @words=[] + @string.each do |word| + @words << if word=~/\{.+?\}(?:https?|ftp):\S+/ + if word =~/\\\{(.+?)\\\}((?:https?|ftp)\S+?)([.,](?:\s|$))/ + r=%r/\\\{(.+?)\\?\}((?:https?|ftp):\S+?)(?:[.,](?:\s|$)|(?:\s|$))/ + d=/\\\{.+?\\?\}(?:https?|ftp):\S+([.,](?:\s|$))/.match(word).captures.to_s + else + r=%r/\\\{(.+?)\\?\}((?:https?|ftp):\S+)/ + d='' + end + z,url=r.match(word).captures if word =~r + url=url.strip + if word =~/\{\s*\S+\.?(?:png|jpg|gif)/ and word=~/\s+\d+x\d+\s+/ + image,x,y=z.scan(/\S+/) + image.gsub!(/\\/,'') + width=200 + width=z[/(\d+)x\d*/,1] ||='200' #watch + dm=case @md.papersize + when /a4/; @tx.a4 + when /letter/; @tx.letter + when /legal/; @tx.legal + when /b5/; @tx.b5 + when /a5/; @tx.a5 + else @tx.a4 + end + ##dm=SiSU_Env::Get_init.instance.tex(@md.papersize).dimensions #test! + #dm=SiSU_Viz::TeX.new(@md.papersize).dimensions + width=if orientation =~/portrait/ #value is not currently passed + width=if width.to_i > dm.portrait.img_px; dm.portrait.img_px + else width + end + else + width=if width.to_i > dm.landscape.img_px; dm.landscape.img_px + else width + end + end + c=z[/``(.+?)''/m,1] + hsp="\n{\\color{mywhite} .}&~\n" # ~ character for hardspace + caption="{\\\\\ \n\\begin{scriptsize}#{hsp*3}#{c}\\end{scriptsize}&}" if c + elsif word =~/\{\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 + ins=if image #most images fc etc. #% clean up ! + out=if @md.fns =~/\._?sst$/ and FileTest.file?("#{dir.path.image_source_local_tex}/#{image}") + @center_begin + + "\\\n\\href{#{url}}" + #not satisfactory: \\ added to ^line to mimic reference file output + "{\\includegraphics*[width=#{width}pt]" + + "{#{dir.path.image_source_local_tex}/#{image}}}" + + "#{caption}" + + @center_end if word =~ /(\{[a-zA-Z0-9_\\]+\.(?:png|jpg|gif).+?\}(?:https?|ftp):\/\/\S+)/ + elsif @md.fns =~/\.-ss[tm]$/ and FileTest.file?("#{dir.path.image_source_remote_tex}/#{image}") + @center_begin + + "\\\n\\href{#{url}}" + #not satisfactory: \\ added to ^line to mimic reference file output + "{\\includegraphics*[width=#{width}pt]" + + "{#{dir.path.image_source_remote_tex}/#{image}}}" + + "#{caption}" + + @center_end if word =~ /(\{[a-zA-Z0-9_\\]+\.(?:png|jpg|gif).+?\}(?:https?|ftp):\/\/\S+)/ + elsif FileTest.file?("#{dir.path.image_source_tex}/#{image}") + @center_begin + + "\\\n\\href{#{url}}\n" + #not satisfactory: \\ added to ^line to mimic reference file output, mirror above ... not tested + "{\\includegraphics*[width=#{width}pt]" + + "{#{dir.path.image_source_tex}/#{image}}}" + + "#{caption}" + + @center_end if word =~/(\{[a-zA-Z0-9_\\]+\.(?:png|jpg|gif).+?\}(?:https?|ftp):\/\/\S+)/ + 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/ + '' if word =~ /\{\S+\.(png|jpg|gif).+?\}(?:https?|ftp):\/\/\S+/ + end + else + link=z.strip #[/(.+?)\\/m,1] + word="\\href{#{url}}{#{link}}#{d}" if word =~/\\\{.+?\\\}(?:https?|ftp):\/\/\S+/ + end + else word + end + end + @words.join + end + def http(orientation) + wm=@string.dup.scan(/\\\{.+?\\\}(?:(?:https?|ftp):\S+|image)|\w+\s*|./m) #first match of interest others passed through + @string=SiSU_TeX_Pdf::Format_text_object.new(@md,wm).http_word_mode(orientation) + end + def language + @lang=if @md.dc_language[:code] + case @md.dc_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 title + @string=Format_text_object.new(@md,@string).special_characters_safe + if @string1 + @string1=Format_text_object.new(@md,@string1).special_characters_safe + @string1.gsub!(/\$/,"\\$") + "\n\\title{#@string#{@@tex_backslash*2} \\textbf{\\normalsize #@string1}\\normalsize}" + else "\n\\title{#@string}" + end + end + def title_landscape + title + end + def title_portrait + title + end + def tex_head_lang #babel 18n + language + #@md.dc_language[:name] + lang=if @lang =~/^(?:en)$/; @lang + else "#@lang,english" + end + end + def tex_head_encode + case @md.file_encoding + when /iso-?8859/i #% iso8859 + <|#{@md.lv1}|#{@md.lv2}|#{@md.lv3}|#{@md.lv4}|#{@md.lv5}|#{@md.lv6})/ + @string.gsub!(/^\s*(.+)/m,"#{paranumber_display}\\1\n") #watch - in 1-6 is suspect + else + if (@string =~/^(?:[1-6a-z-]#{@@tilde}\S*|<:.+?>)/) #watch - in 1-6 is suspect + @string.gsub!(/^([1-6a-z-]#{@@tilde}\S*|<:.+?>)\s*(.+)/m,"\\1 #{paranumber_display} \\2\n") #watch - in 1-6 is suspect + else + @string.gsub!(/(#{@md.lv1}.+)$/,"#{@md.lv1} #{paranumber_display}\\1\n") + @string.gsub!(/(#{@md.lv2}.+)$/,"#{@md.lv2} #{paranumber_display}\\1\n") + @string.gsub!(/(#{@md.lv3}.+)$/,"#{@md.lv3} #{paranumber_display}\\1\n") + @string.gsub!(/(#{@md.lv4}.+)$/,"#{@md.lv4} #{paranumber_display}\\1\n") + @string.gsub!(/(#{@md.lv5}.+)$/,"#{@md.lv5} #{paranumber_display}\\1\n") + @string.gsub!(/(#{@md.lv6}.+)$/,"#{@md.lv6} #{paranumber_display}\\1\n") + end + end + @string + end + def lev1 + end + def lev2 + end + def lev3 + end + def lev4 + end + def lev5 + end + def lev6 + end + end +end +__END__ -- cgit v1.2.3