deplate 0.8 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. data/AUTHORS.TXT +19 -16
  2. data/CHANGES.TXT +214 -248
  3. data/NEWS.TXT +47 -30
  4. data/README.TXT +0 -1
  5. data/TODO.TXT +93 -20
  6. data/VERSION.TXT +1 -1
  7. data/bin/deplate.exy +192 -0
  8. data/etc/deplate.ini +70 -9
  9. data/lib/action_view/helpers/deplate.rb +33 -33
  10. data/lib/deplate.rb +2 -2
  11. data/lib/deplate/bib.rb +72 -41
  12. data/lib/deplate/builtin.rb +1 -1
  13. data/lib/deplate/cache.rb +1 -1
  14. data/lib/deplate/commands.rb +161 -102
  15. data/lib/deplate/common.rb +93 -7
  16. data/lib/deplate/converter.rb +10 -4
  17. data/lib/deplate/core.rb +215 -108
  18. data/lib/deplate/counters.rb +23 -8
  19. data/lib/deplate/css/article.css +9 -5
  20. data/lib/deplate/css/deplate.css +37 -3
  21. data/lib/deplate/css/heading-navbar.css +1 -1
  22. data/lib/deplate/css/highstep.css +18 -0
  23. data/lib/deplate/css/htmldoc.css +43 -0
  24. data/lib/deplate/css/layout-deplate-print.css +1 -1
  25. data/lib/deplate/css/layout-deplate.css +1 -1
  26. data/lib/deplate/css/play.css +101 -0
  27. data/lib/deplate/css/sans-serif.css +1 -1
  28. data/lib/deplate/css/serif-e.css +1 -1
  29. data/lib/deplate/css/serif-rel.css +1 -1
  30. data/lib/deplate/css/serif.css +1 -1
  31. data/lib/deplate/css/slides.css +1 -1
  32. data/lib/deplate/css/styles.css +4 -0
  33. data/lib/deplate/css/tabbar-right.css +54 -8
  34. data/lib/deplate/css/tabbar-top.css +28 -9
  35. data/lib/deplate/css/text-sans-serif.css +1 -1
  36. data/lib/deplate/css/text-serif.css +1 -1
  37. data/lib/deplate/define.rb +71 -38
  38. data/lib/deplate/deplate-string.rb +3 -3
  39. data/lib/deplate/docbook.rb +9 -9
  40. data/lib/deplate/elements.rb +173 -84
  41. data/lib/deplate/etc.rb +6 -8
  42. data/lib/deplate/external.rb +9 -5
  43. data/lib/deplate/fmt/dbk-article-4.1.2.rb +4 -3
  44. data/lib/deplate/fmt/dbk-article.rb +9 -8
  45. data/lib/deplate/fmt/dbk-book.rb +4 -3
  46. data/lib/deplate/fmt/dbk-ref.rb +5 -4
  47. data/lib/deplate/fmt/dbk-slides.rb +4 -3
  48. data/lib/deplate/fmt/dbk-snippet.rb +4 -3
  49. data/lib/deplate/fmt/html-snippet.rb +1 -1
  50. data/lib/deplate/fmt/html.rb +186 -46
  51. data/lib/deplate/fmt/htmlsite.rb +19 -9
  52. data/lib/deplate/fmt/htmlslides.rb +1 -1
  53. data/lib/deplate/fmt/htmlwebsite.rb +1 -1
  54. data/lib/deplate/fmt/latex-dramatist.rb +175 -0
  55. data/lib/deplate/fmt/latex-snippet.rb +1 -1
  56. data/lib/deplate/fmt/latex.rb +132 -80
  57. data/lib/deplate/fmt/null.rb +1 -1
  58. data/lib/deplate/fmt/php.rb +1 -1
  59. data/lib/deplate/fmt/phpsite.rb +1 -1
  60. data/lib/deplate/fmt/plain.rb +16 -9
  61. data/lib/deplate/fmt/template.rb +1 -1
  62. data/lib/deplate/fmt/xhtml10t.rb +1 -1
  63. data/lib/deplate/formatter-snippet.rb +1 -1
  64. data/lib/deplate/formatter.rb +272 -81
  65. data/lib/deplate/guesslanguage.rb +57 -0
  66. data/lib/deplate/input.rb +205 -50
  67. data/lib/deplate/input/deplate-headings.rb +9 -11
  68. data/lib/deplate/input/deplate-restricted.rb +3 -23
  69. data/lib/deplate/input/deplate.rb +1 -1
  70. data/lib/deplate/input/play.rb +208 -0
  71. data/lib/deplate/input/rdoc.rb +37 -15
  72. data/lib/deplate/input/template.rb +6 -11
  73. data/lib/deplate/lib/Makefile.config +53 -4
  74. data/lib/deplate/lib/html/parbreak +3 -0
  75. data/lib/deplate/lib/javascript/StepwiseNextPage.js +8 -0
  76. data/lib/deplate/lib/javascript/StepwiseNextPage_confirm.js +8 -0
  77. data/lib/deplate/lib/latex/deplate.sty +36 -0
  78. data/lib/deplate/lib/latex/parbreak +6 -0
  79. data/lib/deplate/lib/php/page-comment.inc.php +5 -5
  80. data/lib/deplate/lib/plain/parbreak +6 -0
  81. data/lib/deplate/locale/de.latin1 +87 -15
  82. data/lib/deplate/locale/de.latin1_data +60 -0
  83. data/lib/deplate/locale/en.latin1_data +46 -0
  84. data/lib/deplate/locale/fr.latin1_data +74 -0
  85. data/lib/deplate/locale/ru.koi8-r_data +63 -0
  86. data/lib/deplate/locale/{zh_cn.gb2312 → zh_CN.GB2312} +0 -0
  87. data/lib/deplate/macros.rb +106 -32
  88. data/lib/deplate/messages.rb +22 -8
  89. data/lib/deplate/metadata.rb +1 -1
  90. data/lib/deplate/metadata/marshal.rb +1 -1
  91. data/lib/deplate/metadata/xml.rb +1 -1
  92. data/lib/deplate/metadata/yaml.rb +1 -1
  93. data/lib/deplate/mod/anyword.rb +4 -4
  94. data/lib/deplate/mod/babelfish.rb +1 -1
  95. data/lib/deplate/mod/code-gvim.rb +14 -8
  96. data/lib/deplate/mod/code-gvim71.rb +52 -0
  97. data/lib/deplate/mod/code-highlight.rb +35 -19
  98. data/lib/deplate/mod/colored-log.rb +1 -1
  99. data/lib/deplate/mod/endnotes.rb +1 -1
  100. data/lib/deplate/mod/guesslanguage.rb +75 -0
  101. data/lib/deplate/mod/html-asciimath.rb +1 -1
  102. data/lib/deplate/mod/html-deplate-button.rb +1 -1
  103. data/lib/deplate/mod/html-headings-navbar.rb +1 -1
  104. data/lib/deplate/mod/html-highstep.rb +43 -0
  105. data/lib/deplate/mod/html-jsmath.rb +1 -1
  106. data/lib/deplate/mod/html-obfuscate-email.rb +1 -1
  107. data/lib/deplate/mod/html-sidebar.rb +1 -1
  108. data/lib/deplate/mod/iconv.rb +1 -1
  109. data/lib/deplate/mod/imgurl.rb +1 -1
  110. data/lib/deplate/mod/inlatex-compound.rb +1 -1
  111. data/lib/deplate/mod/koma.rb +4 -4
  112. data/lib/deplate/mod/{de.rb → lang-de.rb} +1 -1
  113. data/lib/deplate/mod/{en.rb → lang-en.rb} +1 -1
  114. data/lib/deplate/mod/{ru_koi8-r.rb → lang-ru-koi8-r.rb} +1 -1
  115. data/lib/deplate/mod/lang-ru.rb +9 -0
  116. data/lib/deplate/mod/{zh-cn-autospace.rb → lang-zh_CN-autospace.rb} +3 -3
  117. data/lib/deplate/mod/{zh-cn.rb → lang-zh_CN.rb} +8 -8
  118. data/lib/deplate/mod/latex-emph-table-head.rb +1 -1
  119. data/lib/deplate/mod/latex-styles.rb +6 -6
  120. data/lib/deplate/mod/latex-verbatim-small.rb +1 -1
  121. data/lib/deplate/mod/linkmap.rb +128 -0
  122. data/lib/deplate/mod/makefile.rb +23 -22
  123. data/lib/deplate/mod/mark-external-urls.rb +13 -7
  124. data/lib/deplate/mod/markup-1-warn.rb +1 -1
  125. data/lib/deplate/mod/markup-1.rb +1 -1
  126. data/lib/deplate/mod/navbar-png.rb +5 -4
  127. data/lib/deplate/mod/noindent.rb +1 -1
  128. data/lib/deplate/mod/numpara.rb +1 -1
  129. data/lib/deplate/mod/particle-math.rb +1 -1
  130. data/lib/deplate/mod/php-extra.rb +1 -1
  131. data/lib/deplate/mod/pstoedit.rb +1 -1
  132. data/lib/deplate/mod/recode.rb +1 -1
  133. data/lib/deplate/mod/smart-dash.rb +1 -1
  134. data/lib/deplate/mod/smiley.rb +1 -1
  135. data/lib/deplate/mod/soffice.rb +1 -1
  136. data/lib/deplate/mod/symbols-latin1.rb +1 -1
  137. data/lib/deplate/mod/symbols-od-utf-8.rb +1 -1
  138. data/lib/deplate/mod/symbols-plain.rb +1 -1
  139. data/lib/deplate/mod/symbols-sgml.rb +1 -1
  140. data/lib/deplate/mod/symbols-utf-8.rb +1 -1
  141. data/lib/deplate/mod/symbols-xml.rb +1 -1
  142. data/lib/deplate/mod/syntax-region-alt.rb +1 -1
  143. data/lib/deplate/mod/utf8.rb +1 -1
  144. data/lib/deplate/mod/validate-html.rb +1 -1
  145. data/lib/deplate/mod/xmlrpc.rb +37 -36
  146. data/lib/deplate/nukumi2.rb +4 -4
  147. data/lib/deplate/once-method.rb +1 -1
  148. data/lib/deplate/output.rb +12 -4
  149. data/lib/deplate/particles.rb +52 -22
  150. data/lib/deplate/regions.rb +160 -90
  151. data/lib/deplate/skeletons.rb +4 -3
  152. data/lib/deplate/structured.rb +19 -13
  153. data/lib/deplate/template.rb +17 -9
  154. data/lib/deplate/templates/html-doc.html +8 -11
  155. data/lib/deplate/templates/html-tabbar-right.html +1 -1
  156. data/lib/deplate/templates/html-tabbar-top.html +3 -3
  157. data/lib/deplate/variables.rb +25 -9
  158. data/lib/deplate/wiki-markup.rb +14 -3
  159. data/lib/deplate/xml.rb +3 -4
  160. data/lib/deplate/{zh-cn.rb → zh_CN.rb} +16 -16
  161. data/man/man1/deplate.1 +80 -65
  162. metadata +72 -48
  163. data/lib/deplate/mod/fr.rb +0 -46
