Included Modules

RedCloth::Formatters::LATEX

Constants

ENTITIES

Public Instance Methods

acronym(opts) click to toggle source

acronyms

    # File lib/redcloth/formatters/latex.rb, line 58
58:   def acronym(opts)
59:     "#{opts[:title]} (#{opts[:text]})"
60:   end
arrow(opts) click to toggle source
     # File lib/redcloth/formatters/latex.rb, line 259
259:   def arrow(opts)
260:     "\\rightarrow{}"
261:   end
bc_close(opts) click to toggle source
     # File lib/redcloth/formatters/latex.rb, line 183
183:   def bc_close(opts)
184:     end_chunk("verbatim") + "\n"
185:   end
bc_open(opts) click to toggle source

code blocks

     # File lib/redcloth/formatters/latex.rb, line 178
178:   def bc_open(opts)
179:     opts[:block] = true
180:     begin_chunk("verbatim") + "\n"
181:   end
bq_close(opts) click to toggle source
     # File lib/redcloth/formatters/latex.rb, line 193
193:   def bq_close(opts)
194:     "\\end{quotation}\n\n"
195:   end
bq_open(opts) click to toggle source

block quotations

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

inline code

    # File lib/redcloth/formatters/latex.rb, line 53
53:   def code(opts)
54:     opts[:block] ? opts[:text] : "\\verb@#{opts[:text]}@"
55:   end
dim(opts) click to toggle source
     # File lib/redcloth/formatters/latex.rb, line 282
282:   def dim(opts)
283:     opts[:text].gsub!('x', '\times')
284:     opts[:text].gsub!('"', "''")
285:     period = opts[:text].slice!(/\.$/)
286:     "$#{opts[:text]}$#{period}"
287:   end
ellipsis(opts) click to toggle source
     # File lib/redcloth/formatters/latex.rb, line 247
247:   def ellipsis(opts)
248:     "#{opts[:text]}\\ldots{}"
249:   end
emdash(opts) click to toggle source
     # File lib/redcloth/formatters/latex.rb, line 251
251:   def emdash(opts)
252:     "---"
253:   end
endash(opts) click to toggle source
     # File lib/redcloth/formatters/latex.rb, line 255
255:   def endash(opts)
256:     "--"
257:   end
entity(opts) click to toggle source

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

     # File lib/redcloth/formatters/latex.rb, line 277
277:   def entity(opts)
278:     text = opts[:text][0..0] == '#' ? opts[:text][1..1] : opts[:text] 
279:     ENTITIES[text]
280:   end
fn(opts) click to toggle source
     # File lib/redcloth/formatters/latex.rb, line 230
230:   def fn(opts)
231:     "\\footnotetext[#{opts[:id]}]{#{opts[:text]}}"
232:   end
footno(opts) click to toggle source

footnotes

     # File lib/redcloth/formatters/latex.rb, line 224
224:   def footno(opts)
225:     # TODO: insert a placeholder until we know the footnote content.
226:     # For this to work, we need some kind of post-processing...
227:     "\\footnotemark[#{opts[:text]}]"
228:   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
208:   def image(opts)
209:     # Don't know how to use remote links, plus can we trust them?
210:     return "" if opts[:src] =~ /^\w+\:\/\//
211:     # Resolve CSS styles if any have been set
212:     styling = opts[:class].to_s.split(/\s+/).collect { |style| latex_image_styles[style] }.compact.join ','
213:     # Build latex code
214:     [ "\\begin{figure}",
215:       "  \\centering",
216:       "  \\includegraphics[#{styling}]{#{opts[:src]}}",
217:      ("  \\caption{#{escape opts[:title]}}" if opts[:title]),
218:      ("  \\label{#{escape opts[:alt]}}" if opts[:alt]),
219:       "\\end{figure}",
220:     ].compact.join "\n"
221:   end
inline_html(opts) click to toggle source

TODO: what do we do with HTML?

     # File lib/redcloth/formatters/latex.rb, line 290
290:   def inline_html(opts)
291:     opts[:text] || ""
292:   end
li_close(opts=nil) click to toggle source
     # File lib/redcloth/formatters/latex.rb, line 107
107:   def li_close(opts=nil)
108:     "\n"
109:   end
li_open(opts) click to toggle source
     # File lib/redcloth/formatters/latex.rb, line 103
103:   def li_open(opts)
104:     "  \\item #{opts[:text]}"
105:   end
p(opts) click to toggle source

paragraphs

     # File lib/redcloth/formatters/latex.rb, line 112
