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,32 @@
1
+ # htmlslides-navbar-fh.rb
2
+ # @Author: Thomas Link, Fritz Heinrichmeyer
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: 23-Okt-2005.
7
+ # @Revision: 0.435
8
+
9
+
10
+ class Deplate::Formatter::HTML_Site
11
+ def format_navigation_bar(invoker, type, slot, bartype, first=false, last=false)
12
+ idx, _, _ = navbar_output_index(invoker, first, last)
13
+ navmenu = []
14
+ doctitle = @deplate.get_clip("title")
15
+ doctitle = if doctitle then doctitle.elt.to_s else "" end
16
+ @deplate.each_heading(1) do |section, title|
17
+ unless section.args["noList"]
18
+ f = section.output_file_name
19
+ v = section.description.gsub(/<\/?[^>]*>/, "")
20
+ end
21
+ if @deplate.top_heading_idx(section.top_heading) != idx
22
+ navmenu << %{<a class="navbar" href="#{f}">#{v}</a>}
23
+ else
24
+ set_at(:pre, :head_title, %{<title>#{doctitle} #{v}</title>})
25
+ navmenu << %{<span class="navbartds">#{v}</span>}
26
+ end
27
+ end
28
+ @deplate.options.navmenu = navmenu.join("\n")
29
+ output_at(:body, slot, @deplate.options.navmenu.to_s)
30
+ end
31
+ end
32
+
@@ -0,0 +1,35 @@
1
+ # iconv.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-Apr-2005.
6
+ # @Last Change: 23-Okt-2005.
7
+ # @Revision: 0.84
8
+ #
9
+ # = Description
10
+ # Recode text on-the-fly using +iconv+. The source encoding is
11
+ # taken from the +encoding+ variable (default: latin1), the target
12
+ # encoding is defined in the +recodeEncoding+ (default: utf-8) variable.
13
+
14
+ require 'iconv'
15
+
16
+ class Deplate::Formatter
17
+ def hook_pre_go_iconv
18
+ @iconv_encodings = {}
19
+ unless defined?(@iconv_enc_source)
20
+ source = @deplate.variables['encoding'] || "latin1"
21
+ @iconv_enc_source = canonic_enc_name(source, @iconv_encodings)
22
+ target = @deplate.variables['recodeEncoding'] || "utf-8"
23
+ @iconv_enc_target = canonic_enc_name(target, @iconv_encodings)
24
+ @deplate.variables['encoding'] = target
25
+ end
26
+ unless defined?(@iconv_converter) and @iconv_converter
27
+ @iconv_converter = Iconv.new(@iconv_enc_target, @iconv_enc_source)
28
+ end
29
+ end
30
+
31
+ def plain_text_recode(text)
32
+ @iconv_converter.iconv(text)
33
+ end
34
+ end
35
+
@@ -0,0 +1,30 @@
1
+ # imgurl.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: 05-Mai-2005.
6
+ # @Last Change: 23-Okt-2005.
7
+ # @Revision: 0.26
8
+ #
9
+ # = Description
10
+ # Insert URLs to images as image
11
+
12
+ require 'deplate/wiki-markup'
13
+
14
+ # Insert URLs to images as image
15
+ class Deplate::HyperLink::ImgUrl < Deplate::Input::Wiki::AbstractImgUrl
16
+ insert_particle_before(Deplate::HyperLink::Url)
17
+ @rx = /^((file|https?|mailto|ftps?|www):(\S+?)\.(png|jpg|jpeg|gif|bmp))/
18
+ end
19
+
20
+ class Deplate::HyperLink::Extended
21
+ alias :process_re_imgurl :process
22
+ def process
23
+ if @dest =~ /\.(png|jpg|jpeg|gif|bmp)$/
24
+ @elt = @deplate.formatter.include_image(encode_path(@dest), @args, true)
25
+ else
26
+ process_re_imgurl
27
+ end
28
+ end
29
+ end
30
+
@@ -0,0 +1,69 @@
1
+ # inlatex-compound.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: 07-Apr-2005.
6
+ # @Last Change: 23-Okt-2005.
7
+ # @Revision: 0.39
8
+ #
9
+ # = Description
10
+ # This doesn't work yet.
11
+ #
12
+ # This module changes the way deplate processes inline latex fragments.
13
+ # By default, deplate converts each fragment for its own. When using
14
+ # this module, the latex fragments are collected in one file, are
15
+ # translated to dvi and ps, and then separated to bitmap files.
16
+
17
+ class Deplate::Formatter
18
+ alias :inlatex_compound :inlatex
19
+
20
+ # Process inline latex
21
+ def inlatex(invoker)
22
+ unless defined?(@inlatex_body)
23
+ @inlatex_body = []
24
+ @inlatex_container = []
25
+ @inlatex_suffix = nil
26
+ end
27
+ @inlatex_body << invoker.accum
28
+ @inlatex_body << %{\\newpage{}}
29
+ # @inlatex_body << %{\\clearpage{}}
30
+ rv = @inlatex_container.size
31
+ @inlatex_container << invoker
32
+ @inlatex_suffix ||= invoker.args['sfx']
33
+ rv
34
+ end
35
+
36
+ def hook_pre_process_inlatex
37
+ pseudo = Deplate::PseudoContainer.new(@deplate,
38
+ :accum => @inlatex_body,
39
+ :args => {'sfx' => @inlatex_suffix}
40
+ )
41
+ inlatex_compound(pseudo)
42
+ fnames = pseudo.elt
43
+ if fnames.size != @inlatex_container.size
44
+ log("Conversion if compound Inline LaTeX failed", :error)
45
+ else
46
+ @inlatex_container.each_with_index do |o, i|
47
+ e = fnames[i]
48
+ o.elt = [e]
49
+ end
50
+ end
51
+ end
52
+
53
+ def inlatex_process_latex(invoker, ftex, faux, flog)
54
+ latex2dvi(invoker, ftex, faux, flog)
55
+ end
56
+
57
+ def inlatex_process_dvi(invoker, fdvi, fps)
58
+ dvi2ps(invoker, fdvi, fps, '-i -S 1')
59
+ end
60
+
61
+ def inlatex_process_ps(invoker, device, fps, fout, args)
62
+ fin = File.basename(fps, '.*')
63
+ for fps in Dir["#{fin}.[0-9][0-9][0-9]"]
64
+ File.rename(fps, "#{fps}.ps")
65
+ ps2img(invoker, device, fps, fout, args)
66
+ end
67
+ end
68
+ end
69
+
@@ -0,0 +1,109 @@
1
+ # mod-koma.rb -- Module: use Koma-Script and friends as LaTeX class
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: 07-Mai-2004.
6
+ # @Last Change: 31-Okt-2005.
7
+ # @Revision: 0.106
8
+ #
9
+ # Description:
10
+ #
11
+ # Usage:
12
+ #
13
+ # TODO:
14
+ #
15
+ # CHANGES:
16
+ #
17
+
18
+ class Deplate::Formatter::LaTeX
19
+ @@latexDocClass = "scrartcl"
20
+
21
+ # def hook_pre_prepare_koma
22
+ # push_class_option('tablecaptionabove')
23
+ # end
24
+
25
+ def format_header_or_footer(invoker, left, center, right, linesep=nil)
26
+ args = invoker.args
27
+ elt = invoker.elt
28
+ if elt.size > 1
29
+ format_header_or_footer_error(elt)
30
+ end
31
+ catch :error do
32
+ e = elt[0]
33
+ if e.kind_of?(Deplate::Element::Paragraph)
34
+ l = c = r = nil
35
+ ee = wrap_text(e.elt)
36
+ if args["center"]
37
+ c = ee
38
+ elsif args["right"]
39
+ r = ee
40
+ else
41
+ l = ee
42
+ end
43
+ elsif e.kind_of?(Deplate::Element::Table)
44
+ log("Only the header's first row will be used", :error) if e.elt.size > 1
45
+ l, c, r = e.elt[0].cols.collect {|c| c.cell}
46
+ else
47
+ format_header_or_footer_error(elt)
48
+ end
49
+
50
+ output(invoker, "\\%s{%s}" % [left, l]) if l and !l.empty?
51
+ output(invoker, "\\%s{%s}" % [center, c]) if c and !c.empty?
52
+ output(invoker, "\\%s{%s}" % [right, r]) if r and !r.empty?
53
+ ls = args["linesep"] || args["sep"]
54
+ if ls
55
+ if ls == true
56
+ ls = "0.4pt"
57
+ elsif ls =~ /^[0-9.]+$/
58
+ ls = "%dpt" % ls
59
+ end
60
+ output(invoker, "\\%s{%s}" % [linesep, ls])
61
+ end
62
+ end
63
+ end
64
+
65
+ def format_header_or_footer_error(elt)
66
+ elts = "%s %s" % [elt.size, elt.collect {|e| e.class}.join(", ")]
67
+ log(["Header must contain only 1 element (a paragraph or a table)", elts], :error)
68
+ end
69
+
70
+ def format_header(invoker)
71
+ type = invoker.doc_type(:pre)
72
+ slot = invoker.doc_slot(:body_pre)
73
+ unless @deplate.variables['__pagestyle_initialized']
74
+ add_package("scrpage2")
75
+ type, cslot, slot = format_header_or_footer_slots(type, slot)
76
+ output_at(type, cslot, "", %{\\clearscrheadfoot{}})
77
+ output_at(type, slot, %{\\pagestyle{scrheadings}}, "")
78
+ @deplate.variables['__pagestyle_initialized'] = true
79
+ end
80
+ format_header_or_footer(invoker, "ihead", "chead", "ohead", "setheadsepline")
81
+ end
82
+
83
+ def format_footer(invoker)
84
+ type = invoker.doc_type(:pre)
85
+ slot = invoker.doc_slot(:body_pre)
86
+ unless @deplate.variables['__pagestyle_initialized']
87
+ add_package("scrpage2")
88
+ type, cslot, slot = format_header_or_footer_slots(type, slot)
89
+ output_at(type, cslot, "", %{\\clearscrheadfoot{}})
90
+ output_at(type, slot, %{\\pagestyle{scrheadings}}, "")
91
+ @deplate.variables['__pagestyle_initialized'] = true
92
+ end
93
+ format_header_or_footer(invoker, "ifoot", "cfoot", "ofoot", "setfootsepline")
94
+ end
95
+
96
+ def format_header_or_footer_slots(type, slot)
97
+ if slot == :body_pre and type == :pre
98
+ return [type, :prematter_end, slot]
99
+ else
100
+ return [type, slot, slot]
101
+ end
102
+ end
103
+
104
+ def format_pagenumber(invoker)
105
+ return "\\pagemark{}"
106
+ end
107
+ end
108
+
109
+ # vim: ff=unix
@@ -0,0 +1,38 @@
1
+ # latex-emph-table-head.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: 26-Nov-2004.
6
+ # @Last Change: 23-Okt-2005.
7
+ # @Revision: 0.39
8
+ #
9
+ # Description:
10
+ #
11
+ # Usage:
12
+ #
13
+ # TODO:
14
+ #
15
+ # CHANGES:
16
+ #
17
+
18
+ class Deplate::Formatter::LaTeX
19
+ def formatter_initialize_latex_emph_table_head
20
+ def_advice("latex-emph-table-head", :table_end_head,
21
+ :wrap => Proc.new do |agent, rv, invoker, nth|
22
+ "#{rv}\n #{table_horizontal_ruler_from_to(invoker)}"
23
+ end
24
+ )
25
+ def_advice("latex-emph-table-head", :table_cell,
26
+ :wrap => Proc.new do |agent, rv, invoker, cell, *args|
27
+ hirow = args[0]
28
+ hd = (hirow || cell.head || cell.foot || cell.high)
29
+ if hd
30
+ format_particle(:format_emphasize, invoker, rv)
31
+ else
32
+ rv
33
+ end
34
+ end
35
+ )
36
+ end
37
+ end
38
+
@@ -0,0 +1,461 @@
1
+ # latex-emph-table-head.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: 26-Nov-2004.
6
+ # @Last Change: 23-Okt-2005.
7
+ # @Revision: 0.345
8
+ #
9
+ # Description:
10
+ #
11
+ # Usage:
12
+ #
13
+ # TODO:
14
+ #
15
+ # CHANGES:
16
+ #
17
+
18
+
19
+ # The dummy base style
20
+ class Deplate::Formatter::LaTeX::Styles
21
+
22
+ def initialize(deplate)
23
+ @deplate = deplate
24
+ @formatter = deplate.formatter
25
+ end
26
+
27
+ def format_table(rv, invoker, *args)
28
+ rv
29
+ end
30
+
31
+ def table_args(rv, invoker)
32
+ rv
33
+ end
34
+
35
+ def table_bottom(rv, invoker, *args)
36
+ rv
37
+ end
38
+
39
+ def table_caption(rv, invoker, *args)
40
+ rv
41
+ end
42
+
43
+ def table_caption_text(rv, invoker, *args)
44
+ rv
45
+ end
46
+
47
+ def table_cell(rv, invoker, *args)
48
+ rv
49
+ end
50
+
51
+ def table_cols(rv, invoker, *args)
52
+ rv
53
+ end
54
+
55
+ def table_begin_head(rv, invoker, rown)
56
+ rv
57
+ end
58
+
59
+ def table_end_head(rv, invoker, rown)
60
+ rv
61
+ end
62
+
63
+ def table_begin_body(rv, invoker, rown)
64
+ rv
65
+ end
66
+
67
+ def table_end_body(rv, invoker, rown)
68
+ rv
69
+ end
70
+
71
+ def table_begin_foot(rv, invoker, rown)
72
+ rv
73
+ end
74
+
75
+ def table_end_foot(rv, invoker, rown)
76
+ rv
77
+ end
78
+
79
+ def table_head_row(rv, invoker, *args)
80
+ rv
81
+ end
82
+
83
+ def table_horizontal_ruler(rv, invoker, *args)
84
+ rv
85
+ end
86
+
87
+ def table_horizontal_ruler_from_to(rv, invoker, *args)
88
+ rv
89
+ end
90
+
91
+ def table_longtable_bottom(rv, invoker, *args)
92
+ rv
93
+ end
94
+
95
+ def table_longtable_top(rv, invoker, *args)
96
+ rv
97
+ end
98
+
99
+ def table_normal_row(rv, invoker, *args)
100
+ rv
101
+ end
102
+
103
+ def table_head_row(rv, invoker, *args)
104
+ rv
105
+ end
106
+
107
+ def table_foot_row(rv, invoker, *args)
108
+ rv
109
+ end
110
+
111
+ def table_high_row(rv, invoker, *args)
112
+ rv
113
+ end
114
+
115
+ def table_table_bottom(rv, invoker, *args)
116
+ rv
117
+ end
118
+
119
+ def table_table_top(rv, invoker, *args)
120
+ rv
121
+ end
122
+
123
+ def table_top(rv, invoker, *args)
124
+ rv
125
+ end
126
+
127
+ def tabular_col_widths(rv, invoker, args)
128
+ rv
129
+ end
130
+
131
+ def tabular_col_justifications(rv, invoker, args)
132
+ rv
133
+ end
134
+
135
+ def tabular_vertical_rulers(rv, invoker, args)
136
+ rv
137
+ end
138
+
139
+ def table_indented_row(rv, invoker, row, indent, t)
140
+ rv
141
+ end
142
+
143
+ protected
144
+ def with_agent(agent, *args)
145
+ @formatter.send(agent, *args)
146
+ end
147
+
148
+ def horizontal_ruler(invoker, rv, args={})
149
+ m = /^\s+/.match(rv)
150
+ indent = m ? m[0] : ""
151
+ indent + with_agent(:table_horizontal_ruler_from_to, invoker, args)
152
+ end
153
+
154
+ def first_row?(invoker, rowidx)
155
+ rowidx == 0
156
+ end
157
+
158
+ def last_row?(invoker, rowidx)
159
+ invoker.elt.size - 1 == rowidx
160
+ end
161
+
162
+ def cell_in_first_row?(invoker, cell)
163
+ cell.y == 1
164
+ end
165
+
166
+ def cell_in_last_row?(invoker, cell)
167
+ cell.from_bottom - cell.span_y == 0
168
+ end
169
+
170
+ def cell_in_first_column?(invoker, cell)
171
+ cell.x == 1
172
+ end
173
+
174
+ def cell_in_last_column?(invoker, cell)
175
+ cell.from_right - cell.span_x == 0
176
+ end
177
+ end
178
+
179
+
180
+ # Smaller font sizes
181
+ # class Deplate::Formatter::LaTeX::Styles::TableSmall < Deplate::Formatter::LaTeX::Styles
182
+ # def table_cell(rv, invoker, *args)
183
+ # %{\\small{#{rv}}}
184
+ # end
185
+ # end
186
+ # class Deplate::Formatter::LaTeX::Styles::TableFootnotesize < Deplate::Formatter::LaTeX::Styles
187
+ # def table_cell(rv, invoker, *args)
188
+ # %{\\footnotesize{#{rv}}}
189
+ # end
190
+ # end
191
+ # class Deplate::Formatter::LaTeX::Styles::TableScriptsize < Deplate::Formatter::LaTeX::Styles
192
+ # def table_cell(rv, invoker, *args)
193
+ # %{\\scriptsize{#{rv}}}
194
+ # end
195
+ # end
196
+ class Deplate::Formatter::LaTeX::Styles::TableSmall < Deplate::Formatter::LaTeX::Styles
197
+ def table_top(rv, invoker, capAbove, rown)
198
+ "\\small{}\n#{rv}"
199
+ end
200
+ def table_bottom(rv, invoker, capAbove, rown)
201
+ "#{rv}\\normalsize{}\n"
202
+ end
203
+ def table_caption_text(rv, invoker, *args)
204
+ "\\normalsize{#{rv}}"
205
+ end
206
+ end
207
+ class Deplate::Formatter::LaTeX::Styles::TableFootnotesize < Deplate::Formatter::LaTeX::Styles
208
+ def table_top(rv, invoker, capAbove, rown)
209
+ "\\footnotesize{}\n#{rv}"
210
+ end
211
+ def table_bottom(rv, invoker, capAbove, rown)
212
+ "#{rv}\\normalsize{}\n"
213
+ end
214
+ def table_caption_text(rv, invoker, *args)
215
+ "\\normalsize{#{rv}}"
216
+ end
217
+ end
218
+ class Deplate::Formatter::LaTeX::Styles::TableScriptsize < Deplate::Formatter::LaTeX::Styles
219
+ def table_top(rv, invoker, capAbove, rown)
220
+ "\\scriptsize{}\n#{rv}"
221
+ end
222
+ def table_bottom(rv, invoker, capAbove, rown)
223
+ "#{rv}\\normalsize{}\n"
224
+ end
225
+ def table_caption_text(rv, invoker, *args)
226
+ "\\normalsize{#{rv}}"
227
+ end
228
+ end
229
+
230
+
231
+ # Denser tables
232
+ class Deplate::Formatter::LaTeX::Styles::TableDense08 < Deplate::Formatter::LaTeX::Styles
233
+ @@dense08baselinestretch = false
234
+ def initialize(deplate)
235
+ super
236
+ # unless @@dense08baselinestretch
237
+ # @formatter.output_at(:pre, :body_beg, "\\newcommand{\\origBaseLineStretch}{}")
238
+ # @@dense08baselinestretch = true
239
+ # end
240
+ end
241
+ def table_top(rv, invoker, capAbove, rown)
242
+ "\\renewcommand{\\arraystretch}{0.8}\n\\setlength{\\tabcolsep}{0.8\\tabcolsep}\n#{rv}"
243
+ end
244
+ def table_bottom(rv, invoker, capAbove, rown)
245
+ "#{rv}\\setlength{\\tabcolsep}{1.25\\tabcolsep}\n\\renewcommand{\\arraystretch}{1.0}\n"
246
+ end
247
+ end
248
+
249
+
250
+ # Displays tables as a box
251
+ class Deplate::Formatter::LaTeX::Styles::TableLandscape < Deplate::Formatter::LaTeX::Styles
252
+ def initialize(deplate)
253
+ super
254
+ @formatter.add_package("lscape")
255
+ end
256
+ def table_top(rv, invoker, capAbove, rown)
257
+ "\\begin{landscape}\n#{rv}"
258
+ end
259
+ def table_bottom(rv, invoker, capAbove, rown)
260
+ "#{rv}\\end{landscape}\n"
261
+ end
262
+ end
263
+
264
+
265
+ # Displays tables as a grid
266
+ class Deplate::Formatter::LaTeX::Styles::TableGrid < Deplate::Formatter::LaTeX::Styles
267
+ def table_bottom(rv, invoker, *args)
268
+ [horizontal_ruler(invoker, rv, :bottom => true), rv].join("\n")
269
+ end
270
+
271
+ def table_top(rv, invoker, *args)
272
+ [rv, horizontal_ruler(invoker, rv, :top => true)].join("\n")
273
+ end
274
+
275
+ def table_indented_row(rv, invoker, row, indent, t)
276
+ if row.from_bottom == 0
277
+ rv
278
+ else
279
+ [rv, horizontal_ruler(invoker, rv)].join("\n")
280
+ end
281
+ end
282
+
283
+ def tabular_vertical_rulers(rv, invoker, *args)
284
+ [1] * (@formatter.table_row_size(invoker.elt) + 1)
285
+ end
286
+ end
287
+
288
+
289
+ # Displays tables as found in scientific textbooks
290
+ # <+TBD+> We should also use booktabs.sty here
291
+ class Deplate::Formatter::LaTeX::Styles::TableFormal < Deplate::Formatter::LaTeX::Styles
292
+ def table_args(rv, *args)
293
+ rv + %{ rules="groups"}
294
+ end
295
+
296
+ def table_bottom(rv, invoker, *args)
297
+ [horizontal_ruler(invoker, rv, :bottom => true), rv].compact.join("\n")
298
+ end
299
+
300
+ def table_top(rv, invoker, *args)
301
+ [rv, horizontal_ruler(invoker, rv, :top => true)].compact.join("\n")
302
+ end
303
+
304
+ def table_end_head(rv, invoker, *args)
305
+ [rv, horizontal_ruler(invoker, rv)].compact.join("\n")
306
+ end
307
+
308
+ def table_begin_foot(rv, invoker, *args)
309
+ [horizontal_ruler(invoker, rv), rv].compact.join("\n")
310
+ end
311
+ end
312
+
313
+ # List
314
+ class Deplate::Formatter::LaTeX::Styles::TableList < Deplate::Formatter::LaTeX::Styles
315
+ def table_bottom(rv, invoker, *args)
316
+ [horizontal_ruler(invoker, rv, :bottom => true), rv].compact.join("\n")
317
+ end
318
+
319
+ def table_top(rv, invoker, *args)
320
+ [rv, horizontal_ruler(invoker, rv, :top => true)].compact.join("\n")
321
+ end
322
+
323
+ def table_indented_row(rv, invoker, row, indent, t)
324
+ if row.from_bottom == 0
325
+ rv
326
+ else
327
+ [rv, horizontal_ruler(invoker, rv)].join("\n")
328
+ end
329
+ end
330
+ end
331
+
332
+ # Displays tables as a box
333
+ class Deplate::Formatter::LaTeX::Styles::TableBox < Deplate::Formatter::LaTeX::Styles::TableFormal
334
+ def tabular_vertical_rulers(rv, invoker, *args)
335
+ rv[0] = 1
336
+ rv[@formatter.table_row_size(invoker.elt)] = 1
337
+ prototype = invoker.elt[0]
338
+ prototype.cols.each_with_index do |c, i|
339
+ if c.high
340
+ rv[i + 1] = rv[i] = 1
341
+ end
342
+ end
343
+ rv
344
+ end
345
+ end
346
+
347
+
348
+ # Try some coloring
349
+ class Deplate::Formatter::LaTeX::Styles::TableOverlay < Deplate::Formatter::LaTeX::Styles::TableBox
350
+ def initialize(deplate)
351
+ super
352
+ options = []
353
+ options << "pdftex" if deplate.options.pdftex
354
+ @formatter.add_package("colortbl", *options)
355
+ end
356
+
357
+ def table_head_row(rv, invoker, row, nth)
358
+ rv[0] = styled_head_row_color(rv[0])
359
+ rv
360
+ end
361
+
362
+ def table_foot_row(rv, invoker, row, nth)
363
+ rv[0] = styled_foot_row_color(rv[0])
364
+ rv
365
+ end
366
+
367
+ def table_cell(rv, invoker, cell, row)
368
+ if cell.high and !row.head and !row.foot
369
+ styled_high_cell_color(rv)
370
+ else
371
+ rv
372
+ end
373
+ end
374
+
375
+ def styled_head_row_color(rv)
376
+ %{\\rowcolor[gray]{.8}#{rv}}
377
+ end
378
+
379
+ def styled_foot_row_color(rv)
380
+ %{\\rowcolor[gray]{.9}#{rv}}
381
+ end
382
+
383
+ def styled_high_cell_color(rv)
384
+ %{\\cellcolor[gray]{.9}#{rv}}
385
+ end
386
+ end
387
+
388
+
389
+
390
+ class Deplate::Formatter::LaTeX
391
+ @style_classes = {
392
+ "grid" => Deplate::Formatter::LaTeX::Styles::TableGrid,
393
+ "formal" => Deplate::Formatter::LaTeX::Styles::TableFormal,
394
+ "box" => Deplate::Formatter::LaTeX::Styles::TableBox,
395
+ "overlay" => Deplate::Formatter::LaTeX::Styles::TableOverlay,
396
+ "list" => Deplate::Formatter::LaTeX::Styles::TableList,
397
+ "small" => Deplate::Formatter::LaTeX::Styles::TableSmall,
398
+ "footnotesize" => Deplate::Formatter::LaTeX::Styles::TableFootnotesize,
399
+ "scriptsize" => Deplate::Formatter::LaTeX::Styles::TableScriptsize,
400
+ "dense08" => Deplate::Formatter::LaTeX::Styles::TableDense08,
401
+ "landscape" => Deplate::Formatter::LaTeX::Styles::TableLandscape,
402
+ }
403
+
404
+ class << self
405
+ attr_accessor :style_classes
406
+ end
407
+
408
+ def formatter_initialize_latex_styles
409
+ @style_engines = {
410
+ :default => Deplate::Formatter::LaTeX::Styles.new(@deplate),
411
+ }
412
+
413
+ table_agents = [
414
+ :format_table, :table_args,
415
+ :table_bottom, :table_caption, :table_caption_text, :table_cell, :table_cols,
416
+ :table_begin_head, :table_end_head, :table_head_row,
417
+ :table_begin_foot, :table_end_foot, :table_foot_row,
418
+ :table_begin_body, :table_end_body, :table_high_row, :table_normal_row,
419
+ :table_horizontal_ruler, :table_horizontal_ruler_from_to,
420
+ :table_longtable_top, :table_longtable_bottom,
421
+ :table_table_bottom, :table_table_top, :table_top,
422
+ :tabular_col_widths, :tabular_col_justifications, :tabular_vertical_rulers,
423
+ :table_indented_row,
424
+ ]
425
+ for agent in table_agents
426
+ advice = Proc.new do |agent, rv, invoker, *args|
427
+ styles = []
428
+ stylex_arg = invoker.args["stylex"]
429
+ if stylex_arg
430
+ styles += stylex_arg.split(/\s*,\s*/)
431
+ else
432
+ style_arg = invoker.args["style"]
433
+ styles += style_arg.split(/\s*,\s*/) if style_arg
434
+ style_var = @deplate.variables["tableStyle"]
435
+ styles += style_var.split(/\s*,\s*/) if style_var
436
+ end
437
+ styles.compact!
438
+ for style in styles
439
+ styler = @style_engines[style] || setup_styler(style)
440
+ rv = styler.send(agent, rv, invoker, *args)
441
+ end
442
+ rv
443
+ end
444
+ def_advice("latex-styles", agent, :wrap => advice)
445
+ end
446
+ end
447
+
448
+ def setup_styler(style)
449
+ # <+TBD+> load module or style definition on-demand
450
+ c = self.class.style_classes[style]
451
+ if c
452
+ @style_engines[style] = styler = c.new(@deplate)
453
+ return styler
454
+ else
455
+ log(["Unknown style", style], :error)
456
+ @style_engines[:default]
457
+ end
458
+ end
459
+
460
+ end
461
+