deplate 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. data/AUTHORS.TXT +26 -0
  2. data/CHANGES.TXT +177 -0
  3. data/LICENSE.TXT +340 -0
  4. data/NEWS.TXT +29 -0
  5. data/README.TXT +86 -0
  6. data/TODO.TXT +202 -0
  7. data/VERSION.TXT +1 -0
  8. data/bin/deplate +3 -0
  9. data/bin/deplate.bat +2 -0
  10. data/etc/deplate.ini +361 -0
  11. data/lib/deplate.rb +31 -0
  12. data/lib/deplate/abstract-class.rb +30 -0
  13. data/lib/deplate/builtin.rb +11 -0
  14. data/lib/deplate/cache.rb +59 -0
  15. data/lib/deplate/commands.rb +693 -0
  16. data/lib/deplate/common.rb +335 -0
  17. data/lib/deplate/converter.rb +99 -0
  18. data/lib/deplate/core.rb +2705 -0
  19. data/lib/deplate/css/article.css +545 -0
  20. data/lib/deplate/css/deplate.css +699 -0
  21. data/lib/deplate/css/heading-navbar.css +29 -0
  22. data/lib/deplate/css/layout-deplate-print.css +540 -0
  23. data/lib/deplate/css/layout-deplate.css +764 -0
  24. data/lib/deplate/css/sans-serif.css +160 -0
  25. data/lib/deplate/css/serif-e.css +170 -0
  26. data/lib/deplate/css/serif-rel.css +121 -0
  27. data/lib/deplate/css/serif.css +190 -0
  28. data/lib/deplate/css/slides.css +11 -0
  29. data/lib/deplate/css/tabbar-left.css +91 -0
  30. data/lib/deplate/css/tabbar-right-ie.css +14 -0
  31. data/lib/deplate/css/tabbar-right.css +118 -0
  32. data/lib/deplate/css/tabbar-top.css +64 -0
  33. data/lib/deplate/css/tabbar.css +81 -0
  34. data/lib/deplate/css/text-sans-serif.css +154 -0
  35. data/lib/deplate/css/text-serif.css +175 -0
  36. data/lib/deplate/define.rb +439 -0
  37. data/lib/deplate/docbook.rb +738 -0
  38. data/lib/deplate/elements.rb +1355 -0
  39. data/lib/deplate/etc.rb +199 -0
  40. data/lib/deplate/external.rb +135 -0
  41. data/lib/deplate/fmt/dbk-article-4.1.2.rb +21 -0
  42. data/lib/deplate/fmt/dbk-article.rb +46 -0
  43. data/lib/deplate/fmt/dbk-book.rb +46 -0
  44. data/lib/deplate/fmt/dbk-ref.rb +105 -0
  45. data/lib/deplate/fmt/dbk-slides.rb +47 -0
  46. data/lib/deplate/fmt/dbk-snippet.rb +21 -0
  47. data/lib/deplate/fmt/html-snippet.rb +21 -0
  48. data/lib/deplate/fmt/html.rb +1696 -0
  49. data/lib/deplate/fmt/htmlsite.rb +419 -0
  50. data/lib/deplate/fmt/htmlslides.rb +21 -0
  51. data/lib/deplate/fmt/htmlwebsite.rb +70 -0
  52. data/lib/deplate/fmt/latex-snippet.rb +22 -0
  53. data/lib/deplate/fmt/latex.rb +1242 -0
  54. data/lib/deplate/fmt/php.rb +19 -0
  55. data/lib/deplate/fmt/phpsite.rb +19 -0
  56. data/lib/deplate/fmt/plain.rb +598 -0
  57. data/lib/deplate/fmt/template.rb +34 -0
  58. data/lib/deplate/fmt/xhtml10t.rb +41 -0
  59. data/lib/deplate/formatter-snippet.rb +17 -0
  60. data/lib/deplate/formatter.rb +1210 -0
  61. data/lib/deplate/input.rb +492 -0
  62. data/lib/deplate/input/deplate-headings.rb +48 -0
  63. data/lib/deplate/input/deplate-restricted.rb +70 -0
  64. data/lib/deplate/input/deplate.rb +28 -0
  65. data/lib/deplate/input/rdoc.rb +277 -0
  66. data/lib/deplate/input/template.rb +29 -0
  67. data/lib/deplate/lib/latex/highlight-extra.sty +15 -0
  68. data/lib/deplate/lib/latex/highlight-typical.sty +15 -0
  69. data/lib/deplate/lib/tabmenu.js +146 -0
  70. data/lib/deplate/locale/de.latin1 +708 -0
  71. data/lib/deplate/locale/ru.koi8-r +48 -0
  72. data/lib/deplate/locale/zh_cn.gb2312 +35 -0
  73. data/lib/deplate/macros.rb +639 -0
  74. data/lib/deplate/messages.rb +120 -0
  75. data/lib/deplate/metadata.rb +77 -0
  76. data/lib/deplate/metadata/marshal.rb +24 -0
  77. data/lib/deplate/metadata/xml.rb +42 -0
  78. data/lib/deplate/metadata/yaml.rb +26 -0
  79. data/lib/deplate/mod/anyword.rb +56 -0
  80. data/lib/deplate/mod/babelfish.rb +27 -0
  81. data/lib/deplate/mod/code-gvim.rb +52 -0
  82. data/lib/deplate/mod/code-highlight.rb +91 -0
  83. data/lib/deplate/mod/colored-log.rb +17 -0
  84. data/lib/deplate/mod/de.rb +19 -0
  85. data/lib/deplate/mod/en.rb +17 -0
  86. data/lib/deplate/mod/endnotes.rb +60 -0
  87. data/lib/deplate/mod/fr.rb +46 -0
  88. data/lib/deplate/mod/html-asciimath.rb +40 -0
  89. data/lib/deplate/mod/html-deplate-button.rb +15 -0
  90. data/lib/deplate/mod/html-headings-navbar.rb +39 -0
  91. data/lib/deplate/mod/html-obfuscate-email.rb +47 -0
  92. data/lib/deplate/mod/html-sidebar.rb +232 -0
  93. data/lib/deplate/mod/htmlslides-navbar-fh.rb +32 -0
  94. data/lib/deplate/mod/iconv.rb +35 -0
  95. data/lib/deplate/mod/imgurl.rb +30 -0
  96. data/lib/deplate/mod/inlatex-compound.rb +69 -0
  97. data/lib/deplate/mod/koma.rb +109 -0
  98. data/lib/deplate/mod/latex-emph-table-head.rb +38 -0
  99. data/lib/deplate/mod/latex-styles.rb +461 -0
  100. data/lib/deplate/mod/latex-verbatim-small.rb +29 -0
  101. data/lib/deplate/mod/makefile.rb +194 -0
  102. data/lib/deplate/mod/mark-external-urls.rb +38 -0
  103. data/lib/deplate/mod/markup-1-warn.rb +37 -0
  104. data/lib/deplate/mod/markup-1.rb +41 -0
  105. data/lib/deplate/mod/navbar-png.rb +33 -0
  106. data/lib/deplate/mod/noindent.rb +32 -0
  107. data/lib/deplate/mod/numpara.rb +40 -0
  108. data/lib/deplate/mod/particle-math.rb +34 -0
  109. data/lib/deplate/mod/php-extra.rb +44 -0
  110. data/lib/deplate/mod/pstoedit.rb +71 -0
  111. data/lib/deplate/mod/recode.rb +57 -0
  112. data/lib/deplate/mod/ru_koi8-r.rb +20 -0
  113. data/lib/deplate/mod/smiley.rb +50 -0
  114. data/lib/deplate/mod/soffice.rb +23 -0
  115. data/lib/deplate/mod/symbols-latin1.rb +58 -0
  116. data/lib/deplate/mod/symbols-od-utf-8.rb +16 -0
  117. data/lib/deplate/mod/symbols-plain.rb +58 -0
  118. data/lib/deplate/mod/symbols-sgml.rb +97 -0
  119. data/lib/deplate/mod/symbols-utf-8.rb +81 -0
  120. data/lib/deplate/mod/symbols-xml.rb +34 -0
  121. data/lib/deplate/mod/syntax-region-alt.rb +37 -0
  122. data/lib/deplate/mod/utf8.rb +49 -0
  123. data/lib/deplate/mod/validate-html.rb +35 -0
  124. data/lib/deplate/mod/xmlrpc.rb +233 -0
  125. data/lib/deplate/mod/zh-cn-autospace.rb +108 -0
  126. data/lib/deplate/mod/zh-cn.rb +59 -0
  127. data/lib/deplate/once-method.rb +44 -0
  128. data/lib/deplate/output.rb +249 -0
  129. data/lib/deplate/particles.rb +815 -0
  130. data/lib/deplate/regions.rb +1076 -0
  131. data/lib/deplate/structured.rb +763 -0
  132. data/lib/deplate/template.rb +430 -0
  133. data/lib/deplate/templates/html-doc.html +28 -0
  134. data/lib/deplate/templates/html-left-tabbar-js.html +37 -0
  135. data/lib/deplate/templates/html-left-tabbar.html +31 -0
  136. data/lib/deplate/templates/html-tabbar-right-table.html +43 -0
  137. data/lib/deplate/templates/html-tabbar-right.html +23 -0
  138. data/lib/deplate/templates/html-tabbar-top.html +43 -0
  139. data/lib/deplate/templates/html-tabbar.html +31 -0
  140. data/lib/deplate/wiki-markup.rb +117 -0
  141. data/lib/deplate/xml.rb +109 -0
  142. data/lib/deplate/zh-cn.rb +59 -0
  143. data/lib/ps2ppm.rb +239 -0
  144. data/man/man1/deplate.1 +692 -0
  145. metadata +210 -0
