class SiSU_TeX_Pdf::FormatHead
Public Class Methods
new(md,t_o)
click to toggle source
# File lib/sisu/texpdf_format.rb, line 743 def initialize(md,t_o) @md,@t_o=md,t_o @env=SiSU_Env::InfoEnv.new(@md.fns) if t_o.is_a?(Hash) @txt =t_o[:txt] || nil @subtitle=t_o[:subtitle] || nil @ps=t_o[:paper_size] || nil @ocn=t_o[:ocn] || nil @layout=t_o[:orientation] || nil else p t_o.class p caller end @tx=SiSU_Env::GetInit.new.tex @tex2pdf=@@tex3pdf ||=SiSU_Env::SystemCall.new.tex2pdf_engine @ps=@txt if @txt=~/(?:a4|letter|legal|book|a5|b5)/i @lang ||=SiSU_i18n::Languages.new #.list[@md.opt.lng][:xlp] @author=if defined? @md.creator.author \ and @md.creator.author=~/\S+/ SiSU_TeX_Pdf::SpecialCharacters.new(@md,@md.creator.author).special_characters_safe else '' end @subject=if defined? @md.classify.subject \ and @md.classify.subject=~/\S+/ SiSU_TeX_Pdf::SpecialCharacters.new(@md,@md.classify.subject).special_characters_safe else '' end @keywords=if defined? @md.classify.keywords \ and @md.classify.keywords=~/\S+/ SiSU_TeX_Pdf::SpecialCharacters.new(@md,@md.classify.keywords).special_characters_safe else '' end end
Public Instance Methods
a4generic()
click to toggle source
# File lib/sisu/texpdf_format.rb, line 1228 def a4generic end
document_head_with_orientation(codeblock_box_type)
click to toggle source
# File lib/sisu/texpdf_format.rb, line 1146 def document_head_with_orientation(codeblock_box_type) endnotes=("\\usepackage{endnotes}" if @txt =~/endnotes?/) || '' #not implemented see also def endnotes @lang.list[@md.i18n[0]][:xlp] <<-WOK #{tex_head_paper} #{tex_head_encode} #{tex_head_pdftex} #{tex_head_misc} #{tex_head_codeblock(codeblock_box_type)} \\setcounter{secnumdepth}{2} \\setcounter{tocdepth}{4} \\makeatletter #{endnotes} \\usepackage[multiple,ragged]{footmisc} \\setlength\\footnotemargin{12pt} \\usepackage[para]{manyfoot} \\DeclareNewFootnote{A} %\\DeclareNewFootnote[para]{A} \\newenvironment{ParagraphIndent}[1]% { \\begin{list}{}{% \\setlength\\topsep{0pt}% \\addtolength{\\leftmargin}{#1} \\setlength\\parsep{0pt plus 1pt}% } \\item[] } {\\end{list}} \\newenvironment{ParagraphHang}[2]% { \\begin{list}{}{% \\setlength\\topsep{0pt}% \\addtolength{\\leftmargin}{#1} \\itemindent=#2 \\setlength\\parsep{0pt plus 1pt}% } \\item[] } {\\end{list}} \\newenvironment{Bullet}[1]% { \\begin{list}{}{% \\setlength\\topsep{0pt}% \\addtolength{\\leftmargin}{#1} \\itemindent=-1em \\setlength\\parsep{0pt plus 1pt}% } \\item[] } {\\end{list}} \\usepackage{fancyhdr} \\lhead{} \\renewcommand{\\part}{\\\@startsection {part}{1}{-2mm}% {-\\baselineskip}{0.5\\baselineskip}% {\\bfseries\\large\\upshape\\raggedright}} \\renewcommand{\\section}{\\\@startsection {section}{2}{-2mm}% {-\\baselineskip}{0.5\\baselineskip}% {\\bfseries\\large\\upshape\\raggedright}} \\renewcommand{\\subsection}{\\\@startsection {subsection}{3}{-2mm}% {-\\baselineskip}{0.5\\baselineskip}% {\\bfseries\\large\\upshape\\raggedright}} \\renewcommand{\\subsubsection}{\\\@startsection {subsubsection}{4}{-2mm}% {-\\baselineskip}{0.5\\baselineskip}% {\\normalfont\\normalsize\\bfseries\\raggedright}} \\renewcommand{\\paragraph}{\\\@startsection {paragraph}{5}{-2mm}% {-\\baselineskip}{0.5\\baselineskip}% {\\normalfont\\normalsize\\itshape\\raggedright}} \\renewcommand{\\subparagraph}{\\\@startsection {subparagraph}%{6}%{-2mm}% {-\\baselineskip}{0.5\\baselineskip}% {\\normalfont\\normalsize\\itshape\\raggedright}} % \\makeatother \\selectlanguage{#{@lang.list[@md.i18n[0]][:xlp]}} WOK end
hyperlinks_color?()
click to toggle source
# File lib/sisu/texpdf_format.rb, line 1046 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
hyperlinks_colored()
click to toggle source
# File lib/sisu/texpdf_format.rb, line 1038 def hyperlinks_colored <<-WOK colorlinks=true, urlcolor=myblue, % \\href{...}{...} external url filecolor=mygreen, % \\href{...} local file linkcolor=myred, % \\href{...} and \\pageref{...} WOK end
hyperlinks_monochrome()
click to toggle source
# File lib/sisu/texpdf_format.rb, line 1030 def hyperlinks_monochrome <<-WOK colorlinks=true, urlcolor=myblack, filecolor=myblack, linkcolor=myblack, WOK end
tex_head_codeblock(codeblock_box_type)
click to toggle source
# File lib/sisu/texpdf_format.rb, line 1116 def tex_head_codeblock(codeblock_box_type) codeblock_box=if codeblock_box_type=='listings' <<-WOK \\usepackage{listings} \\usepackage{color} \\usepackage{textcomp} WOK elsif codeblock_box_type=='boites' "\\usepackage{boites}" else "\\usepackage{boites}" end codeblock_box end
tex_head_encode()
click to toggle source
# File lib/sisu/texpdf_format.rb, line 795 def tex_head_encode 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_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_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_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_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_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_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_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 when /ja/ then @env.font.texpdf.cjk_ja when /ko/ then @env.font.texpdf.cjk_ko else @env.font.texpdf.cjk end end # you may wish to check selected font against available fonts: # fc-list :outline -f "%{family}\n" # fc-list :lang=ja case @tex2pdf when /xe/ if @md.opt.lng =~/(?:zh|ja|ko)/ <<-WOK \\usepackage{ucs, fontspec, xltxtra, xunicode, xeCJK} \\setmainCJKlanguage{#{tex_head_lang[:mainlang]}} \\setCJKmainfont{#{texpdf_fontface_cjk}} \\XeTeXlinebreaklocale "#{tex_head_lang[:mainlang]}" \\XeTeXlinebreakskip = 0pt plus 1pt \\setotherlanguage{#{tex_head_lang[:otherlang]}} \\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_fontface}} \\setmonofont[Scale=0.85]{#{texpdf_fontface_mono}} % \\setsansfont{#{texpdf_fontface_sans}} % \\setromanfont{#{texpdf_fontface_serif}} WOK end when /pdf/ if @md.file_encoding =~ /iso-?8859/i #% iso8859 <<-WOK % \\usepackage[latin1]{inputenc} \\usepackage{fontspec} WOK else #% utf-8 assumed <<-WOK \\usepackage{babel} \\usepackage{ucs} \\usepackage[utf8x]{inputenc} WOK end end end
tex_head_info()
click to toggle source
# File lib/sisu/texpdf_format.rb, line 890 def tex_head_info generator="Generated by: #{@md.project_details.project} #{@md.project_details.version} of #{@md.project_details.date_stamp} (#{@md.project_details.date})" if @md.project_details.version lastdone="Last Generated on: #{Time.now}" rubyv="Ruby version: #{@md.ruby_version}" <<-WOK %% SiSU (Linux & Ruby - \"better ways\") LaTeX output %% #{generator} %% #{rubyv} %% LaTeX output %% #{lastdone} %% SiSU http://www.jus.uio.no/sisu WOK end
tex_head_lang()
click to toggle source
# File lib/sisu/texpdf_format.rb, line 776 def tex_head_lang #babel 18n lang_char_arr=@md.i18n mainlang_char=if @md.i18n == Array \ and @md.i18n.length > 0 lang_char_arr.slice(0) else @md.opt.lng end mainlang=@lang.list[mainlang_char][:xlp] otherlang=if mainlang != 'english' [ @lang.list['en'][:xlp] ] else [] end if lang_char_arr.length > 0 lang_char_arr.slice(1..9).each { |ch| otherlang << @lang.list[ch][:xlp] } otherlang=otherlang.uniq end otherlang=otherlang.join(',') { mainlang: mainlang, otherlang: otherlang } end
tex_head_misc()
click to toggle source
# File lib/sisu/texpdf_format.rb, line 1130 def tex_head_misc <<-WOK \\usepackage{textcomp} \\usepackage[parfill]{parskip} \\usepackage[normalem]{ulem} \\usepackage{soul} \\usepackage{longtable} \\usepackage[tc]{titlepic} \\usepackage{graphicx} \\makeatletter \\parindent0pt %\\usepackage{mathptmx} \\usepackage{amssymb} % amssymb used for backslash WOK end
tex_head_paper()
click to toggle source
# File lib/sisu/texpdf_format.rb, line 1022 def tex_head_paper case @layout when :portrait tex_head_paper_portrait(tex_head_paper_dimensions) when :landscape tex_head_paper_landscape(tex_head_paper_dimensions) end end
tex_head_paper_dimensions()
click to toggle source
# File lib/sisu/texpdf_format.rb, line 942 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 d end
tex_head_paper_landscape(d)
click to toggle source
# File lib/sisu/texpdf_format.rb, line 917 def tex_head_paper_landscape(d) <<-WOK #{tex_head_info} \\documentclass[#{d[:fontsize]},#{d[:papertype]},landscape,titlepage,twocolumn]{scrartcl} %with titlepage \\setlength{\\textheight}{#{d[:textheight]}mm} \\setlength{\\textwidth}{#{d[:textwidth]}mm} \\setlength{\\oddsidemargin}{#{d[:oddsidemargin]}} \\setlength{\\evensidemargin}{#{d[:evensidemargin]}} \\setlength{\\topmargin}{#{d[:topmargin]}} \\setlength{\\headheight}{#{d[:headheight]}} \\setlength{\\headsep}{#{d[:headsep]}} \\setlength{\\columnsep}{#{d[:columnsep]}} \\setlength{\\marginparsep}{#{d[:marginparsep]}} \\setlength{\\marginparwidth}{#{d[:marginparwidth]}} WOK end
tex_head_paper_portrait(d)
click to toggle source
# File lib/sisu/texpdf_format.rb, line 903 def tex_head_paper_portrait(d) multicol=(@md.book_idx ? '\usepackage{multicol}' : '') <<-WOK #{tex_head_info} \\documentclass[#{d[:fontsize]},#{d[:papertype]},titlepage]{scrartcl} %with titlepage \\setlength{\\textheight}{#{d[:textheight]}mm} \\setlength{\\textwidth}{#{d[:textwidth]}mm} \\setlength{\\oddsidemargin}{#{d[:oddsidemargin]}} \\setlength{\\evensidemargin}{#{d[:evensidemargin]}} \\setlength{\\topmargin}{#{d[:topmargin]}} \\setlength{\\headheight}{#{d[:headheight]}} \\setlength{\\headsep}{#{d[:headsep]}} \\setlength{\\marginparsep}{#{d[:marginparsep]}} \\setlength{\\marginparwidth}{#{d[:marginparwidth]}} #{multicol} WOK end
tex_head_paper_portrait_dvi(d)
click to toggle source
# File lib/sisu/texpdf_format.rb, line 930 def tex_head_paper_portrait_dvi(d) <<-WOK #{tex_head_info} \\documentclass[#{d[:fontsize]},#{d[:papertype]},titlepage]{scrartcl} %with titlepage \\setlength{\\textheight}{#{d[:textheight]}mm} \\setlength{\\textwidth}{#{d[:textwidth]}mm} \\setlength{\\oddsidemargin}{#{d[:oddsidemargin]}} \\setlength{\\evensidemargin}{#{d[:evensidemargin]}} \\setlength{\\topmargin}{#{d[:topmargin]}} \\setlength{\\headheight}{#{d[:headheight]}} \\setlength{\\headsep}{#{d[:headsep]}} \\setlength{\\marginparsep}{#{d[:marginparsep]}} \\setlength{\\marginparwidth}{#{d[:marginparwidth]}} WOK end
tex_head_pdftex()
click to toggle source
# File lib/sisu/texpdf_format.rb, line 1068 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 <<-WOK \\usepackage{alltt} \\usepackage{thumbpdf} \\usepackage[#{@tex2pdf}, #{hyperlinks_color?.strip} pdftitle={#{@txt}}, pdfauthor={#{author}}, pdfsubject={#{@subject}}, pdfkeywords={#{@keywords}}, pageanchor=true, plainpages=true, pdfpagelabels=true, pagebackref, bookmarks=true, bookmarksopen=true, pdfmenubar=true, pdfpagemode=UseOutline, pdffitwindow=true, pdfwindowui=true, plainpages=false, % pdfusetitle=true, % pdfpagelayout=SinglePage, % pdfpagelayout=TwoColumnRight, % pdfpagelayout=TwoColumnLeft, % pdfstartpage=3, pdfstartview=FitH ] {hyperref} %% trace lost characters % \\tracinglostchars = 1 % \\tracingonline = 1 \\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} \\urlstyle{sf} %\\usepackage{breakurl} WOK end