patcito-maruku 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. data/AUTHORS +23 -0
  2. data/LICENSE +340 -0
  3. data/README.md +73 -0
  4. data/bin/maruku +196 -0
  5. data/bin/marutex +4 -0
  6. data/data/entities.xml +261 -0
  7. data/docs/changelog.md +334 -0
  8. data/docs/div_syntax.md +36 -0
  9. data/docs/entity_test.md +23 -0
  10. data/docs/markdown_syntax.md +899 -0
  11. data/docs/maruku.md +346 -0
  12. data/docs/math.md +194 -0
  13. data/docs/other_stuff.md +51 -0
  14. data/docs/proposal.md +309 -0
  15. data/docs/website/src/bluecloth.md +25 -0
  16. data/docs/website/src/download.md +31 -0
  17. data/docs/website/src/maruku.md +261 -0
  18. data/docs/website/src/proposal.md +271 -0
  19. data/lib/maruku.rb +132 -0
  20. data/lib/maruku/attributes.rb +138 -0
  21. data/lib/maruku/defaults.rb +69 -0
  22. data/lib/maruku/errors.rb +89 -0
  23. data/lib/maruku/ext/div.rb +121 -0
  24. data/lib/maruku/ext/fenced_code.rb +78 -0
  25. data/lib/maruku/ext/math.rb +37 -0
  26. data/lib/maruku/ext/math/elements.rb +21 -0
  27. data/lib/maruku/ext/math/latex_fix.rb +12 -0
  28. data/lib/maruku/ext/math/mathml_engines/blahtex.rb +93 -0
  29. data/lib/maruku/ext/math/mathml_engines/itex2mml.rb +39 -0
  30. data/lib/maruku/ext/math/mathml_engines/none.rb +21 -0
  31. data/lib/maruku/ext/math/mathml_engines/ritex.rb +24 -0
  32. data/lib/maruku/ext/math/parsing.rb +125 -0
  33. data/lib/maruku/ext/math/to_html.rb +237 -0
  34. data/lib/maruku/ext/math/to_latex.rb +36 -0
  35. data/lib/maruku/ext/yaml.rb +43 -0
  36. data/lib/maruku/helpers.rb +214 -0
  37. data/lib/maruku/input/charsource.rb +326 -0
  38. data/lib/maruku/input/extensions.rb +69 -0
  39. data/lib/maruku/input/html_helper.rb +189 -0
  40. data/lib/maruku/input/linesource.rb +111 -0
  41. data/lib/maruku/input/parse_block.rb +608 -0
  42. data/lib/maruku/input/parse_doc.rb +240 -0
  43. data/lib/maruku/input/parse_span_better.rb +746 -0
  44. data/lib/maruku/input/rubypants.rb +225 -0
  45. data/lib/maruku/input/type_detection.rb +147 -0
  46. data/lib/maruku/input_textile2/t2_parser.rb +163 -0
  47. data/lib/maruku/maruku.rb +31 -0
  48. data/lib/maruku/output/s5/fancy.rb +756 -0
  49. data/lib/maruku/output/s5/to_s5.rb +138 -0
  50. data/lib/maruku/output/to_html.rb +994 -0
  51. data/lib/maruku/output/to_latex.rb +580 -0
  52. data/lib/maruku/output/to_latex_entities.rb +101 -0
  53. data/lib/maruku/output/to_latex_strings.rb +64 -0
  54. data/lib/maruku/output/to_markdown.rb +164 -0
  55. data/lib/maruku/output/to_s.rb +54 -0
  56. data/lib/maruku/string_utils.rb +185 -0
  57. data/lib/maruku/structures.rb +143 -0
  58. data/lib/maruku/structures_inspect.rb +51 -0
  59. data/lib/maruku/structures_iterators.rb +48 -0
  60. data/lib/maruku/textile2.rb +1 -0
  61. data/lib/maruku/toc.rb +214 -0
  62. data/lib/maruku/usage/example1.rb +33 -0
  63. data/lib/maruku/version +0 -0
  64. data/lib/maruku/version.rb +54 -0
  65. data/spec/block_docs/abbreviations.md +52 -0
  66. data/spec/block_docs/alt.md +17 -0
  67. data/spec/block_docs/attributes/att2.md +20 -0
  68. data/spec/block_docs/attributes/att3.md +28 -0
  69. data/spec/block_docs/attributes/attributes.md +57 -0
  70. data/spec/block_docs/attributes/circular.md +26 -0
  71. data/spec/block_docs/attributes/default.md +22 -0
  72. data/spec/block_docs/blank.md +24 -0
  73. data/spec/block_docs/blanks_in_code.md +75 -0
  74. data/spec/block_docs/bug_def.md +16 -0
  75. data/spec/block_docs/bug_table.md +46 -0
  76. data/spec/block_docs/code.md +34 -0
  77. data/spec/block_docs/code2.md +28 -0
  78. data/spec/block_docs/code3.md +71 -0
  79. data/spec/block_docs/data_loss.md +25 -0
  80. data/spec/block_docs/divs/div1.md +167 -0
  81. data/spec/block_docs/divs/div2.md +21 -0
  82. data/spec/block_docs/divs/div3_nest.md +45 -0
  83. data/spec/block_docs/easy.md +15 -0
  84. data/spec/block_docs/email.md +20 -0
  85. data/spec/block_docs/encoding/iso-8859-1.md +23 -0
  86. data/spec/block_docs/encoding/utf-8.md +18 -0
  87. data/spec/block_docs/entities.md +94 -0
  88. data/spec/block_docs/escaping.md +67 -0
  89. data/spec/block_docs/extra_dl.md +52 -0
  90. data/spec/block_docs/extra_header_id.md +63 -0
  91. data/spec/block_docs/extra_table1.md +37 -0
  92. data/spec/block_docs/footnotes.md +97 -0
  93. data/spec/block_docs/headers.md +37 -0
  94. data/spec/block_docs/hex_entities.md +37 -0
  95. data/spec/block_docs/hrule.md +39 -0
  96. data/spec/block_docs/html2.md +22 -0
  97. data/spec/block_docs/html3.md +31 -0
  98. data/spec/block_docs/html4.md +25 -0
  99. data/spec/block_docs/html5.md +23 -0
  100. data/spec/block_docs/ie.md +49 -0
  101. data/spec/block_docs/images.md +90 -0
  102. data/spec/block_docs/images2.md +31 -0
  103. data/spec/block_docs/inline_html.md +152 -0
  104. data/spec/block_docs/inline_html2.md +21 -0
  105. data/spec/block_docs/links.md +152 -0
  106. data/spec/block_docs/links2.md +22 -0
  107. data/spec/block_docs/list1.md +46 -0
  108. data/spec/block_docs/list12.md +28 -0
  109. data/spec/block_docs/list2.md +56 -0
  110. data/spec/block_docs/list3.md +64 -0
  111. data/spec/block_docs/list4.md +89 -0
  112. data/spec/block_docs/lists.md +192 -0
  113. data/spec/block_docs/lists10.md +34 -0
  114. data/spec/block_docs/lists11.md +23 -0
  115. data/spec/block_docs/lists6.md +41 -0
  116. data/spec/block_docs/lists9.md +64 -0
  117. data/spec/block_docs/lists_after_paragraph.md +208 -0
  118. data/spec/block_docs/lists_ol.md +262 -0
  119. data/spec/block_docs/loss.md +16 -0
  120. data/spec/block_docs/math/equations.md +45 -0
  121. data/spec/block_docs/math/inline.md +46 -0
  122. data/spec/block_docs/math/math2.md +45 -0
  123. data/spec/block_docs/math/notmath.md +25 -0
  124. data/spec/block_docs/math/table.md +25 -0
  125. data/spec/block_docs/math/table2.md +42 -0
  126. data/spec/block_docs/misc_sw.md +525 -0
  127. data/spec/block_docs/notyet/escape.md +21 -0
  128. data/spec/block_docs/notyet/header_after_par.md +58 -0
  129. data/spec/block_docs/notyet/ticks.md +18 -0
  130. data/spec/block_docs/notyet/triggering.md +157 -0
  131. data/spec/block_docs/olist.md +45 -0
  132. data/spec/block_docs/one.md +15 -0
  133. data/spec/block_docs/paragraph.md +16 -0
  134. data/spec/block_docs/paragraph_rules/dont_merge_ref.md +42 -0
  135. data/spec/block_docs/paragraph_rules/tab_is_blank.md +24 -0
  136. data/spec/block_docs/paragraphs.md +46 -0
  137. data/spec/block_docs/pending/amps.md +15 -0
  138. data/spec/block_docs/pending/empty_cells.md +37 -0
  139. data/spec/block_docs/pending/link.md +72 -0
  140. data/spec/block_docs/pending/ref.md +21 -0
  141. data/spec/block_docs/recover/recover_links.md +15 -0
  142. data/spec/block_docs/red_tests/abbrev.md +679 -0
  143. data/spec/block_docs/red_tests/lists7.md +32 -0
  144. data/spec/block_docs/red_tests/lists7b.md +65 -0
  145. data/spec/block_docs/red_tests/lists8.md +42 -0
  146. data/spec/block_docs/red_tests/ref.md +23 -0
  147. data/spec/block_docs/red_tests/xml.md +35 -0
  148. data/spec/block_docs/references/long_example.md +71 -0
  149. data/spec/block_docs/references/spaces_and_numbers.md +15 -0
  150. data/spec/block_docs/smartypants.md +114 -0
  151. data/spec/block_docs/syntax_hl.md +52 -0
  152. data/spec/block_docs/table_attributes.md +34 -0
  153. data/spec/block_docs/test.md +19 -0
  154. data/spec/block_docs/underscore_in_words.md +15 -0
  155. data/spec/block_docs/wrapping.md +67 -0
  156. data/spec/block_docs/xml2.md +19 -0
  157. data/spec/block_docs/xml3.md +26 -0
  158. data/spec/block_docs/xml_instruction.md +52 -0
  159. data/spec/block_spec.rb +49 -0
  160. data/spec/span_spec.rb +254 -0
  161. data/spec/spec_helper.rb +6 -0
  162. metadata +247 -0
