# module RedCloth::Formatters::LATEX

### Public Class Methods

entities() click to toggle source

    # File lib/redcloth/formatters/latex.rb, line 6
    def self.entities
      @entities ||= YAML.load(File.read(File.dirname(__FILE__)+'/latex_entities.yml'))
    end

### Public Instance Methods

acronym(opts) click to toggle source

acronyms

    # File lib/redcloth/formatters/latex.rb, line 60
    def acronym(opts)
      "#{opts[:title]} (#{opts[:text]})"
    end

arrow(opts) click to toggle source

    # File lib/redcloth/formatters/latex.rb, line 261
    def arrow(opts)
      "\\rightarrow{}"
    end

bc_close(opts) click to toggle source

    # File lib/redcloth/formatters/latex.rb, line 185
    def bc_close(opts)
      end_chunk("verbatim") + "\n"
    end

bc_open(opts) click to toggle source

code blocks

    # File lib/redcloth/formatters/latex.rb, line 180
    def bc_open(opts)
      opts[:block] = true
      begin_chunk("verbatim") + "\n"
    end

bq_close(opts) click to toggle source

    # File lib/redcloth/formatters/latex.rb, line 195
    def bq_close(opts)
      "\\end{quotation}\n\n"
    end

bq_open(opts) click to toggle source

block quotations

    # File lib/redcloth/formatters/latex.rb, line 190
    def bq_open(opts)
      opts[:block] = true
      "\\begin{quotation}\n"
    end

code(opts) click to toggle source

inline code

    # File lib/redcloth/formatters/latex.rb, line 55
    def code(opts)
      opts[:block] ? opts[:text] : "\\verb@#{opts[:text]}@"
    end

copyright(opts) click to toggle source

    # File lib/redcloth/formatters/latex.rb, line 273
    def copyright(opts)
      "\\copyright{}"
    end

dim(opts) click to toggle source

    # File lib/redcloth/formatters/latex.rb, line 284
    def dim(opts)
      opts[:text].gsub!('x', '\times')
      opts[:text].gsub!('"', "''")
      period = opts[:text].slice!(/\.$/)
      "$#{opts[:text]}$#{period}"
    end

ellipsis(opts) click to toggle source

    # File lib/redcloth/formatters/latex.rb, line 249
    def ellipsis(opts)
      "#{opts[:text]}\\ldots{}"
    end

emdash(opts) click to toggle source

    # File lib/redcloth/formatters/latex.rb, line 253
    def emdash(opts)
      "---"
    end

endash(opts) click to toggle source

    # File lib/redcloth/formatters/latex.rb, line 257
    def endash(opts)
      " -- "
    end

entity(opts) click to toggle source

TODO: what do we do with (unknown) unicode entities ?

    # File lib/redcloth/formatters/latex.rb, line 279
    def entity(opts)
      text = opts[:text][0..0] == '#' ? opts[:text][1..-1] : opts[:text]
      RedCloth::Formatters::LATEX.entities[text]
    end

fn(opts) click to toggle source

    # File lib/redcloth/formatters/latex.rb, line 232
    def fn(opts)
      "\\footnotetext[#{opts[:id]}]{#{opts[:text]}}"
    end

footno(opts) click to toggle source

footnotes

    # File lib/redcloth/formatters/latex.rb, line 226
    def footno(opts)
      # TODO: insert a placeholder until we know the footnote content.
      # For this to work, we need some kind of post-processing...
      "\\footnotemark[#{opts[:text]}]"
    end

image(opts) click to toggle source

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.

    # File lib/redcloth/formatters/latex.rb, line 210
    def image(opts)
      # Don't know how to use remote links, plus can we trust them?
      return "" if opts[:src] =~ /^\w+\:\/\//
      # Resolve CSS styles if any have been set
      styling = opts[:class].to_s.split(/\s+/).collect { |style| latex_image_styles[style] }.compact.join ','
      # Build latex code
      [ "\\begin{figure}",
        "  \\centering",
        "  \\includegraphics[#{styling}]{#{opts[:src]}}",
       ("  \\caption{#{escape opts[:title]}}" if opts[:title]),
       ("  \\label{#{escape opts[:alt]}}" if opts[:alt]),
        "\\end{figure}",
      ].compact.join "\n"
    end