112:   def p(opts)
113:     case opts[:align]
114:     when 'left' then
115:       "\\begin{flushleft}#{opts[:text]}\\end{flushleft}\n\n" 
116:     when 'right' then
117:       "\\begin{flushright}#{opts[:text]}\\end{flushright}\n\n" 
118:     when 'center' then
119:       "\\begin{center}#{opts[:text]}\\end{center}\n\n" 
120:     else
121:       "#{opts[:text]}\n\n"
122:     end
123:   end
quote1(opts) click to toggle source
     # File lib/redcloth/formatters/latex.rb, line 239
239:   def quote1(opts)
240:     "`#{opts[:text]}'"
241:   end
quote2(opts) click to toggle source
     # File lib/redcloth/formatters/latex.rb, line 243
243:   def quote2(opts)
244:     "``#{opts[:text]}\""
245:   end
registered(opts) click to toggle source
     # File lib/redcloth/formatters/latex.rb, line 267
267:   def registered(opts)
268:     "\\textregistered{}"
269:   end
snip(opts) click to toggle source

inline verbatim

     # File lib/redcloth/formatters/latex.rb, line 235
235:   def snip(opts)
236:     "\\verb`#{opts[:text]}`"
237:   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
165:   def table_close(opts)
166:     output  = "\\begin{table}\n"
167:     output << "  \\centering\n"
168:     output << "  \\begin{tabular}{ #{"l " * @table[0].size }}\n"
169:     @table.each do |row|
170:       output << "    #{row.join(" & ")} \\\\\n"
171:     end
172:     output << "  \\end{tabular}\n"
173:     output << "\\end{table}\n"
174:     output
175:   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
157:   def table_open(opts)
158:     @table = []
159:     @table_multirow = {}
160:     @table_multirow_next = {}
161:     return ""
162:   end
td(opts) click to toggle source

tables

     # File lib/redcloth/formatters/latex.rb, line 126
126:   def td(opts)
127:     column = @table_row.size
128:     if opts[:colspan]
129:       opts[:text] = "\\multicolumn{#{opts[:colspan]}}{ #{"l " * opts[:colspan].to_i}}{#{opts[:text]}}"
130:     end
131:     if opts[:rowspan]
132:       @table_multirow_next[column] = opts[:rowspan].to_i - 1
133:       opts[:text] = "\\multirow{#{opts[:rowspan]}}{*}{#{opts[:text]}}"
134:     end
135:     @table_row.push(opts[:text])
136:     return ""
137:   end
tr_close(opts) click to toggle source
     # File lib/redcloth/formatters/latex.rb, line 144
144:   def tr_close(opts)
145:     multirow_columns = @table_multirow.find_all {|c,n| n > 0}
146:     multirow_columns.each do |c,n|
147:       @table_row.insert(c,"")
148:       @table_multirow[c] -= 1
149:     end
150:     @table_multirow.merge!(@table_multirow_next)
151:     @table_multirow_next = {}
152:     @table.push(@table_row)
153:     return ""
154:   end
tr_open(opts) click to toggle source
     # File lib/redcloth/formatters/latex.rb, line 139
139:   def tr_open(opts)
140:     @table_row = []
141:     return ""
142:   end
trademark(opts) click to toggle source
     # File lib/redcloth/formatters/latex.rb, line 263
263:   def trademark(opts)
264:     "\\texttrademark{}"
265:   end

Private Instance Methods

begin_chunk(type) click to toggle source

Use this for block level commands that use begin

     # File lib/redcloth/formatters/latex.rb, line 305
305:   def begin_chunk(type)
306:     chunk_counter[type] += 1
307:     return "\\begin{#{type}}" if 1 == chunk_counter[type]
308:     ''
309:   end
chunk_counter() click to toggle source
     # File lib/redcloth/formatters/latex.rb, line 319
319:   def chunk_counter
320:     @chunk_counter ||= Hash.new 0
321:   end
end_chunk(type) click to toggle source

Use this for block level commands that use end

     # File lib/redcloth/formatters/latex.rb, line 312
312:   def end_chunk(type)
313:     chunk_counter[type] -= 1
314:     raise RuntimeError, "Bad latex #{type} nesting detected" if chunk_counter[type] < 0 # This should never need to happen
315:     return "\\end{#{type}}" if 0 == chunk_counter[type]
316:     ''
317:   end
escape(text) click to toggle source
     # File lib/redcloth/formatters/latex.rb, line 296
296:   def escape(text)
297:     latex_esc(text)
298:   end
escape_pre(text) click to toggle source
     # File lib/redcloth/formatters/latex.rb, line 300
300:   def escape_pre(text)
301:     text
302:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.