Module: RedCloth::Formatters::LATEX

### Home Classes Methods

### In Files

- lib/redcloth/formatters/latex.rb

### Namespace

- MODULE RedCloth::Formatters::LATEX::Settings

### Methods

- #acronym
- #arrow
- #bc_close
- #bc_open
- #bq_close
- #bq_open
- #code
- #copyright
- #dim
- #ellipsis
- #emdash
- #endash
- #entity
- #fn
- #footno
- #image
- #inline_html
- #li_close
- #li_open
- #link
- #p
- #quote1
- #quote2
- #registered
- #snip
- #table_close
- #table_open
- #td
- #tr_close
- #tr_open
- #trademark

### Included Modules

- RedCloth::Formatters::Base

### Files

- COPYING
- README.rdoc
- Makefile

### Class/Module Index

Quicksearch

- RedCloth
- RedCloth::Formatters
- RedCloth::Formatters::Base
- RedCloth::Formatters::HTML
- RedCloth::Formatters::LATEX
- RedCloth::Formatters::LATEX::Settings
- RedCloth::TextileDoc
- RedCloth::TextileDoc::ParseError
- RedCloth::VERSION
- ERB
- ERB::Util
- Object

No matching classes.

# RedCloth::Formatters::LATEX

### Constants

ENTITIES

### Public Instance Methods

acronym(opts) click to toggle source

acronyms

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

arrow(opts) click to toggle source

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

bc_close(opts) click to toggle source

    # File lib/redcloth/formatters/latex.rb, line 183
    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 178
    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 193
    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 188
    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 53
    def code(opts)
      opts[:block] ? opts[:text] : "\\verb@#{opts[:text]}@"
    end

copyright(opts) click to toggle source

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

dim(opts) click to toggle source

    # File lib/redcloth/formatters/latex.rb, line 282
    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 247
    def ellipsis(opts)
      "#{opts[:text]}\\ldots{}"
    end

emdash(opts) click to toggle source

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

endash(opts) click to toggle source

    # File lib/redcloth/formatters/latex.rb, line 255
    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 277
    def entity(opts)
      text = opts[:text][0..0] == '#' ? opts[:text][1..-1] : opts[:text]
      ENTITIES[text]
    end

fn(opts) click to toggle source

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

footno(opts) click to toggle source

footnotes

    # File lib/redcloth/formatters/latex.rb, line 224
    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 208
    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 290
    def inline_html(opts)
      opts[:text] || ""
    end

li_close(opts=nil) click to toggle source

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

li_open(opts) click to toggle source

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

link(opts) click to toggle source

links

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

p(opts) click to toggle source

paragraphs

    # File lib/redcloth/formatters/latex.rb, line 112
    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 239
    def quote1(opts)
      "`#{opts[:text]}'"
    end

quote2(opts) click to toggle source

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

registered(opts) click to toggle source

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

snip(opts) click to toggle source

inline verbatim

    # File lib/redcloth/formatters/latex.rb, line 235
    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 165
    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 157
    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 126
    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 144
    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 139
    def tr_open(opts)
      @table_row = []
      return ""
    end

trademark(opts) click to toggle source

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.