Module: RedCloth::Formatters::LATEX
- Includes:
- Base
- Defined in:
- lib/redcloth/formatters/latex.rb
Defined Under Namespace
Modules: Settings
Class Method Summary collapse
Instance Method Summary collapse
-
#acronym(opts) ⇒ Object
acronyms.
- #arrow(opts) ⇒ Object
- #auto_link(opts) ⇒ Object
- #bc_close(opts) ⇒ Object
-
#bc_open(opts) ⇒ Object
code blocks.
- #bq_close(opts) ⇒ Object
-
#bq_open(opts) ⇒ Object
block quotations.
-
#code(opts) ⇒ Object
inline code.
- #copyright(opts) ⇒ Object
- #dim(opts) ⇒ Object
- #ellipsis(opts) ⇒ Object
- #emdash(opts) ⇒ Object
- #endash(opts) ⇒ Object
-
#entity(opts) ⇒ Object
TODO: what do we do with (unknown) unicode entities ?.
- #fn(opts) ⇒ Object
-
#footno(opts) ⇒ Object
footnotes.
-
#image(opts) ⇒ Object
FIXME: use includegraphics with security verification.
-
#inline_html(opts) ⇒ Object
TODO: what do we do with HTML?.
- #li_close(opts = nil) ⇒ Object
- #li_open(opts) ⇒ Object
-
#link(opts) ⇒ Object
links.
-
#p(opts) ⇒ Object
paragraphs.
- #quote1(opts) ⇒ Object
- #quote2(opts) ⇒ Object
- #registered(opts) ⇒ Object
-
#snip(opts) ⇒ Object
inline verbatim.
-
#table_close(opts) ⇒ Object
FIXME: need caption and label elements similar to image -> figure.
-
#table_open(opts) ⇒ Object
We need to know the column count before opening tabular context.
-
#td(opts) ⇒ Object
tables.
- #tr_close(opts) ⇒ Object
- #tr_open(opts) ⇒ Object
- #trademark(opts) ⇒ Object
Methods included from Base
#ignore, #inline_redcloth_version, #redcloth_version
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class RedCloth::Formatters::Base
Class Method Details
.entities ⇒ Object
6 7 8 |
# File 'lib/redcloth/formatters/latex.rb', line 6 def self.entities @entities ||= YAML.load(File.read(File.dirname(__FILE__)+'/latex_entities.yml')) end |
Instance Method Details
#acronym(opts) ⇒ Object
acronyms
60 61 62 |
# File 'lib/redcloth/formatters/latex.rb', line 60 def acronym(opts) "#{opts[:title]} (#{opts[:text]})" end |
#arrow(opts) ⇒ Object
268 269 270 |
# File 'lib/redcloth/formatters/latex.rb', line 268 def arrow(opts) "\\rightarrow{}" end |
#auto_link(opts) ⇒ Object
204 205 206 207 208 209 |
# File 'lib/redcloth/formatters/latex.rb', line 204 def auto_link(opts) return opts[:href] unless auto_link_urls href_with_proto = opts[:href] href_with_proto = 'http://' + href_with_proto unless href_with_proto.index('http') == 0 "\\href{#{href_with_proto}}{#{opts[:href]}}" end |
#bc_close(opts) ⇒ Object
185 186 187 |
# File 'lib/redcloth/formatters/latex.rb', line 185 def bc_close(opts) end_chunk("verbatim") + "\n" end |
#bc_open(opts) ⇒ Object
code blocks
180 181 182 183 |
# File 'lib/redcloth/formatters/latex.rb', line 180 def bc_open(opts) opts[:block] = true begin_chunk("verbatim") + "\n" end |
#bq_close(opts) ⇒ Object
195 196 197 |
# File 'lib/redcloth/formatters/latex.rb', line 195 def bq_close(opts) "\\end{quotation}\n\n" end |
#bq_open(opts) ⇒ Object
block quotations
190 191 192 193 |
# File 'lib/redcloth/formatters/latex.rb', line 190 def bq_open(opts) opts[:block] = true "\\begin{quotation}\n" end |
#code(opts) ⇒ Object
inline code
55 56 57 |
# File 'lib/redcloth/formatters/latex.rb', line 55 def code(opts) opts[:block] ? opts[:text] : "\\verb@#{opts[:text]}@" end |
#copyright(opts) ⇒ Object
280 281 282 |
# File 'lib/redcloth/formatters/latex.rb', line 280 def copyright(opts) "\\copyright{}" end |
#dim(opts) ⇒ Object
291 292 293 294 295 296 |
# File 'lib/redcloth/formatters/latex.rb', line 291 def dim(opts) opts[:text].gsub!('x', '\times') opts[:text].gsub!('"', "''") period = opts[:text].slice!(/\.$/) "$#{opts[:text]}$#{period}" end |
#ellipsis(opts) ⇒ Object
256 257 258 |
# File 'lib/redcloth/formatters/latex.rb', line 256 def ellipsis(opts) "#{opts[:text]}\\ldots{}" end |
#emdash(opts) ⇒ Object
260 261 262 |
# File 'lib/redcloth/formatters/latex.rb', line 260 def emdash(opts) "---" end |
#endash(opts) ⇒ Object
264 265 266 |
# File 'lib/redcloth/formatters/latex.rb', line 264 def endash(opts) " -- " end |
#entity(opts) ⇒ Object
TODO: what do we do with (unknown) unicode entities ?
286 287 288 289 |
# File 'lib/redcloth/formatters/latex.rb', line 286 def entity(opts) text = opts[:text][0..0] == '#' ? opts[:text][1..-1] : opts[:text] RedCloth::Formatters::LATEX.entities[text] end |
#fn(opts) ⇒ Object
239 240 241 |
# File 'lib/redcloth/formatters/latex.rb', line 239 def fn(opts) "\\footnotetext[#{opts[:id]}]{#{opts[:text]}}" end |
#footno(opts) ⇒ Object
footnotes
233 234 235 236 237 |
# File 'lib/redcloth/formatters/latex.rb', line 233 def footno(opts) # TODO: insert a placeholder until we know the footnote content. # For this to work, we need some kind of post-processing... "\\footnotemark[#{opts[:text]}]" end |
#image(opts) ⇒ Object
FIXME: use includegraphics with security verification
Remember to use ‘RequirePackagegraphicx’ 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.
217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/redcloth/formatters/latex.rb', line 217 def image(opts) # Don't know how to use remote links, plus can we trust them? return "" if opts[:src] =~ /^\w+\:\/\// # Resolve CSS styles if any have been set styling = opts[:class].to_s.split(/\s+/).collect { |style| latex_image_styles[style] }.compact.join ',' # Build latex code [ "\\begin{figure}", " \\centering", " \\includegraphics[#{styling}]{#{opts[:src]}}", (" \\caption{#{escape opts[:title]}}" if opts[:title]), (" \\label{#{escape opts[:alt]}}" if opts[:alt]), "\\end{figure}", ].compact.join "\n" end |
#inline_html(opts) ⇒ Object
TODO: what do we do with HTML?
299 300 301 |
# File 'lib/redcloth/formatters/latex.rb', line 299 def inline_html(opts) opts[:text] || "" end |
#li_close(opts = nil) ⇒ Object
109 110 111 |
# File 'lib/redcloth/formatters/latex.rb', line 109 def li_close(opts=nil) "\n" end |
#li_open(opts) ⇒ Object
105 106 107 |
# File 'lib/redcloth/formatters/latex.rb', line 105 def li_open(opts) " \\item #{opts[:text]}" end |
#link(opts) ⇒ Object
links
200 201 202 |
# File 'lib/redcloth/formatters/latex.rb', line 200 def link(opts) "\\href{#{opts[:href]}}{#{opts[:name]}}" end |
#p(opts) ⇒ Object
paragraphs
114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/redcloth/formatters/latex.rb', line 114 def p(opts) case opts[:align] when 'left' then "\\begin{flushleft}#{opts[:text]}\\end{flushleft}\n\n" when 'right' then "\\begin{flushright}#{opts[:text]}\\end{flushright}\n\n" when 'center' then "\\begin{center}#{opts[:text]}\\end{center}\n\n" else "#{opts[:text]}\n\n" end end |
#quote1(opts) ⇒ Object
248 249 250 |
# File 'lib/redcloth/formatters/latex.rb', line 248 def quote1(opts) "`#{opts[:text]}'" end |
#quote2(opts) ⇒ Object
252 253 254 |
# File 'lib/redcloth/formatters/latex.rb', line 252 def quote2(opts) "``#{opts[:text]}''" end |
#registered(opts) ⇒ Object
276 277 278 |
# File 'lib/redcloth/formatters/latex.rb', line 276 def registered(opts) "\\textregistered{}" end |
#snip(opts) ⇒ Object
inline verbatim
244 245 246 |
# File 'lib/redcloth/formatters/latex.rb', line 244 def snip(opts) "\\verb`#{opts[:text]}`" end |
#table_close(opts) ⇒ Object
FIXME: need caption and label elements similar to image -> figure
167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/redcloth/formatters/latex.rb', line 167 def table_close(opts) output = "\\begin{table}\n" output << " \\centering\n" output << " \\begin{tabular}{ #{"l " * @table[0].size }}\n" @table.each do |row| output << " #{row.join(" & ")} \\\\\n" end output << " \\end{tabular}\n" output << "\\end{table}\n" output end |
#table_open(opts) ⇒ Object
We need to know the column count before opening tabular context.
159 160 161 162 163 164 |
# File 'lib/redcloth/formatters/latex.rb', line 159 def table_open(opts) @table = [] @table_multirow = {} @table_multirow_next = {} return "" end |
#td(opts) ⇒ Object
tables
128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/redcloth/formatters/latex.rb', line 128 def td(opts) column = @table_row.size if opts[:colspan] opts[:text] = "\\multicolumn{#{opts[:colspan]}}{ #{"l " * opts[:colspan].to_i}}{#{opts[:text]}}" end if opts[:rowspan] @table_multirow_next[column] = opts[:rowspan].to_i - 1 opts[:text] = "\\multirow{#{opts[:rowspan]}}{*}{#{opts[:text]}}" end @table_row.push(opts[:text]) return "" end |
#tr_close(opts) ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/redcloth/formatters/latex.rb', line 146 def tr_close(opts) multirow_columns = @table_multirow.find_all {|c,n| n > 0} multirow_columns.each do |c,n| @table_row.insert(c,"") @table_multirow[c] -= 1 end @table_multirow.merge!(@table_multirow_next) @table_multirow_next = {} @table.push(@table_row) return "" end |
#tr_open(opts) ⇒ Object
141 142 143 144 |
# File 'lib/redcloth/formatters/latex.rb', line 141 def tr_open(opts) @table_row = [] return "" end |
#trademark(opts) ⇒ Object
272 273 274 |
# File 'lib/redcloth/formatters/latex.rb', line 272 def trademark(opts) "\\texttrademark{}" end |