@@ -1,5 +1,5 @@
1
1
  # null.rb
2
- # @Author: Thomas Link (samul AT web.de)
2
+ # @Author: Thomas Link (micathom AT gmail com)
3
3
  # @Website: http://deplate.sf.net/
4
4
  # @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
5
5
  # @Created: 17-M�r-2004.
@@ -1,5 +1,5 @@
1
1
  # php.rb
2
- # @Author: Thomas Link (samul AT web.de)
2
+ # @Author: Thomas Link (micathom AT gmail com)
3
3
  # @Website: http://deplate.sf.net/
4
4
  # @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
5
5
  # @Created: 17-M�r-2004.
@@ -1,5 +1,5 @@
1
1
  # phpsite.rb
2
- # @Author: Thomas Link (samul AT web.de)
2
+ # @Author: Thomas Link (micathom AT gmail com)
3
3
  # @Website: http://deplate.sf.net/
4
4
  # @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
5
5
  # @Created: 17-M�r-2004.
@@ -1,10 +1,10 @@
1
1
  # fmt-html.rb
2
- # @Author: Thomas Link (samul AT web.de)
2
+ # @Author: Thomas Link (micathom AT gmail com)
3
3
  # @Website: http://deplate.sf.net/
4
4
  # @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
5
5
  # @Created: 17-M�r-2004.
