From 16c30474f06ed3774ad524a38b55b7840de057d0 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Sun, 25 May 2014 10:01:43 -0400 Subject: v5: merge v6 to v5, version bump to 5.4.*, reason adds structure check * ao, document structure check, stop processing on major error (with error message & text at location of failure) [reason for version bump the addition of structure check] * utils, add ok code marker * ao, heading with no ocn, distinguish ~# from -# * ~# is general & means no ocn (for any object to which it is applied) * -# is relevant only for 1~ dummy headings & instructs that they should be removed from output where possible * applied so far to pdf, odt & plaintext * ao_images, reduce warnings when ruby RMagic absent as program used directly * reduced dependency on ruby RMagic library (as some time way back had issues) * ao, document markup structure check, skip processing file on major error * with error message & text at location of failure * texpdf, urls in creator cause breakage * texpdf, mailto markup links set for normal text objects * texpdf, '&' in heading breaks toc (now removed from toc (not heading)), bug * revisit, bug * texpdf, for urls switch to sans serif (small fontsize) * instead of typewriter, latex default * texpdf, pdf colored hyperlinks configurable * --pdf-hyperlinks-color --pdf-hyperlinks-no-color or --pdf-hyperlinks-monochrome * ['default']['pdf_hyperlinks']='color' (other options switch hyperlink color off 'no-color' 'color-off' 'monochrome') * texpdf, pdf default font size configurable (cli & sisurc.yml) (no fractions) * --pdf-fontsize-12 --pdf-fontsize-8 * default: texpdf_fontsize: 12 * texpdf, headings and table of contents representation * fixes 1~ and 2~ result in the same formatting 1~ 2~ & 3~ now differentiated, see discussion in sisu.org under #744383 * fixes :A smaller formatted than :B A~ B~ C~ now the same size, see discussion in sisu.org under #744383 * :B and :C result in the same formatting, issue explained see sisu.org * texpdf, (internal coding) fontface, rename texpdf_font texpdf_fontface * texpdf, (internal coding) use symbols to identify page orientation * param, metadata rights, line-breaks instead of semicolons separating rights * fixes remove trailing semicolon after :copyright: * digests sha512 option implemented * options sha512 sha256 md5 * command line --sha512 * rcconf.yml ['defsault']['digest'] = sha512 * xml object citation numbering (docbook fictionbook) --- lib/sisu/v5/texpdf_format.rb | 417 ++++++++++++++++++++++++------------------- 1 file changed, 233 insertions(+), 184 deletions(-) (limited to 'lib/sisu/v5/texpdf_format.rb') diff --git a/lib/sisu/v5/texpdf_format.rb b/lib/sisu/v5/texpdf_format.rb index d97f3618..4693059d 100644 --- a/lib/sisu/v5/texpdf_format.rb +++ b/lib/sisu/v5/texpdf_format.rb @@ -69,8 +69,8 @@ module SiSU_TeX_Pdf @brace_url=SiSU_Viz::Defaults.new.url_decoration end def bare_urls - @dob.obj=@dob.obj.gsub(/#{Mx[:url_o]}([a-zA-Z0-9._-]+\@\S+?\.[a-zA-Z0-9._-]+)#{Mx[:url_c]}/, - "#{@brace_url.tex_open}\\1#{@brace_url.tex_close}") + @dob.obj=@dob.obj.gsub(/#{Mx[:url_o]}([a-zA-Z0-9._-]+\@[a-zA-Z0-9_-]+?\.[a-zA-Z0-9._-]+)#{Mx[:url_c]}/, + "#{@brace_url.tex_open}\\begin{scriptsize}\\email{\\1}#{@brace_url.tex_close}") @dob.tmp=@dob.tmp.gsub(/(^|[^\\])_/m,'\1\_'). #watch may not work 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}") @@ -219,95 +219,110 @@ module SiSU_TeX_Pdf else '' end end - def heading_major + 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 + def title_level_A dob=@dob - title=@md.title.full 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,'') - clearp=(dob.lv =~/B/ && dob.obj =='Metadata') ? "\\clearpage\n" : '' - if dob.tmp =~/\\[Ff]ootnote/ #and dob =~/^[1-6]#{Tex[:tilde]}/ # removing footnotes from headings! - cont_ln=cont_ln.gsub(/\s*\\footnote\[\d+\]\{%\n .+? \}\s*/,' '). - gsub(/\s*\\Footnote[A]\{[*+]+\d*\}\{%\n .+? \}\s*/,' ') - end + cont_ln=remove_footnotes(cont_ln) + cont_ln=cont_ln.gsub(/\{[\\]+(&)\}/,'\\1') + titleset='' dob.tmp=dob.tmp.gsub(/^(.*)\n?$/m, - "#{clearp}\\part*{\\1} -\\addcontentsline{toc}{section}{#{cont_ln}} -\\markboth{#{title}}\n") + "#{titleset}\\part*{\\1} +\\markboth{#{@md.title.full}}\n") dob end - def level4 - dob=@dob + 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,''). - 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 - title=@md.title.full - if dob.name =~/endnotes/ - dob.tmp=dob.tmp.gsub(/.+/m,'') - end - if dob.tmp =~/\\footnote/ #and dob =~/^[1-6]#{Tex[:tilde]}/ # removing footnotes from headings! - cont_ln=cont_ln.gsub(/\s*\\footnote\[\d+\]\{%\n .+? \}\s*/,' '). - gsub(/\s*\\Footnote[A]\{[*+]+\d*\}\{%\n .+? \}\s*/,' ') - end - dob.tmp=dob.tmp.gsub(/^(.*)?\n?$/m,"\\subsubsection*{\\1} -\\addcontentsline{toc}{subsection}{#{cont_ln}} -\\markright{#{title}}") + 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 - 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=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(/\\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 - 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=cont_ln.gsub(/\s*\\footnote\[\d+\]\{%\n .+? \}\s*/,' '). - gsub(/\s*\\Footnote[A]\{[*+]+\d*\}\{%\n .+? \}\s*/,' ') - end - dob.tmp=dob.tmp.gsub(/^(.*)?\n?$/m, - "\\subsubsection*{\\1} -\\addcontentsline{toc}{subsubsection}{#{cont_ln} \\\\ -}") + def heading_dev_null(dob) + dob.tmp,dob.obj='','' 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 + 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.tmp =~/\\footnote/ #and dob =~/^[1-6]#{Tex[:tilde]}/ # removing footnotes from headings! - cont_ln=cont_ln.gsub(/\s*\\footnote\[\d+\]\{%\n .+? \}\s*/,' '). - gsub(/\s*\\Footnote[A]\{[*+]+\d*\}\{%\n .+? \}\s*/,' ') + 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, - "\\subsubsection*{\\1} -\\addcontentsline{toc}{subsubsection}{~~~~#{cont_ln} \\\\ -}") - #dob.tmp.gsub(/^(.*)?\n?$/m, - # '\subsubsection*{\1}') + "\\#{sect}*{\\1} +#{tocadd}{#{pre}#{cont_ln}#{post}}#{headadd}") dob end + def section_heading_level_B + section_heading_level(@dob) + end + def section_heading_level_C + section_heading_level(@dob) + end + def section_heading_level_D + section_heading_level(@dob) + end + def heading_level_1 + if not @dob.use_ == :dummy + heading_sublevels(@dob) + else + heading_dev_null(@dob) + end + end + def heading_level_2 + heading_sublevels(@dob) + end + def heading_level_3 + heading_sublevels(@dob) + end def hang case @dob.indent when /0/ @@ -771,50 +786,50 @@ module SiSU_TeX_Pdf { mainlang: mainlang, otherlang: otherlang } end def tex_head_encode - texpdf_font=if defined? @md.make.texpdf_font.main \ - and not @md.make.texpdf_font.main.nil? \ - and @md.make.texpdf_font.main=~/\S{3,}/ - @md.make.texpdf_font.main + texpdf_fontface=if defined? @md.make.texpdf_fontface.main \ + and not @md.make.texpdf_fontface.main.nil? \ + and @md.make.texpdf_fontface.main=~/\S{3,}/ + @md.make.texpdf_fontface.main else @env.font.texpdf.main end - texpdf_font_sans=if defined? @md.make.texpdf_font.sans \ - and not @md.make.texpdf_font.sans.nil? \ - and @md.make.texpdf_font.sans=~/\S{3,}/ # not used - @md.make.texpdf_font.sans + texpdf_fontface_sans=if defined? @md.make.texpdf_fontface.sans \ + and not @md.make.texpdf_fontface.sans.nil? \ + and @md.make.texpdf_fontface.sans=~/\S{3,}/ # not used + @md.make.texpdf_fontface.sans else @env.font.texpdf.sans end - texpdf_font_serif=if defined? @md.make.texpdf_font.serif \ - and not @md.make.texpdf_font.serif.nil? \ - and @md.make.texpdf_font.serif=~/\S{3,}/ # not used - @md.make.texpdf_font.serif + texpdf_fontface_serif=if defined? @md.make.texpdf_fontface.serif \ + and not @md.make.texpdf_fontface.serif.nil? \ + and @md.make.texpdf_fontface.serif=~/\S{3,}/ # not used + @md.make.texpdf_fontface.serif else @env.font.texpdf.serif end - texpdf_font_mono=if defined? @md.make.texpdf_font.mono \ - and not @md.make.texpdf_font.mono.nil? \ - and @md.make.texpdf_font.mono=~/\S{3,}/ - @md.make.texpdf_font.mono + texpdf_fontface_mono=if defined? @md.make.texpdf_fontface.mono \ + and not @md.make.texpdf_fontface.mono.nil? \ + and @md.make.texpdf_fontface.mono=~/\S{3,}/ + @md.make.texpdf_fontface.mono else @env.font.texpdf.mono end - texpdf_font_cjk=if @md.opt.lng =~/zh/ \ - and defined? @md.make.texpdf_font.cjk_zh \ - and not @md.make.texpdf_font.cjk_zh.nil? \ - and @md.make.texpdf_font.cjk_zh=~/\S{3,}/ - @md.make.texpdf_font.cjk_zh + texpdf_fontface_cjk=if @md.opt.lng =~/zh/ \ + and defined? @md.make.texpdf_fontface.cjk_zh \ + and not @md.make.texpdf_fontface.cjk_zh.nil? \ + and @md.make.texpdf_fontface.cjk_zh=~/\S{3,}/ + @md.make.texpdf_fontface.cjk_zh elsif @md.opt.lng =~/ja/ \ - and defined? @md.make.texpdf_font.cjk_ja \ - and not @md.make.texpdf_font.cjk_ja.nil? \ - and @md.make.texpdf_font.cjk_ja=~/\S{3,}/ - @md.make.texpdf_font.cjk_ja + and defined? @md.make.texpdf_fontface.cjk_ja \ + and not @md.make.texpdf_fontface.cjk_ja.nil? \ + and @md.make.texpdf_fontface.cjk_ja=~/\S{3,}/ + @md.make.texpdf_fontface.cjk_ja elsif @md.opt.lng =~/ko/ \ - and defined? @md.make.texpdf_font.cjk_ko \ - and not @md.make.texpdf_font.cjk_ko.nil? \ - and @md.make.texpdf_font.cjk_ko=~/\S{3,}/ - @md.make.texpdf_font.cjk_ko + and defined? @md.make.texpdf_fontface.cjk_ko \ + and not @md.make.texpdf_fontface.cjk_ko.nil? \ + and @md.make.texpdf_fontface.cjk_ko=~/\S{3,}/ + @md.make.texpdf_fontface.cjk_ko elsif @md.opt.lng =~/(?:zh|ja|ko)/ \ - and defined? @md.make.texpdf_font.cjk \ - and not @md.make.texpdf_font.cjk.nil? \ - and @md.make.texpdf_font.cjk=~/\S{3,}/ - @md.make.texpdf_font.cjk + and defined? @md.make.texpdf_fontface.cjk \ + and not @md.make.texpdf_fontface.cjk.nil? \ + and @md.make.texpdf_fontface.cjk=~/\S{3,}/ + @md.make.texpdf_fontface.cjk else case @md.opt.lng when /zh/ then @env.font.texpdf.cjk_zh @@ -832,22 +847,22 @@ module SiSU_TeX_Pdf <<-WOK \\usepackage{ucs, fontspec, xltxtra, xunicode, xeCJK} \\setmainCJKlanguage{#{tex_head_lang[:mainlang]}} -\\setCJKmainfont{#{texpdf_font_cjk}} +\\setCJKmainfont{#{texpdf_fontface_cjk}} \\XeTeXlinebreaklocale "#{tex_head_lang[:mainlang]}" \\XeTeXlinebreakskip = 0pt plus 1pt \\setotherlanguage{#{tex_head_lang[:otherlang]}} -\\setmainfont{#{texpdf_font}} -\\setmonofont[Scale=0.85]{#{texpdf_font_mono}} +\\setmainfont{#{texpdf_fontface}} +\\setmonofont[Scale=0.85]{#{texpdf_fontface_mono}} WOK else <<-WOK \\usepackage{polyglossia, ucs, fontspec, xltxtra, xunicode} \\setmainlanguage{#{tex_head_lang[:mainlang]}} \\setotherlanguage{#{tex_head_lang[:otherlang]}} -\\setmainfont{#{texpdf_font}} -\\setmonofont[Scale=0.85]{#{texpdf_font_mono}} -% \\setsansfont{#{texpdf_font_sans}} -% \\setromanfont{#{texpdf_font_serif}} +\\setmainfont{#{texpdf_fontface}} +\\setmonofont[Scale=0.85]{#{texpdf_fontface_mono}} +% \\setsansfont{#{texpdf_fontface_sans}} +% \\setromanfont{#{texpdf_fontface_serif}} WOK end when /pdf/ @@ -919,60 +934,79 @@ module SiSU_TeX_Pdf end def tex_head_paper_dimensions d={} + fontsize_set=if defined? @env.font.texpdf.size(@md.opt.act[:pdf_font_size]) \ + and not @env.font.texpdf.size(@md.opt.act[:pdf_font_size]).nil? + @env.font.texpdf.size(@md.opt.act[:pdf_font_size]) + else :na + end case @layout - when /portrait/ - d[:papertype],d[:fontsize]='a4paper','11pt' + when :portrait + fontsize=(fontsize_set==:na) ? '11pt' : (fontsize_set + 'pt') + d[:papertype],d[:fontsize]='a4paper',fontsize d[:oddsidemargin],d[:evensidemargin],d[:topmargin]='0mm','0mm','-12pt' d[:headheight],d[:headsep],d[:columnsep]='12pt','35pt','' d[:marginparsep],d[:marginparwidth]='4mm','8mm' case @ps #@md.papersize when /a4/i #European default, SiSU default - d[:papertype],d[:fontsize]='a4paper','12pt' + fontsize=(fontsize_set==:na) ? '12pt' : (fontsize_set + 'pt') + d[:papertype],d[:fontsize]='a4paper',fontsize d[:textheight],d[:textwidth]=@tx.a4.portrait.h,@tx.a4.portrait.w when /letter/i #U.S. default - d[:papertype],d[:fontsize]='letterpaper','12pt' + fontsize=(fontsize_set==:na) ? '12pt' : (fontsize_set + 'pt') + d[:papertype],d[:fontsize]='letterpaper',fontsize d[:textheight],d[:textwidth]=@tx.letter.portrait.h,@tx.letter.portrait.w when /legal/i #U.S. alternative - d[:papertype],d[:fontsize]='legalpaper','12pt' + fontsize=(fontsize_set==:na) ? '12pt' : (fontsize_set + 'pt') + d[:papertype],d[:fontsize]='legalpaper',fontsize d[:textheight],d[:textwidth]=@tx.legal.portrait.h,@tx.legal.portrait.w when /book|b5/i #book default - larger - d[:papertype],d[:fontsize]='b5paper','11pt' + fontsize=(fontsize_set==:na) ? '11pt' : (fontsize_set + 'pt') + d[:papertype],d[:fontsize]='b5paper',fontsize d[:oddsidemargin],d[:evensidemargin],d[:topmargin]='-4mm','-4mm','-36pt' d[:headheight],d[:headsep],d[:columnsep]='12pt','20pt','' d[:textheight],d[:textwidth]=@tx.b5.portrait.h,@tx.b5.portrait.w when /a5/i - d[:papertype],d[:fontsize]='a5paper','11pt' + fontsize=(fontsize_set==:na) ? '11pt' : (fontsize_set + 'pt') + d[:papertype],d[:fontsize]='a5paper',fontsize d[:oddsidemargin],d[:evensidemargin],d[:topmargin]='-4mm','-4mm','-36pt' d[:headheight],d[:headsep],d[:columnsep]='11pt','12pt','' d[:marginparsep],d[:marginparwidth]='4mm','6mm' d[:textheight],d[:textwidth]=@tx.a5.portrait.h,@tx.a5.portrait.w else #default currently A4 - d[:papertype],d[:fontsize]='a4paper','12pt' + fontsize=(fontsize_set==:na) ? '12pt' : (fontsize_set + 'pt') + d[:papertype],d[:fontsize]='a4paper',fontsize d[:textheight],d[:textwidth]=@tx.a4.portrait.h,@tx.a4.portrait.w end - when /landscape/ - d[:papertype],d[:fontsize]='a4paper','11pt' + when :landscape + fontsize=(fontsize_set==:na) ? '11pt' : (fontsize_set + 'pt') + d[:papertype],d[:fontsize]='a4paper',fontsize d[:oddsidemargin],d[:evensidemargin],d[:topmargin]='6mm','6mm','-12mm' d[:headheight],d[:headsep],d[:columnsep]='12pt','20pt','40pt' d[:marginparsep],d[:marginparwidth]='4mm','8mm' case @ps #@md.papersize when /a4/i #European default, SiSU default - d[:papertype],d[:fontsize]='a4paper','11pt' + fontsize=(fontsize_set==:na) ? '11pt' : (fontsize_set + 'pt') + d[:papertype],d[:fontsize]='a4paper',fontsize d[:textheight],d[:textwidth]=@tx.a4.landscape.h,@tx.a4.landscape.w when /letter/i #U.S. default - d[:papertype],d[:fontsize]='letterpaper','11pt' + fontsize=(fontsize_set==:na) ? '11pt' : (fontsize_set + 'pt') + d[:papertype],d[:fontsize]='letterpaper',fontsize d[:textheight],d[:textwidth]=@tx.letter.landscape.h,@tx.letter.landscape.w when /legal/i #U.S. alternative - d[:papertype],d[:fontsize],d[:columnsep]='legalpaper','11pt','48pt' + fontsize=(fontsize_set==:na) ? '11pt' : (fontsize_set + 'pt') + d[:papertype],d[:fontsize],d[:columnsep]='legalpaper',fontsize,'48pt' d[:textheight],d[:textwidth]=@tx.legal.landscape.h,@tx.legal.landscape.w when /book|b5/i #book default - larger - d[:papertype],d[:fontsize],d[:columnsep]='b5paper','11pt','35pt' + fontsize=(fontsize_set==:na) ? '11pt' : (fontsize_set + 'pt') + d[:papertype],d[:fontsize],d[:columnsep]='b5paper',fontsize,'35pt' d[:textheight],d[:textwidth]=@tx.b5.landscape.h,@tx.b5.landscape.w when /a5/i - d[:papertype],d[:fontsize],d[:columnsep]='a5paper','10pt','32pt' + fontsize=(fontsize_set==:na) ? '10pt' : (fontsize_set + 'pt') + d[:papertype],d[:fontsize],d[:columnsep]='a5paper',fontsize,'32pt' d[:textheight],d[:textwidth]=@tx.a5.landscape.h,@tx.a5.landscape.w else #default currently A4 - d[:papertype],d[:fontsize]='a4paper','12pt' + fontsize=(fontsize_set==:na) ? '12pt' : (fontsize_set + 'pt') + d[:papertype],d[:fontsize]='a4paper',fontsize d[:textheight],d[:textwidth]=@tx.a4.landscape.h,@tx.a4.landscape.w end end @@ -980,37 +1014,63 @@ module SiSU_TeX_Pdf end def tex_head_paper case @layout - when /portrait/ + when :portrait tex_head_paper_portrait(tex_head_paper_dimensions) - when /landscape/ + when :landscape tex_head_paper_landscape(tex_head_paper_dimensions) end end - def tex_head_pdftex_dvi - color=case @layout - when /portrait/ + def hyperlinks_monochrome <<-WOK colorlinks=true, urlcolor=myblack, filecolor=myblack, linkcolor=myblack, - WOK - when /landscape/ + WOK + end + def hyperlinks_colored <<-WOK colorlinks=true, urlcolor=myblue, % \\href{...}{...} external url - filecolor=mygreen, % \\href{...} local file + filecolor=mygreen, % \\href{...} local file linkcolor=myred, % \\href{...} and \\pageref{...} - WOK + WOK + end + def hyperlinks_color? + case @layout + when :portrait then hyperlinks_monochrome + if @env.texpdf_hyperlinks(@md.opt.act[:pdf_hyperlink_colors]).portrait != :na + case @env.texpdf_hyperlinks(@md.opt.act[:pdf_hyperlink_colors]).portrait + when :color then hyperlinks_colored + when :mono then hyperlinks_monochrome + else p __LINE__.to_s + ':error' + end + else hyperlinks_monochrome + end + when :landscape + if @env.texpdf_hyperlinks(@md.opt.act[:pdf_hyperlink_colors]).landscape != :na + case @env.texpdf_hyperlinks(@md.opt.act[:pdf_hyperlink_colors]).landscape + when :color then hyperlinks_colored + when :mono then hyperlinks_monochrome + else p __LINE__.to_s + ':error' + end + else hyperlinks_colored + end + end + end + def tex_head_pdftex + author=if defined? @md.creator.author \ + and @md.creator.author=~/\S+/ + SiSU_TeX_Pdf::SpecialCharacters.new(@md,@md.creator.author).special_characters_safe_no_urls + else '' end - if @layout =~/portrait|landscape/ <<-WOK \\usepackage{alltt} \\usepackage{thumbpdf} \\usepackage[#{@tex2pdf}, - #{color.strip} + #{hyperlinks_color?.strip} pdftitle={#{@txt}}, - pdfauthor={#{@author}}, + pdfauthor={#{author}}, pdfsubject={#{@subject}}, pdfkeywords={#{@keywords}}, pageanchor=true, @@ -1042,30 +1102,9 @@ module SiSU_TeX_Pdf \\definecolor{myblue}{rgb}{0,0,0.5} \\definecolor{mywhite}{rgb}{1,1,1} \\usepackage{url} +\\urlstyle{sf} %\\usepackage{breakurl} WOK - elsif @txt =~/dvi/ - <<-WOK -\\usepackage{alltt} - #{color.strip} - pageanchor=true, - plainpages=true, - pagebackref, - bookmarks=true, - bookmarksopen=true, - plainpages=false, -] -{hyperref} -\\usepackage[usenames]{color} -\\definecolor{myblack}{rgb}{0,0,0} -\\definecolor{myred}{rgb}{0.75,0,0} -\\definecolor{mygreen}{rgb}{0,0.5,0} -\\definecolor{myblue}{rgb}{0,0,0.5} -\\definecolor{mywhite}{rgb}{1,1,1} -\\usepackage{url} -%\\usepackage{breakurl} - WOK - end end def tex_head_codeblock(codeblock_box_type) codeblock_box=if codeblock_box_type=='listings' @@ -1103,7 +1142,7 @@ module SiSU_TeX_Pdf <<-WOK #{tex_head_paper} #{tex_head_encode} -#{tex_head_pdftex_dvi} +#{tex_head_pdftex} #{tex_head_misc} #{tex_head_codeblock(codeblock_box_type)} \\setcounter{secnumdepth}{2} @@ -1188,16 +1227,16 @@ module SiSU_TeX_Pdf @brace_url=SiSU_Viz::Defaults.new.url_decoration @tex2pdf=@@tex3pdf ||=SiSU_Env::SystemCall.new.tex2pdf_engine end - def xetex_code_listings(str,is=:default) # ~ ^ $ & % _ { } #LaTeX special characters - KEEP list + def xetex_code_listings(str,is=:default) # ~ ^ $ & % _ { } #LaTeX special characters - KEEP list word=str.scan(/\S+|\n/) #unless line =~/^(?:@\S|%+\s)/ para_array=[] str=if word word.each do |w| # _ - / # | : ! ^ ~ w=w.gsub(/#{Mx[:gl_o]}#lt#{Mx[:gl_c]}/,'<').gsub(/#{Mx[:gl_o]}#gt#{Mx[:gl_c]}/,'>'). gsub(/[\\]?~/,'~'). - gsub(/[#{Mx[:br_line]}#{Mx[:br_paragraph]}]/,"\n"). #watch - gsub(/#{Mx[:gl_o]}#(?:126|152)#{Mx[:gl_c]}/,'~'). #126 usual - gsub(/\\?\||#{Mx[:gl_o]}#124#{Mx[:gl_c]}/,'|') #unless is=='code' #unless w=~/<~\d+;(?:[ohmu]|[0-6]:)\d+;\w\d+>/ # | SiSU not really special sisu character but done, also LaTeX + gsub(/[#{Mx[:br_line]}#{Mx[:br_paragraph]}]/,"\n"). #watch + gsub(/#{Mx[:gl_o]}#(?:126|152)#{Mx[:gl_c]}/,'~'). #126 usual + gsub(/\\?\||#{Mx[:gl_o]}#124#{Mx[:gl_c]}/,'|') #unless is=='code' #unless w=~/<~\d+;(?:[ohmu]|[0-6]:)\d+;\w\d+>/ # | SiSU not really special sisu character but done, also LaTeX para_array << w end str=para_array.join(' ') @@ -1210,30 +1249,30 @@ module SiSU_TeX_Pdf gsub(/#{Mx[:br_eof]}/,''). gsub(/#{Mx[:br_endnotes]}/,''). #problem sequence -> - gsub(/&(?:lt|#060);/,'<'). # < SiSU special character also LaTeX - gsub(/#{Mx[:gl_o]}#(?:gt|062)#{Mx[:gl_c]}/,'>'). # > SiSU special character also LaTeX - gsub(/#{Mx[:gl_o]}#123#{Mx[:gl_c]}/,'{'). # { SiSU special character also LaTeX - gsub(/#{Mx[:gl_o]}#125#{Mx[:gl_c]}/,'}'). # } SiSU special character also LaTeX - gsub(/#{Mx[:gl_o]}#(?:126|152)#{Mx[:gl_c]}/,'~'). # ~ SiSU special character also LaTeX - gsub(/#{Mx[:gl_o]}#035#{Mx[:gl_c]}/,'#'). # # SiSU special character also LaTeX + gsub(/&(?:lt|#060);/,'<'). # < SiSU special character also LaTeX + gsub(/#{Mx[:gl_o]}#(?:gt|062)#{Mx[:gl_c]}/,'>'). # > SiSU special character also LaTeX + gsub(/#{Mx[:gl_o]}#123#{Mx[:gl_c]}/,'{'). # { SiSU special character also LaTeX + gsub(/#{Mx[:gl_o]}#125#{Mx[:gl_c]}/,'}'). # } SiSU special character also LaTeX + gsub(/#{Mx[:gl_o]}#(?:126|152)#{Mx[:gl_c]}/,'~'). # ~ SiSU special character also LaTeX + gsub(/#{Mx[:gl_o]}#035#{Mx[:gl_c]}/,'#'). # SiSU special character also LaTeX gsub(/#{Mx[:gl_o]}#033#{Mx[:gl_c]}/,'!'). # ! SiSU not really special sisu character but done, also LaTeX #gsub(/(^|\s)\*\s/,'\1\asterisk '). # * should you wish to escape astrisk e.g. describing \*{bold}* - gsub(/#{Mx[:gl_o]}#042#{Mx[:gl_c]}/,'*'). # * should you wish to escape astrisk e.g. describing \*{bold}* + gsub(/#{Mx[:gl_o]}#042#{Mx[:gl_c]}/,'*'). # * should you wish to escape astrisk e.g. describing \*{bold}* gsub(/#{Mx[:gl_o]}#045#{Mx[:gl_c]}/,'-'). # - SiSU special character also LaTeX gsub(/#{Mx[:gl_o]}#043#{Mx[:gl_c]}/,'+'). # + SiSU special character also LaTeX gsub(/#{Mx[:gl_o]}#044#{Mx[:gl_c]}/,','). # + SiSU special character also LaTeX - gsub(/#{Mx[:gl_o]}#038#{Mx[:gl_c]}/,'&'). #unless @txt=~/<:code>/ # / SiSU special character also LaTeX - gsub(/#{Mx[:gl_o]}#047#{Mx[:gl_c]}/,'/'). # / SiSU special character also LaTeX - gsub(/#{Mx[:gl_o]}#092#{Mx[:gl_c]}/,'\\'). # \ SiSU special character also LaTeX - gsub(/#{Mx[:gl_o]}#095#{Mx[:gl_c]}/,'_'). # _ SiSU special character also LaTeX + gsub(/#{Mx[:gl_o]}#038#{Mx[:gl_c]}/,'&'). #unless @txt=~/<:code>/ # / SiSU special character also LaTeX + gsub(/#{Mx[:gl_o]}#047#{Mx[:gl_c]}/,'/'). # / SiSU special character also LaTeX + gsub(/#{Mx[:gl_o]}#092#{Mx[:gl_c]}/,'\\'). # \ SiSU special character also LaTeX + gsub(/#{Mx[:gl_o]}#095#{Mx[:gl_c]}/,'_'). # _ SiSU special character also LaTeX gsub(/#{Mx[:gl_o]}#124#{Mx[:gl_c]}/,'|'). # | SiSU not really special sisu character but done, also LaTeX gsub(/#{Mx[:gl_o]}#058#{Mx[:gl_c]}/,':'). # : SiSU not really special sisu character but done, also LaTeX - gsub(/#{Mx[:gl_o]}#094#{Mx[:gl_c]}|\^/,'^'). # ^ SiSU not really special sisu character but done, also LaTeX + gsub(/#{Mx[:gl_o]}#094#{Mx[:gl_c]}|\^/,'^'). # ^ SiSU not really special sisu character but done, also LaTeX ##watch placement, problem sequence ^ gsub(/&atild;<\/font><\/sup>/,' '). - gsub(/\\copy(right|mark)?/,'<=copymark>') # ok problem with superscript + gsub(/\\copy(right|mark)?/,'<=copymark>') # ok problem with superscript end - def xetex_special_characters_1(str,is=:default) # ~ ^ $ & % _ { } #LaTeX special characters - KEEP list + def xetex_special_characters_1(str,is=:default) # ~ ^ $ & % _ { } #LaTeX special characters - KEEP list word=str.scan(/\S+|\n/) #unless line =~/^(?:@\S|%+\s)/ para_array=[] str=if word @@ -1245,9 +1284,9 @@ module SiSU_TeX_Pdf end w=w.gsub(/#{Mx[:gl_o]}#lt#{Mx[:gl_c]}/,'<').gsub(/#{Mx[:gl_o]}#gt#{Mx[:gl_c]}/,'>'). gsub(/[\\]?~/,'<=tilde>'). - gsub(/[#{Mx[:br_line]}#{Mx[:br_paragraph]}]/,' \newline '). #watch - gsub(/#{Mx[:gl_o]}#(?:126|152)#{Mx[:gl_c]}/,'<=tilde>'). #126 usual - 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 + gsub(/[#{Mx[:br_line]}#{Mx[:br_paragraph]}]/,' \newline '). #watch + gsub(/#{Mx[:gl_o]}#(?:126|152)#{Mx[:gl_c]}/,'<=tilde>'). #126 usual + 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 if w !~/#{Mx[:rel_o]}/ \ and w !~/#{Mx[:gl_o]}#/ w=w.gsub(/\#/,'<=hash>') @@ -1264,8 +1303,8 @@ module SiSU_TeX_Pdf gsub(/#{Mx[:br_eof]}/,''). gsub(/#{Mx[:br_endnotes]}/,'') #problem sequence -> - str=str.gsub(/&(?:nbsp);|#{Mx[:nbsp]}/,'\hardspace') unless is==:code # < SiSU special character also LaTeX - str=str.gsub(/&(?:lt|#060);/,'\lt'). # < SiSU special character also LaTeX + str=str.gsub(/&(?:nbsp);|#{Mx[:nbsp]}/,'\hardspace') unless is==:code # < SiSU special character also LaTeX + str=str.gsub(/&(?:lt|#060);/,'\lt'). # < SiSU special character also LaTeX gsub(/#{Mx[:gl_o]}#(?:gt|062)#{Mx[:gl_c]}/,'\gt'). # > SiSU special character also LaTeX gsub(/#{Mx[:gl_o]}#123#{Mx[:gl_c]}/,'\curlyopen'). # { SiSU special character also LaTeX gsub(/#{Mx[:gl_o]}#125#{Mx[:gl_c]}/,'\curlyclose'). # } SiSU special character also LaTeX @@ -1315,14 +1354,17 @@ module SiSU_TeX_Pdf gsub(/§/u,'\S'). #latex: space between next character not preserved? #str.gsub(/§ /,'\S ') gsub(/£/u,'\pounds'). gsub(//,' '). - gsub(/<\/a>/,' '). - 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 - gsub(/#{Mx[:url_o]}\\_(\S+?)#{Mx[:url_c]}/, - '\begin{scriptsize}\url{\1}\end{scriptsize}'). #special case \{ e.g. \}http://url - gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/, - '\begin{scriptsize}\\url{\1}\end{scriptsize}') #specially escaped url no decoration - unless is==:code + gsub(/<\/a>/,' ') + unless is==:no_urls + str=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 + gsub(/#{Mx[:url_o]}\\_(\S+?)#{Mx[:url_c]}/, + '\begin{scriptsize}\url{\1}\end{scriptsize}'). #special case \{ e.g. \}http://url + gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/, + '\begin{scriptsize}\\url{\1}\end{scriptsize}') #specially escaped url no decoration + end + if is !=:code \ + and is !=:no_urls str=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 end @@ -1412,6 +1454,13 @@ module SiSU_TeX_Pdf str=special_characters_safe_close(str) unless str.nil? @txt=str end + def special_characters_safe_no_urls + str,is=@txt,:no_urls + 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 + str=special_characters_safe_close(str) unless str.nil? + @txt=str + end def characters_code_listings #special characters - some substitutions are sequence sensitive, rearrange with care. str,is=@txt,@is str=xetex_code_listings(str,is) unless str.nil? @@ -1484,11 +1533,11 @@ module SiSU_TeX_Pdf #BOOK standard dimensions - 229x156 def newpage(orientation) case orientation - when /landscape/ # using longtable latex package + when :landscape # using longtable latex package <<-WOK \\clearpage WOK - when /portrait/ + when :portrait <<-WOK \\newpage WOK -- cgit v1.2.3