Class: TexlabFile
- Inherits:
-
LatexFile
- Object
- LatexFile
- TexlabFile
- Defined in:
- lib/texlab/texlabfile.rb
Instance Method Summary collapse
- #documentHeader(extras = {}) ⇒ Object
- #env(name, *args) ⇒ Object
-
#initialize(_erbout) ⇒ TexlabFile
constructor
create new instance.
- #plain_table(entries, caption, opts = {}) ⇒ Object
- #prettyPrintCell(x) ⇒ Object
- #print(string) ⇒ Object
- #puts(string) ⇒ Object
- #table(entries, caption, args = {}) ⇒ Object
- #tables(data, caption, opts = {}) ⇒ Object
Constructor Details
#initialize(_erbout) ⇒ TexlabFile
create new instance.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/texlab/texlabfile.rb', line 7 def initialize _erbout # we don't call super @_erbout = _erbout # replay actions in super @extras = { :documentclass => :article, :fontsize => "12pt" } #use defaults for unused entries: @indent = 0 # indent lines in blocks @usePackages = { :inputenc=>:latin1, :graphics=>:final, :graphicx=>:pdftex, :color=>:dvips, :amsfonts=>true, :subfigure=>true, :lscape=>true, :hyperref=>true, :amsmath=>true, :units=>true, :float=>true, :xcolor=>"table", :rmpage=>[:wider,:taller] #:subfig=>["lofdepth", "lotdepth"] } @default_table_align = 'c' @lastWasPrint = false end |
Instance Method Details
#documentHeader(extras = {}) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/texlab/texlabfile.rb', line 69 def documentHeader extras={} @extras.merge! extras @usePackages.merge! extras[:usePackages] || {} dcsettings = [@extras[:fontsize]] dcsettings << "twocolumn" if @extras[:twocolumn] puts "\\documentclass[#{dcsettings.join(",")}]{#{@extras[:documentclass]}}" @usePackages.each do |package, settings| case settings when true then puts "\\usepackage{#{package}}" when Array then puts "\\usepackage[#{settings.join(",")}]{#{package}}" else puts "\\usepackage[#{settings}]{#{package}}" end end #puts "\\addtolength{\\oddsidemargin}{-3.5cm}" #puts "\\addtolength{\\textwidth}{7cm}" #puts "\\addtolength{\\topmargin}{-3cm}" #puts "\\addtolength{\\textheight}{5cm}" puts "\\newcommand{\\hide}[1]{}" puts "\\special{landscape}" if @extras[:landscape] #puts "\\begin{document}" puts "\\DeclareGraphicsExtensions{.jpg,.pdf,.mps,.png}" end |
#env(name, *args) ⇒ Object
98 99 100 101 102 103 |
# File 'lib/texlab/texlabfile.rb', line 98 def env(name, *args) # overridden for compatibility with new Array#to_s puts "\\begin{#{name}}#{args.join("")}" yield if block_given? puts "\\end{#{name}}" end |
#plain_table(entries, caption, opts = {}) ⇒ Object
123 124 125 126 127 128 129 130 131 132 |
# File 'lib/texlab/texlabfile.rb', line 123 def plain_table entries, , opts={} # capture output of table() temp_erbout = @_erbout; @_erbout = "" table(entries, , opts) src = @_erbout; @_erbout = temp_erbout src.sub!(/\A.*?\\begin{center}(.*)\\end{center}.*\z/m, '\1') or raise "internal error" src.sub!(/\\caption{#{}}/, "") or raise "internal error" end |
#prettyPrintCell(x) ⇒ Object
65 66 67 |
# File 'lib/texlab/texlabfile.rb', line 65 def prettyPrintCell x x.to_latex end |
#print(string) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/texlab/texlabfile.rb', line 58 def print string @lastWasPrint = true @indent -= 2 if string[/\\end/] @indent += 2 if string[/\\begin/] @_erbout << string.latex! << "\n" end |
#puts(string) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/texlab/texlabfile.rb', line 44 def puts string lines = string.split("\n") for line in lines @indent -= 2 if line[0,5]=='\\end{' && @indent >= 2 if @lastWasPrint @_erbout << line.latex! << "\n" @lastWasPrint = false else @_erbout << (" " * @indent).latex! << line.latex! << "\n" end @indent += 2 if line[0,7]=='\\begin{' end end |
#table(entries, caption, args = {}) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/texlab/texlabfile.rb', line 105 def table entries, , args={} # override defaults args = { :sort=> proc{0}, :header_hlines=>true, :placement => (args[:label] ? 'htbp' : 'H'), :empty => "---" }.merge(args) args[:rowTitle] = args[:rowTitle].to_latex if args[:rowTitle] entries = convertKeysToLatex(entries) super(entries, , args) end |
#tables(data, caption, opts = {}) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/texlab/texlabfile.rb', line 134 def tables data, , opts={} placement = opts.delete(:placement) || "htbp" tableLandscape = opts.delete(:landscape) tableFontSize = opts.delete(:fontSize) || @defaultTableFontSize tableLabel = opts.delete(:label) || "" tableCaption = puts "\\begin{landscape}" if tableLandscape puts "\n\\begin{table}[#{placement}]\n\\begin{center}" puts "\\#{tableFontSize}" if tableFontSize puts data.map { |args| entries, , opts = *args "\\subtable[#{}]{#{plain_table(*args)}}" }.join("\\qquad") puts "\\caption{#{tableCaption}}\n" if tableCaption puts "\\label{tab:#{tableLabel}}" if tableLabel puts "\\end{center}\n\\end{table}\n" puts "\\end{landscape}" if @tableLandscape end |