6
- # @Last Change: 05-Jun-2006.
7
- # @Revision: 0.3577
6
+ # @Last Change: 2007-09-28.
7
+ # @Revision: 0.3591
8
8
 
9
9
  require "deplate/formatter"
10
10
 
@@ -23,6 +23,7 @@ class Deplate::Formatter::Plain < Deplate::Formatter
23
23
  super
24
24
  @color = deplate.variables['ansiColor'] && defined?(Deplate::Color)
25
25
  @list_counter = {}
26
+ @references = {}
26
27
  end
27
28
 
28
29
  def read_bib(bibfiles)
@@ -275,6 +276,9 @@ class Deplate::Formatter::Plain < Deplate::Formatter
275
276
  if explicit or item.explicit and item.item
276
277
  # and !item.item.empty?
277
278
  i = item.item
279
+ elsif (itemize_markers = @deplate.variables['itemizeMarkers'])
280
+ itemize_markers = Deplate::Core.split_list(itemize_markers)
281
+ i = itemize_markers[(level % itemize_markers.size) - 1]
278
282
  else
279
283
  i = LIST_ITEMIZE_MARKERS[level % LIST_ITEMIZE_MARKERS_N]
280
284
  end
@@ -372,15 +376,17 @@ class Deplate::Formatter::Plain < Deplate::Formatter
372
376
 
373
377
  # <+TBD+> [1] + urls at the bottom
374
378
  def format_url(invoker, name, dest, anchor, literal=false)
375
- idx = @deplate.footnote_last_idx += 1
376
- fn = "[#{idx}]"
377
- # invoker.container.postponed_format << Proc.new do |container|
378
- hlink = Deplate::HyperLink.url_anchor(dest, anchor)
379
+ hlink = Deplate::HyperLink.url_anchor(dest, anchor)
380
+ fn = @references[hlink]
381
+ unless fn
382
+ idx = @deplate.footnote_last_idx += 1
383
+ fn = "[#{idx}]"
384
+ @references[hlink] = fn
379
385
  if @color
380
386
  hlink = Deplate::Color.underline(hlink)
381
387
  end