@@ -0,0 +1,22 @@
1
+ # latex-snippet.rb
2
+ # @Author: Thomas Link (samul AT web.de)
3
+ # @Website: http://deplate.sf.net/
4
+ # @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
5
+ # @Created: 11-Aug-2005.
6
+ # @Last Change: 23-Okt-2005.
7
+ # @Revision: 0.14
8
+
9
+ require 'deplate/fmt/latex.rb'
10
+ require 'deplate/formatter-snippet.rb'
11
+
12
+ class Deplate::Formatter::LaTeX_Snippet < Deplate::Formatter::LaTeX
13
+ self.myname = "latex-snippet"
14
+ self.rx = /(la)?tex(-snippet)?/i
15
+
16
+ include Deplate::Snippet
17
+
18
+ def format_paragraph(invoker)
19
+ invoker.elt
20
+ end
21
+ end
22
+
@@ -0,0 +1,1242 @@
1
+ # fmt-latex.rb
2
+ # @Author: Thomas Link (samul AT web.de)
3
+ # @Website: http://deplate.sf.net/
4
+ # @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
5
+ # @Created: 17-M�r-2004.
6
+ # @Last Change: 02-Nov-2005.
7
+ # @Revision: 0.1817
8
+
9
+ require "deplate/formatter"
10
+
11
+ # A sample LaTeX formatter.
12
+
13
+ class Deplate::Formatter::LaTeX < Deplate::Formatter
14
+ self.myname = "latex"
15
+ self.rx = /(la)?tex/i
16
+ self.suffix = ".tex"
17
+
18
+ self.label_mode = :after
19
+
20
+ self.label_delegate = [
21
+ :format_heading,
22
+ :format_LIST,
23
+ :format_table,
24
+ :format_inlatex,
25
+ :format_IMG,
26
+ :format_list,
27
+ :format_list_env,
28
+ ]
29
+
30
+ self.label_once = [
31
+ :format_anchor,
32
+ ]
33
+
34
+ @@latexDocClass = "article"
35
+ @@latexVariables = ["11pt", "a4paper"]
36
+
37
+
38
+ ################################################ Setup {{{1
39
+ def initialize(deplate, args)
40
+ super
41
+ @special_symbols = {
42
+ "\\" => "\\textbackslash{}",
43
+ ">" => "$>$",
44
+ "<" => "$<$",
45
+ "|" => "$|$",
46
+ "^" => "\\^{}",
47
+ "~" => "\\~{}",
48
+ "\"" => "``",
49
+ "[" => "{[}",
50
+ "]" => "{]}",
51
+ "$" => "\\$",
52
+ "&" => "\\&",
53
+ "%" => "\\%",
54
+ "#" => "\\#",
55
+ "_" => "\\_",
56
+ "{" => "\\{",
57
+ "}" => "\\}",
58
+ " " => Proc.new do |escaped|
59
+ escaped ? "~" : " "
60
+ end,
61
+ }
62
+ @packages = {}
63
+ @consumed_preludes = []
64
+ build_plain_text_rx
65
+ end
66
+
67
+ def prepare
68
+ @document_class = @deplate.variables["class"] || @@latexDocClass
69
+
70
+ lco = @deplate.variables["classOptions"]
71
+ lco = lco ? lco.strip.split(/[, ]/) : @@latexVariables
72
+ lang = @deplate.options.messages.prop('lang', self)
73
+ if lang
74
+ lco << lang
75
+ end
76
+ lco = lco.uniq.join(",")
77
+
78
+ output_at(:pre, :doc_def, "\\documentclass[#{lco}]{#{@document_class}}")
79
+
80
+ set_document_encoding
81
+
82
+ @booktabs = @deplate.variables["useBooktabs"]
83
+ add_package("booktabs") if @booktabs
84
+
85
+
86
+ div = @deplate.variables["DIV"]
87
+ add_package("typearea", "DIV#{div}") if div
88
+
89
+ lang_cmd = @deplate.options.messages.prop('lang_cmd', self)
90
+ if lang_cmd
91
+ output_at(:pre, :doc_beg, lang_cmd)
92
+ end
93
+
94
+ output_at(:pre, :body_beg, "\\begin{document}\n")
95
+
96
+ lspread = @deplate.variables["linespread"]
97
+ if lspread
98
+ output_at(:pre, :body_beg, "\\linespread{#{lspread}}")
99
+ end
100
+
101
+ output_at(:post, :body_end, "\\end{document}")
102
+ end
103
+
104
+ def prepare_headings
105
+ case @document_class
106
+ when "book"
107
+ @headings = ["chapter", "section", "subsection", "subsubsection", "paragraph", "subparagraph"]
108
+ else
109
+ @headings = ["section", "subsection", "subsubsection", "paragraph", "subparagraph"]
110
+ end
111
+ end
112
+
113
+ def wrap_text(text, args={})
114
+ args[:check] ||= lambda do |line|
115
+ mt = /\\verb(.)/.match(line)
116
+ mt && line =~ /\\verb#{mt[1]}[^#{mt[1]}]+$/
117
+ end
118
+ super(text, args)
119
+ end
120
+
121
+ def prelude(name)
122
+ case name
123
+ when 'ltxPrelude', 'mathPrelude'
124
+ if @consumed_preludes.include?(name)
125
+ return nil
126
+ else
127
+ @consumed_preludes << name
128
+ end
129
+ end
130
+ return @deplate.variables[name]
131
+ end
132
+
133
+ def inlatex(invoker)
134
+ pkgs, body = inlatex_split(invoker.accum)
135
+ invoker.elt = body.join("\n")
136
+ inlatex_add_packages(pkgs)
137
+ end
138
+
139
+ def inlatex_add_packages(pkgs)
140
+ for p in pkgs
141
+ m = /^\s*\\(usepackage|input)\s*(\[(.*)\])?\s*\{(.+)\}\s*$/.match(p)
142
+ if m
143
+ pkg = m[4]
144
+ if m[3]
145
+ add_package(pkg, m[3].split(","))
146
+ else
147
+ add_package(pkg)
148
+ end
149
+ else
150
+ output_at(:pre, :user_head, p)
151
+ end
152
+ end
153
+ end
154
+
155
+
156
+ ################################################ Lists {{{1
157
+ def format_list_item(invoker, type, level, item)
158
+ indent = format_indent(level, true)
159
+ ctag = list_wide? ? '' : :empty
160
+ explv = list_item_explicit_value(item)
161
+ if explv
162
+ explv = %{[#{explv}]}
163
+ end
164
+ case type
165
+ when "Numbered"
166
+ return wrap_text("#{indent}\\item#{explv} #{item.body}", :indent => " "), ctag
167
+ when "Itemize"
168
+ return wrap_text("#{indent}\\item #{item.body}", :indent => " "), ctag
169
+ when "Description"
170
+ return wrap_text("#{indent}\\item[#{item.item}] #{item.body}", :indent => " "), ctag
171
+ when "Paragraph"
172
+ fs = list_wide? ? "\n%s\n" : "\n%s"
173
+ return fs % wrap_text("#{indent}#{item.body}", :indent => " "), nil
174
+ else
175
+ raise "Unknown list type: #{item.inspect}"
176
+ end
177
+ end
178
+
179
+ def format_list_env(invoker, type, level, what, subtype=nil)
180
+ indent = format_indent(level)
181
+ case what
182
+ when :open
183
+ w = "begin"
184
+ if list_wide?
185
+ pre = "\n#{indent}"
186
+ post = "\n"
187
+ else
188
+ pre = indent
189
+ post = ""
190
+ end
191
+ when :close
192
+ w = "end"
193
+ pre = indent
194
+ post = ""
195
+ end
196
+ case type
197
+ when "Numbered"
198
+ case subtype
199
+ when "a", "A"
200
+ return format_list_enumerate_alpha(invoker, what, subtype, w, pre, post)
201
+ else
202
+ return "#{pre}\\#{w}{enumerate}#{post}"
203
+ end
204
+ when "Itemize"
205
+ return "#{pre}\\#{w}{itemize}#{post}"
206
+ when "Description"
207
+ return "#{pre}\\#{w}{description}#{post}"
208
+ else
209
+ raise "Unknown list type: #{self.inspect}"
210
+ end
211
+ end
212
+
213
+
214
+ ################################################ General {{{1
215
+ def format_environment(invoker, env, text, opts=nil)
216
+ join_blocks(["\\begin{#{env}}", text, "\\end{#{env}}\n"])
217
+ end
218
+
219
+ def format_label(invoker, mode=nil, label=nil)
220
+ acc = []
221
+ label = use_labels(invoker.args, label || invoker.label, :with_id => true)
222
+ unless label.empty?
223
+ case mode
224
+ when :before
225
+ # when :after, :once
226
+ # for l in label
227
+ # acc << "\\label{#{l}}"
228
+ # end
229
+ else
230
+ for l in label
231
+ acc << "\\label{#{l}}"
232
+ end
233
+ end
234
+ end
235
+ return acc.join
236
+ end
237
+
238
+ def format_figure(invoker, inline=false, elt=nil)
239
+ elt ||= invoker.elt
240
+ args = invoker.args
241
+ caption = invoker.caption
242
+ acc = []
243
+ if inline
244
+ acc << include_image(elt, args, true)
245
+ else
246
+ floatPos, alignCmd = float_options(invoker)
247
+ in_env = !(args["inline"] || @deplate.variables["imgInline"])
248
+ in_env &&= floatPos || alignCmd || caption
249
+ if in_env
250
+ acc << figure_top(invoker)
251
+ acc << include_image(elt, args)
252
+ acc << figure_bottom(invoker)
253
+ else
254
+ acc << include_image(elt, args)
255
+ acc << format_label(invoker, :once)
256
+ end
257
+ end
258
+ join_blocks(acc)
259
+ end
260
+
261
+ def figure_top(invoker)
262
+ caption = invoker.caption
263
+ capAbove = caption && (caption.args && caption.args.include?("above") || @deplate.variables["floatCaptionAbove"])
264
+ floatPos, alignCmd = float_options(invoker)
265
+ acc = []
266
+ acc << "\\begin{figure}%s" % [floatPos]
267
+ acc << alignCmd
268
+ if caption and capAbove
269
+ acc << "\\caption{#{caption.elt}}"
270
+ end
271
+ join_blocks(acc)
272
+ end
273
+
274
+ def figure_bottom(invoker)
275
+ caption = invoker.caption
276
+ capAbove = caption && (caption.args && caption.args.include?("above") || @deplate.variables["floatCaptionAbove"])
277
+ acc = []
278
+ if caption and !capAbove
279
+ acc << "\\caption{#{caption.elt}}"
280
+ end
281
+ acc << format_label(invoker, :once)
282
+ acc << "\\end{figure}\n"
283
+ join_blocks(acc)
284
+ end
285
+
286
+ def include_image(file, options, inline=false)
287
+ ff = ""
288
+ o = []
289
+ bw, bh, bx, by, desc = nil
290
+ @deplate.in_working_dir do
291
+ f = file[0..-(File.extname(file).size + 1)]
292
+ ls = Dir[File.join("%s.*" % f)]
293
+ suffixes = image_suffixes
294
+ catch(:found) do
295
+ for sfx in suffixes
296
+ ff = f + sfx
297
+ if ls.include?(ff)
298
+ throw :found
299
+ end
300
+ end
301
+ ff = file
302
+ end
303
+ bw = options["bw"]
304
+ bh = options["bh"]
305
+ desc = Deplate::External.image_dimension(ff)
306
+ unless (bw and bh) or @deplate.options.pdftex
307
+ bw, bh, bx, by = desc[:bw]
308
+ end
309
+ end
310
+ unless @deplate.options.pdftex
311
+ o << "bb=0 0 #{bw || "100"} #{bh || "100"}"
312
+ end
313
+ width = options["w"] || options["width"]
314
+ if width
315
+ if width =~ /^\d+%$/
316
+ width = width.to_f / 100
317
+ o << "width=#{width}\\textwidth{}"
318
+ elsif width =~ /^[.\d]+(cm|mm|in|em|pt)$/
319
+ o << "width=#{width}"
320
+ else
321
+ o << "width=#{width}pt"
322
+ end
323
+ elsif !inline
324
+ bb = desc[:bw]
325
+ bw = bb ? bb[0] : nil
326
+ res = desc[:res]
327
+ if desc and bb and res
328
+ estimated_width = bw.to_f / res
329
+ if estimated_width > 6
330
+ o << "width=\\textwidth{}"
331
+ end
332
+ end
333
+ end
334
+ height = options["h"]
335
+ if height
336
+ if height =~ /^\d+%$/
337
+ height = height.to_f / 100
338
+ o << "height=#{height}\\textheight{}"
339
+ elsif height =~ /^\d+(cm|mm|in|em|pt)$/
340
+ o << "height=#{height}"
341
+ else
342
+ o << "height=#{height}pt"
343
+ end
344
+ end
345
+ o = o.join(",")
346
+ if !o.empty?
347
+ o = "[" + o + "]"
348
+ end
349
+ add_package("graphicx")
350
+ rv = "\\includegraphics#{o}{#{ff}}"
351
+ rot = options["rotate"] || @deplate.variables["imgRotate"]
352
+ if rot
353
+ rv = %{\\rotatebox{#{rot}}{#{rv}}}
354
+ end
355
+ return rv
356
+ end
357
+
358
+ def image_suffixes
359
+ if @deplate.options.pdftex
360
+ [".pdf", ".jpeg", ".jpg", ".png", ".gif", ".bmp"]
361
+ else
362
+ [".eps", ".ps", ".jpeg", ".jpg", ".png", ".gif", ".bmp"]
363
+ end
364
+ end
365
+
366
+ def add_package(pkg, *options)
367
+ pkg_previous = @packages[pkg]
368
+ if pkg_previous
369
+ if options != pkg_previous
370
+ log(["Already required package with different options", pkg, pkg_previous, options], :error)
371
+ end
372
+ return
373
+ else
374
+ @packages[pkg] = options.dup
375
+ case pkg
376
+ when "hyperref", "graphicx"
377
+ if @deplate.options.pdftex
378
+ options << "pdftex"
379
+ end
380
+ end
381
+
382
+ unless options.empty?
383
+ options = "[" + options.join(",") + "]"
384
+ end
385
+ if pkg =~ /\.\w+$/
386
+ output_at(:pre, :user_packages, "\\input{#{pkg}}")
387
+ else
388
+ output_at(:pre, :user_packages, "\\usepackage#{options}{#{pkg}}")
389
+ end
390
+ end
391
+ end
392
+
393
+
394
+ ################################################ Elements {{{1
395
+ def format_note(invoker)
396
+ elt = invoker.elt
397
+ marker = invoker.marker
398
+ case marker
399
+ when "#"
400
+ note = "Note"
401
+ when "+"
402
+ note = "Elaborate"
403
+ when "?"
404
+ note = "Discussion"
405
+ when "!"
406
+ note = "Important"
407
+ else
408
+ Deplate::Core.log(["Unknown marker", marker], :error)
409
+ note = "Note"
410
+ end
411
+ note = "%s: " % @deplate.msg(note)
412
+ size = @deplate.variables["noteSize"] || "footnotesize"
413
+ "\\protect\\marginpar{\\%s{}%s%s}" % [size, note, elt]
414
+ end
415
+
416
+ def format_table(invoker)
417
+ args = invoker.args
418
+ elt = invoker.elt
419
+ caption = invoker.caption
420
+ capAbove = caption && (caption.args && caption.args.include?("above") || @deplate.variables["floatCaptionAbove"])
421
+ indent = format_indent(1)
422
+ dblindent = format_indent(2)
423
+ mode = :normal
424
+ rown = elt.size - 1
425
+ invoker.printed_header = false
426
+ acc = []
427
+ acc << with_agent(:table_top, String, invoker, capAbove, rown)
428
+ elt.each_with_index do |row, rnth|
429
+ if row.is_ruler
430
+ t = with_agent(:table_horizontal_ruler, String, invoker, row, rnth)
431
+ elsif row.head
432
+ acc << with_agent(:table_begin_head, String, invoker, rown)
433
+ t = with_agent(:table_head_row, Array, invoker, row, rnth)
434
+ mode = :head
435
+ elsif row.foot
436
+ case mode
437
+ when :foot
438
+ else
439
+ acc << with_agent(:table_end_body, String, invoker, rown)
440
+ acc << with_agent(:table_begin_foot, String, invoker, rown)
441
+ end
442
+ t = with_agent(:table_foot_row, Array, invoker, row, rnth)
443
+ mode = :foot
444
+ elsif row.high
445
+ t = with_agent(:table_high_row, Array, invoker, row, rnth)
446
+ mode = :high
447
+ else
448
+ case mode
449
+ when :head
450
+ acc << with_agent(:table_end_head, String, invoker, rown)
451
+ acc << with_agent(:table_begin_body, String, invoker, rown)
452
+ else
453
+ end
454
+ mode = :body
455
+ t = with_agent(:table_normal_row, Array, invoker, row, rnth)
456
+ end
457
+ if t
458
+ t = table_join_cells(t)
459
+ acc << with_agent(:table_indented_row, String, invoker, row, dblindent, t)
460
+ end
461
+ end
462
+ if mode == :foot
463
+ acc << with_agent(:table_end_foot, String, invoker, rown)
464
+ end
465
+ acc << with_agent(:table_bottom, String, invoker, capAbove, rown)
466
+ join_blocks(acc)
467
+ end
468
+
469
+ def format_heading(invoker)
470
+ args = invoker.args
471
+ elt = invoker.elt
472
+ caption = invoker.caption
473
+ level = invoker.level
474
+ if caption
475
+ cap = "[#{caption.elt}]"
476
+ else
477
+ cap = ""
478
+ end
479
+ hd = @headings[level - 1]
480
+ if args["noList"]
481
+ mod = "*"
482
+ else
483
+ mode = ""
484
+ end
485
+ invoker.label << args[:id]
486
+ labels = format_label(invoker, :string)
487
+ if hd
488
+ join_blocks(["\n\\#{hd}#{mod}#{cap}{#{elt}}", labels])
489
+ else
490
+ "\n#{elt}#{labels}: "
491
+ end
492
+ end
493
+
494
+ def format_list(invoker)
495
+ add_package("hyperref")
496
+ acc = list_wide? ? [""] : []
497
+ lab = format_label(invoker)
498
+ unless lab.empty?
499
+ acc << lab
500
+ end
501
+ acc << printable_list(invoker)
502
+ acc << ""
503
+ join_blocks(acc)
504
+ end
505
+
506
+ def format_break(invoker)
507
+ format_pagebreak(invoker, "break")
508
+ end
509
+
510
+ def format_anchor(invoker)
511
+ end
512
+
513
+ def format_paragraph(invoker)
514
+ join_blocks([wrap_text(invoker.elt), ""])
515
+ end
516
+
517
+
518
+ ################################################ Regions {{{1
519
+ def format_verbatim(invoker, text=nil)
520
+ format_environment(invoker, "verbatim", text || invoker.elt)
521
+ end
522
+
523
+ def format_abstract(invoker)
524
+ format_environment(invoker, "abstract", wrap_text(invoker.elt))
525
+ end
526
+
527
+ def format_quote(invoker)
528
+ env = invoker.args["long"] ? "quotation" : "quote"
529
+ elt = wrap_text(invoker.elt)
530
+ format_environment(invoker, env, elt)
531
+ end
532
+
533
+ def format_header(invoker)
534
+ args = invoker.args
535
+ elt = invoker.elt
536
+ acc = []
537
+ acc << %{\\pagestyle{myheadings}}
538
+ catch :error do
539
+ if elt.size == 1
540
+ e = elt[0]
541
+ if e.kind_of?(Deplate::Element::Paragraph)
542
+ header = e.format_current
543
+ elsif e.kind_of?(Deplate::Element::Table)
544
+ if e.elt.size > 1
545
+ log("Only the header's first row will be used", :error)
546
+ end
547
+ header = e.elt[0].cols.collect{|c| c.cell}
548
+ while header.last.empty?
549
+ header.pop
550
+ end
551
+ header = header.compact.join(" -- ")
552
+ else
553
+ throw :error
554
+ end
555
+ header.gsub!(/\n+/, " ")
556
+ acc << %{\\markright{#{header}}}
557
+ return join_blocks(acc)
558
+ end
559
+ end
560
+ elts = "%s %s" % [elt.size, elt.collect {|e| e.class}.join(", ")]
561
+ log(["Header must contain only 1 element (a paragraph or a table)", elts], :error)
562
+ end
563
+
564
+ def format_footer(invoker)
565
+ invoker.log("Footer ignored", :error)
566
+ end
567
+
568
+ def format_inlatex(invoker)
569
+ args = invoker.args
570
+ elt = invoker.elt
571
+ acc = []
572
+ if args["inline"]
573
+ acc << elt
574
+ elsif args["type"] == "table"
575
+ cap = invoker.caption
576
+ capAbove = cap && cap.args && cap.args.include?("above")
577
+ acc << with_agent(:table_top, String, invoker, capAbove, nil)
578
+ acc << elt
579
+ acc << with_agent(:table_bottom, String, invoker, capAbove, nil)
580
+ else
581
+ acc << with_agent(:figure_top, String, invoker)
582
+ acc << elt
583
+ acc << with_agent(:figure_bottom, String, invoker)
584
+ end
585
+ join_blocks(acc)
586
+ end
587
+
588
+
589
+ ################################################ Commands {{{1
590
+ def format_title(invoker)
591
+ acc = []
592
+ elts = []
593
+ # if @args["page"]
594
+ # +++
595
+ # else
596
+ for i, c in [ ["title", "\\title{%s}"],
597
+ ["author", "\\author{%s}"],
598
+ ["date", "\\date{%s}"]
599
+ ]
600
+ ii = @deplate.get_clip(i)
601
+ if ii
602
+ elts << i
603
+ elt = ii.elt
604
+ case i
605
+ when "author"
606
+ an = @deplate.get_clip("authornote")
607
+ elt += %{\\protect\\footnote{#{an.elt}}} if an
608
+ end
609
+ acc << c % elt
610
+ end
611
+ end
612
+ acc << "\\maketitle\n" if elts.include?("title") and elts.include?("author")
613
+ kw = keywords
614
+ acc << %{#{@deplate.msg("Keywords:")} #{kw.join(", ")}} << "" if kw
615
+ # end
616
+ join_blocks(acc)
617
+ end
618
+
619
+ alias :format_IMG :format_figure
620
+
621
+ alias :format_MAKETITLE :format_title
622
+
623
+ def format_MAKEBIB(invoker)
624
+ style = invoker.elt
625
+ bib = @deplate.options.bib.collect{|f| File.basename(f, ".bib")}.join(",")
626
+ "\\bibliographystyle{#{style}}\n\\bibliography{#{bib}}\n"
627
+ end
628
+ alias :format_bibliography :format_MAKEBIB
629
+
630
+ def format_IDX(invoker)
631
+ invoker.elt
632
+ end
633
+
634
+ def format_pagebreak(invoker, style=nil, major=false)
635
+ "\\clearpage{}"
636
+ end
637
+
638
+
639
+ ################################################ Particles {{{1
640
+ def format_emphasize(invoker, text)
641
+ "\\emph{%s}" % text
642
+ end
643
+
644
+ def format_code(invoker, text)
645
+ "\\texttt{%s}" % plain_text(text, true)
646
+ end
647
+
648
+ def format_url(invoker, name, dest, anchor, literal=false)
649
+ add_package("hyperref")
650
+ # if @deplate.options.pdftex and dest =~ /^~/
651
+ # dest = "file://" + File.expand_path(dest)
652
+ # end
653
+ dest = Deplate::HyperLink.url_anchor(dest, anchor)
654
+ dest.gsub!(/([%#])/, "\\\\\\1")
655
+ "\\href{%s}{%s}" % [dest, name]
656
+ end
657
+
658
+ def format_wiki(invoker, name, dest, anchor)
659
+ add_package("hyperref")
660
+ if dest and !dest.empty?
661
+ log(["Wiki name as url", dest], :debug)
662
+ format_url(invoker, name, dest, anchor)
663
+ else
664
+ # "%s~($\\Rightarrow{}$\\pageref{%s})" % [plain_text(name), anchor]
665
+ # "%s~($\\Rightarrow{}$\\pageref{%s})" % [name, anchor]
666
+ p = @deplate.parse_and_format(invoker.container, @deplate.msg('p.\\ '))
667
+ "#{name}~(#{p}\\pageref{#{anchor}})"
668
+ end
669
+ end
670
+
671
+ def format_symbol(invoker, text)
672
+ case text
673
+ when "<-"
674
+ return "$\\leftarrow{}$"
675
+ when "->"
676
+ return "$\\rightarrow{}$"
677
+ when "<="
678
+ return "$\\Leftarrow{}$"
679
+ when "=>"
680
+ return "$\\Rightarrow{}$"
681
+ when "<<<"
682
+ return "$\\Longleftarrow{}$"
683
+ when ">>>"
684
+ return "$\\Longrightarrow{}$"
685
+ # when "<~"
686
+ # return "\\{}"
687
+ when "~>"
688
+ add_package("latexsym")
689
+ return "$\\leadsto{}$"
690
+ when "<->"
691
+ return "$\\leftrightarrow{}$"
692
+ when "<=>"
693
+ return "$\\Leftrightarrow{}$"
694
+ when "<~>"
695
+ return "$\\rightleftharpoons{}$"
696
+ when "!="
697
+ return "$\\neq{}$"
698
+ when "~~"
699
+ return "$\\approx{}$"
700
+ when "..."
701
+ return "\\ldots{}"
702
+ when "--"
703
+ return text
704
+ when "=="
705
+ return "$\\equiv{}$"
706
+ when "+++"
707
+ return "$^{*}$\\protect\\marginpar{$^{*}$\\emph{+++}}"
708
+ when "###"
709
+ return "$^{*}$\\protect\\marginpar{$^{*}$\\emph{\\#\\#\\#}}"
710
+ when "???"
711
+ return "$^{*}$\\protect\\marginpar{$^{*}$\\emph{???}}"
712
+ when "!!!"
713
+ return "$^{*}$\\protect\\marginpar{$^{*}$\\emph{!!!}}"
714
+ else
715
+ return plain_text(text)
716
+ end
717
+ end
718
+
719
+ def doublequote_open(invoker)
720
+ "``"
721
+ end
722
+
723
+ def doublequote_close(invoker)
724
+ "''"
725
+ end
726
+
727
+ def singlequote_open(invoker)
728
+ "`"
729
+ end
730
+
731
+ def singlequote_close(invoker)
732
+ "'"
733
+ end
734
+
735
+
736
+ ################################################ Macros {{{1
737
+ def format_index(invoker, idx)
738
+ i = Deplate::Core.get_index_name(idx)
739
+ # n = @deplate.parse_and_format(@container, i, false)
740
+ # n = n.gsub(/,/, "{,}")
741
+ n = plain_text(i).gsub(/,/, "{,}")
742
+ return "\\protect\\index{#{n}}"
743
+ end
744
+
745
+ def format_footnote(invoker)
746
+ elt = invoker.elt
747
+ if elt
748
+ fn = elt.elt
749
+ return "\\footnote{#{fn.body}}"
750
+ else
751
+ return ""
752
+ end
753
+ end
754
+
755
+ def format_ref(invoker)
756
+ add_package("hyperref")
757
+ args = invoker.args
758
+ text = invoker.text
759
+ p = args["p"]
760
+ if p
761
+ return "~\\pageref{#{text}}"
762
+ else
763
+ return "~\\ref{#{text}}"
764
+ end
765
+ end
766
+
767
+ def format_linebreak(invoker)
768
+ return "\\newline{}"
769
+ end
770
+
771
+ # Currently assumes the use of natbib
772
+ def format_cite(invoker)
773
+ args = invoker.args
774
+ elt = invoker.elt
775
+ add_package("natbib", "round")
776
+ n = args["n"]
777
+ p = args["p"]
778
+ np = args["np"]
779
+ y = args["y"]
780
+ c = elt
781
+ o = []
782
+ o << "[#{n}]" if n
783
+ if p
784
+ p = @deplate.parse_and_format(invoker.container, "#{@deplate.msg('p.\\ ')}#{p}")
785
+ o << "[#{p}]"
786
+ elsif n
787
+ o << "[]"
788
+ end
789
+ o = o.join unless o.empty?
790
+ if np
791
+ cmd = if y then "citeyear" else "citealp" end
792
+ else
793
+ cmd = if y then "citeyearpar" else "citep" end
794
+ end
795
+ return "~\\#{cmd}#{o}{#{c.join(",")}}"
796
+ end
797
+
798
+ def format_subscript(invoker)
799
+ elt = invoker.elt
800
+ return %{$\\mathrm{_{#{elt.sub(/([{}])/, "\\\\\\1")}}}$}
801
+ end
802
+
803
+ def format_superscript(invoker)
804
+ elt = invoker.elt
805
+ return %{$\\mathrm{^{#{elt.sub(/([{}])/, "\\\\\\1")}}}$}
806
+ end
807
+
808
+ def format_stacked(invoker)
809
+ elt = invoker.elt
810
+ sup = %{#{elt[0].sub(/([{}])/, "\\\\\\1")}}
811
+ sub = %{#{elt[1].sub(/([{}])/, "\\\\\\1")}}
812
+ return %{$\\mathrm{^{#{sup}}_{#{sub}}}$}
813
+ end
814
+
815
+ def format_pagenumber(invoker)
816
+ args = invoker.args
817
+ if args["hd"] || args["ft"] || args["header"] || args["footer"]
818
+ return ""
819
+ else
820
+ return "\\thepage{}"
821
+ end
822
+ end
823
+
824
+ def format_ltx(invoker, other_args={})
825
+ invoker.elt
826
+ end
827
+
828
+ # Format the math macro
829
+ alias :format_math :format_ltx
830
+
831
+
832
+ protected ###################################### protected {{{1
833
+ ################################################ General {{{1
834
+ def set_document_encoding
835
+ enc = @deplate.variables["encoding"] || "latin1"
836
+ enc = canonic_enc_name(enc)
837
+ output_at(:pre, :fmt_packages, "\\usepackage[#{enc}]{inputenc}")
838
+ end
839
+
840
+
841
+ ################################################ Lists {{{1
842
+ def format_list_enumerate_alpha(invoker, what, subtype, w, pre, post)
843
+ if what == :open
844
+ if defined?(@@enumerateCounters)
845
+ @@enumerateCounters += 1
846
+ else
847
+ @@enumerateCounters = 0
848
+ end
849
+ cnt = "deplateEnumerate#{@@enumerateCounters}"
850
+ pre = %{#{pre}\\newcounter{#{cnt}}}
851
+ case subtype
852
+ when "a"
853
+ alph = "\\alph{#{cnt}}"
854
+ when "A"
855
+ alph = "\\Alph{#{cnt}}"
856
+ end
857
+ arg = "\\usecounter{#{cnt}}\\setlength{\\rightmargin}{\\leftmargin}"
858
+ return "#{pre}\\#{w}{list}{#{alph}.}{#{arg}}#{post}"
859
+ else
860
+ return "#{pre}\\#{w}{list}#{post}"
861
+ end
862
+ end
863
+
864
+ def list_wide?
865
+ @deplate.variables['texLists'] == 'wide'
866
+ end
867
+
868
+
869
+ ################################################ List of ... {{{1
870
+ def format_list_of_contents(invoker)
871
+ "\\tableofcontents{}"
872
+ end
873
+ alias format_list_of_toc format_list_of_contents
874
+
875
+ def format_list_of_tables(invoker)
876
+ "\\listoftables{}"
877
+ end
878
+
879
+ def format_list_of_figures(invoker)
880
+ "\\listoffigures{}"
881
+ end
882
+
883
+ def format_list_of_index(invoker)
884
+ add_package("makeidx")
885
+ union_at(:pre, :mod_head, "\\makeindex{}")
886
+ "\\printindex{}"
887
+ end
888
+
889
+
890
+ ################################################ Table {{{1
891
+ def table_indented_row(invoker, row, indent, cells)
892
+ # indent_text(cells)
893
+ indent + cells
894
+ end
895
+
896
+ def table_normal_row(invoker, row, nth)
897
+ args = tabular_args(invoker)
898
+ just = tabular_col_justifications(invoker)
899
+ widths = tabular_col_widths(invoker)
900
+ acc = []
901
+ row.cols.each_with_index do |cell, x|
902
+ case cell
903
+ when :join_left
904
+ when :join_above
905
+ acc << ""
906
+ when :ruler, :noruler
907
+ raise "Shouldn't be here"
908
+ else
909
+ rv = with_agent(:table_cell, String, invoker, cell, row)
910
+ wi = widths[x]
911
+ if wi
912
+ case just[x]
913
+ when "r", "right"
914
+ rv = %{\\parbox[t]{#{wi}}{\\raggedleft{}#{rv}}}
915
+ when "c", "center"
916
+ rv = %{\\parbox[t]{#{wi}}{\\centering{}#{rv}}}
917
+ when "l", "left"
918
+ rv = %{\\parbox[t]{#{wi}}{\\raggedright{}#{rv}}}
919
+ # when "j", "justify"
920
+ # else
921
+ end
922
+ end
923
+ # span = cell.span_y
924
+ # if span > 1
925
+ # add_package("multirow")
926
+ # rv = %{\\multirow{#{span}}{*}{#{rv}}}
927
+ # end
928
+ span = cell.span_x
929
+ if span > 1
930
+ coldef = args[x]
931
+ if args[x + span - 1] =~ /\|$/ and coldef !=~ /\|$/
932
+ coldef << "|"
933
+ end
934
+ rv = %{\\multicolumn{#{span}}{#{coldef}}{#{rv}}}
935
+ end
936
+ # if rv.empty?
937
+ # rv = "{ }"
938
+ # end
939
+ acc << rv
940
+ end
941
+ end
942
+ return acc
943
+ end
944
+
945
+ alias :table_head_row :table_normal_row
946
+ alias :table_foot_row :table_normal_row
947
+ alias :table_high_row :table_normal_row
948
+
949
+ def table_horizontal_ruler(invoker, row, nth)
950
+ acc = []
951
+ from = nil
952
+ row.cols.each_with_index do | cell, i |
953
+ unless cell.instance_of?(Symbol)
954
+ cell = cell.cell
955
+ end
956
+ case cell
957
+ when :ruler
958
+ from = i unless from
959
+ when :noruler, /^\s*$/
960
+ if from
961
+ acc << with_agent(:table_horizontal_ruler_from_to, String, invoker,
962
+ :from => from, :to => i, :top => (i == 0))
963
+ from = nil
964
+ end
965
+ else
966
+ invoker.log(["Malformed ruler definition", cell, row], :error)
967
+ end
968
+ end
969
+ if from == 0
970
+ acc << with_agent(:table_horizontal_ruler_from_to, String, invoker, :bottom => true)
971
+ end
972
+ acc.join(" ")
973
+ end
974
+
975
+ def table_horizontal_ruler_from_to(invoker, args={})
976
+ from = args[:from]
977
+ to = args[:to]
978
+ top = args[:top] || false
979
+ bottom = args[:bottom] || false
980
+ unless top or bottom
981
+ row = args[:row]
982
+ if row
983
+
984
+ end
985
+ end
986
+ if from and to
987
+ cline = @booktabs ? "cmidrule" : "cline"
988
+ %{\\#{cline}{#{from + 1}-#{to}}}
989
+ else
990
+ if @booktabs
991
+ hline = if top
992
+ "toprule"
993
+ elsif bottom
994
+ "bottomrule"
995
+ else
996
+ "midrule"
997
+ end
998
+ else
999
+ hline = "hline"
1000
+ end
1001
+ %{\\#{hline}}
1002
+ end
1003
+ end
1004
+
1005
+ def table_cell(invoker, cell, row)
1006
+ cell.cell
1007
+ end
1008
+
1009
+ def is_longtable?(invoker, rown)
1010
+ args = invoker.args
1011
+ if args["long"]
1012
+ return true
1013
+ elsif args["short"]
1014
+ return false
1015
+ elsif rown
1016
+ return rown > 20
1017
+ else
1018
+ return false
1019
+ end
1020
+ end
1021
+
1022
+ def table_join_cells(cells)
1023
+ if cells.kind_of?(Array)
1024
+ cells.join(" & ") + " \\\\"
1025
+ else
1026
+ cells
1027
+ end
1028
+ end
1029
+
1030
+ def tabular_args(invoker, args=nil)
1031
+ colwidth = with_agent(:tabular_col_widths, Array, invoker, args)
1032
+ coljust = with_agent(:tabular_col_justifications, Array, invoker, args)
1033
+ vertruler = with_agent(:tabular_vertical_rulers, Array, invoker, args)
1034
+ rv = []
1035
+ rowsize = table_row_size(invoker.elt)
1036
+ for i in 0..(rowsize - 1)
1037
+ this = ""
1038
+ r = vertruler[i]
1039
+ if r
1040
+ this << ("|" * r.to_i)
1041
+ end
1042
+ w = colwidth[i]
1043
+ if w
1044
+ this << %{p{%s}} % w
1045
+ else
1046
+ j = coljust[i]
1047
+ case j
1048
+ when "r", "right"
1049
+ j = "r"
1050
+ when "c", "center"
1051
+ j = "c"
1052
+ # when "left", "justify"
1053
+ # j = "l"
1054
+ else
1055
+ j = "l"
1056
+ end
1057
+ this << j
1058
+ end
1059
+ rv << this
1060
+ end
1061
+ r = vertruler[rowsize]
1062
+ if r
1063
+ rv.last << ("|" * r.to_i)
1064
+ end
1065
+ return rv
1066
+ end
1067
+
1068
+ def tabular_col_widths(invoker, args=nil)
1069
+ args ||= invoker.args
1070
+ Deplate::Core.props(args["cols"], "w")
1071
+ end
1072
+
1073
+ def tabular_col_justifications(invoker, args=nil)
1074
+ args ||= invoker.args
1075
+ Deplate::Core.props(args["cols"], "j")
1076
+ end
1077
+
1078
+ def tabular_vertical_rulers(invoker, args=nil)
1079
+ args ||= invoker.args
1080
+ Deplate::Core.props(args["cols"], "r")
1081
+ end
1082
+
1083
+ def table_cols(invoker)
1084
+ args = invoker.args
1085
+ elt = invoker.elt
1086
+ tabular_args(invoker).join
1087
+ end
1088
+
1089
+ def table_table_top(invoker, capAbove)
1090
+ floatPos, alignCmd = float_options(invoker)
1091
+ acc = []
1092
+ acc << "\\begin{table}%s" % [floatPos]
1093
+ acc << alignCmd
1094
+ acc << with_agent(:table_caption, String, invoker, false) if capAbove
1095
+ note = invoker.args["note"]
1096
+ if invoker.contains_footnotes or note
1097
+ acc << "\\begin{minipage}{\\textwidth}"
1098
+ acc << alignCmd
1099
+ end
1100
+ acc << "\\begin{tabular}{#{table_cols(invoker)}}"
1101
+ join_blocks(acc)
1102
+ end
1103
+
1104
+ def table_table_bottom(invoker, capAbove)
1105
+ acc = []
1106
+ acc << "\\end{tabular}"
1107
+ note = with_agent(:table_note, String, invoker)
1108
+ acc << "\\end{minipage}" if invoker.contains_footnotes or note
1109
+ acc << note if note
1110
+ acc << format_label(invoker, :once)
1111
+ acc << with_agent(:table_caption, String, invoker, false) if !capAbove
1112
+ acc << "\\end{table}"
1113
+ join_blocks(acc)
1114
+ end
1115
+
1116
+ def table_longtable_top(invoker, capAbove)
1117
+ add_package("longtable")
1118
+ # floatPos, alignCmd = float_options(invoker)
1119
+ acc = []
1120
+ acc << "\\begin{longtable}{%s}" % table_cols(invoker)
1121
+ # <+TBD+> acc << alignCmd
1122
+ acc << "#{with_agent(:table_caption, String, invoker, true)} \\\\" if capAbove
1123
+ join_blocks(acc)
1124
+ end
1125
+
1126
+ def table_longtable_bottom(invoker, capAbove)
1127
+ acc = []
1128
+ acc << "#{with_agent(:table_caption, String, invoker, true)} \\\\" if !capAbove
1129
+ acc << "\\end{longtable}"
1130
+ join_blocks(acc)
1131
+ end
1132
+
1133
+ def table_top(invoker, capAbove, rown)
1134
+ acc = []
1135
+ if is_longtable?(invoker, rown)
1136
+ acc << table_longtable_top(invoker, capAbove)
1137
+ elsif invoker.caption
1138
+ acc << table_table_top(invoker, capAbove)
1139
+ else
1140
+ if invoker.contains_footnotes or invoker.args["note"]
1141
+ acc << "\\begin{minipage}{\\textwidth}"
1142
+ end
1143
+ acc << "\\begin{tabular}{#{table_cols(invoker)}}"
1144
+ end
1145
+ join_blocks(acc)
1146
+ end
1147
+
1148
+ def table_bottom(invoker, capAbove, rown)
1149
+ acc = []
1150
+ if is_longtable?(invoker, rown)
1151
+ acc << table_longtable_bottom(invoker, capAbove)
1152
+ elsif invoker.caption
1153
+ acc << table_table_bottom(invoker, capAbove)
1154
+ else
1155
+ acc << format_label(invoker, :once)
1156
+ acc << "\\end{tabular}"
1157
+ note = with_agent(:table_note, String, invoker)
1158
+ acc << "\\end{minipage}" if invoker.contains_footnotes or note
1159
+ acc << note if note
1160
+ end
1161
+ acc << ""
1162
+ join_blocks(acc)
1163
+ end
1164
+
1165
+ def table_note(invoker)
1166
+ note = invoker.args["note"]
1167
+ note ? %{\\footnotesize{#{@deplate.parse_and_format(invoker, note)}}} : nil
1168
+ end
1169
+
1170
+ def table_caption(invoker, do_label)
1171
+ caption = invoker.caption
1172
+ if caption
1173
+ cap = [caption.elt]
1174
+ cap << format_label(invoker, :string) if do_label
1175
+ text = with_agent(:table_caption_text, String, invoker, cap.join)
1176
+ "\\caption{#{text}}"
1177
+ elsif do_label
1178
+ format_label(invoker, :once)
1179
+ end
1180
+ end
1181
+
1182
+ def table_caption_text(invoker, text)
1183
+ text
1184
+ end
1185
+
1186
+ def table_begin_head(invoker, rown)
1187
+ nil
1188
+ end
1189
+
1190
+ def table_end_head(invoker, rown)
1191
+ caption = invoker.caption
1192
+ if caption and is_longtable?(invoker, rown)
1193
+ " \\endhead"
1194
+ end
1195
+ end
1196
+
1197
+ def table_begin_body(invoker, rown)
1198
+ nil
1199
+ end
1200
+
1201
+ def table_end_body(invoker, rown)
1202
+ # <+TBD+>
1203
+ end
1204
+
1205
+ def table_begin_foot(invoker, rown)
1206
+ nil
1207
+ end
1208
+
1209
+ def table_end_foot(invoker, rown)
1210
+ nil
1211
+ end
1212
+
1213
+ def float_options(invoker)
1214
+ args = invoker.args
1215
+ if args["here"] or @deplate.variables["floatHere"]
1216
+ floatPos = "[hptb]"
1217
+ else
1218
+ floatPos = nil
1219
+ end
1220
+ align = args["align"] || @deplate.variables["floatAlign"]
1221
+ align ||= "center" if invoker.caption
1222
+ case align
1223
+ when "right"
1224
+ alignCmd = "\\raggedleft{}"
1225
+ when "left"
1226
+ alignCmd = "\\raggedright{}"
1227
+ when "center"
1228
+ alignCmd = "\\centering{}"
1229
+ else
1230
+ alignCmd = nil
1231
+ end
1232
+ return floatPos, alignCmd
1233
+ end
1234
+ end
1235
+
1236
+
1237
+ class Deplate::Regions::Img
1238
+ @@ImgSuffix[Deplate::Formatter::LaTeX] = Proc.new do |invoker|
1239
+ invoker.deplate.options.pdftex ? "png" : "ps"
1240
+ end
1241
+ end
1242
+