| 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')) |
# File lib/redcloth/formatters/latex.rb, line 219
219: def arrow(opts)
220: "\\rightarrow{}"
221: end
# File lib/redcloth/formatters/latex.rb, line 219
219: def arrow(opts)
220: "\\rightarrow{}"
221: end
# File lib/redcloth/formatters/latex.rb, line 148
148: def bc_close(opts)
149: end_chunk("verbatim") + "\n"
150: end
# File lib/redcloth/formatters/latex.rb, line 148
148: def bc_close(opts)
149: end_chunk("verbatim") + "\n"
150: end
# File lib/redcloth/formatters/latex.rb, line 143
143: def bc_open(opts)
144: opts[:block] = true
145: begin_chunk("verbatim") + "\n"
146: end
# File lib/redcloth/formatters/latex.rb, line 143
143: def bc_open(opts)
144: opts[:block] = true
145: begin_chunk("verbatim") + "\n"
146: end
# File lib/redcloth/formatters/latex.rb, line 157
157: def bq_close(opts)
158: "\\end{quotation}\n\n"
159: end
# File lib/redcloth/formatters/latex.rb, line 157
157: def bq_close(opts)
158: "\\end{quotation}\n\n"
159: end
# File lib/redcloth/formatters/latex.rb, line 152
152: def bq_open(opts)
153: opts[:block] = true
154: "\\begin{quotation}\n"
155: end
# File lib/redcloth/formatters/latex.rb, line 152
152: def bq_open(opts)
153: opts[:block] = true
154: "\\begin{quotation}\n"
155: end
# File lib/redcloth/formatters/latex.rb, line 231
231: def copyright(opts)
232: "\\copyright{}"
233: end
# File lib/redcloth/formatters/latex.rb, line 231
231: def copyright(opts)
232: "\\copyright{}"
233: end
# File lib/redcloth/formatters/latex.rb, line 242
242: def dim(opts)
243: opts[:text].gsub!('x', '\times')
244: opts[:text].gsub!('"', "''")
245: period = opts[:text].slice!(/\.$/)
246: "$#{opts[:text]}$#{period}"
247: end
# File lib/redcloth/formatters/latex.rb, line 242
242: def dim(opts)
243: opts[:text].gsub!('x', '\times')
244: opts[:text].gsub!('"', "''")
245: period = opts[:text].slice!(/\.$/)
246: "$#{opts[:text]}$#{period}"
247: end
# File lib/redcloth/formatters/latex.rb, line 207
207: def ellipsis(opts)
208: "#{opts[:text]}\\ldots{}"
209: end
# File lib/redcloth/formatters/latex.rb, line 207
207: def ellipsis(opts)
208: "#{opts[:text]}\\ldots{}"
209: end
TODO: what do we do with (unknown) unicode entities ?
# File lib/redcloth/formatters/latex.rb, line 237
237: def entity(opts)
238: text = opts[:text][0..0] == '#' ? opts[:text][1..-1] : opts[:text]
239: ENTITIES[text]
240: end
TODO: what do we do with (unknown) unicode entities ?
# File lib/redcloth/formatters/latex.rb, line 237
237: def entity(opts)
238: text = opts[:text][0..0] == '#' ? opts[:text][1..-1] : opts[:text]
239: ENTITIES[text]
240: end
# File lib/redcloth/formatters/latex.rb, line 191
191: def fn(opts)
192: "\\footnotetext[#{opts[:id]}]{#{opts[:text]}}"
193: end
# File lib/redcloth/formatters/latex.rb, line 191
191: def fn(opts)
192: "\\footnotetext[#{opts[:id]}]{#{opts[:text]}}"
193: end
# File lib/redcloth/formatters/latex.rb, line 185
185: def footno(opts)
186: # TODO: insert a placeholder until we know the footnote content.
187: # For this to work, we need some kind of post-processing...
188: "\\footnotemark[#{opts[:text]}]"
189: end
# File lib/redcloth/formatters/latex.rb, line 185
185: def footno(opts)
186: # TODO: insert a placeholder until we know the footnote content.
187: # For this to work, we need some kind of post-processing...
188: "\\footnotemark[#{opts[:text]}]"
189: 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 171
171: def image(opts)
172: # Don't know how to use remote links, plus can we trust them?
173: return "" if opts[:src] =~ /^\w+\:\/\//
174: # Resolve CSS styles if any have been set
175: styling = opts[:class].to_s.split(/\s+/).collect { |style| latex_image_styles[style] }.compact.join ','
176: # Build latex code
177: [ "\\begin{figure}[htp]",
178: " \\includegraphics[#{styling}]{#{opts[:src]}}",
179: (" \\caption{#{escape opts[:title]}}" if opts[:title]),
180: (" \\label{#{escape opts[:alt]}}" if opts[:alt]),
181: "\\end{figure}",
182: ].compact.join "\n"
183: 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 171
171: def image(opts)
172: # Don't know how to use remote links, plus can we trust them?
173: return "" if opts[:src] =~ /^\w+\:\/\//
174: # Resolve CSS styles if any have been set
175: styling = opts[:class].to_s.split(/\s+/).collect { |style| latex_image_styles[style] }.compact.join ','
176: # Build latex code
177: [ "\\begin{figure}[htp]",
178: " \\includegraphics[#{styling}]{#{opts[:src]}}",
179: (" \\caption{#{escape opts[:title]}}" if opts[:title]),
180: (" \\label{#{escape opts[:alt]}}" if opts[:alt]),
181: "\\end{figure}",
182: ].compact.join "\n"
183: end
# File lib/redcloth/formatters/latex.rb, line 84
84: def li_open(opts)
85: "#{li_close unless opts.delete(:first)}\t\\item #{opts[:text]}"
86: end
# File lib/redcloth/formatters/latex.rb, line 84
84: def li_open(opts)
85: "#{li_close unless opts.delete(:first)}\t\\item #{opts[:text]}"
86: end
# File lib/redcloth/formatters/latex.rb, line 161
161: def link(opts)
162: "\\href{#{opts[:href]}}{#{opts[:name]}}"
163: end
# File lib/redcloth/formatters/latex.rb, line 161
161: def link(opts)
162: "\\href{#{opts[:href]}}{#{opts[:name]}}"
163: end
# File lib/redcloth/formatters/latex.rb, line 199
199: def quote1(opts)
200: "`#{opts[:text]}'"
201: end
# File lib/redcloth/formatters/latex.rb, line 199
199: def quote1(opts)
200: "`#{opts[:text]}'"
201: end
# File lib/redcloth/formatters/latex.rb, line 203
203: def quote2(opts)
204: "``#{opts[:text]}\""
205: end
# File lib/redcloth/formatters/latex.rb, line 203
203: def quote2(opts)
204: "``#{opts[:text]}\""
205: end
# File lib/redcloth/formatters/latex.rb, line 227
227: def registered(opts)
228: "\\textregistered{}"
229: end
# File lib/redcloth/formatters/latex.rb, line 227
227: def registered(opts)
228: "\\textregistered{}"
229: end
# File lib/redcloth/formatters/latex.rb, line 195
195: def snip(opts)
196: "\\begin{verbatim}#{opts[:text]}\\end{verbatim}"
197: end
# File lib/redcloth/formatters/latex.rb, line 195
195: def snip(opts)
196: "\\begin{verbatim}#{opts[:text]}\\end{verbatim}"
197: end
# File lib/redcloth/formatters/latex.rb, line 134
134: def table_close(opts)
135: output = "\\begin{tabular}{ #{"l " * @table[0].size }}\n"
136: @table.each do |row|
137: output << " #{row.join(" & ")} \\\\\n"
138: end
139: output << "\\end{tabular}\n"
140: output
141: end
# File lib/redcloth/formatters/latex.rb, line 134
134: def table_close(opts)
135: output = "\\begin{tabular}{ #{"l " * @table[0].size }}\n"
136: @table.each do |row|
137: output << " #{row.join(" & ")} \\\\\n"
138: end
139: output << "\\end{tabular}\n"
140: output
141: end
We need to know the column count before opening tabular context.
# File lib/redcloth/formatters/latex.rb, line 127
127: def table_open(opts)
128: @table = []
129: @table_multirow = {}
130: @table_multirow_next = {}
131: return ""
132: end
We need to know the column count before opening tabular context.
# File lib/redcloth/formatters/latex.rb, line 127
127: def table_open(opts)
128: @table = []
129: @table_multirow = {}
130: @table_multirow_next = {}
131: return ""
132: end
# File lib/redcloth/formatters/latex.rb, line 96
96: def td(opts)
97: column = @table_row.size
98: if opts[:colspan]
99: opts[:text] = "\\multicolumn{#{opts[:colspan]}}{ #{"l " * opts[:colspan].to_i}}{#{opts[:text]}}"
100: end
101: if opts[:rowspan]
102: @table_multirow_next[column] = opts[:rowspan].to_i - 1
103: opts[:text] = "\\multirow{#{opts[:rowspan]}}{*}{#{opts[:text]}}"
104: end
105: @table_row.push(opts[:text])
106: return ""
107: end
# File lib/redcloth/formatters/latex.rb, line 96
96: def td(opts)
97: column = @table_row.size
98: if opts[:colspan]
99: opts[:text] = "\\multicolumn{#{opts[:colspan]}}{ #{"l " * opts[:colspan].to_i}}{#{opts[:text]}}"
100: end
101: if opts[:rowspan]
102: @table_multirow_next[column] = opts[:rowspan].to_i - 1
103: opts[:text] = "\\multirow{#{opts[:rowspan]}}{*}{#{opts[:text]}}"
104: end
105: @table_row.push(opts[:text])
106: return ""
107: end
# File lib/redcloth/formatters/latex.rb, line 114
114: def tr_close(opts)
115: multirow_columns = @table_multirow.find_all {|c,n| n > 0}
116: multirow_columns.each do |c,n|
117: @table_row.insert(c,"")
118: @table_multirow[c] -= 1
119: end
120: @table_multirow.merge!(@table_multirow_next)
121: @table_multirow_next = {}
122: @table.push(@table_row)
123: return ""
124: end
# File lib/redcloth/formatters/latex.rb, line 114
114: def tr_close(opts)
115: multirow_columns = @table_multirow.find_all {|c,n| n > 0}
116: multirow_columns.each do |c,n|
117: @table_row.insert(c,"")
118: @table_multirow[c] -= 1
119: end
120: @table_multirow.merge!(@table_multirow_next)
121: @table_multirow_next = {}
122: @table.push(@table_row)
123: return ""
124: end
# File lib/redcloth/formatters/latex.rb, line 109
109: def tr_open(opts)
110: @table_row = []
111: return ""
112: end
# File lib/redcloth/formatters/latex.rb, line 109
109: def tr_open(opts)
110: @table_row = []
111: return ""
112: end
# File lib/redcloth/formatters/latex.rb, line 223
223: def trademark(opts)
224: "\\texttrademark{}"
225: end