382
388
  output_at(:body, :footnotes, %{#{fn} #{hlink}})
383
- # end
389
+ end
384
390
  if name and !(name.empty?)
385
391
  rv = [name, fn].join
386
392
  else
@@ -435,7 +441,8 @@ class Deplate::Formatter::Plain < Deplate::Formatter
435
441
 
436
442
  def format_ref(invoker)
437
443
  prefix = invoker.args['prefix'] || ' '
438
- prefix + @deplate.labels[invoker.text]
444
+ text = (invoker.text && @deplate.labels[invoker.text]) || ''
445
+ prefix + text
439
446
  end
440
447
 
441
448
  def format_break(invoker)
@@ -1,5 +1,5 @@
1
1
  # template.rb
2
- # @Author: Thomas Link (samul AT web.de)
2
+ # @Author: Thomas Link (micathom AT gmail com)
3
3
  # @Website: http://deplate.sf.net/
4
4
  # @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
5
5
  # @Created: 25-M�r-2005.
@@ -1,5 +1,5 @@
1
1
  # fmt-xhtml.rb
2
- # @Author: Thomas Link (samul AT web.de)
2
+ # @Author: Thomas Link (micathom AT gmail com)
3
3
  # @Website: http://deplate.sf.net/
4
4
  # @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
5
5
  # @Created: 03-Aug-2004.
@@ -1,5 +1,5 @@
1
1
  # formatter-snippet.rb
2
- # @Author: Thomas Link (samul AT web.de)
2
+ # @Author: Thomas Link (micathom AT gmail com)
3
3
  # @Website: http://deplate.sf.net/
4
4
  # @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
5
5
  # @Created: 11-Aug-2005.
@@ -1,10 +1,10 @@
1
1
  # formatter.rb
2
- # @Author: Thomas Link (samul AT web.de)
2
+ # @Author: Thomas Link (micathom AT gmail com)
3
3
  # @Website: http://deplate.sf.net/
4
4
  # @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
5
5
  # @Created: 31-Okt-2004.
6
- # @Last Change: 05-Jun-2006.
7
- # @Revision: 0.1443
6
+ # @Last Change: 2007-10-21.
7
+ # @Revision: 0.1574
8
8
 
9
9
  require 'deplate/abstract-class'
10
10
  require 'deplate/common'
@@ -76,6 +76,54 @@ class Deplate::Formatter < Deplate::CommonObject
76
76
  end
77
77
  end
78
78
  end
79
+
80
+ def set_options_for_file(options, file=nil)
81
+ case file
82
+ when '-'
83
+ options.ext = ''
84
+ options.srcdir ||= Dir.pwd
85
+ options.out ||= '-'
86
+ else
87
+ options.suffix ||= self.suffix
88
+ unless file.nil?
89
+ options.ext = File.extname(file)
90
+ options.srcdir ||= File.dirname(file)
91
+ end
92
+ if options.out
93
+ options.out = Deplate::Core.file_join(options.dir, options.out)
94
+ # if options.out != '-'
95
+ # options.out = options.dir ? Deplate::Core.file_join(options.dir, options.out) : options.out
96
+ # end
97
+ elsif file.nil?
98
+ options.out = '-'
99
+ else
100
+ options.out = Deplate::Core.get_out_fullname(file, options.suffix, options)
101
+ end
102
+ end
103
+ options
104
+ end
105
+
106
+ def formatter_family_members(args={})
107
+ acc = []
108
+ formatter_names = args[:names] || []
109
+ formatter_class = fmt = self
110
+ myname = fmt.myname
111
+ while myname
112
+ acc << myname
113
+ yield(myname) if block_given?
114
+ fmt = fmt.superclass
115
+ myname = fmt.myname
116
+ end
117
+ (formatter_class.related + formatter_names).each do |myname|
118
+ acc << myname
119
+ yield(myname) if block_given?
120
+ end
121
+ acc
122
+ end
123
+
124
+ def formatter_related?(name)
125
+ formatter_family_members.include?(name)
126
+ end
79
127
  end
80
128
 
81
129
  @@custom_particles = {}
@@ -99,11 +147,29 @@ class Deplate::Formatter < Deplate::CommonObject
99
147
  reset!
100
148
  end
101
149
 
150
+ def formatter_related?(name)
151
+ self.class.formatter_related?(name)
152
+ end
153
+
102
154
  def reset!
103
155
  @bibentries = {}
104
156
  @open_labels = []
105
- @consumed_labels = []
106
- @consumed_ids = []
157
+ # @consumed_labels = []
158
+ # @consumed_ids = []
159
+ end
160
+
161
+ def consumed_labels
162
+ @deplate.output.attributes[:consumed_labels]
163
+ end
164
+ def consumed_labels=(arg)
165
+ @deplate.output.attributes[:consumed_labels] = arg
166
+ end
167
+
168
+ def consumed_ids
169
+ @deplate.output.attributes[:consumed_ids]
170
+ end
171
+ def consumed_ids=(arg)
172
+ @deplate.output.attributes[:consumed_ids] = arg
107
173
  end
108
174
 
109
175
  def retrieve_particle(id, body=nil, specific=false)
@@ -164,8 +230,8 @@ class Deplate::Formatter < Deplate::CommonObject
164
230
  log(['Calling service failed', name, e], :error)
165
231
  end
166
232
  else
167
- p "DBG"
168
- puts @doc_services.keys.sort.join("\n")
233
+ # p "DBG"
234
+ # puts @doc_services.keys.sort.join("\n")
169
235
  log(['Unknown service', name], :error)
170
236
  end
171
237
  end
@@ -274,9 +340,11 @@ class Deplate::Formatter < Deplate::CommonObject
274
340
  begin
275
341
  inner = self.send(agent, *args)
276
342
  rescue Exception => e
277
- puts "DBG: #{agent}"
343
+ log("We shouldn't be here. If you can track down when this happens, please send an example to the author.", :error)
344
+ puts "DBG: #{agent}: #{e}"
278
345
  puts e.backtrace[0..10].join("\n")
279
- raise e
346
+ # raise e
347
+ return nil
280
348
  end
281
349
  prototype ||= inner.class
282
350
  end
@@ -292,7 +360,7 @@ class Deplate::Formatter < Deplate::CommonObject
292
360
  # return rv
293
361
  return inner
294
362
  else
295
- invoker.log(["Unknown formatting agent", agent], :error)
363
+ invoker.log(['Unknown formatting agent', agent], :error)
296
364
  return nil
297
365
  end
298
366
  end
@@ -448,7 +516,7 @@ class Deplate::Formatter < Deplate::CommonObject
448
516
  end
449
517
 
450
518
  def encode_id(id)
451
- id ? Deplate::Core.clean_file_name(id, "__") : id
519
+ id ? Deplate::Core.clean_name(id) : id
452
520
  end
453
521
 
454
522
  def label_mode
@@ -485,12 +553,15 @@ class Deplate::Formatter < Deplate::CommonObject
485
553
  end
486
554
 
487
555
  def matches?(text)
488
- if text[0..0] == "~"
489
- rv = (formatter_name =~ Regexp.new(text[1..-1]))
490
- else
491
- rv = (text =~ formatter_rx)
556
+ self.class.formatter_family_members.any? do |fmtname|
557
+ fmt = @deplate.get_formatter_class(fmtname)
558
+ if text[0..0] == '~'
559
+ rv = (fmt.myname =~ Regexp.new(text[1..-1]))
560
+ else
561
+ rv = (text =~ fmt.rx)
562
+ end
563
+ return rv ? true : false
492
564
  end
493
- return rv ? true : false
494
565
  end
495
566
 
496
567
  def format_GET(invoker)
@@ -533,7 +604,21 @@ class Deplate::Formatter < Deplate::CommonObject
533
604
  def format_PAGEBREAK(invoker)
534
605
  format_pagebreak(invoker, nil, true)
535
606
  end
536
-
607
+
608
+ def format_CAST(invoker)
609
+ return ''
610
+ end
611
+
612
+ def format_ACT(invoker)
613
+ return ''
614
+ end
615
+
616
+ def format_direct(invoker, text=nil)
617
+ # invoker.push_styles(['emphasized'])
618
+ invoker.push_styles(['play-direct'])
619
+ "(%s)" % (text || invoker.elt || invoker.text)
620
+ end
621
+
537
622
  def fill_in_template(invoker)
538
623
  invoker.elt
539
624
  end
@@ -542,11 +627,11 @@ class Deplate::Formatter < Deplate::CommonObject
542
627
  end
543
628
 
544
629
  def bib_entry(key)
545
- b = @bibentries[key] || []
546
- crossref = b.assoc('crossref')
630
+ b = @bibentries[key] || {}
631
+ crossref = b['crossref']
547
632
  if crossref
548
- cb = @bibentries[crossref[1]]
549
- b += cb if cb
633
+ cb = @bibentries[crossref]
634
+ b.update(cb) {|k, o, n| o} if cb
550
635
  end
551
636
  return b
552
637
  end
@@ -597,7 +682,11 @@ class Deplate::Formatter < Deplate::CommonObject
597
682
  def_abstract :format_index, :format_footnote, :format_ref,
598
683
  :format_linebreak, :format_subscript, :format_superscript, :format_stacked,
599
684
  :format_pagenumber
600
-
685
+
686
+ def format_region(invoker)
687
+ invoker.elt.strip
688
+ end
689
+
601
690
  def format_cite(invoker)
602
691
  bib_styler.bib_cite(invoker)
603
692
  end
@@ -661,6 +750,11 @@ class Deplate::Formatter < Deplate::CommonObject
661
750
  rx = /\s+/
662
751
  end
663
752
  text.each do |text|
753
+ if text.kind_of?(Array)
754
+ log("We shouldn't be here. If you can track down when this happens, please send an example to the author.", :error)
755
+ puts caller[0..10].join("\n")
756
+ return ''
757
+ end
664
758
  m = /^(\s*)(.*)$/.match(text)
665
759
  idt = m[1] + moreIndent
666
760
  accum = [m[1]]
@@ -671,7 +765,7 @@ class Deplate::Formatter < Deplate::CommonObject
671
765
  this, rest = break_line(rest, rx, imx, block)
672
766
  accum << this
673
767
  if rest
674
- accum << "\n"
768
+ accum << " \n"
675
769
  accum << idt
676
770
  accum << hang_idt if hang_idt
677
771
  end
@@ -714,8 +808,8 @@ class Deplate::Formatter < Deplate::CommonObject
714
808
  # Format the Inlatex region
715
809
  def format_inlatex(invoker)
716
810
  args = invoker.args
717
- inline = args["inline"]
718
- args["h"] ||= (args["inlineLatexHeight"] || args["inlatexHeight"]) if inline
811
+ inline = args['inline']
812
+ args['h'] ||= (args['inlineLatexHeight'] || args['inlatexHeight']) if inline
719
813
  acc = []
720
814
  elt = invoker.elt
721
815
  if elt
@@ -732,9 +826,9 @@ class Deplate::Formatter < Deplate::CommonObject
732
826
  def format_ltx(invoker, other_args={})
733
827
  args = invoker.args
734
828
  acc = []
735
- args["h"] ||= (args["inlineLatexHeight"] || other_args["h"])
736
- args["alt"] ||= invoker.text
737
- args["style"] = "latex"
829
+ args['h'] ||= (args['inlineLatexHeight'] || other_args['h'])
830
+ args['alt'] ||= invoker.text
831
+ args['style'] = 'latex'
738
832
  inlatex = invoker.elt
739
833
  if !inlatex or inlatex.empty?
740
834
  acc << invoker.text
@@ -755,27 +849,30 @@ class Deplate::Formatter < Deplate::CommonObject
755
849
  def inlatex(invoker)
756
850
  pkgs, body = inlatex_split(invoker.accum)
757
851
  id = inlatex_id(invoker)
758
- sfx = invoker.args["sfx"] || @deplate.variables['ltxSfx'] || inlatex_sfx
852
+ sfx = invoker.args['sfx'] || @deplate.variables['ltxSfx'] || inlatex_sfx
759
853
  currDir = Dir.pwd
760
854
  @deplate.in_working_dir do
761
- ftex = id + ".tex"
762
- flog = id + ".log"
763
- faux = id + ".aux"
764
- fdvi = id + ".dvi"
765
- fps = id + ".ps"
855
+ ftex = id + '.tex'
856
+ flog = id + '.log'
857
+ faux = id + '.aux'
858
+ fdvi = id + '.dvi'
859
+ fps = id + '.ps'
766
860
  checkOW = true
767
861
 
768
862
  case sfx
769
- when "ps"
863
+ when 'ps'
770
864
  device = nil
771
865
  fout = fps
772
866
  checkOW = false
773
- when "pdf"
774
- device = "pdfwrite"
775
- fout = id + ".*.pdf"
776
- when "jpeg", "jpg"
777
- device = "jpeg"
778
- fout = id + ".*.jpeg"
867
+ when 'pdf'
868
+ device = 'pdfwrite'
869
+ fout = id + '.*.pdf'
870
+ when 'jpeg', 'jpg'
871
+ device = 'jpeg'
872
+ fout = id + '.*.jpeg'
873
+ when "png"
874
+ device = "png"
875
+ fout = id + ".png"
779
876
  else
780
877
  raise "Unknown device/suffix: #{sfx}"
781
878
  end
@@ -787,6 +884,7 @@ class Deplate::Formatter < Deplate::CommonObject
787
884
  "\\usepackage{amsmath}",
788
885
  "\\usepackage{amsfonts}",
789
886
  "\\usepackage{amssymb}",
887
+ # "\\usepackage{mathabx}",
790
888
  ]
791
889
  acc += pkgs
792
890
  acc << "\\begin{document}" << "\\pagestyle{empty}"
@@ -794,7 +892,7 @@ class Deplate::Formatter < Deplate::CommonObject
794
892
  acc << "\\end{document}"
795
893
 
796
894
  if Deplate::Region.check_file(invoker, fout, ftex, acc)
797
- invoker.log(["Files exist! Using", fout], :anyway)
895
+ invoker.log(['Files exist! Using', fout], :anyway)
798
896
  else
799
897
  if checkOW and !@deplate.options.force
800
898
  for f in [ftex, flog, faux, fdvi, fout]
@@ -811,11 +909,16 @@ class Deplate::Formatter < Deplate::CommonObject
811
909
  if block_given?
812
910
  yield(invoker, device, fdvi, fps, fout)
813
911
  else
814
- inlatex_process_dvi(invoker, fdvi, fps) if File.exist?(fdvi)
815
- if device
816
- inlatex_process_ps(invoker, device, fps, fout, invoker.args)
817
- elsif fps != fout
818
- File.rename(fps, fout)
912
+ case device
913
+ when "png"
914
+ inlatex_process_dvi_png(invoker, fdvi, fout) if File.exist?(fdvi)
915
+ else
916
+ inlatex_process_dvi(invoker, fdvi, fps) if File.exist?(fdvi)
917
+ if device
918
+ inlatex_process_ps(invoker, device, fps, fout, invoker.args)
919
+ elsif fps != fout
920
+ File.rename(fps, fout)
921
+ end
819
922
  end
820
923
  end
821
924
  end
@@ -848,6 +951,10 @@ class Deplate::Formatter < Deplate::CommonObject
848
951
  dvi2ps(invoker, fdvi, fps)
849
952
  end
850
953
 
954
+ def inlatex_process_dvi_png(invoker, fdvi, fout)
955
+ dvi2png(invoker, fdvi, fout)
956
+ end
957
+
851
958
  def inlatex_process_ps(invoker, device, fps, fout, args)
852
959
  ps2img(invoker, device, fps, fout, args) if File.exist?(fps)
853
960
  end
@@ -913,6 +1020,13 @@ class Deplate::Formatter < Deplate::CommonObject
913
1020
  end
914
1021
  end
915
1022
 
1023
+ def dvi2png(invoker, fdvi, fout, other_options=nil)
1024
+ if Deplate::External.dvi2png(invoker, fdvi, fout, other_options) and @deplate.options.clean
1025
+ File.delete(fdvi) if @deplate.options.clean
1026
+ invoker.log(["Deleting", fdvi])
1027
+ end
1028
+ end
1029
+
916
1030
  def ps2img(invoker, device, fps, fout, args)
917
1031
  if Deplate::External.ps2img(invoker, device, fps, fout, args) and @deplate.options.clean
918
1032
  File.delete(fps)
@@ -1006,6 +1120,15 @@ class Deplate::Formatter < Deplate::CommonObject
1006
1120
  # end
1007
1121
  # end
1008
1122
 
1123
+ def stepwise_prepare
1124
+ # @deplate.output.attributes[:stepwiseIdx] ||= 0
1125
+ end
1126
+
1127
+ def stepwise_next
1128
+ stepwise_prepare
1129
+ @deplate.output.attributes[:stepwiseIdx] += 1
1130
+ end
1131
+
1009
1132
 
1010
1133
  private
1011
1134
  def initialize_services
@@ -1104,11 +1227,11 @@ class Deplate::Formatter < Deplate::CommonObject
1104
1227
  def consume_label(label, warn=false)
1105
1228
  if !label
1106
1229
  return false
1107
- elsif @consumed_labels.include?(label)
1230
+ elsif consumed_labels.include?(label)
1108
1231
  log(['Duplicate label'], label, :error) if warn
1109
1232
  return false
1110
1233
  else
1111
- @consumed_labels << label
1234
+ consumed_labels << label
1112
1235
  return true
1113
1236
  end
1114
1237
  end
@@ -1129,7 +1252,7 @@ class Deplate::Formatter < Deplate::CommonObject
1129
1252
  args ||= {}
1130
1253
  labels = labels ? labels.dup : []
1131
1254
  id = use_id(args, opts)
1132
- l = args["label"]
1255
+ l = args['label']
1133
1256
  labels << l if l
1134
1257
  # i = opts[:invoker]
1135
1258
  # if i
@@ -1140,11 +1263,11 @@ class Deplate::Formatter < Deplate::CommonObject
1140
1263
  elsif id
1141
1264
  labels.delete(id)
1142
1265
  end
1143
- labels.delete_if {|e| @consumed_labels.include?(e)}
1266
+ labels.delete_if {|e| consumed_labels.include?(e)}
1144
1267
  labels.flatten!
1145
1268
  labels.compact!
1146
1269
  labels.uniq!
1147
- @consumed_labels += labels unless labels.empty?
1270
+ self.consumed_labels += labels unless labels.empty?
1148
1271
  return labels
1149
1272
  end
1150
1273
 
@@ -1164,7 +1287,7 @@ class Deplate::Formatter < Deplate::CommonObject
1164
1287
  if kw.kind_of?(Array)
1165
1288
  kw
1166
1289
  elsif kw.kind_of?(String)
1167
- kw.split(/\s*[,;]\s*/)
1290
+ Deplate::Core.split_list(kw, ';', ',')
1168
1291
  elsif kw
1169
1292
  log(["Shouldn't be here", kw, kw.class], :error)
1170
1293
  else
@@ -1177,14 +1300,14 @@ class Deplate::Formatter < Deplate::CommonObject
1177
1300
  def build_plain_text_rx
1178
1301
  @plain_text_rx = Regexp.new('(%s)' % @special_symbols.keys.collect {|x| Regexp.escape(x)}.join('|'))
1179
1302
  end
1180
-
1303
+
1181
1304
 
1182
1305
  ################################################ Bibliography {{{1
1183
1306
  def bib_styler
1184
1307
  style = @deplate.variables['bibStyle']
1185
1308
  @deplate.bib_styler(style)
1186
1309
  end
1187
-
1310
+
1188
1311
  def simple_bibtex_reader(bibfiles)
1189
1312
  acc = []
1190
1313
  for b in bibfiles
@@ -1197,41 +1320,109 @@ class Deplate::Formatter < Deplate::CommonObject
1197
1320
  end
1198
1321
  File.open(b) {|io| acc << io.read}
1199
1322
  end
1323
+ text = acc.join("\n")
1324
+ @configuration = self
1325
+ @crossreferenced = []
1326
+ entries, prelude = simple_bibtex_parser(text)
1327
+ @bibentries.update(entries)
1328
+ end
1329
+
1330
+ def simple_bibtex_parser(text, strings_expansion=true)
1331
+ prelude = []
1200
1332
  strings = {}
1201
- acc = acc.join("\n")
1202
- loop do
1203
- m = /^\s*@string\{\s*(\S+?)\s*=\s*(.+?)\s*\}/m.match(acc)
1204
- if m
1205
- r = m[2]
1333
+ entries = {}
1334
+ lineno = 1
1335
+ # m = /^\s*(@(\w+)\{(.*?)\})\s*(?=(^@|\z))/m.match(text)
1336
+ while (m = /^\s*(@(\w+)\{(.*?))\s*(?=(^@|\z))/m.match(text))
1337
+ text = m.post_match
1338
+ body = m[0]
1339
+ type = m[2]
1340
+ inner = m[3]
1341
+ case type.downcase
1342
+ when 'string'
1343
+ prelude << body
1344
+ mi = /^\s*(\S+?)\s*=\s*(.+?)\s*\}?\s*$/m.match(inner)
1345
+ r = mi[2]
1206
1346
  if r =~ /^(".*?"|'.*?'|\{.*?\})$/
1207
1347
  r = r[1..-2]
1208
1348
  end
1209
- strings[m[1]] = r
1210
- acc = m.post_match
1211
- next
1212
- end
1213
- m = /^\s*(@(\w+)\{\s*(\S+?)\s*,.*?)(?=(^@|\z))/m.match(acc)
1214
- if m
1215
- id = m[3]
1216
- e = m[1]
1217
- arr = e.scan(/^\s*(\w+)\s*=\s*(\{.*?\}|\d+)\s*[,}]\s*$/m)
1218
- arr.collect! do |var, val, rest|
1219
- n = /^\s*\{(.*?)\}\s*($|\}\s*\z)/m.match(val)
1220
- if n
1349
+ strings[mi[1]] = r
1350
+ else
1351
+ mi = /^\s*(\S+?)\s*,(.*)$/m.match(inner)
1352
+ id = mi[1]
1353
+ e = mi[2]
1354
+ # arr = e.scan(/^\s*(\w+)\s*=\s*(\{.*?\}|\d+)\s*[,}]\s*$/m)
1355
+ arr = e.scan(/^\s*(\w+)\s*=\s*(\{.*?\}|".*?"|\d+)\s*[,}]\s*$/m)
1356
+ entry = {}
1357
+ arr.each do |var, val, rest|
1358
+ # EXPERIMENTAL: something like author={{Top Institute}} didn't work. I'm not sure though if this is able to deal with the last field in a bibtex entry correctly
1359
+ # n = /^\s*\{(.*?)\}\s*($|\}\s*\z)/m.match(val)
1360
+ if (n = /^\s*\{(.*?)\}\s*$/m.match(val))
1361
+ val = n[1]
1362
+ elsif (n = /^\s*"(.*?)"\s*$/m.match(val))
1221
1363
  val = n[1]
