module RedCloth::Formatters::LATEX

Public Class Methods

entities() click to toggle 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

acronym(opts) click to toggle source

acronyms

   # File lib/redcloth/formatters/latex.rb
60 def acronym(opts)
61   "#{opts[:title]} (#{opts[:text]})"
62 end
arrow(opts) click to toggle source
    # File lib/redcloth/formatters/latex.rb
261 def arrow(opts)
262   "\\rightarrow{}"
263 end
bc_close(opts) click to toggle source
    # File lib/redcloth/formatters/latex.rb
185 def bc_close(opts)
186   end_chunk("verbatim") + "\n"
187 end
bc_open(opts) click to toggle source

code blocks

    # File lib/redcloth/formatters/latex.rb
180 def bc_open(opts)
181   opts[:block] = true
182   begin_chunk("verbatim") + "\n"
183 end
bq_close(opts) click to toggle source
    # File lib/redcloth/formatters/latex.rb
195 def bq_close(opts)
196   "\\end{quotation}\n\n"
197 end
bq_open(opts) click to toggle source

block quotations

    # File lib/redcloth/formatters/latex.rb
190 def bq_open(opts)
191   opts[:block] = true
192   "\\begin{quotation}\n"
193 end
code(opts) click to toggle source

inline code

   # File lib/redcloth/formatters/latex.rb
55 def code(opts)
56   opts[:block] ? opts[:text] : "\\verb@#{opts[:text]}@"
57 end
dim(opts) click to toggle 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
ellipsis(opts) click to toggle source
    # File lib/redcloth/formatters/latex.rb
249 def ellipsis(opts)
250   "#{opts[:text]}\\ldots{}"
251 end
emdash(opts) click to toggle source
    # File lib/redcloth/formatters/latex.rb
253 def emdash(opts)
254   "---"
255 end
endash(opts) click to toggle source
    # File lib/redcloth/formatters/latex.rb
257 def endash(opts)
258   " -- "
259 end
entity(opts) click to toggle source

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

    # 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
fn(opts) click to toggle source
    # File lib/redcloth/formatters/latex.rb
232 def fn(opts)
233   "\\footnotetext[#{opts[:id]}]{#{opts[:text]}}"
234 end
footno(opts) click to toggle source

footnotes

    # 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
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
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
inline_html(opts) click to toggle source

TODO: what do we do with HTML?

    # File lib/redcloth/formatters/latex.rb
292 def inline_html(opts)
293   opts[:text] || ""
294 end
li_close(opts=nil) click to toggle source
    # File lib/redcloth/formatters/latex.rb
109 def li_close(opts=nil)
110   "\n"
111 end
li_open(opts) click to toggle source
    # File lib/redcloth/formatters/latex.rb
105 def li_open(opts)
106   "  \\item #{opts[:text]}"
107 end
p(opts) click to toggle source

paragraphs

    # 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
quote1(opts) click to toggle source
    # File lib/redcloth/formatters/latex.rb
241 def quote1(opts)
242   "`#{opts[:text]}'"
243 end
quote2(opts) click to toggle source
    # File lib/redcloth/formatters/latex.rb
245 def quote2(opts)
246   "``#{opts[:text]}''"
247 end
registered(opts) click to toggle source
    # File lib/redcloth/formatters/latex.rb
269 def registered(opts)
270   "\\textregistered{}"
271 end
snip(opts) click to toggle source

inline verbatim

    # File lib/redcloth/formatters/latex.rb
237 def snip(opts)
238   "\\verb`#{opts[:text]}`"
239 end
table_close(opts) click to toggle source

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

    # File lib/redcloth/formatters/latex.rb
167 def table_close(opts)
168   output  = "\\begin{table}\n".dup
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
table_open(opts) click to toggle source

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

    # File lib/redcloth/formatters/latex.rb
159 def table_open(opts)
160   @table = []
161   @table_multirow = {}
162   @table_multirow_next = {}
163   return ""
164 end
td(opts) click to toggle source

tables

    # 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
tr_close(opts) click to toggle 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
tr_open(opts) click to toggle source
    # File lib/redcloth/formatters/latex.rb
141 def tr_open(opts)
142   @table_row = []
143   return ""
144 end
trademark(opts) click to toggle source
    # File lib/redcloth/formatters/latex.rb
265 def trademark(opts)
266   "\\texttrademark{}"
267 end