| Module | RedCloth::Formatters::LATEX |
| In: |
lib/redcloth/formatters/latex.rb
lib/redcloth/formatters/latex.rb |
| ENTITIES | = | YAML::load(File.read(File.dirname(__FILE__)+'/latex_entities.yml')) |
| ENTITIES | = | YAML::load(File.read(File.dirname(__FILE__)+'/latex_entities.yml')) |
acronyms
# File lib/redcloth/formatters/latex.rb, line 58
58: def acronym(opts)
59: "#{opts[:title]} (#{opts[:text]})"
60: end
acronyms
# File lib/redcloth/formatters/latex.rb, line 58
58: def acronym(opts)
59: "#{opts[:title]} (#{opts[:text]})"
60: end
# File lib/redcloth/formatters/latex.rb, line 259
259: def arrow(opts)
260: "\\rightarrow{}"
261: end
# File lib/redcloth/formatters/latex.rb, line 259
259: def arrow(opts)
260: "\\rightarrow{}"
261: end
# File lib/redcloth/formatters/latex.rb, line 183
183: def bc_close(opts)
184: end_chunk("verbatim") + "\n"
185: end
# File lib/redcloth/formatters/latex.rb, line 183
183: def bc_close(opts)
184: end_chunk("verbatim") + "\n"
185: end
# File lib/redcloth/formatters/latex.rb, line 193
193: def bq_close(opts)
194: "\\end{quotation}\n\n"
195: end
# File lib/redcloth/formatters/latex.rb, line 193
193: def bq_close(opts)
194: "\\end{quotation}\n\n"
195: end
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
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
# File lib/redcloth/formatters/latex.rb, line 271
271: def copyright(opts)
272: "\\copyright{}"
273: end
# File lib/redcloth/formatters/latex.rb, line 271
271: def copyright(opts)
272: "\\copyright{}"
273: end
# 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
# 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
# File lib/redcloth/formatters/latex.rb, line 247
247: def ellipsis(opts)
248: "#{opts[:text]}\\ldots{}"
249: end
# File lib/redcloth/formatters/latex.rb, line 247
247: def ellipsis(opts)
248: "#{opts[:text]}\\ldots{}"
249: end
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
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
# File lib/redcloth/formatters/latex.rb, line 230
230: def fn(opts)
231: "\\footnotetext[#{opts[:id]}]{#{opts[:text]}}"
232: end
# File lib/redcloth/formatters/latex.rb, line 230
230: def fn(opts)
231: "\\footnotetext[#{opts[:id]}]{#{opts[:text]}}"
232: end
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
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
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
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
# File lib/redcloth/formatters/latex.rb, line 103
103: def li_open(opts)
104: " \\item #{opts[:text]}"
105: end
# File lib/redcloth/formatters/latex.rb, line 103
103: def li_open(opts)
104: " \\item #{opts[:text]}"
105: end
links
# File lib/redcloth/formatters/latex.rb, line 198
198: def link(opts)
199: "\\href{#{opts[:href]}}{#{opts[:name]}}"
200: end
links
# File lib/redcloth/formatters/latex.rb, line 198
198: def link(opts)
199: "\\href{#{opts[:href]}}{#{opts[:name]}}"
200: end
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
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
# File lib/redcloth/formatters/latex.rb, line 239
239: def quote1(opts)
240: "`#{opts[:text]}'"
241: end
# File lib/redcloth/formatters/latex.rb, line 239
239: def quote1(opts)
240: "`#{opts[:text]}'"
241: end
# File lib/redcloth/formatters/latex.rb, line 243
243: def quote2(opts)
244: "``#{opts[:text]}\""
245: end
# File lib/redcloth/formatters/latex.rb, line 243
243: def quote2(opts)
244: "``#{opts[:text]}\""
245: end
# File lib/redcloth/formatters/latex.rb, line 267
267: def registered(opts)
268: "\\textregistered{}"
269: end
# File lib/redcloth/formatters/latex.rb, line 267
267: def registered(opts)
268: "\\textregistered{}"
269: end
inline verbatim
# File lib/redcloth/formatters/latex.rb, line 235
235: def snip(opts)
236: "\\verb`#{opts[:text]}`"
237: end
inline verbatim
# 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
# 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
# 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.
# 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.
# 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
# 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
# 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
# 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
# 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
# File lib/redcloth/formatters/latex.rb, line 139
139: def tr_open(opts)
140: @table_row = []
141: return ""
142: end
# File lib/redcloth/formatters/latex.rb, line 139
139: def tr_open(opts)
140: @table_row = []
141: return ""
142: end
# File lib/redcloth/formatters/latex.rb, line 263
263: def trademark(opts)
264: "\\texttrademark{}"
265: end