1222
1364
  end
1223
- if strings[val]
1365
+ if strings_expansion and strings[val]
1224
1366
  val = strings[val]
1225
1367
  end
1226
- [var, val]
1368
+ if (oldval = entry[var])
1369
+ if oldval != val
1370
+ meth = "duplicate_field_#{var}"
1371
+ if @configuration.respond_to?(meth)
1372
+ $stderr.puts "Resolve duplicate fields with mismatching values: #{id}.#{var}" if $VERBOSE
1373
+ val = @configuration.send(meth, oldval, val)
1374
+ else
1375
+ $stderr.puts "Cannot resolve duplicate fields with mismatching values: #{id}.#{var}"
1376
+ end
1377
+ end
1378
+ end
1379
+ entry[var] = val
1380
+ case var
1381
+ when 'crossref'
1382
+ @crossreferenced << val
1383
+ end
1384
+ end
1385
+ entry['_lineno'] = lineno.to_s
1386
+ entry['_type'] = type
1387
+ entry['_id'] = id
1388
+ entry['_entry'] = body
1389
+ if entries[id]
1390
+ if entries[id] != entry
1391
+ $stderr.puts "Duplicate key, mismatching entries: #{id}"
1392
+ if $DEBUG
1393
+ $stderr.puts entries[id]['_entry'].chomp
1394
+ $stderr.puts '<=>'
1395
+ $stderr.puts entry['_entry'].chomp
1396
+ $stderr.puts
1397
+ end
1398
+ end
1399
+ entries[id].update(entry)
1400
+ else
1401
+ entries[id] = entry
1227
1402
  end