@@ -0,0 +1,580 @@
1
+ #--
2
+ # Copyright (C) 2006 Andrea Censi <andrea (at) rubyforge.org>
3
+ #
4
+ # This file is part of Maruku.
5
+ #
6
+ # Maruku is free software; you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation; either version 2 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Maruku is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Maruku; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
+ #++
20
+
21
+ module MaRuKu
22
+
23
+ class MDDocument
24
+
25
+ Latex_preamble_enc_cjk =
26
+ "\\usepackage[C40]{fontenc}
27
+ \\usepackage[cjkjis]{ucs}
28
+ \\usepackage[utf8x]{inputenc}"
29
+
30
+ Latex_preamble_enc_utf8 =
31
+ "\\usepackage{ucs}
32
+ \\usepackage[utf8x]{inputenc}"
33
+
34
+ def latex_require_package(p)
35
+ if not self.latex_required_packages.include? p
36
+ self.latex_required_packages.push p
37
+ end
38
+ end
39
+
40
+ # Render as a LaTeX fragment
41
+ def to_latex
42
+ children_to_latex
43
+ end
44
+
45
+ =begin maruku_doc
46
+ Attribute: maruku_signature
47
+ Scope: document
48
+ Output: html, latex
49
+ Summary: Enables Maruku's signature.
50
+ Default: true
51
+
52
+ If false, Maruku does not append a signature to the
53
+ generated file.
54
+ =end
55
+
56
+ # Render as a complete LaTeX document
57
+ def to_latex_document
58
+ body = to_latex
59
+
60
+ if get_setting(:maruku_signature)
61
+ body += render_latex_signature
62
+ end
63
+
64
+ required =
65
+ self.latex_required_packages.map {|p|
66
+ "\\usepackage{#{p}}\n"
67
+ }.join
68
+
69
+ =begin maruku_doc
70
+ Attribute: latex_cjk
71
+ Scope: document
72
+ Output: latex
73
+ Summary: Support for CJK characters.
74
+
75
+ If the `latex_cjk` attribute is specified, then appropriate headers
76
+ are added to the LaTeX preamble to support Japanese fonts.
77
+ You have to have these fonts installed -- and this can be a pain.
78
+
79
+ If `latex_cjk` is specified, this is added to the preamble:
80
+
81
+ <?mrk puts "ciao" ?>
82
+
83
+ <?mrk md_codeblock(Maruku::MDDocument::Latex_preamble_enc_cjk) ?>
84
+
85
+
86
+ while the default is to add this:
87
+
88
+ <?mrk md_codeblock(Maruku::MDDocument::Latex_preamble_enc_utf8) ?>
89
+
90
+ =end
91
+ encoding = get_setting(:latex_cjk) ?
92
+ Latex_preamble_enc_cjk : Latex_preamble_enc_utf8
93
+
94
+ =begin maruku_doc
95
+ Attribute: latex_preamble
96
+ Scope: document
97
+ Output: latex
98
+ Summary: User-defined preamble.
99
+
100
+ If the `latex_preamble` attribute is specified, then its value
101
+ will be used as a custom preamble.
102
+
103
+ For example:
104
+
105
+ Title: My document
106
+ Latex preamble: preamble.tex
107
+
108
+ will produce:
109
+
110
+ ...
111
+ \input{preamble.tex}
112
+ ...
113
+
114
+ =end
115
+ user_preamble = (file = @doc.attributes[:latex_preamble]) ?
116
+ "\\input{#{file}}\n" : ""
117
+
118
+ "\\documentclass{article}
119
+
120
+ % Packages required to support encoding
121
+ #{encoding}
122
+
123
+ % Packages required by code
124
+ #{required}
125
+
126
+ % Packages always used
127
+ \\usepackage{hyperref}
128
+ \\usepackage{xspace}
129
+ \\usepackage[usenames,dvipsnames]{color}
130
+ \\hypersetup{colorlinks=true,urlcolor=blue}
131
+
132
+ #{user_preamble}
133
+
134
+ \\begin{document}
135
+ #{body}
136
+ \\end{document}
137
+ "
138
+ end
139
+
140
+
141
+ def render_latex_signature
142
+ "\\vfill
143
+ \\hrule
144
+ \\vspace{1.2mm}
145
+ \\begin{tiny}
146
+ Created by \\href{http://maruku.rubyforge.org}{Maruku} #{self.nice_date}.
147
+ \\end{tiny}"
148
+ end
149
+
150
+ end end
151
+
152
+ module MaRuKu; module Out; module Latex
153
+
154
+ def to_latex_hrule; "\n\\vspace{.5em} \\hrule \\vspace{.5em}\n" end
155
+ def to_latex_linebreak; "\\newline " end
156
+
157
+ def to_latex_paragraph
158
+ children_to_latex+"\n\n"
159
+ end
160
+
161
+
162
+ =begin maruku_doc
163
+ Title: Input format for colors
164
+ Output: latex, html
165
+ Related: code_background_color
166
+
167
+ Admissible formats:
168
+
169
+ green
170
+ #abc
171
+ #aabbcc
172
+ =end
173
+
174
+ # \color[named]{name}
175
+ # \color[rgb]{1,0.2,0.3}
176
+ def latex_color(s, command='color')
177
+ if s =~ /^\#(\w\w)(\w\w)(\w\w)$/
178
+ r = $1.hex; g = $2.hex; b=$3.hex
179
+ # convert from 0-255 to 0.0-1.0
180
+ r = r / 255.0; g = g / 255.0; b = b / 255.0;
181
+ "\\#{command}[rgb]{%0.2f,%0.2f,%0.2f}" % [r,g,b]
182
+ elsif s =~ /^\#(\w)(\w)(\w)$/
183
+ r = $1.hex; g = $2.hex; b=$3.hex
184
+ # convert from 0-15 to 0.0-1.0
185
+ r = r / 15.0; g = g / 15.0; b = b / 15.0;
186
+ "\\#{command}[rgb]{%0.2f,%0.2f,%0.2f}" % [r,g,b]
187
+ else
188
+ "\\#{command}{#{s}}"
189
+ end
190
+ end
191
+
192
+ =begin maruku_doc
193
+ Attribute: code_show_spaces
194
+ Scope: global, document, element
195
+
196
+ If `true`, shows spaces and tabs in code blocks.
197
+
198
+ Example:
199
+
200
+ One space
201
+ Two spaces
202
+ Tab, space, tab
203
+ Tab, tab, tab and all is green!
204
+ {:code_show_spaces code_background_color=#ffeedd}
205
+ {:markdown}
206
+
207
+ That will produce:
208
+
209
+ One space
210
+ Two spaces
211
+ Tab, space, tab
212
+ Tab, tab, tab and all is green!
213
+ {:code_show_spaces code_background_color=#ffeedd}
214
+
215
+ =end
216
+
217
+ =begin maruku_doc
218
+ Attribute: latex_use_listings
219
+ Scope: document
220
+ Output: latex
221
+ Summary: Support for `listings` package.
222
+ Related: code_show_spaces, code_background_color, lang, code_lang
223
+
224
+ If the `latex_use_listings` attribute is specified, then
225
+ code block are rendered using the `listings` package.
226
+ Otherwise, a standard `verbatim` environment is used.
227
+
228
+ * If the `lang` attribute for the code block has been specified,
229
+ it gets passed to the `listings` package using the `lstset` macro.
230
+ The default lang for code blocks is specified through
231
+ the `code_lang` attribute.
232
+
233
+ \lstset{language=ruby}
234
+
235
+ Please refer to the documentation of the `listings` package for
236
+ supported languages.
237
+
238
+ If a language is not supported, the `listings` package will emit
239
+ a warning during the compilation. Just press enter and nothing
240
+ wrong will happen.
241
+
242
+ * If the `code_show_spaces` is specified, than spaces and tabs will
243
+ be shown using the macro:
244
+
245
+ \lstset{showspaces=true,showtabs=true}
246
+
247
+ * The background color is given by `code_background_color`.
248
+
249
+ =end
250
+
251
+ def to_latex_code;
252
+ raw_code = self.raw_code
253
+
254
+ if get_setting(:latex_use_listings)
255
+ @doc.latex_require_package('listings')
256
+
257
+ s = "\\lstset{columns=fixed,frame=shadowbox}"
258
+
259
+ if get_setting(:code_show_spaces)
260
+ s+= "\\lstset{showspaces=true,showtabs=true}\n"
261
+ else
262
+ s+= "\\lstset{showspaces=false,showtabs=false}\n"
263
+ end
264
+
265
+ color = latex_color get_setting(:code_background_color)
266
+
267
+ s+= "\\lstset{backgroundcolor=#{color}}\n"
268
+
269
+ s+= "\\lstset{basicstyle=\\ttfamily\\footnotesize}\n"
270
+
271
+
272
+ lang = self.attributes[:lang] || @doc.attributes[:code_lang] || '{}'
273
+ if lang
274
+ s += "\\lstset{language=#{lang}}\n"
275
+ end
276
+
277
+ "#{s}\n\\begin{lstlisting}\n#{raw_code}\n\\end{lstlisting}"
278
+ else
279
+ "\\begin{verbatim}#{raw_code}\\end{verbatim}\n"
280
+ end
281
+ end
282
+
283
+ TexHeaders = {
284
+ 1=>'section',
285
+ 2=>'subsection',
286
+ 3=>'subsubsection',
287
+ 4=>'paragraph'}
288
+
289
+ def to_latex_header
290
+ h = TexHeaders[self.level] || 'paragraph'
291
+
292
+ title = children_to_latex
293
+ if number = section_number
294
+ title = number + title
295
+ end
296
+
297
+ if id = self.attributes[:id]
298
+ # drop '#' at the beginning
299
+ if id[0,1] == '#' then id = [1,id.size] end
300
+ %{\\hypertarget{%s}{}\\%s*{{%s}}\\label{%s}\n\n} % [ id, h, title, id ]
301
+ else
302
+ %{\\%s*{%s}\n\n} % [ h, title]
303
+ end
304
+ end
305
+
306
+
307
+ def to_latex_ul;
308
+ if self.attributes[:toc]
309
+ @doc.toc.to_latex
310
+ else
311
+ wrap_as_environment('itemize')
312
+ end
313
+ end
314
+
315
+ def to_latex_quote; wrap_as_environment('quote') end
316
+ def to_latex_ol; wrap_as_environment('enumerate') end
317
+ def to_latex_li;
318
+ "\\item #{children_to_latex}\n"
319
+ end
320
+ def to_latex_li_span;
321
+ "\\item #{children_to_latex}\n"
322
+ end
323
+
324
+ def to_latex_strong
325
+ "\\textbf{#{children_to_latex}}"
326
+ end
327
+ def to_latex_emphasis
328
+ "\\emph{#{children_to_latex}}"
329
+ end
330
+
331
+ def wrap_as_span(c)
332
+ "{#{c} #{children_to_latex}}"
333
+ end
334
+
335
+ def wrap_as_environment(name)
336
+ "\\begin{#{name}}%
337
+ #{children_to_latex}
338
+ \\end{#{name}}\n"
339
+ end
340
+
341
+ SAFE_CHARS = Set.new(('a'..'z').to_a + ('A'..'Z').to_a)
342
+ # the ultimate escaping
343
+ # (is much better than using \verb)
344
+ def latex_escape(source)
345
+ s="";
346
+
347
+ source.each_char do |b|
348
+ if b == '\\'
349
+ s << '~'
350
+ elsif SAFE_CHARS.include? b
351
+ s << b
352
+ else
353
+ s += "\\char%d" % b[0].ord
354
+ end
355
+ end
356
+ s
357
+ end
358
+
359
+ def to_latex_inline_code;
360
+ source = self.raw_code
361
+
362
+ # Convert to printable latex chars
363
+ s = latex_escape(source)
364
+
365
+ color = get_setting(:code_background_color)
366
+ colorspec = latex_color(color, 'colorbox')
367
+
368
+ "{#{colorspec}{\\tt #{s}}}"
369
+ end
370
+
371
+ def to_latex_immediate_link
372
+ return "\\url{#{url}}"
373
+ end
374
+
375
+ def to_latex_im_link
376
+ url = self.url
377
+
378
+ if url[0,1] == '#'
379
+ url = url[1,url.size]
380
+ return "\\hyperlink{#{url}}{#{children_to_latex}}"
381
+ else
382
+ return "\\href{#{url}}{#{children_to_latex}}"
383
+ end
384
+ end
385
+
386
+ def to_latex_link
387
+ id = self.ref_id
388
+ ref = @doc.refs[id]
389
+ if not ref
390
+ $stderr.puts "Could not find id = '#{id}'"
391
+ return children_to_latex
392
+ else
393
+ url = ref[:url]
394
+ #title = ref[:title] || 'no title'
395
+
396
+ if url[0,1] == '#'
397
+ url = url[1,url.size]
398
+ return "\\hyperlink{#{url}}{#{children_to_latex}}"
399
+ else
400
+ return "\\href{#{url}}{#{children_to_latex}}"
401
+ end
402
+ end
403
+
404
+ end
405
+
406
+ def to_latex_email_address
407
+ email = self.email
408
+ "\\href{mailto:#{email}}{#{latex_escape(email)}}"
409
+ end
410
+
411
+
412
+ def to_latex_table
413
+ align = self.align
414
+ num_columns = align.size
415
+
416
+ head = @children.slice(0, num_columns)
417
+ rows = []
418
+ i = num_columns
419
+ while i<@children.size
420
+ rows << @children.slice(i, num_columns)
421
+ i+=num_columns
422
+ end
423
+
424
+ h = {:center=>'c',:left=>'l',:right=>'r'}
425
+ align_string = align.map{|a| h[a]}.join('|')
426
+
427
+ s = "\\begin{tabular}{#{align_string}}\n"
428
+
429
+ s += array_to_latex(head, '&') + "\\\\" +"\n"
430
+
431
+ s += "\\hline \n"
432
+
433
+ rows.each do |row|
434
+ s += array_to_latex(row, '&') + "\\\\" +"\n"
435
+ end
436
+
437
+ s += "\\end{tabular}"
438
+
439
+ # puts table in its own paragraph
440
+ s += "\n\n"
441
+
442
+ s
443
+ end
444
+
445
+
446
+ def to_latex_head_cell; children_to_latex end
447
+ def to_latex_cell; children_to_latex end
448
+
449
+
450
+ def to_latex_footnote_reference
451
+ id = self.footnote_id
452
+ f = @doc.footnotes[id]
453
+ if f
454
+ "\\footnote{#{f.children_to_latex.strip}} "
455
+ else
456
+ $stderr.puts "Could not find footnote '#{fid}'"
457
+ end
458
+ end
459
+
460
+ def to_latex_raw_html
461
+ #'{\bf Raw HTML removed in latex version }'
462
+ ""
463
+ end
464
+
465
+ ## Definition lists ###
466
+ def to_latex_definition_list
467
+ s = "\\begin{description}\n"
468
+ s += children_to_latex
469
+ s += "\\end{description}\n"
470
+ s
471
+ end
472
+
473
+ def to_latex_definition
474
+ terms = self.terms
475
+ definitions = self.definitions
476
+
477
+ s = ""
478
+ terms.each do |t|
479
+ s +="\n\\item[#{t.children_to_latex}] "
480
+ end
481
+
482
+ definitions.each do |d|
483
+ s += "#{d.children_to_latex} \n"
484
+ end
485
+
486
+ s
487
+ end
488
+
489
+
490
+ def to_latex_abbr
491
+ children_to_latex
492
+ end
493
+
494
+ def to_latex_image
495
+ id = self.ref_id
496
+ ref = @doc.refs[id]
497
+ if not ref
498
+ maruku_error "Could not find ref #{id.inspect} for image.\n"+
499
+ "Available are: #{@docs.refs.keys.inspect}"
500
+ # $stderr.puts "Could not find id = '#{id}'"
501
+ ""
502
+ else
503
+ url = ref[:url]
504
+ $stderr.puts "Images not supported yet (#{url})"
505
+ # "{\\bf Images not supported yet (#{latex_escape(url)})}"
506
+ ""
507
+ end
508
+
509
+ end
510
+
511
+ def to_latex_div
512
+ type = self.attributes[:class]
513
+ id = self.attributes[:id]
514
+ case type
515
+ when /^un_(\w*)/
516
+ s = "\\begin{u#{$1}}"
517
+ # s += "[#{@children[0].send('children_to_latex')}]"
518
+ @children.delete_at(0)
519
+ s += "\n" + children_to_latex
520
+ s += "\\end{u#{$1}}\n"
521
+ when /^num_(\w*)/
522
+ s = "\\begin{#{$1}}"
523
+ # s += "[#{@children[0].send('children_to_latex')}]"
524
+ @children.delete_at(0)
525
+ s += "\n\\label{#{id}}\\hypertarget{#{id}}{}\n"
526
+ s += children_to_latex
527
+ s += "\\end{#{$1}}\n"
528
+ when /^proof/
529
+ s = "\\begin{proof}"
530
+ @children.delete_at(0)
531
+ s += "\n" + children_to_latex
532
+ s += "\\end{proof}\n"
533
+ else
534
+ s = children_to_latex
535
+ end
536
+ s
537
+ end
538
+
539
+ # Convert each child to html
540
+ def children_to_latex
541
+ array_to_latex(@children)
542
+ end
543
+
544
+ def array_to_latex(array, join_char='')
545
+ e = []
546
+ array.each do |c|
547
+ method = c.kind_of?(MDElement) ?
548
+ "to_latex_#{c.node_type}" : "to_latex"
549
+
550
+ if not c.respond_to?(method)
551
+ # raise "Object does not answer to #{method}: #{c.class} #{c.inspect[0,100]}"
552
+ next
553
+ end
554
+
555
+ h = c.send(method)
556
+
557
+ if h.nil?
558
+ raise "Nil html for #{c.inspect} created with method #{method}"
559
+ end
560
+
561
+ if h.kind_of?Array
562
+ e = e + h
563
+ else
564
+ e << h
565
+ end
566
+ end
567
+
568
+ # puts a space after commands if needed
569
+ # e.each_index do |i|
570
+ # if e[i] =~ /\\\w+\s*$/ # command
571
+ # if (s=e[i+1]) && s[0] == ?\ # space
572
+ # e[i] = e[i] + "\\ "
573
+ # end
574
+ # end
575
+ # end
576
+
577
+ e.join(join_char)
578
+ end
579
+
580
+ end end end # MaRuKu::Out::Latex