module RedCloth::Formatters::LATEX
Public Class Methods
Source
# File lib/redcloth/formatters/latex.rb 6 def self.entities 7 @entities ||= YAML.load(File.read(File.dirname(__FILE__)+'/latex_entities.yml')) 8 end
Public Instance Methods
Source
# File lib/redcloth/formatters/latex.rb 60 def acronym(opts) 61 "#{opts[:title]} (#{opts[:text]})" 62 end
acronyms
Source
# File lib/redcloth/formatters/latex.rb 261 def arrow(opts) 262 "\\rightarrow{}" 263 end
Source
# File lib/redcloth/formatters/latex.rb 185 def bc_close(opts) 186 end_chunk("verbatim") + "\n" 187 end
Source
# File lib/redcloth/formatters/latex.rb 180 def bc_open(opts) 181 opts[:block] = true 182 begin_chunk("verbatim") + "\n" 183 end
code blocks
Source
# File lib/redcloth/formatters/latex.rb 195 def bq_close(opts) 196 "\\end{quotation}\n\n" 197 end
Source
# File lib/redcloth/formatters/latex.rb 190 def bq_open(opts) 191 opts[:block] = true 192 "\\begin{quotation}\n" 193 end
block quotations
Source
# File lib/redcloth/formatters/latex.rb 55 def code(opts) 56 opts[:block] ? opts[:text] : "\\verb@#{opts[:text]}@" 57 end
inline code
Source
# File lib/redcloth/formatters/latex.rb 273 def copyright(opts) 274 "\\copyright{}" 275 end
Source
# File lib/redcloth/formatters/latex.rb 284 def dim(opts) 285 opts[:text].gsub!('x', '\times') 286 opts[:text].gsub!('"', "''") 287 period = opts[:text].slice!(/\.$/) 288 "$#{opts[:text]}$#{period}" 289 end
Source
# File lib/redcloth/formatters/latex.rb 249 def ellipsis(opts) 250 "#{opts[:text]}\\ldots{}" 251 end
Source
# File lib/redcloth/formatters/latex.rb 257 def endash(opts) 258 " -- " 259 end
Source
# File lib/redcloth/formatters/latex.rb 279 def entity(opts) 280 text = opts[:text][0..0] == '#' ? opts[:text][1..-1] : opts[:text] 281 RedCloth::Formatters::LATEX.entities[text] 282 end
TODO: what do we do with (unknown) unicode entities ?
Source
# File lib/redcloth/formatters/latex.rb 232 def fn(opts) 233 "\\footnotetext[#{opts[:id]}]{#{opts[:text]}}" 234 end
Source
# File lib/redcloth/formatters/latex.rb 226 def footno(opts) 227 # TODO: insert a placeholder until we know the footnote content. 228 # For this to work, we need some kind of post-processing... 229 "\\footnotemark[#{opts[:text]}]" 230 end
footnotes
Source
# File lib/redcloth/formatters/latex.rb 210 def image(opts) 211 # Don't know how to use remote links, plus can we trust them? 212 return "" if opts[:src] =~ /^\w+\:\/\// 213 # Resolve CSS styles if any have been set 214 styling = opts[:class].to_s.split(/\s+/).collect { |style| latex_image_styles[style] }.compact.join ',' 215 # Build latex code 216 [ "\\begin{figure}", 217 " \\centering", 218 " \\includegraphics[#{styling}]{#{opts[:src]}}", 219 (" \\caption{#{escape opts[:title]}}" if opts[:title]), 220 (" \\label{#{escape opts[:alt]}}" if opts[:alt]), 221 "\\end{figure}", 222 ].compact.join "\n" 223 end
FIXME: use includegraphics with security verification
Remember to use ‘RequirePackage{graphicx}’ in your LaTeX header
FIXME: Look at dealing with width / height gracefully as this should be specified in a unit like cm rather than px.
Source
# File lib/redcloth/formatters/latex.rb 292 def inline_html(opts) 293 opts[:text] || "" 294 end
TODO: what do we do with HTML
?
Source
# File lib/redcloth/formatters/latex.rb 109 def li_close(opts=nil) 110 "\n" 111 end
Source
# File lib/redcloth/formatters/latex.rb 105 def li_open(opts) 106 " \\item #{opts[:text]}" 107 end
Source
# File lib/redcloth/formatters/latex.rb 200 def link(opts) 201 "\\href{#{opts[:href]}}{#{opts[:name]}}" 202 end
links
Source
# File lib/redcloth/formatters/latex.rb 114 def p(opts) 115 case opts[:align] 116 when 'left' then 117 "\\begin{flushleft}#{opts[:text]}\\end{flushleft}\n\n" 118 when 'right' then 119 "\\begin{flushright}#{opts[:text]}\\end{flushright}\n\n" 120 when 'center' then 121 "\\begin{center}#{opts[:text]}\\end{center}\n\n" 122 else 123 "#{opts[:text]}\n\n" 124 end 125 end
paragraphs
Source
# File lib/redcloth/formatters/latex.rb 241 def quote1(opts) 242 "`#{opts[:text]}'" 243 end
Source
# File lib/redcloth/formatters/latex.rb 245 def quote2(opts) 246 "``#{opts[:text]}''" 247 end
Source
# File lib/redcloth/formatters/latex.rb 269 def registered(opts) 270 "\\textregistered{}" 271 end
Source
# File lib/redcloth/formatters/latex.rb 237 def snip(opts) 238 "\\verb`#{opts[:text]}`" 239 end
inline verbatim
Source
# File lib/redcloth/formatters/latex.rb 167 def table_close(opts) 168 output = "\\begin{table}\n" 169 output << " \\centering\n" 170 output << " \\begin{tabular}{ #{"l " * @table[0].size }}\n" 171 @table.each do |row| 172 output << " #{row.join(" & ")} \\\\\n" 173 end 174 output << " \\end{tabular}\n" 175 output << "\\end{table}\n" 176 output 177 end
FIXME: need caption and label elements similar to image -> figure
Source
# File lib/redcloth/formatters/latex.rb 159 def table_open(opts) 160 @table = [] 161 @table_multirow = {} 162 @table_multirow_next = {} 163 return "" 164 end
We need to know the column count before opening tabular context.
Source
# File lib/redcloth/formatters/latex.rb 128 def td(opts) 129 column = @table_row.size 130 if opts[:colspan] 131 opts[:text] = "\\multicolumn{#{opts[:colspan]}}{ #{"l " * opts[:colspan].to_i}}{#{opts[:text]}}" 132 end 133 if opts[:rowspan] 134 @table_multirow_next[column] = opts[:rowspan].to_i - 1 135 opts[:text] = "\\multirow{#{opts[:rowspan]}}{*}{#{opts[:text]}}" 136 end 137 @table_row.push(opts[:text]) 138 return "" 139 end
tables
Source
# File lib/redcloth/formatters/latex.rb 146 def tr_close(opts) 147 multirow_columns = @table_multirow.find_all {|c,n| n > 0} 148 multirow_columns.each do |c,n| 149 @table_row.insert(c,"") 150 @table_multirow[c] -= 1 151 end 152 @table_multirow.merge!(@table_multirow_next) 153 @table_multirow_next = {} 154 @table.push(@table_row) 155 return "" 156 end
Source
# File lib/redcloth/formatters/latex.rb 141 def tr_open(opts) 142 @table_row = [] 143 return "" 144 end
Source
# File lib/redcloth/formatters/latex.rb 265 def trademark(opts) 266 "\\texttrademark{}" 267 end
Private Instance Methods
Source
# File lib/redcloth/formatters/latex.rb 307 def begin_chunk(type) 308 chunk_counter[type] += 1 309 return "\\begin{#{type}}" if 1 == chunk_counter[type] 310 '' 311 end
Use this for block level commands that use begin
Source
# File lib/redcloth/formatters/latex.rb 321 def chunk_counter 322 @chunk_counter ||= Hash.new 0 323 end
Source
# File lib/redcloth/formatters/latex.rb 314 def end_chunk(type) 315 chunk_counter[type] -= 1 316 raise RuntimeError, "Bad latex #{type} nesting detected" if chunk_counter[type] < 0 # This should never need to happen 317 return "\\end{#{type}}" if 0 == chunk_counter[type] 318 '' 319 end
Use this for block level commands that use end
Source
# File lib/redcloth/formatters/latex.rb 298 def escape(text) 299 latex_esc(text) 300 end
Source
# File lib/redcloth/formatters/latex.rb 302 def escape_pre(text) 303 text 304 end