1228
- arr << ['@type', m[2]] << ['@id', id]
1229
- @bibentries[id] = arr
1230
- acc = m.post_match
1231
- else
1232
- break
1233
1403
  end
1404
+ lineno += (m.pre_match.scan(/\n/).size + body.scan(/\n/).size)
1405
+ end
1406
+ if text =~ /\S/
1407
+ $stderr.puts "Trash in bibtex input: #{text}" if $VERBOSE
1234
1408
  end
1409
+ return entries, prelude.join
1410
+ end
1411
+
1412
+ def duplicate_field_author(oldval, val)
1413
+ [oldval, val].join(' and ')
1414
+ end
1415
+
1416
+ def duplicate_field_abstract(oldval, val)
1417
+ [oldval, val].join("\n")
1418
+ end
1419
+
1420
+ def duplicate_field_url(oldval, val)
1421
+ [oldval, val].join(' ')
1422
+ end
1423
+
1424
+ def duplicate_field_keywords(oldval, val)
1425
+ (oldval.split(/[;,]\s*/) | val.split(/[;,]\s*/)).join(', ')
1235
1426
  end
1236
1427
 
1237
1428
  def cited_keys
@@ -1266,8 +1457,8 @@ class Deplate::Formatter < Deplate::CommonObject
1266
1457
  return @deplate.parse_and_format_without_wikinames(invoker, text)
1267
1458
  end
1268
1459
 
1269
- def simple_latex_reformat(text)
1270
- text.gsub!(/^\{(.*)\}$/, "\\1")
1460
+ def simple_latex_reformat(text, remove_brackets=false)
1461
+ text.gsub!(/^\{(.*)\}$/, "\\1") if remove_brackets
1271
1462
  text.gsub!(/\s+/m, " ")
1272
1463
  text.gsub!(/``/, %{"})
1273
1464
  text.gsub!(/''/, %{"})