rdoc-f95 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/History.txt +4 -0
  2. data/Manifest.txt +79 -0
  3. data/PostInstall.txt +7 -0
  4. data/README.rdoc +147 -0
  5. data/Rakefile +28 -0
  6. data/bin/rdoc-f95 +70 -0
  7. data/lib/rdoc-f95.rb +306 -0
  8. data/lib/rdoc-f95/code_objects.rb +776 -0
  9. data/lib/rdoc-f95/diagram.rb +342 -0
  10. data/lib/rdoc-f95/dot.rb +249 -0
  11. data/lib/rdoc-f95/generator.rb +1088 -0
  12. data/lib/rdoc-f95/generator/chm.rb +113 -0
  13. data/lib/rdoc-f95/generator/chm/chm.rb +98 -0
  14. data/lib/rdoc-f95/generator/html.rb +370 -0
  15. data/lib/rdoc-f95/generator/html/hefss.rb +414 -0
  16. data/lib/rdoc-f95/generator/html/html.rb +708 -0
  17. data/lib/rdoc-f95/generator/html/kilmer.rb +418 -0
  18. data/lib/rdoc-f95/generator/html/one_page_html.rb +121 -0
  19. data/lib/rdoc-f95/generator/ri.rb +229 -0
  20. data/lib/rdoc-f95/generator/xhtml.rb +106 -0
  21. data/lib/rdoc-f95/generator/xhtml/ctop.xsl +1318 -0
  22. data/lib/rdoc-f95/generator/xhtml/mathml.xsl +42 -0
  23. data/lib/rdoc-f95/generator/xhtml/pmathml.xsl +612 -0
  24. data/lib/rdoc-f95/generator/xhtml/pmathmlcss.xsl +872 -0
  25. data/lib/rdoc-f95/generator/xhtml/xhtml.rb +732 -0
  26. data/lib/rdoc-f95/generator/xml.rb +120 -0
  27. data/lib/rdoc-f95/generator/xml/rdf.rb +113 -0
  28. data/lib/rdoc-f95/generator/xml/xml.rb +111 -0
  29. data/lib/rdoc-f95/install.rb +166 -0
  30. data/lib/rdoc-f95/markup.rb +506 -0
  31. data/lib/rdoc-f95/markup/formatter.rb +14 -0
  32. data/lib/rdoc-f95/markup/fragments.rb +337 -0
  33. data/lib/rdoc-f95/markup/inline.rb +361 -0
  34. data/lib/rdoc-f95/markup/install.rb +57 -0
  35. data/lib/rdoc-f95/markup/lines.rb +152 -0
  36. data/lib/rdoc-f95/markup/mathml_wrapper.rb +91 -0
  37. data/lib/rdoc-f95/markup/preprocess.rb +71 -0
  38. data/lib/rdoc-f95/markup/sample/rdoc2latex.rb +16 -0
  39. data/lib/rdoc-f95/markup/sample/sample.rb +42 -0
  40. data/lib/rdoc-f95/markup/to_flow.rb +185 -0
  41. data/lib/rdoc-f95/markup/to_html.rb +357 -0
  42. data/lib/rdoc-f95/markup/to_html_crossref.rb +123 -0
  43. data/lib/rdoc-f95/markup/to_latex.rb +328 -0
  44. data/lib/rdoc-f95/markup/to_test.rb +50 -0
  45. data/lib/rdoc-f95/markup/to_xhtml_texparser.rb +234 -0
  46. data/lib/rdoc-f95/options.rb +745 -0
  47. data/lib/rdoc-f95/parsers/parse_c.rb +775 -0
  48. data/lib/rdoc-f95/parsers/parse_f95.rb +2499 -0
  49. data/lib/rdoc-f95/parsers/parse_rb.rb +2587 -0
  50. data/lib/rdoc-f95/parsers/parse_simple.rb +39 -0
  51. data/lib/rdoc-f95/parsers/parserfactory.rb +99 -0
  52. data/lib/rdoc-f95/ri.rb +2 -0
  53. data/lib/rdoc-f95/ri/cache.rb +188 -0
  54. data/lib/rdoc-f95/ri/descriptions.rb +147 -0
  55. data/lib/rdoc-f95/ri/display.rb +244 -0
  56. data/lib/rdoc-f95/ri/driver.rb +435 -0
  57. data/lib/rdoc-f95/ri/formatter.rb +603 -0
  58. data/lib/rdoc-f95/ri/paths.rb +105 -0
  59. data/lib/rdoc-f95/ri/reader.rb +106 -0
  60. data/lib/rdoc-f95/ri/util.rb +81 -0
  61. data/lib/rdoc-f95/ri/writer.rb +64 -0
  62. data/lib/rdoc-f95/stats.rb +23 -0
  63. data/lib/rdoc-f95/template.rb +64 -0
  64. data/lib/rdoc-f95/tokenstream.rb +33 -0
  65. data/lib/rdoc-f95/usage.rb +210 -0
  66. data/script/console +10 -0
  67. data/script/destroy +14 -0
  68. data/script/generate +14 -0
  69. data/test/test_helper.rb +3 -0
  70. data/test/test_rdoc-f95.rb +11 -0
  71. metadata +156 -0
