Module RedCloth::Formatters::LATEX
In: lib/redcloth/formatters/latex.rb
lib/redcloth/formatters/latex.rb

Methods

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

Included Modules

RedCloth::Formatters::Base RedCloth::Formatters::Base

Classes and Modules

Module RedCloth::Formatters::LATEX::Settings

Constants

ENTITIES = YAML::load(File.read(File.dirname(__FILE__)+'/latex_entities.yml'))
ENTITIES = YAML::load(File.read(File.dirname(__FILE__)+'/latex_entities.yml'))

Public Instance methods

acronyms

[Source]

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

acronyms

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

code blocks

[Source]

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

code blocks

[Source]

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

[Source]

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

[Source]

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

block quotations

[Source]

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

block quotations

[Source]

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

inline code

[Source]

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

inline code

[Source]

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

[Source]

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

[Source]

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

[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

[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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

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

[Source]

     # 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

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

[Source]

     # 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

[Source]

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

[Source]

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

footnotes

[Source]

     # 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

footnotes

[Source]

     # 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

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, 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

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, 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

TODO: what do we do with HTML?

[Source]

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

TODO: what do we do with HTML?

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

links

[Source]

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

links

[Source]

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

paragraphs

[Source]

     # 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

paragraphs

[Source]

     # 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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

inline verbatim

[Source]

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

inline verbatim

[Source]

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

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

[Source]

     # 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

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

[Source]

     # 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

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

[Source]

     # 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

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

[Source]

     # 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

tables

[Source]

     # 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

tables

[Source]

     # 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

[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

[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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Validate]