inline_html(opts) click to toggle source

TODO: what do we do with HTML?

    # File lib/redcloth/formatters/latex.rb, line 292
    def inline_html(opts)
      opts[:text] || ""
    end

li_close(opts=nil) click to toggle source

    # File lib/redcloth/formatters/latex.rb, line 109
    def li_close(opts=nil)
      "\n"
    end

li_open(opts) click to toggle source

    # File lib/redcloth/formatters/latex.rb, line 105
    def li_open(opts)
      "  \\item #{opts[:text]}"
    end

link(opts) click to toggle source

links

    # File lib/redcloth/formatters/latex.rb, line 200
    def link(opts)
      "\\href{#{opts[:href]}}{#{opts[:name]}}"
    end

p(opts) click to toggle source

paragraphs

    # File lib/redcloth/formatters/latex.rb, line 114
    def p(opts)
      case opts[:align]
      when 'left' then
        "\\begin{flushleft}#{opts[:text]}\\end{flushleft}\n\n"
      when 'right' then
        "\\begin{flushright}#{opts[:text]}\\end{flushright}\n\n"
      when 'center' then
        "\\begin{center}#{opts[:text]}\\end{center}\n\n"
      else
        "#{opts[:text]}\n\n"
      end
    end

quote1(opts) click to toggle source

    # File lib/redcloth/formatters/latex.rb, line 241
    def quote1(opts)
      "`#{opts[:text]}'"
    end

quote2(opts) click to toggle source

    # File lib/redcloth/formatters/latex.rb, line 245
    def quote2(opts)
      "``#{opts[:text]}''"
    end

registered(opts) click to toggle source

    # File lib/redcloth/formatters/latex.rb, line 269
    def registered(opts)
      "\\textregistered{}"
    end

snip(opts) click to toggle source

inline verbatim

    # File lib/redcloth/formatters/latex.rb, line 237
    def snip(opts)
      "\\verb`#{opts[:text]}`"
    end

table_close(opts) click to toggle source

FIXME: need caption and label elements similar to image -> figure

    # File lib/redcloth/formatters/latex.rb, line 167
    def table_close(opts)
      output  = "\\begin{table}\n"
      output << "  \\centering\n"
      output << "  \\begin{tabular}{ #{"l " * @table[0].size }}\n"
      @table.each do |row|
        output << "    #{row.join(" & ")} \\\\\n"
      end
      output << "  \\end{tabular}\n"
      output << "\\end{table}\n"
      output
    end

table_open(opts) click to toggle source

We need to know the column count before opening tabular context.

    # File lib/redcloth/formatters/latex.rb, line 159
    def table_open(opts)
      @table = []
      @table_multirow = {}
      @table_multirow_next = {}
      return ""
    end

td(opts) click to toggle source

tables

    # File lib/redcloth/formatters/latex.rb, line 128
    def td(opts)
      column = @table_row.size
      if opts[:colspan]
        opts[:text] = "\\multicolumn{#{opts[:colspan]}}{ #{"l " * opts[:colspan].to_i}}{#{opts[:text]}}"
      end
      if opts[:rowspan]
        @table_multirow_next[column] = opts[:rowspan].to_i - 1
        opts[:text] = "\\multirow{#{opts[:rowspan]}}{*}{#{opts[:text]}}"
      end
      @table_row.push(opts[:text])
      return ""
    end

tr_close(opts) click to toggle source

    # File lib/redcloth/formatters/latex.rb, line 146
    def tr_close(opts)
      multirow_columns = @table_multirow.find_all {|c,n| n > 0}
      multirow_columns.each do |c,n|
        @table_row.insert(c,"")
        @table_multirow[c] -= 1
      end
      @table_multirow.merge!(@table_multirow_next)
      @table_multirow_next = {}
      @table.push(@table_row)
      return ""
    end

tr_open(opts) click to toggle source

    # File lib/redcloth/formatters/latex.rb, line 141
    def tr_open(opts)
      @table_row = []
      return ""
    end

trademark(opts) click to toggle source

    # File lib/redcloth/formatters/latex.rb, line 265
    def trademark(opts)
      "\\texttrademark{}"
    end