@@ -0,0 +1,328 @@
1
+ require 'rdoc-f95/markup/formatter'
2
+ require 'rdoc-f95/markup/fragments'
3
+ require 'rdoc-f95/markup/inline'
4
+
5
+ require 'cgi'
6
+
7
+ ##
8
+ # Convert SimpleMarkup to basic LaTeX report format.
9
+
10
+ class RDocF95::Markup::ToLaTeX < RDocF95::Markup::Formatter
11
+
12
+ BS = "\020" # \
13
+ OB = "\021" # {
14
+ CB = "\022" # }
15
+ DL = "\023" # Dollar
16
+
17
+ BACKSLASH = "#{BS}symbol#{OB}92#{CB}"
18
+ HAT = "#{BS}symbol#{OB}94#{CB}"
19
+ BACKQUOTE = "#{BS}symbol#{OB}0#{CB}"
20
+ TILDE = "#{DL}#{BS}sim#{DL}"
21
+ LESSTHAN = "#{DL}<#{DL}"
22
+ GREATERTHAN = "#{DL}>#{DL}"
23
+
24
+ def self.l(str)
25
+ str.tr('\\', BS).tr('{', OB).tr('}', CB).tr('$', DL)
26
+ end
27
+
28
+ def l(arg)
29
+ RDocF95::Markup::ToLaTeX.l(arg)
30
+ end
31
+
32
+ LIST_TYPE_TO_LATEX = {
33
+ :BULLET => [ l("\\begin{itemize}"), l("\\end{itemize}") ],
34
+ :NUMBER => [ l("\\begin{enumerate}"), l("\\end{enumerate}"), "\\arabic" ],
35
+ :UPPERALPHA => [ l("\\begin{enumerate}"), l("\\end{enumerate}"), "\\Alph" ],
36
+ :LOWERALPHA => [ l("\\begin{enumerate}"), l("\\end{enumerate}"), "\\alph" ],
37
+ :LABELED => [ l("\\begin{description}"), l("\\end{description}") ],
38
+ :NOTE => [
39
+ l("\\begin{tabularx}{\\linewidth}{@{} l X @{}}"),
40
+ l("\\end{tabularx}") ],
41
+ }
42
+
43
+ InlineTag = Struct.new(:bit, :on, :off)
44
+
45
+ def initialize
46
+ init_tags
47
+ @list_depth = 0
48
+ @prev_list_types = []
49
+ end
50
+
51
+ ##
52
+ # Set up the standard mapping of attributes to LaTeX
53
+
54
+ def init_tags
55
+ @attr_tags = [
56
+ InlineTag.new(RDocF95::Markup::Attribute.bitmap_for(:BOLD), l("\\textbf{"), l("}")),
57
+ InlineTag.new(RDocF95::Markup::Attribute.bitmap_for(:TT), l("\\texttt{"), l("}")),
58
+ InlineTag.new(RDocF95::Markup::Attribute.bitmap_for(:EM), l("\\emph{"), l("}")),
59
+ ]
60
+ end
61
+
62
+ ##
63
+ # Escape a LaTeX string
64
+
65
+ def escape(str)
66
+ $stderr.print "FE: ", str if $DEBUG_RDOC
67
+ s = str.
68
+ sub(/\s+$/, '').
69
+ gsub(/([_\${}&%#])/, "#{BS}\\1").
70
+ gsub(/\\/, BACKSLASH).
71
+ gsub(/\^/, HAT).
72
+ gsub(/~/, TILDE).
73
+ gsub(/</, LESSTHAN).
74
+ gsub(/>/, GREATERTHAN).
75
+ gsub(/,,/, ",{},").
76
+ gsub(/\`/, BACKQUOTE)
77
+ $stderr.print "-> ", s, "\n" if $DEBUG_RDOC
78
+ s
79
+ end
80
+
81
+ ##
82
+ # Add a new set of LaTeX tags for an attribute. We allow
83
+ # separate start and end tags for flexibility
84
+
85
+ def add_tag(name, start, stop)
86
+ @attr_tags << InlineTag.new(RDocF95::Markup::Attribute.bitmap_for(name), start, stop)
87
+ end
88
+
89
+ ##
90
+ # Here's the client side of the visitor pattern
91
+
92
+ def start_accepting
93
+ @res = ""
94
+ @in_list_entry = []
95
+ end
96
+
97
+ def end_accepting
98
+ @res.tr(BS, '\\').tr(OB, '{').tr(CB, '}').tr(DL, '$')
99
+ end
100
+
101
+ def accept_paragraph(am, fragment)
102
+ @res << wrap(convert_flow(am.flow(fragment.txt)))
103
+ @res << "\n"
104
+ end
105
+
106
+ def accept_verbatim(am, fragment)
107
+ @res << "\n\\begin{code}\n"
108
+ @res << fragment.txt.sub(/[\n\s]+\Z/, '')
109
+ @res << "\n\\end{code}\n\n"
110
+ end
111
+
112
+ def accept_rule(am, fragment)
113
+ size = fragment.param
114
+ size = 10 if size > 10
115
+ @res << "\n\n\\rule{\\linewidth}{#{size}pt}\n\n"
116
+ end
117
+
118
+ def accept_list_start(am, fragment)
119
+ @res << list_name(fragment.type, true) << "\n"
120
+ @in_list_entry.push false
121
+ end
122
+
123
+ def accept_list_end(am, fragment)
124
+ if tag = @in_list_entry.pop
125
+ @res << tag << "\n"
126
+ end
127
+ @res << list_name(fragment.type, false) << "\n"
128
+ end
129
+
130
+ def accept_list_item(am, fragment)
131
+ if tag = @in_list_entry.last
132
+ @res << tag << "\n"
133
+ end
134
+ @res << list_item_start(am, fragment)
135
+ @res << wrap(convert_flow(am.flow(fragment.txt))) << "\n"
136
+ @in_list_entry[-1] = list_end_for(fragment.type)
137
+ end
138
+
139
+ def accept_blank_line(am, fragment)
140
+ # @res << "\n"
141
+ end
142
+
143
+ def accept_heading(am, fragment)
144
+ @res << convert_heading(fragment.head_level, am.flow(fragment.txt))
145
+ end
146
+
147
+ ##
148
+ # This is a higher speed (if messier) version of wrap
149
+
150
+ def wrap(txt, line_len = 76)
151
+ res = ""
152
+ sp = 0
153
+ ep = txt.length
154
+ while sp < ep
155
+ # scan back for a space
156
+ p = sp + line_len - 1
157
+ if p >= ep
158
+ p = ep
159
+ else
160
+ while p > sp and txt[p] != ?\s
161
+ p -= 1
162
+ end
163
+ if p <= sp
164
+ p = sp + line_len
165
+ while p < ep and txt[p] != ?\s
166
+ p += 1
167
+ end
168
+ end
169
+ end
170
+ res << txt[sp...p] << "\n"
171
+ sp = p
172
+ sp += 1 while sp < ep and txt[sp] == ?\s
173
+ end
174
+ res
175
+ end
176
+
177
+ private
178
+
179
+ def on_tags(res, item)
180
+ attr_mask = item.turn_on
181
+ return if attr_mask.zero?
182
+
183
+ @attr_tags.each do |tag|
184
+ if attr_mask & tag.bit != 0
185
+ res << tag.on
186
+ end
187
+ end
188
+ end
189
+
190
+ def off_tags(res, item)
191
+ attr_mask = item.turn_off
192
+ return if attr_mask.zero?
193
+
194
+ @attr_tags.reverse_each do |tag|
195
+ if attr_mask & tag.bit != 0
196
+ res << tag.off
197
+ end
198
+ end
199
+ end
200
+
201
+ def convert_flow(flow)
202
+ res = ""
203
+ flow.each do |item|
204
+ case item
205
+ when String
206
+ $stderr.puts "Converting '#{item}'" if $DEBUG_RDOC
207
+ res << convert_string(item)
208
+ when AttrChanger
209
+ off_tags(res, item)
210
+ on_tags(res, item)
211
+ when Special
212
+ res << convert_special(item)
213
+ else
214
+ raise "Unknown flow element: #{item.inspect}"
215
+ end
216
+ end
217
+ res
218
+ end
219
+
220
+ ##
221
+ # some of these patterns are taken from SmartyPants...
222
+
223
+ def convert_string(item)
224
+ escape(item).
225
+
226
+ # convert ... to elipsis (and make sure .... becomes .<elipsis>)
227
+ gsub(/\.\.\.\./, '.\ldots{}').gsub(/\.\.\./, '\ldots{}').
228
+
229
+ # convert single closing quote
230
+ gsub(%r{([^ \t\r\n\[\{\(])\'}, '\1\'').
231
+ gsub(%r{\'(?=\W|s\b)}, "'" ).
232
+
233
+ # convert single opening quote
234
+ gsub(/'/, '`').
235
+
236
+ # convert double closing quote
237
+ gsub(%r{([^ \t\r\n\[\{\(])\"(?=\W)}, "\\1''").
238
+
239
+ # convert double opening quote
240
+ gsub(/"/, "``").
241
+
242
+ # convert copyright
243
+ gsub(/\(c\)/, '\copyright{}')
244
+
245
+ end
246
+
247
+ def convert_special(special)
248
+ handled = false
249
+ Attribute.each_name_of(special.type) do |name|
250
+ method_name = "handle_special_#{name}"
251
+ if self.respond_to? method_name
252
+ special.text = send(method_name, special)
253
+ handled = true
254
+ end
255
+ end
256
+ raise "Unhandled special: #{special}" unless handled
257
+ special.text
258
+ end
259
+
260
+ def convert_heading(level, flow)
261
+ res =
262
+ case level
263
+ when 1 then "\\chapter{"
264
+ when 2 then "\\section{"
265
+ when 3 then "\\subsection{"
266
+ when 4 then "\\subsubsection{"
267
+ else "\\paragraph{"
268
+ end +
269
+ convert_flow(flow) +
270
+ "}\n"
271
+ end
272
+
273
+ def list_name(list_type, is_open_tag)
274
+ tags = LIST_TYPE_TO_LATEX[list_type] || raise("Invalid list type: #{list_type.inspect}")
275
+ if tags[2] # enumerate
276
+ if is_open_tag
277
+ @list_depth += 1
278
+ if @prev_list_types[@list_depth] != tags[2]
279
+ case @list_depth
280
+ when 1
281
+ roman = "i"
282
+ when 2
283
+ roman = "ii"
284
+ when 3
285
+ roman = "iii"
286
+ when 4
287
+ roman = "iv"
288
+ else
289
+ raise("Too deep list: level #{@list_depth}")
290
+ end
291
+ @prev_list_types[@list_depth] = tags[2]
292
+ return l("\\renewcommand{\\labelenum#{roman}}{#{tags[2]}{enum#{roman}}}") + "\n" + tags[0]
293
+ end
294
+ else
295
+ @list_depth -= 1
296
+ end
297
+ end
298
+ tags[ is_open_tag ? 0 : 1]
299
+ end
300
+
301
+ def list_item_start(am, fragment)
302
+ case fragment.type
303
+ when :BULLET, :NUMBER, :UPPERALPHA, :LOWERALPHA then
304
+ "\\item "
305
+
306
+ when :LABELED then
307
+ "\\item[" + convert_flow(am.flow(fragment.param)) + "] "
308
+
309
+ when :NOTE then
310
+ convert_flow(am.flow(fragment.param)) + " & "
311
+ else
312
+ raise "Invalid list type"
313
+ end
314
+ end
315
+
316
+ def list_end_for(fragment_type)
317
+ case fragment_type
318
+ when :BULLET, :NUMBER, :UPPERALPHA, :LOWERALPHA, :LABELED then
319
+ ""
320
+ when :NOTE
321
+ "\\\\\n"
322
+ else
323
+ raise "Invalid list type"
324
+ end
325
+ end
326
+
327
+ end
328
+
@@ -0,0 +1,50 @@
1
+ require 'rdoc-f95/markup'
2
+ require 'rdoc-f95/markup/formatter'
3
+
4
+ ##
5
+ # This Markup outputter is used for testing purposes.
6
+
7
+ class RDocF95::Markup::ToTest < RDocF95::Markup::Formatter
8
+
9
+ def start_accepting
10
+ @res = []
11
+ end
12
+
13
+ def end_accepting
14
+ @res
15
+ end
16
+
17
+ def accept_paragraph(am, fragment)
18
+ @res << fragment.to_s
19
+ end
20
+
21
+ def accept_verbatim(am, fragment)
22
+ @res << fragment.to_s
23
+ end
24
+
25
+ def accept_list_start(am, fragment)
26
+ @res << fragment.to_s
27
+ end
28
+
29
+ def accept_list_end(am, fragment)
30
+ @res << fragment.to_s
31
+ end
32
+
33
+ def accept_list_item(am, fragment)
34
+ @res << fragment.to_s
35
+ end
36
+
37
+ def accept_blank_line(am, fragment)
38
+ @res << fragment.to_s
39
+ end
40
+
41
+ def accept_heading(am, fragment)
42
+ @res << fragment.to_s
43
+ end
44
+
45
+ def accept_rule(am, fragment)
46
+ @res << fragment.to_s
47
+ end
48
+
49
+ end
50
+
@@ -0,0 +1,234 @@
1
+ require 'fileutils'
2
+ require 'rdoc-f95/markup/to_html_crossref'
3
+ require 'rdoc-f95/markup/mathml_wrapper'
4
+
5
+ ##
6
+ #<b>Note that Japanese and English are described in parallel.</b>
7
+ #
8
+ #== TeX �ο����� MathML ���Ѵ�
9
+ #
10
+ #TeX �ǵ��Ҥ��줿������ MathML ���Ѵ����ޤ�.
11
+ #����饤���ɽ�����������, TeX �ο�����ʲ��Τ褦�� $ ... $ �Ǥ����ä�
12
+ #���Ҥ��Ƥ�������. $ ��
13
+ #����ˤ�Ⱦ�Ѷ�����ʸ���ʾ�����Ʋ�����.
14
+ #(�ʤ�, "$ID: ... $" �� "$LOG: ... $
15
+ #�Ȥ��ä�, CVS �Υ�����ɤȤ���
16
+ #�Ѥ����Ƥ�������Ͽ����Ȥ��ư����ޤ���.)
17
+ #
18
+ # ����饤���ɽ����������� $ f(x) = x^2 + 1 $ �Τ褦�˵��Ҥ��ޤ�.
19
+ # ($ ������˶����˺��ʤ�).
20
+ #
21
+ #�֥��å���ɽ��������, �ʲ��Τ褦�� \[ ��
22
+ #\] �ȤǤ����äƵ��Ҥ��Ƥ�������. \[, ��ɬ����Ƭ�˵��Ҥ��Ƥ�������.
23
+ #
24
+ # \[
25
+ # \sum_{i=1}^nf_n(x)
26
+ # \]
27
+ #
28
+ #������ʣ���Ԥ�ɽ��������ˤ�, ���Ԥ�����ʬ�� "\] \[" �򵭽Ҥ��Ƥ�������.
29
+ #
30
+ # \[
31
+ # d\zeta/dt + J(\psi,\zeta) = Ra \; dT/dx + \nabla\zeta, \] \[
32
+ # dT/dt + J(\psi,T) - d\psi/dx = \nabla T, \] \[
33
+ # \nabla\psi = \zeta
34
+ # \]
35
+ #
36
+ #TeX �ο������� MathML �Ѵ��ˤ�
37
+ #<b>Ruby �� MathML �饤�֥��ΥС������ 0.8</b> ����Ѥ��Ƥ��ޤ�.
38
+ #���Υ饤�֥���{�Ҥ餯�ι�˼}[http://www.hinet.mydns.jp/~hiraku/]
39
+ #�ˤƸ�������Ƥ��ޤ�. ���ѤǤ��� TeX ���ޥ�ɤξܺ٤˴ؤ��Ƥ�
40
+ #������Υ����Ȥ򻲾Ȥ��Ƥ�������.
41
+ #
42
+ #�������줿�ɥ�����Ȥ��������ݤˤ� MathML ���б�����
43
+ #�֥饦������Ѥ���ɬ�פ�
44
+ #����ޤ�. {MathML ���ܸ����}[http://washitake.com/MathML/]
45
+ #�� {MathML Software - Browsers}[http://www.w3.org/Math/Software/mathml_software_cat_browsers.html]
46
+ #�ʤɤ򻲾Ȥ��Ƥ�������.
47
+ #
48
+ #
49
+ #== TeX is converted to MathML
50
+ #
51
+ #TeX formula is converted to MathML.
52
+ #When inline display, TeX formula should be bundled by $ ... $
53
+ #as follows.
54
+ #One or more normal-width blank is necessary before and behind "$".
55
+ #(The format of CVS keywords, that is "$ID: ... $" or
56
+ #"$LOG: ... $ etc. is ignored.)
57
+ #
58
+ # Inline formula is $ f(x) = x^2 + 1 $ .
59
+ #
60
+ #When block display, TeX formula should be bundled by \[ ... \]
61
+ #as follows.
62
+ #Describe \[ at the head of line.
63
+ #
64
+ # \[
65
+ # \sum_{i=1}^nf_n(x)
66
+ # \]
67
+ #
68
+ #To write equations across multiple lines, describe "\] \["
69
+ #as follows.
70
+ #
71
+ # \[
72
+ # d\zeta/dt + J(\psi,\zeta) = Ra \; dT/dx + \nabla\zeta, \] \[
73
+ # dT/dt + J(\psi,T) - d\psi/dx = \nabla T, \] \[
74
+ # \nabla\psi = \zeta
75
+ # \]
76
+ #
77
+ #<b>MathML library for Ruby version 0.8</b> is needed to
78
+ #convert TeX formula to MathML.
79
+ #This library is available from {Bottega of Hiraku (JAPANESE only)}[http://www.hinet.mydns.jp/~hiraku/].
80
+ #See this site about available TeX commands.
81
+ #
82
+ #When you browse generated documents, you need to use
83
+ #browers that can handle MathML.
84
+ #See {MathML Software - Browsers}[http://www.w3.org/Math/Software/mathml_software_cat_browsers.html], etc.
85
+ #
86
+ #
87
+ #== \newcommand, \newenvironment �λ�����ˡ
88
+ #
89
+ #\newcommand �� \newenvironment ̿��ˤ��ޥ�������Ѥ���ˤ�,
90
+ #Ruby �Υ����ɥѥ��ʲ��� '<b><tt>mathml/macro</tt></b>' �ǥ��쥯�ȥ��
91
+ #������, ���Υǥ��쥯�ȥ�ʲ��˥ޥ���̿��򵭤����ե�������֤��Ƥ�������.
92
+ #�ե�����̾���䤤�ޤ���.
93
+ #
94
+ #�㤨��, '<tt>/usr/lib/ruby/1.8</tt>' �� Ruby �Υ����ɥѥ��Ǥ�����,
95
+ #'<tt>/usr/lib/ruby/1.8/mathml</tt>' �����
96
+ #'<tt>/usr/lib/ruby/1.8/mathml/macro</tt>' �ǥ��쥯�ȥ�������,
97
+ #���Υǥ��쥯�ȥ�ʲ���, 'D6math.sty' �Ȥ����ե������������ޤ�
98
+ #(���Ҥ����褦�ˤ��Υե�����̾�ϲ��Ǥ⹽���ޤ���). ���Υե��������
99
+ #�ʲ��Τ褦�� \newcommand ̿��򵭽Ҥ��Ƥ������Ȥ�, '<b>\DP{}{}</b>'
100
+ #(����ʬ���ñ�˵��Ҥ��뤿��Υޥ���) ���ޥ�ɤ����Ѳ�ǽ�ˤʤ�ޤ�.
101
+ #
102
+ # \newcommand{\DP}[2]{\frac{\partial #1}{\partial #2}}
103
+ #
104
+ #�ϵ�ή����Ǿ��������󶡤��Ƥ��� {TeX �ޥ��� (�̾�: ��Ǿ��������)}[http://www.gfd-dennou.org/library/cc-env/TeXmacro/dennou/SIGEN.htm]
105
+ #�˴ޤޤ�� 'D6math.sty' �� Ruby �� Mathml �饤�֥��ǻ��ѤǤ���褦��
106
+ #���������ѥå������� libmathml-macro-dennou-ruby[http://www.gfd-dennou.org/library/cc-env/libmathml-macro-dennou-ruby/debian/stable/] �Ȥ���
107
+ #�󶡤��Ƥ��ޤ�. ����ץ�Ȥ������Ѥ��ƤߤƤ�������.
108
+ #
109
+ #
110
+ #== Usage of \newcommand and \newenvironment
111
+ #
112
+ #If you want to use macros defined by \newcommand and
113
+ #\newenvironment commands, make '<b><tt>mathml/macro</tt></b>' directory
114
+ #under load paths of Ruby, and prepare a file that macro commands are
115
+ #described in the directory. A name of the file is free.
116
+ #
117
+ #For example, if your load path of Ruby is '<tt>/usr/lib/ruby/1.8</tt>',
118
+ #you should make '<tt>/usr/lib/ruby/1.8/mathml</tt>' and
119
+ #'<tt>/usr/lib/ruby/1.8/mathml/macro</tt>' directories,
120
+ #and make 'D6math.sty' file (already mentioned, the file name is free).
121
+ #When you describe a following \newcommand command, you can use
122
+ #'<b>\DP{}{}</b>' (a macro for partial differentiations) command.
123
+ #
124
+ # \newcommand{\DP}[2]{\frac{\partial #1}{\partial #2}}
125
+ #
126
+ #As a sample, please use libmathml-macro-dennou-ruby[http://www.gfd-dennou.org/library/cc-env/libmathml-macro-dennou-ruby/debian/stable/].
127
+ #The original style file is 'D6math.sty' in {TeX macro (Dennou style)}[http://www.gfd-dennou.org/library/cc-env/TeXmacro/dennou/SIGEN.htm].
128
+ #libmathml-macro-dennou-ruby is a reconfigured package for Mathml library for Ruby.
129
+ #
130
+ #
131
+ class RDocF95::Markup::ToXHtmlTexParser < RDocF95::Markup::ToHtmlCrossref
132
+
133
+ attr_accessor :context
134
+ attr_reader :block_exceptions
135
+
136
+ ##
137
+ # We need to record the html path of our caller so we can generate
138
+ # correct relative paths for any hyperlinks that we find
139
+
140
+ def initialize(from_path, context, show_hash, mathml=nil)
141
+ super(from_path, context, show_hash)
142
+ @mathml = mathml
143
+
144
+ if @mathml
145
+ # TeX inline form
146
+ @markup.add_special(/(\$(.*?)[^\\]\$)/im, :TEXINLINE)
147
+
148
+ # TeX inline delimiter
149
+ @markup.add_special(/(\\\$)/im, :TEXINLINEDELIMITER)
150
+
151
+ # TeX block form
152
+ @markup.add_special(/(\\\[(.+?)\\\])/im, :TEXBLOCK)
153
+ end
154
+
155
+ @block_exceptions = []
156
+ if @markup
157
+ @block_exceptions << {
158
+ 'name' => :texblockform,
159
+ 'start' => Regexp.new("^\\\\\\["),
160
+ 'end' => Regexp.new("\\\\\\]$"),
161
+ 'replaces' => []
162
+ }
163
+ @block_exceptions[0]['replaces'] << {
164
+ 'from' => Regexp.new("\\\\\\\\"),
165
+ 'to' => "\\\\\\\\\\\\\\\\",
166
+ }
167
+ end
168
+
169
+ end
170
+
171
+ def file_location
172
+ if @context.context.parent
173
+ class_or_method = @context.context.name
174
+ end
175
+ context = @context.context
176
+ while context.parent
177
+ context = context.parent
178
+ end
179
+ location = context.file_relative_name
180
+ if class_or_method
181
+ location += "#"+class_or_method
182
+ end
183
+ return location
184
+ end
185
+
186
+ ##
187
+ # TEXINLINE pattern $...$ is converted to MathML format
188
+ # when --mathml option is given.
189
+ #
190
+ def handle_special_TEXINLINE(special)
191
+ text = special.text
192
+ return text unless @mathml
193
+ raw_text = text.scan(/^.*?\$/).to_s.sub(/\$$/, '')
194
+ return text if text =~ /^.*?\$[A-Z]\w+:/ # CVS keywords are skipped
195
+ text.sub!(/^.*?\$/, '')
196
+ text.sub!(/\$$/, '')
197
+ tex = MathMLWrapper.new
198
+ mathml, stat = tex.parse(text)
199
+ if !(stat == 0)
200
+ $stderr.puts "Warning: in #{file_location}, following TeX commands can not be converted to MathML\n\n",
201
+ " #{text}\n\n"
202
+ end
203
+ return raw_text + mathml
204
+ end
205
+
206
+ ##
207
+ # TEXINLINEDELIMITER pattern "\$" is converted to single dollar "$"
208
+ # when --mathml option is given.
209
+ #
210
+ def handle_special_TEXINLINEDELIMITER(special)
211
+ text = special.text
212
+ return text unless @mathml
213
+ return text.gsub(/\\\$/, '$')
214
+ end
215
+
216
+ ##
217
+ # TEXBLOCK pattern \[...\] is converted to MathML format
218
+ # when --mathml option is given.
219
+ #
220
+ def handle_special_TEXBLOCK(special)
221
+ text = special.text
222
+ return text unless @mathml
223
+ text.sub!(/^\\\[/, '')
224
+ text.sub!(/\\\]$/, '')
225
+ tex = MathMLWrapper.new
226
+ mathml, stat = tex.parse(text, true)
227
+ if !(stat == 0)
228
+ $stderr.puts "Warning: in #{file_location}, following TeX commands can not be converted to MathML\n\n",
229
+ " #{text}\n\n"
230
+ end
231
+ return mathml
232
+ end
233
+
234
+ end