asciimath 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ae64f8f21a57a2628a5e8ca6c04aaa15a7d6cae4
4
- data.tar.gz: 88ffb4452dd16e56a9fc72876ecb0321f6724d82
3
+ metadata.gz: 82151a09eeb08692d5879ebb592fff3522834e6f
4
+ data.tar.gz: 8d5d844b47b7ffbb6473535f7366aefed1783d6e
5
5
  SHA512:
6
- metadata.gz: 5d53d55278be758c46d356214fd764b07839a2e64eac67e333b1de409b3a29ff3e1341adeb4eb8d9db084617f3f686dc19b069fe3cc15795938fa9a257f96144
7
- data.tar.gz: 4a8f1ac5d07d7776a232d763cd6b435274916319783bfb356a668db96af99f9b6892e3ace5445222cc9c3f6eee604628d9a0476a0c42c61601b9cfbe7c0e810e
6
+ metadata.gz: bec21ba3ea7e11c768f85036c1091ab7e3b312e11b98ad4da55af55caf8f4a8d4638990daf1747a5bfb4387728977fb95d6a0770bde3eead18b449b8f9adf8c8
7
+ data.tar.gz: 1f0c2af41feb89b48dc9aba6f595e38d3f1ed787ab6274761f16ff8fa1330fcb252f9c1b6867ef680708d012ada805417eb524ad1b17f4358d37072f4485404f
@@ -9,6 +9,10 @@ rvm:
9
9
  - 1.9.3
10
10
  - 2.0.0
11
11
  - 2.1.0
12
- - jruby
12
+ - jruby-1.7.27
13
+ # - jruby
14
+ before_install:
15
+ - gem update --system
16
+ - gem install bundler
13
17
  install:
14
18
  - bundle install --path vendor/bundle --jobs=3 --retry=3
@@ -1,7 +1,16 @@
1
1
  # AsciiMath
2
+ ifndef::env-site[:status:]
2
3
 
3
4
  An http://asciimath.org[AsciiMath] parser and MathML generator written in pure Ruby.
4
5
 
6
+ ifdef::status[]
7
+ [discrete]
8
+ ## Status
9
+
10
+ image:https://travis-ci.org/pepijnve/asciimath.svg?branch=master["Linux Build Status", link="https://travis-ci.org/asciidoctor/asciimath"]
11
+ image:https://img.shields.io/gem/v/asciimath.svg?label=gem%20version[Gem Version, link=https://rubygems.org/gems/asciimath]
12
+ endif::status[]
13
+
5
14
  ## Installation
6
15
 
7
16
  Add this line to your application's Gemfile:
@@ -39,25 +48,52 @@ parsed_expression = AsciiMath.parse(asciimath)
39
48
 
40
49
  The parsed expression is a set of nested Array and Hash objects.
41
50
 
42
- This expression can then be converted to MathML.
51
+ This expression can then be converted to MathML or HTML (experimental.
43
52
 
44
53
  [source,ruby]
45
54
  ----
46
55
  math_ml = parsed_expression.to_mathml
56
+ html = parsed_expression.to_html
47
57
  ----
48
58
 
49
- The MathML code is returned as a String.
59
+ The MathML or HTML code is returned as a String.
50
60
 
51
61
  ### Command line
52
62
 
53
- The AsciiMath parser and MathML converter can be invoked via the command line as follows:
63
+ The AsciiMath parser and converters can be invoked via the command line as follows:
54
64
 
65
+ .MathML Generation
55
66
  [source]
56
67
  ----
57
68
  asciimath "an asciimath string"
69
+
70
+ or
71
+
72
+ asciimath mathml "an asciimath string"
73
+ ----
74
+
75
+ .HTML Generation
76
+ [source]
58
77
  ----
78
+ asciimath html "an asciimath string"
79
+ ----
80
+
81
+ This command will print out the generated code on stdout.
82
+
83
+
84
+ ## Notes on the HTML Output
85
+
86
+ The HTML output is still regarded somewhat experimental - for basic usage it is fine, but it is not yet complete.
87
+ Known issues are as follows:
88
+
89
+ * `sqrt` function does not generate sane output
90
+ * Use of font commands (e.g. `bb`) will result in broken output.
91
+ * Accents do not extend to match what they cover.
92
+ * Rendering of "integrals" uses a generic path that does not look amazing.
93
+ * The size of braces does not account for complex content - so a matrix will render with the right sized braces if all of its elements are single-height text, but braces around e.g. fractions will render at the incorrect height.
59
94
 
60
- This command will print out the generated MathML code on stdout.
95
+ Rendering the HTML output correctly requires the inclusion of `style/math.css` in the html document.
96
+ There is currently no specific required font for this output, it simply selects a `serif` font family - change the `@font-family` attribute in the `.math-inline` class to select something specific.
61
97
 
62
98
  ## Contributing
63
99
 
@@ -1,3 +1,4 @@
1
1
  require File.join(File.dirname(__FILE__), 'asciimath/version')
2
2
  require File.join(File.dirname(__FILE__), 'asciimath/parser')
3
3
  require File.join(File.dirname(__FILE__), 'asciimath/mathml')
4
+ require File.join(File.dirname(__FILE__), 'asciimath/html')
@@ -1,12 +1,18 @@
1
1
  require_relative 'parser'
2
2
  require_relative 'mathml'
3
+ require_relative 'html'
3
4
 
4
5
  module AsciiMath
5
6
  module CLI
6
7
  def self.run(args)
7
8
  asciimath = args.last
8
- mathml = AsciiMath.parse(asciimath).to_mathml
9
- puts mathml
9
+ output = ''
10
+ if args.length == 1 || args.first == "mathml"
11
+ output = AsciiMath.parse(asciimath).to_mathml
12
+ elsif args.first == "html"
13
+ output = AsciiMath.parse(asciimath).to_html
14
+ end
15
+ puts output
10
16
  end
11
17
  end
12
18
  end
@@ -0,0 +1,220 @@
1
+ module AsciiMath
2
+ class HTMLBuilder
3
+ def initialize(prefix)
4
+ @prefix = prefix
5
+ @html = ''
6
+ end
7
+
8
+ def to_s
9
+ @html
10
+ end
11
+
12
+ def append_expression(expression, inline, attrs = {})
13
+ if inline
14
+ inline('', attrs) do
15
+ append(expression, :single_child => true)
16
+ end
17
+ else
18
+ block('', attrs) do
19
+ append(expression, :single_child => true)
20
+ end
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def append(expression, opts = {})
27
+ case expression
28
+ when Array
29
+ row do
30
+ expression.each { |e| append(e) }
31
+ end
32
+ when Hash
33
+ case expression[:type]
34
+ when :operator
35
+ operator(expression[:c])
36
+ when :identifier
37
+ identifier(expression[:c])
38
+ when :number
39
+ number(expression[:c])
40
+ when :text
41
+ text(expression[:c])
42
+ when :paren
43
+ paren = !opts[:strip_paren]
44
+ if paren
45
+ if opts[:single_child]
46
+ brace(expression[:lparen]) if expression[:lparen]
47
+ append(expression[:e], :single_child => true)
48
+ brace(expression[:rparen]) if expression[:rparen]
49
+ else
50
+ row do
51
+ brace(expression[:lparen]) if expression[:lparen]
52
+ append(expression[:e], :single_child => true)
53
+ brace(expression[:rparen]) if expression[:rparen]
54
+ end
55
+ end
56
+ else
57
+ append(expression[:e])
58
+ end
59
+ when :font
60
+ #TODO - currently ignored
61
+ when :unary
62
+ operator = expression[:operator]
63
+ tag(operator) do
64
+ append(expression[:s], :single_child => true, :strip_paren => true)
65
+ end
66
+ when :binary
67
+ operator = expression[:operator]
68
+ if operator == :frac
69
+ append_fraction(expression[:s1],expression[:s2])
70
+ elsif operator == :sub
71
+ append_subsup(expression[:s1],expression[:s2],nil)
72
+ elsif operator == :sup
73
+ append_subsup(expression[:s1],nil,expression[:s2])
74
+ elsif operator == :under
75
+ append_underover(expression[:s1],expression[:s2],nil)
76
+ elsif operator == :over
77
+ append_underover(expression[:s1],nil,expression[:s2])
78
+ else
79
+ tag(operator) do
80
+ append(expression[:s1], :strip_paren => true)
81
+ append(expression[:s2], :strip_paren => true)
82
+ end
83
+ end
84
+ when :ternary
85
+ operator = expression[:operator]
86
+ if operator == :subsup
87
+ append_subsup(expression[:s1],expression[:s2],expression[:s3])
88
+ elsif operator == :underover
89
+ # TODO: Handle over/under braces in some way? SVG maybe?
90
+ append_underover(expression[:s1],expression[:s2],expression[:s3])
91
+ end
92
+ when :matrix
93
+ row do
94
+ # Figures out a font size for the braces, based on the height of the matrix.
95
+ # NOTE: This does not currently consider the size of each element within the matrix.
96
+ brace_height = "font-size: " + expression[:rows].length.to_s + "00%;"
97
+
98
+ if expression[:lparen]
99
+ brace(expression[:lparen], {:style => brace_height})
100
+ else
101
+ blank("‍")
102
+ end
103
+ matrix_width = "grid-template-columns:repeat(" + expression[:rows][0].length.to_s + ",1fr);"
104
+ matrix_height = "grid-template-rows:repeat(" + expression[:rows].length.to_s + ",1fr);"
105
+
106
+ matrix({:style => (matrix_width + matrix_height)}) do
107
+ expression[:rows].each do |row|
108
+ row.each do |col|
109
+ row do
110
+ append(col)
111
+ end
112
+ end
113
+ end
114
+ end
115
+ if expression[:rparen]
116
+ brace(expression[:rparen], {:style => brace_height})
117
+ else
118
+ blank("‍")
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
124
+
125
+ def append_subsup(base, sub, sup)
126
+ append(base)
127
+ subsup do
128
+ if sup
129
+ smaller do
130
+ append(sup, :strip_paren => true)
131
+ end
132
+ else
133
+ smaller("‍")
134
+ end
135
+ if sub
136
+ smaller do
137
+ append(sub, :strip_paren => true)
138
+ end
139
+ else
140
+ smaller("‍")
141
+ end
142
+ end
143
+ end
144
+
145
+ def append_underover(base, under, over)
146
+ blank("‍")
147
+ underover do
148
+ smaller do
149
+ if over
150
+ append(over, :strip_paren => true)
151
+ else
152
+ blank("‍")
153
+ end
154
+ end
155
+ append(base)
156
+ smaller do
157
+ if under
158
+ append(under, :strip_paren => true)
159
+ else
160
+ blank("‍")
161
+ end
162
+ end
163
+ end
164
+ end
165
+
166
+ def append_fraction(numerator, denominator)
167
+ blank("‍")
168
+ fraction do
169
+ fraction_row do
170
+ fraction_cell do
171
+ smaller do
172
+ row do
173
+ append(numerator, :strip_paren => true)
174
+ end
175
+ end
176
+ end
177
+ end
178
+ fraction_row do
179
+ fraction_cell do
180
+ smaller do
181
+ row do
182
+ append(denominator, :strip_paren => true)
183
+ end
184
+ end
185
+ end
186
+ end
187
+ end
188
+ end
189
+
190
+ def method_missing(meth, *args, &block)
191
+ tag(meth, *args, &block)
192
+ end
193
+
194
+ def tag(tag, *args)
195
+ attrs = args.last.is_a?(Hash) ? args.pop : {}
196
+ text = args.last.is_a?(String) ? args.pop : ''
197
+
198
+ @html << '<span class="math-' << @prefix << tag.to_s << '"'
199
+
200
+ attrs.each_pair do |key, value|
201
+ @html << ' ' << key.to_s << '="' << value.to_s << '"'
202
+ end
203
+
204
+ if block_given? || text
205
+ @html << '>'
206
+ @html << text
207
+ yield if block_given?
208
+ @html << '</span>'
209
+ else
210
+ @html << '/>'
211
+ end
212
+ end
213
+ end
214
+
215
+ class Expression
216
+ def to_html(prefix = "", inline = true, attrs = {})
217
+ HTMLBuilder.new(prefix).append_expression(@parsed_expression, inline, attrs).to_s
218
+ end
219
+ end
220
+ end
@@ -353,10 +353,17 @@ module AsciiMath
353
353
  'text' => {:value => :text, :type => :unary},
354
354
  'bb' => {:value => :bold, :type => :font},
355
355
  'bbb' => {:value => :double_struck, :type => :font},
356
+ 'ii' => {:value => :italic, :type => :font},
357
+ 'bii' => {:value => :bold_italic, :type => :font},
356
358
  'cc' => {:value => :script, :type => :font},
359
+ 'bcc' => {:value => :bold_script, :type => :font},
357
360
  'tt' => {:value => :monospace, :type => :font},
358
361
  'fr' => {:value => :fraktur, :type => :font},
362
+ 'bfr' => {:value => :bold_fraktur, :type => :font},
359
363
  'sf' => {:value => :sans_serif, :type => :font},
364
+ 'bsf' => {:value => :bold_sans_serif, :type => :font},
365
+ 'sfi' => {:value => :sans_serif_italic, :type => :font},
366
+ 'sfbi' => {:value => :sans_serif_bold_italic, :type => :font},
360
367
  'frac' => {:value => :frac, :type => :binary},
361
368
  'root' => {:value => :root, :type => :binary},
362
369
  'stackrel' => {:value => :over, :type => :binary},
@@ -1,3 +1,3 @@
1
1
  module AsciiMath
2
- VERSION = "1.0.4"
2
+ VERSION = "1.0.5"
3
3
  end
@@ -1,63 +1,138 @@
1
+ #encoding: utf-8
1
2
  require 'rspec'
2
3
  require 'asciimath'
3
4
 
4
5
  TEST_CASES = {
5
6
  'x+b/(2a)<+-sqrt((b^2)/(4a^2)-c/a)' =>
6
- '<math><mi>x</mi><mo>+</mo><mfrac><mi>b</mi><mrow><mn>2</mn><mi>a</mi></mrow></mfrac><mo>&#x003C;</mo><mo>&#x00B1;</mo><msqrt><mrow><mfrac><msup><mi>b</mi><mn>2</mn></msup><mrow><mn>4</mn><msup><mi>a</mi><mn>2</mn></msup></mrow></mfrac><mo>&#x2212;</mo><mfrac><mi>c</mi><mi>a</mi></mfrac></mrow></msqrt></math>',
7
+ {
8
+ :mathml => '<math><mi>x</mi><mo>+</mo><mfrac><mi>b</mi><mrow><mn>2</mn><mi>a</mi></mrow></mfrac><mo>&#x003C;</mo><mo>&#x00B1;</mo><msqrt><mrow><mfrac><msup><mi>b</mi><mn>2</mn></msup><mrow><mn>4</mn><msup><mi>a</mi><mn>2</mn></msup></mrow></mfrac><mo>&#x2212;</mo><mfrac><mi>c</mi><mi>a</mi></mfrac></mrow></msqrt></math>',
9
+ :html => 'Unsupported',
10
+ },
7
11
  'a^2 + b^2 = c^2' =>
8
- '<math><msup><mi>a</mi><mn>2</mn></msup><mo>+</mo><msup><mi>b</mi><mn>2</mn></msup><mo>=</mo><msup><mi>c</mi><mn>2</mn></msup></math>',
12
+ {
13
+ :mathml => '<math><msup><mi>a</mi><mn>2</mn></msup><mo>+</mo><msup><mi>b</mi><mn>2</mn></msup><mo>=</mo><msup><mi>c</mi><mn>2</mn></msup></math>',
14
+ :html => '<span class="math-inline"><span class="math-row"><span class="math-identifier">a</span><span class="math-subsup"><span class="math-smaller"><span class="math-number">2</span></span><span class="math-smaller">&zwj;</span></span><span class="math-operator">+</span><span class="math-identifier">b</span><span class="math-subsup"><span class="math-smaller"><span class="math-number">2</span></span><span class="math-smaller">&zwj;</span></span><span class="math-operator">=</span><span class="math-identifier">c</span><span class="math-subsup"><span class="math-smaller"><span class="math-number">2</span></span><span class="math-smaller">&zwj;</span></span></span></span>',
15
+ },
9
16
  'x = (-b+-sqrt(b^2-4ac))/(2a)' =>
10
- '<math><mi>x</mi><mo>=</mo><mfrac><mrow><mo>&#x2212;</mo><mi>b</mi><mo>&#x00B1;</mo><msqrt><mrow><msup><mi>b</mi><mn>2</mn></msup><mn>-4</mn><mi>a</mi><mi>c</mi></mrow></msqrt></mrow><mrow><mn>2</mn><mi>a</mi></mrow></mfrac></math>',
17
+ {
18
+ :mathml => '<math><mi>x</mi><mo>=</mo><mfrac><mrow><mo>&#x2212;</mo><mi>b</mi><mo>&#x00B1;</mo><msqrt><mrow><msup><mi>b</mi><mn>2</mn></msup><mn>-4</mn><mi>a</mi><mi>c</mi></mrow></msqrt></mrow><mrow><mn>2</mn><mi>a</mi></mrow></mfrac></math>',
19
+ :html => 'Unsupported'
20
+ },
11
21
  'm = (y_2 - y_1)/(x_2 - x_1) = (Deltay)/(Deltax)' =>
12
- '<math><mi>m</mi><mo>=</mo><mfrac><mrow><msub><mi>y</mi><mn>2</mn></msub><mo>&#x2212;</mo><msub><mi>y</mi><mn>1</mn></msub></mrow><mrow><msub><mi>x</mi><mn>2</mn></msub><mo>&#x2212;</mo><msub><mi>x</mi><mn>1</mn></msub></mrow></mfrac><mo>=</mo><mfrac><mrow><mo>&#x0394;</mo><mi>y</mi></mrow><mrow><mo>&#x0394;</mo><mi>x</mi></mrow></mfrac></math>',
22
+ {
23
+ :mathml => '<math><mi>m</mi><mo>=</mo><mfrac><mrow><msub><mi>y</mi><mn>2</mn></msub><mo>&#x2212;</mo><msub><mi>y</mi><mn>1</mn></msub></mrow><mrow><msub><mi>x</mi><mn>2</mn></msub><mo>&#x2212;</mo><msub><mi>x</mi><mn>1</mn></msub></mrow></mfrac><mo>=</mo><mfrac><mrow><mo>&#x0394;</mo><mi>y</mi></mrow><mrow><mo>&#x0394;</mo><mi>x</mi></mrow></mfrac></math>',
24
+ :html => '<span class="math-inline"><span class="math-row"><span class="math-identifier">m</span><span class="math-operator">=</span><span class="math-blank">&zwj;</span><span class="math-fraction"><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-row"><span class="math-identifier">y</span><span class="math-subsup"><span class="math-smaller">&zwj;</span><span class="math-smaller"><span class="math-number">2</span></span></span><span class="math-operator">&#x2212;</span><span class="math-identifier">y</span><span class="math-subsup"><span class="math-smaller">&zwj;</span><span class="math-smaller"><span class="math-number">1</span></span></span></span></span></span></span></span><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-row"><span class="math-identifier">x</span><span class="math-subsup"><span class="math-smaller">&zwj;</span><span class="math-smaller"><span class="math-number">2</span></span></span><span class="math-operator">&#x2212;</span><span class="math-identifier">x</span><span class="math-subsup"><span class="math-smaller">&zwj;</span><span class="math-smaller"><span class="math-number">1</span></span></span></span></span></span></span></span></span><span class="math-operator">=</span><span class="math-blank">&zwj;</span><span class="math-fraction"><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-row"><span class="math-operator">&#x0394;</span><span class="math-identifier">y</span></span></span></span></span></span><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-row"><span class="math-operator">&#x0394;</span><span class="math-identifier">x</span></span></span></span></span></span></span></span></span>'
25
+ },
13
26
  'f\'(x) = lim_(Deltax->0)(f(x+Deltax)-f(x))/(Deltax)' =>
14
- '<math><mi>f</mi><mi>\'</mi><mrow><mo>(</mo><mi>x</mi><mo>)</mo></mrow><mo>=</mo><munder><mo>lim</mo><mrow><mo>&#x0394;</mo><mi>x</mi><mo>&#x2192;</mo><mn>0</mn></mrow></munder><mfrac><mrow><mi>f</mi><mrow><mo>(</mo><mi>x</mi><mo>+</mo><mo>&#x0394;</mo><mi>x</mi><mo>)</mo></mrow><mo>&#x2212;</mo><mi>f</mi><mrow><mo>(</mo><mi>x</mi><mo>)</mo></mrow></mrow><mrow><mo>&#x0394;</mo><mi>x</mi></mrow></mfrac></math>',
27
+ {
28
+ :mathml => '<math><mi>f</mi><mi>\'</mi><mrow><mo>(</mo><mi>x</mi><mo>)</mo></mrow><mo>=</mo><munder><mo>lim</mo><mrow><mo>&#x0394;</mo><mi>x</mi><mo>&#x2192;</mo><mn>0</mn></mrow></munder><mfrac><mrow><mi>f</mi><mrow><mo>(</mo><mi>x</mi><mo>+</mo><mo>&#x0394;</mo><mi>x</mi><mo>)</mo></mrow><mo>&#x2212;</mo><mi>f</mi><mrow><mo>(</mo><mi>x</mi><mo>)</mo></mrow></mrow><mrow><mo>&#x0394;</mo><mi>x</mi></mrow></mfrac></math>',
29
+ :html => '<span class="math-inline"><span class="math-row"><span class="math-identifier">f</span><span class="math-identifier">\'</span><span class="math-row"><span class="math-brace">(</span><span class="math-row"><span class="math-identifier">x</span></span><span class="math-brace">)</span></span><span class="math-operator">=</span><span class="math-blank">&zwj;</span><span class="math-underover"><span class="math-smaller"><span class="math-blank">&zwj;</span></span><span class="math-operator">lim</span><span class="math-smaller"><span class="math-row"><span class="math-operator">&#x0394;</span><span class="math-identifier">x</span><span class="math-operator">&#x2192;</span><span class="math-number">0</span></span></span></span><span class="math-blank">&zwj;</span><span class="math-fraction"><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-row"><span class="math-identifier">f</span><span class="math-row"><span class="math-brace">(</span><span class="math-row"><span class="math-identifier">x</span><span class="math-operator">+</span><span class="math-operator">&#x0394;</span><span class="math-identifier">x</span></span><span class="math-brace">)</span></span><span class="math-operator">&#x2212;</span><span class="math-identifier">f</span><span class="math-row"><span class="math-brace">(</span><span class="math-row"><span class="math-identifier">x</span></span><span class="math-brace">)</span></span></span></span></span></span></span><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-row"><span class="math-operator">&#x0394;</span><span class="math-identifier">x</span></span></span></span></span></span></span></span></span>'
30
+ },
15
31
  'd/dx [x^n] = nx^(n - 1)' =>
16
- '<math><mfrac><mi>d</mi><mi>dx</mi></mfrac><mrow><mo>[</mo><msup><mi>x</mi><mi>n</mi></msup><mo>]</mo></mrow><mo>=</mo><mi>n</mi><msup><mi>x</mi><mrow><mi>n</mi><mo>&#x2212;</mo><mn>1</mn></mrow></msup></math>',
32
+ {
33
+ :mathml => '<math><mfrac><mi>d</mi><mi>dx</mi></mfrac><mrow><mo>[</mo><msup><mi>x</mi><mi>n</mi></msup><mo>]</mo></mrow><mo>=</mo><mi>n</mi><msup><mi>x</mi><mrow><mi>n</mi><mo>&#x2212;</mo><mn>1</mn></mrow></msup></math>',
34
+ :html => '<span class="math-inline"><span class="math-row"><span class="math-blank">&zwj;</span><span class="math-fraction"><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-identifier">d</span></span></span></span></span><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-identifier">dx</span></span></span></span></span></span><span class="math-row"><span class="math-brace">[</span><span class="math-row"><span class="math-identifier">x</span><span class="math-subsup"><span class="math-smaller"><span class="math-identifier">n</span></span><span class="math-smaller">&zwj;</span></span></span><span class="math-brace">]</span></span><span class="math-operator">=</span><span class="math-identifier">n</span><span class="math-identifier">x</span><span class="math-subsup"><span class="math-smaller"><span class="math-row"><span class="math-identifier">n</span><span class="math-operator">&#x2212;</span><span class="math-number">1</span></span></span><span class="math-smaller">&zwj;</span></span></span></span>'
35
+ },
17
36
  'int_a^b f(x) dx = [F(x)]_a^b = F(b) - F(a)' =>
18
- '<math><msubsup><mo>&#x222B;</mo><mi>a</mi><mi>b</mi></msubsup><mi>f</mi><mrow><mo>(</mo><mi>x</mi><mo>)</mo></mrow><mi>dx</mi><mo>=</mo><msubsup><mrow><mo>[</mo><mi>F</mi><mrow><mo>(</mo><mi>x</mi><mo>)</mo></mrow><mo>]</mo></mrow><mi>a</mi><mi>b</mi></msubsup><mo>=</mo><mi>F</mi><mrow><mo>(</mo><mi>b</mi><mo>)</mo></mrow><mo>&#x2212;</mo><mi>F</mi><mrow><mo>(</mo><mi>a</mi><mo>)</mo></mrow></math>',
37
+ {
38
+ :mathml => '<math><msubsup><mo>&#x222B;</mo><mi>a</mi><mi>b</mi></msubsup><mi>f</mi><mrow><mo>(</mo><mi>x</mi><mo>)</mo></mrow><mi>dx</mi><mo>=</mo><msubsup><mrow><mo>[</mo><mi>F</mi><mrow><mo>(</mo><mi>x</mi><mo>)</mo></mrow><mo>]</mo></mrow><mi>a</mi><mi>b</mi></msubsup><mo>=</mo><mi>F</mi><mrow><mo>(</mo><mi>b</mi><mo>)</mo></mrow><mo>&#x2212;</mo><mi>F</mi><mrow><mo>(</mo><mi>a</mi><mo>)</mo></mrow></math>',
39
+ :html => '<span class="math-inline"><span class="math-row"><span class="math-operator">&#x222B;</span><span class="math-subsup"><span class="math-smaller"><span class="math-identifier">b</span></span><span class="math-smaller"><span class="math-identifier">a</span></span></span><span class="math-identifier">f</span><span class="math-row"><span class="math-brace">(</span><span class="math-row"><span class="math-identifier">x</span></span><span class="math-brace">)</span></span><span class="math-identifier">dx</span><span class="math-operator">=</span><span class="math-row"><span class="math-brace">[</span><span class="math-row"><span class="math-identifier">F</span><span class="math-row"><span class="math-brace">(</span><span class="math-row"><span class="math-identifier">x</span></span><span class="math-brace">)</span></span></span><span class="math-brace">]</span></span><span class="math-subsup"><span class="math-smaller"><span class="math-identifier">b</span></span><span class="math-smaller"><span class="math-identifier">a</span></span></span><span class="math-operator">=</span><span class="math-identifier">F</span><span class="math-row"><span class="math-brace">(</span><span class="math-row"><span class="math-identifier">b</span></span><span class="math-brace">)</span></span><span class="math-operator">&#x2212;</span><span class="math-identifier">F</span><span class="math-row"><span class="math-brace">(</span><span class="math-row"><span class="math-identifier">a</span></span><span class="math-brace">)</span></span></span></span>'
40
+ },
19
41
  'int_a^b f(x) dx = f(c)(b - a)' =>
20
- '<math><msubsup><mo>&#x222B;</mo><mi>a</mi><mi>b</mi></msubsup><mi>f</mi><mrow><mo>(</mo><mi>x</mi><mo>)</mo></mrow><mi>dx</mi><mo>=</mo><mi>f</mi><mrow><mo>(</mo><mi>c</mi><mo>)</mo></mrow><mrow><mo>(</mo><mi>b</mi><mo>&#x2212;</mo><mi>a</mi><mo>)</mo></mrow></math>',
42
+ {
43
+ :mathml => '<math><msubsup><mo>&#x222B;</mo><mi>a</mi><mi>b</mi></msubsup><mi>f</mi><mrow><mo>(</mo><mi>x</mi><mo>)</mo></mrow><mi>dx</mi><mo>=</mo><mi>f</mi><mrow><mo>(</mo><mi>c</mi><mo>)</mo></mrow><mrow><mo>(</mo><mi>b</mi><mo>&#x2212;</mo><mi>a</mi><mo>)</mo></mrow></math>',
44
+ :html => '<span class="math-inline"><span class="math-row"><span class="math-operator">&#x222B;</span><span class="math-subsup"><span class="math-smaller"><span class="math-identifier">b</span></span><span class="math-smaller"><span class="math-identifier">a</span></span></span><span class="math-identifier">f</span><span class="math-row"><span class="math-brace">(</span><span class="math-row"><span class="math-identifier">x</span></span><span class="math-brace">)</span></span><span class="math-identifier">dx</span><span class="math-operator">=</span><span class="math-identifier">f</span><span class="math-row"><span class="math-brace">(</span><span class="math-row"><span class="math-identifier">c</span></span><span class="math-brace">)</span></span><span class="math-row"><span class="math-brace">(</span><span class="math-row"><span class="math-identifier">b</span><span class="math-operator">&#x2212;</span><span class="math-identifier">a</span></span><span class="math-brace">)</span></span></span></span>'
45
+ },
21
46
  'ax^2 + bx + c = 0' =>
22
- '<math><mi>a</mi><msup><mi>x</mi><mn>2</mn></msup><mo>+</mo><mi>b</mi><mi>x</mi><mo>+</mo><mi>c</mi><mo>=</mo><mn>0</mn></math>',
47
+ {
48
+ :mathml => '<math><mi>a</mi><msup><mi>x</mi><mn>2</mn></msup><mo>+</mo><mi>b</mi><mi>x</mi><mo>+</mo><mi>c</mi><mo>=</mo><mn>0</mn></math>',
49
+ :html => '<span class="math-inline"><span class="math-row"><span class="math-identifier">a</span><span class="math-identifier">x</span><span class="math-subsup"><span class="math-smaller"><span class="math-number">2</span></span><span class="math-smaller">&zwj;</span></span><span class="math-operator">+</span><span class="math-identifier">b</span><span class="math-identifier">x</span><span class="math-operator">+</span><span class="math-identifier">c</span><span class="math-operator">=</span><span class="math-number">0</span></span></span>'
50
+ },
23
51
  '"average value"=1/(b-a) int_a^b f(x) dx' =>
24
- '<math><mtext>average value</mtext><mo>=</mo><mfrac><mn>1</mn><mrow><mi>b</mi><mo>&#x2212;</mo><mi>a</mi></mrow></mfrac><msubsup><mo>&#x222B;</mo><mi>a</mi><mi>b</mi></msubsup><mi>f</mi><mrow><mo>(</mo><mi>x</mi><mo>)</mo></mrow><mi>dx</mi></math>',
52
+ {
53
+ :mathml => '<math><mtext>average value</mtext><mo>=</mo><mfrac><mn>1</mn><mrow><mi>b</mi><mo>&#x2212;</mo><mi>a</mi></mrow></mfrac><msubsup><mo>&#x222B;</mo><mi>a</mi><mi>b</mi></msubsup><mi>f</mi><mrow><mo>(</mo><mi>x</mi><mo>)</mo></mrow><mi>dx</mi></math>',
54
+ :html => '<span class="math-inline"><span class="math-row"><span class="math-text">average value</span><span class="math-operator">=</span><span class="math-blank">&zwj;</span><span class="math-fraction"><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-number">1</span></span></span></span></span><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-row"><span class="math-identifier">b</span><span class="math-operator">&#x2212;</span><span class="math-identifier">a</span></span></span></span></span></span></span><span class="math-operator">&#x222B;</span><span class="math-subsup"><span class="math-smaller"><span class="math-identifier">b</span></span><span class="math-smaller"><span class="math-identifier">a</span></span></span><span class="math-identifier">f</span><span class="math-row"><span class="math-brace">(</span><span class="math-row"><span class="math-identifier">x</span></span><span class="math-brace">)</span></span><span class="math-identifier">dx</span></span></span>'
55
+ },
25
56
  'd/dx[int_a^x f(t) dt] = f(x)' =>
26
- '<math><mfrac><mi>d</mi><mi>dx</mi></mfrac><mrow><mo>[</mo><msubsup><mo>&#x222B;</mo><mi>a</mi><mi>x</mi></msubsup><mi>f</mi><mrow><mo>(</mo><mi>t</mi><mo>)</mo></mrow><mi>dt</mi><mo>]</mo></mrow><mo>=</mo><mi>f</mi><mrow><mo>(</mo><mi>x</mi><mo>)</mo></mrow></math>',
57
+ {
58
+ :mathml => '<math><mfrac><mi>d</mi><mi>dx</mi></mfrac><mrow><mo>[</mo><msubsup><mo>&#x222B;</mo><mi>a</mi><mi>x</mi></msubsup><mi>f</mi><mrow><mo>(</mo><mi>t</mi><mo>)</mo></mrow><mi>dt</mi><mo>]</mo></mrow><mo>=</mo><mi>f</mi><mrow><mo>(</mo><mi>x</mi><mo>)</mo></mrow></math>',
59
+ :html => '<span class="math-inline"><span class="math-row"><span class="math-blank">&zwj;</span><span class="math-fraction"><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-identifier">d</span></span></span></span></span><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-identifier">dx</span></span></span></span></span></span><span class="math-row"><span class="math-brace">[</span><span class="math-row"><span class="math-operator">&#x222B;</span><span class="math-subsup"><span class="math-smaller"><span class="math-identifier">x</span></span><span class="math-smaller"><span class="math-identifier">a</span></span></span><span class="math-identifier">f</span><span class="math-row"><span class="math-brace">(</span><span class="math-row"><span class="math-identifier">t</span></span><span class="math-brace">)</span></span><span class="math-identifier">dt</span></span><span class="math-brace">]</span></span><span class="math-operator">=</span><span class="math-identifier">f</span><span class="math-row"><span class="math-brace">(</span><span class="math-row"><span class="math-identifier">x</span></span><span class="math-brace">)</span></span></span></span>'
60
+ },
27
61
  'hat(ab) bar(xy) ul(A) vec(v)' =>
28
- '<math><mover><mrow><mi>a</mi><mi>b</mi></mrow><mo>&#x005E;</mo></mover><mover><mrow><mi>x</mi><mi>y</mi></mrow><mo>&#x00AF;</mo></mover><munder><mi>A</mi><mo>_</mo></munder><mover><mi>v</mi><mo>&#x2192;</mo></mover></math>',
62
+ {
63
+ :mathml => '<math><mover><mrow><mi>a</mi><mi>b</mi></mrow><mo>&#x005E;</mo></mover><mover><mrow><mi>x</mi><mi>y</mi></mrow><mo>&#x00AF;</mo></mover><munder><mi>A</mi><mo>_</mo></munder><mover><mi>v</mi><mo>&#x2192;</mo></mover></math>',
64
+ :html => '<span class="math-inline"><span class="math-row"><span class="math-blank">&zwj;</span><span class="math-underover"><span class="math-smaller"><span class="math-operator">&#x005E;</span></span><span class="math-row"><span class="math-brace">(</span><span class="math-row"><span class="math-identifier">a</span><span class="math-identifier">b</span></span><span class="math-brace">)</span></span><span class="math-smaller"><span class="math-blank">&zwj;</span></span></span><span class="math-blank">&zwj;</span><span class="math-underover"><span class="math-smaller"><span class="math-operator">&#x00AF;</span></span><span class="math-row"><span class="math-brace">(</span><span class="math-row"><span class="math-identifier">x</span><span class="math-identifier">y</span></span><span class="math-brace">)</span></span><span class="math-smaller"><span class="math-blank">&zwj;</span></span></span><span class="math-blank">&zwj;</span><span class="math-underover"><span class="math-smaller"><span class="math-blank">&zwj;</span></span><span class="math-row"><span class="math-brace">(</span><span class="math-row"><span class="math-identifier">A</span></span><span class="math-brace">)</span></span><span class="math-smaller"><span class="math-operator">_</span></span></span><span class="math-blank">&zwj;</span><span class="math-underover"><span class="math-smaller"><span class="math-operator">&#x2192;</span></span><span class="math-row"><span class="math-brace">(</span><span class="math-row"><span class="math-identifier">v</span></span><span class="math-brace">)</span></span><span class="math-smaller"><span class="math-blank">&zwj;</span></span></span></span></span>'
65
+ },
29
66
  'z_12^34' =>
30
- '<math><msubsup><mi>z</mi><mn>12</mn><mn>34</mn></msubsup></math>',
67
+ {
68
+ :mathml => '<math><msubsup><mi>z</mi><mn>12</mn><mn>34</mn></msubsup></math>',
69
+ :html => '<span class="math-inline"><span class="math-row"><span class="math-identifier">z</span><span class="math-subsup"><span class="math-smaller"><span class="math-number">34</span></span><span class="math-smaller"><span class="math-number">12</span></span></span></span></span>'
70
+ },
31
71
  'lim_(x->c)(f(x)-f(c))/(x-c)' =>
32
- '<math><munder><mo>lim</mo><mrow><mi>x</mi><mo>&#x2192;</mo><mi>c</mi></mrow></munder><mfrac><mrow><mi>f</mi><mrow><mo>(</mo><mi>x</mi><mo>)</mo></mrow><mo>&#x2212;</mo><mi>f</mi><mrow><mo>(</mo><mi>c</mi><mo>)</mo></mrow></mrow><mrow><mi>x</mi><mo>&#x2212;</mo><mi>c</mi></mrow></mfrac></math>',
72
+ {
73
+ :mathml => '<math><munder><mo>lim</mo><mrow><mi>x</mi><mo>&#x2192;</mo><mi>c</mi></mrow></munder><mfrac><mrow><mi>f</mi><mrow><mo>(</mo><mi>x</mi><mo>)</mo></mrow><mo>&#x2212;</mo><mi>f</mi><mrow><mo>(</mo><mi>c</mi><mo>)</mo></mrow></mrow><mrow><mi>x</mi><mo>&#x2212;</mo><mi>c</mi></mrow></mfrac></math>',
74
+ :html => '<span class="math-inline"><span class="math-row"><span class="math-blank">&zwj;</span><span class="math-underover"><span class="math-smaller"><span class="math-blank">&zwj;</span></span><span class="math-operator">lim</span><span class="math-smaller"><span class="math-row"><span class="math-identifier">x</span><span class="math-operator">&#x2192;</span><span class="math-identifier">c</span></span></span></span><span class="math-blank">&zwj;</span><span class="math-fraction"><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-row"><span class="math-identifier">f</span><span class="math-row"><span class="math-brace">(</span><span class="math-row"><span class="math-identifier">x</span></span><span class="math-brace">)</span></span><span class="math-operator">&#x2212;</span><span class="math-identifier">f</span><span class="math-row"><span class="math-brace">(</span><span class="math-row"><span class="math-identifier">c</span></span><span class="math-brace">)</span></span></span></span></span></span></span><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-row"><span class="math-identifier">x</span><span class="math-operator">&#x2212;</span><span class="math-identifier">c</span></span></span></span></span></span></span></span></span>'
75
+ },
33
76
  'int_0^(pi/2) g(x) dx' =>
34
- '<math><msubsup><mo>&#x222B;</mo><mn>0</mn><mfrac><mi>&#x03c0;</mi><mn>2</mn></mfrac></msubsup><mi>g</mi><mrow><mo>(</mo><mi>x</mi><mo>)</mo></mrow><mi>dx</mi></math>',
77
+ {
78
+ :mathml => '<math><msubsup><mo>&#x222B;</mo><mn>0</mn><mfrac><mi>&#x03c0;</mi><mn>2</mn></mfrac></msubsup><mi>g</mi><mrow><mo>(</mo><mi>x</mi><mo>)</mo></mrow><mi>dx</mi></math>',
79
+ :html => '<span class="math-inline"><span class="math-row"><span class="math-operator">&#x222B;</span><span class="math-subsup"><span class="math-smaller"><span class="math-row"><span class="math-blank">&zwj;</span><span class="math-fraction"><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-identifier">&#x03c0;</span></span></span></span></span><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-number">2</span></span></span></span></span></span></span></span><span class="math-smaller"><span class="math-number">0</span></span></span><span class="math-identifier">g</span><span class="math-row"><span class="math-brace">(</span><span class="math-row"><span class="math-identifier">x</span></span><span class="math-brace">)</span></span><span class="math-identifier">dx</span></span></span>'
80
+ },
35
81
  'sum_(n=0)^oo a_n' =>
36
- '<math><munderover><mo>&#x2211;</mo><mrow><mi>n</mi><mo>=</mo><mn>0</mn></mrow><mo>&#x221E;</mo></munderover><msub><mi>a</mi><mi>n</mi></msub></math>',
82
+ {
83
+ :mathml => '<math><munderover><mo>&#x2211;</mo><mrow><mi>n</mi><mo>=</mo><mn>0</mn></mrow><mo>&#x221E;</mo></munderover><msub><mi>a</mi><mi>n</mi></msub></math>',
84
+ :html => '<span class="math-inline"><span class="math-row"><span class="math-blank">&zwj;</span><span class="math-underover"><span class="math-smaller"><span class="math-operator">&#x221E;</span></span><span class="math-operator">&#x2211;</span><span class="math-smaller"><span class="math-row"><span class="math-identifier">n</span><span class="math-operator">=</span><span class="math-number">0</span></span></span></span><span class="math-identifier">a</span><span class="math-subsup"><span class="math-smaller">&zwj;</span><span class="math-smaller"><span class="math-identifier">n</span></span></span></span></span>'
85
+ },
37
86
  '((1,2,3),(4,5,6),(7,8,9))' =>
38
- '<math><mrow><mo>(</mo><mtable><mtr><mtd><mn>1</mn></mtd><mtd><mn>2</mn></mtd><mtd><mn>3</mn></mtd></mtr><mtr><mtd><mn>4</mn></mtd><mtd><mn>5</mn></mtd><mtd><mn>6</mn></mtd></mtr><mtr><mtd><mn>7</mn></mtd><mtd><mn>8</mn></mtd><mtd><mn>9</mn></mtd></mtr></mtable><mo>)</mo></mrow></math>',
87
+ {
88
+ :mathml => '<math><mrow><mo>(</mo><mtable><mtr><mtd><mn>1</mn></mtd><mtd><mn>2</mn></mtd><mtd><mn>3</mn></mtd></mtr><mtr><mtd><mn>4</mn></mtd><mtd><mn>5</mn></mtd><mtd><mn>6</mn></mtd></mtr><mtr><mtd><mn>7</mn></mtd><mtd><mn>8</mn></mtd><mtd><mn>9</mn></mtd></mtr></mtable><mo>)</mo></mrow></math>',
89
+ :html => '<span class="math-inline"><span class="math-row"><span class="math-row"><span class="math-brace" style="font-size: 300%;">(</span><span class="math-matrix" style="grid-template-columns:repeat(3,1fr);grid-template-rows:repeat(3,1fr);"><span class="math-row"><span class="math-number">1</span></span><span class="math-row"><span class="math-number">2</span></span><span class="math-row"><span class="math-number">3</span></span><span class="math-row"><span class="math-number">4</span></span><span class="math-row"><span class="math-number">5</span></span><span class="math-row"><span class="math-number">6</span></span><span class="math-row"><span class="math-number">7</span></span><span class="math-row"><span class="math-number">8</span></span><span class="math-row"><span class="math-number">9</span></span></span><span class="math-brace" style="font-size: 300%;">)</span></span></span></span>'
90
+ },
39
91
  '|(a,b),(c,d)|=ad-bc' =>
40
- '<math><mrow><mo>|</mo><mtable><mtr><mtd><mi>a</mi></mtd><mtd><mi>b</mi></mtd></mtr><mtr><mtd><mi>c</mi></mtd><mtd><mi>d</mi></mtd></mtr></mtable><mo>|</mo></mrow><mo>=</mo><mi>a</mi><mi>d</mi><mo>&#x2212;</mo><mi>b</mi><mi>c</mi></math>',
92
+ {
93
+ :mathml => '<math><mrow><mo>|</mo><mtable><mtr><mtd><mi>a</mi></mtd><mtd><mi>b</mi></mtd></mtr><mtr><mtd><mi>c</mi></mtd><mtd><mi>d</mi></mtd></mtr></mtable><mo>|</mo></mrow><mo>=</mo><mi>a</mi><mi>d</mi><mo>&#x2212;</mo><mi>b</mi><mi>c</mi></math>',
94
+ :html => '<span class="math-inline"><span class="math-row"><span class="math-row"><span class="math-brace" style="font-size: 200%;">|</span><span class="math-matrix" style="grid-template-columns:repeat(2,1fr);grid-template-rows:repeat(2,1fr);"><span class="math-row"><span class="math-identifier">a</span></span><span class="math-row"><span class="math-identifier">b</span></span><span class="math-row"><span class="math-identifier">c</span></span><span class="math-row"><span class="math-identifier">d</span></span></span><span class="math-brace" style="font-size: 200%;">|</span></span><span class="math-operator">=</span><span class="math-identifier">a</span><span class="math-identifier">d</span><span class="math-operator">&#x2212;</span><span class="math-identifier">b</span><span class="math-identifier">c</span></span></span>'
95
+ },
41
96
  '((a_(11), cdots , a_(1n)),(vdots, ddots, vdots),(a_(m1), cdots , a_(mn)))' =>
42
- '<math><mrow><mo>(</mo><mtable><mtr><mtd><msub><mi>a</mi><mn>11</mn></msub></mtd><mtd><mo>&#x22EF;</mo></mtd><mtd><msub><mi>a</mi><mrow><mn>1</mn><mi>n</mi></mrow></msub></mtd></mtr><mtr><mtd><mo>&#x22EE;</mo></mtd><mtd><mo>&#x22F1;</mo></mtd><mtd><mo>&#x22EE;</mo></mtd></mtr><mtr><mtd><msub><mi>a</mi><mrow><mi>m</mi><mn>1</mn></mrow></msub></mtd><mtd><mo>&#x22EF;</mo></mtd><mtd><msub><mi>a</mi><mrow><mi>m</mi><mi>n</mi></mrow></msub></mtd></mtr></mtable><mo>)</mo></mrow></math>',
97
+ {
98
+ :mathml => '<math><mrow><mo>(</mo><mtable><mtr><mtd><msub><mi>a</mi><mn>11</mn></msub></mtd><mtd><mo>&#x22EF;</mo></mtd><mtd><msub><mi>a</mi><mrow><mn>1</mn><mi>n</mi></mrow></msub></mtd></mtr><mtr><mtd><mo>&#x22EE;</mo></mtd><mtd><mo>&#x22F1;</mo></mtd><mtd><mo>&#x22EE;</mo></mtd></mtr><mtr><mtd><msub><mi>a</mi><mrow><mi>m</mi><mn>1</mn></mrow></msub></mtd><mtd><mo>&#x22EF;</mo></mtd><mtd><msub><mi>a</mi><mrow><mi>m</mi><mi>n</mi></mrow></msub></mtd></mtr></mtable><mo>)</mo></mrow></math>',
99
+ :html => '<span class="math-inline"><span class="math-row"><span class="math-row"><span class="math-brace" style="font-size: 300%;">(</span><span class="math-matrix" style="grid-template-columns:repeat(3,1fr);grid-template-rows:repeat(3,1fr);"><span class="math-row"><span class="math-identifier">a</span><span class="math-subsup"><span class="math-smaller">&zwj;</span><span class="math-smaller"><span class="math-row"><span class="math-number">11</span></span></span></span></span><span class="math-row"><span class="math-operator">&#x22EF;</span></span><span class="math-row"><span class="math-identifier">a</span><span class="math-subsup"><span class="math-smaller">&zwj;</span><span class="math-smaller"><span class="math-row"><span class="math-number">1</span><span class="math-identifier">n</span></span></span></span></span><span class="math-row"><span class="math-operator">&#x22EE;</span></span><span class="math-row"><span class="math-operator">&#x22F1;</span></span><span class="math-row"><span class="math-operator">&#x22EE;</span></span><span class="math-row"><span class="math-identifier">a</span><span class="math-subsup"><span class="math-smaller">&zwj;</span><span class="math-smaller"><span class="math-row"><span class="math-identifier">m</span><span class="math-number">1</span></span></span></span></span><span class="math-row"><span class="math-operator">&#x22EF;</span></span><span class="math-row"><span class="math-identifier">a</span><span class="math-subsup"><span class="math-smaller">&zwj;</span><span class="math-smaller"><span class="math-row"><span class="math-identifier">m</span><span class="math-identifier">n</span></span></span></span></span></span><span class="math-brace" style="font-size: 300%;">)</span></span></span></span>'
100
+ },
43
101
  'sum_(k=1)^n k = 1+2+ cdots +n=(n(n+1))/2' =>
44
- '<math><munderover><mo>&#x2211;</mo><mrow><mi>k</mi><mo>=</mo><mn>1</mn></mrow><mi>n</mi></munderover><mi>k</mi><mo>=</mo><mn>1</mn><mo>+</mo><mn>2</mn><mo>+</mo><mo>&#x22EF;</mo><mo>+</mo><mi>n</mi><mo>=</mo><mfrac><mrow><mi>n</mi><mrow><mo>(</mo><mi>n</mi><mo>+</mo><mn>1</mn><mo>)</mo></mrow></mrow><mn>2</mn></mfrac></math>',
102
+ {
103
+ :mathml => '<math><munderover><mo>&#x2211;</mo><mrow><mi>k</mi><mo>=</mo><mn>1</mn></mrow><mi>n</mi></munderover><mi>k</mi><mo>=</mo><mn>1</mn><mo>+</mo><mn>2</mn><mo>+</mo><mo>&#x22EF;</mo><mo>+</mo><mi>n</mi><mo>=</mo><mfrac><mrow><mi>n</mi><mrow><mo>(</mo><mi>n</mi><mo>+</mo><mn>1</mn><mo>)</mo></mrow></mrow><mn>2</mn></mfrac></math>',
104
+ :html => '<span class="math-inline"><span class="math-row"><span class="math-blank">&zwj;</span><span class="math-underover"><span class="math-smaller"><span class="math-identifier">n</span></span><span class="math-operator">&#x2211;</span><span class="math-smaller"><span class="math-row"><span class="math-identifier">k</span><span class="math-operator">=</span><span class="math-number">1</span></span></span></span><span class="math-identifier">k</span><span class="math-operator">=</span><span class="math-number">1</span><span class="math-operator">+</span><span class="math-number">2</span><span class="math-operator">+</span><span class="math-operator">&#x22EF;</span><span class="math-operator">+</span><span class="math-identifier">n</span><span class="math-operator">=</span><span class="math-blank">&zwj;</span><span class="math-fraction"><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-row"><span class="math-identifier">n</span><span class="math-row"><span class="math-brace">(</span><span class="math-row"><span class="math-identifier">n</span><span class="math-operator">+</span><span class="math-number">1</span></span><span class="math-brace">)</span></span></span></span></span></span></span><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-number">2</span></span></span></span></span></span></span></span>'
105
+ },
45
106
  '"Скорость"=("Расстояние")/("Время")' =>
46
- '<math><mtext>Скорость</mtext><mo>=</mo><mfrac><mtext>Расстояние</mtext><mtext>Время</mtext></mfrac></math>',
107
+ {
108
+ :mathml => '<math><mtext>Скорость</mtext><mo>=</mo><mfrac><mtext>Расстояние</mtext><mtext>Время</mtext></mfrac></math>',
109
+ :html => '<span class="math-inline"><span class="math-row"><span class="math-text">Скорость</span><span class="math-operator">=</span><span class="math-blank">&zwj;</span><span class="math-fraction"><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-row"><span class="math-text">Расстояние</span></span></span></span></span></span><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-row"><span class="math-text">Время</span></span></span></span></span></span></span></span></span>'
110
+ },
47
111
  'bb (a + b) + cc c = fr (d^n)' =>
48
- '<math><mstyle mathvariant=\"bold\"><mrow><mi>a</mi><mo>+</mo><mi>b</mi></mrow></mstyle><mo>+</mo><mstyle mathvariant=\"script\"><mi>c</mi></mstyle><mo>=</mo><mstyle mathvariant=\"fraktur\"><msup><mi>d</mi><mi>n</mi></msup></mstyle></math>'
112
+ {
113
+ :mathml => '<math><mstyle mathvariant="bold"><mrow><mi>a</mi><mo>+</mo><mi>b</mi></mrow></mstyle><mo>+</mo><mstyle mathvariant="script"><mi>c</mi></mstyle><mo>=</mo><mstyle mathvariant="fraktur"><msup><mi>d</mi><mi>n</mi></msup></mstyle></math>',
114
+ :html => 'Unsupported'
115
+ }
49
116
  }
50
117
 
51
118
  version = RUBY_VERSION.split('.').map { |s| s.to_i }
52
119
 
53
120
  if version[0] > 1 || version[1] > 8
54
- TEST_CASES['Скорость=(Расстояние)/(Время)'] = '<math><mi>С</mi><mi>к</mi><mi>о</mi><mi>р</mi><mi>о</mi><mi>с</mi><mi>т</mi><mi>ь</mi><mo>=</mo><mfrac><mrow><mi>Р</mi><mi>а</mi><mi>с</mi><mi>с</mi><mi>т</mi><mi>о</mi><mi>я</mi><mi>н</mi><mi>и</mi><mi>е</mi></mrow><mrow><mi>В</mi><mi>р</mi><mi>е</mi><mi>м</mi><mi>я</mi></mrow></mfrac></math>'
121
+ TEST_CASES['Скорость=(Расстояние)/(Время)'] =
122
+ {
123
+ :mathml => '<math><mi>С</mi><mi>к</mi><mi>о</mi><mi>р</mi><mi>о</mi><mi>с</mi><mi>т</mi><mi>ь</mi><mo>=</mo><mfrac><mrow><mi>Р</mi><mi>а</mi><mi>с</mi><mi>с</mi><mi>т</mi><mi>о</mi><mi>я</mi><mi>н</mi><mi>и</mi><mi>е</mi></mrow><mrow><mi>В</mi><mi>р</mi><mi>е</mi><mi>м</mi><mi>я</mi></mrow></mfrac></math>',
124
+ :html => '<span class="math-inline"><span class="math-row"><span class="math-identifier">С</span><span class="math-identifier">к</span><span class="math-identifier">о</span><span class="math-identifier">р</span><span class="math-identifier">о</span><span class="math-identifier">с</span><span class="math-identifier">т</span><span class="math-identifier">ь</span><span class="math-operator">=</span><span class="math-blank">&zwj;</span><span class="math-fraction"><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-row"><span class="math-identifier">Р</span><span class="math-identifier">а</span><span class="math-identifier">с</span><span class="math-identifier">с</span><span class="math-identifier">т</span><span class="math-identifier">о</span><span class="math-identifier">я</span><span class="math-identifier">н</span><span class="math-identifier">и</span><span class="math-identifier">е</span></span></span></span></span></span><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-row"><span class="math-identifier">В</span><span class="math-identifier">р</span><span class="math-identifier">е</span><span class="math-identifier">м</span><span class="math-identifier">я</span></span></span></span></span></span></span></span></span>'
125
+ }
55
126
  end
56
127
 
57
128
  module AsciiMathHelper
58
129
  def expect_mathml(asciimath, mathml)
59
130
  expect(AsciiMath.parse(asciimath).to_mathml).to eq(mathml)
60
131
  end
132
+
133
+ def expect_html(asciimath, html)
134
+ expect(AsciiMath.parse(asciimath).to_html).to eq(html)
135
+ end
61
136
  end
62
137
 
63
138
  RSpec.configure do |c|
@@ -65,9 +140,14 @@ RSpec.configure do |c|
65
140
  end
66
141
 
67
142
  describe "AsciiMath::MathMLBuilder" do
68
- TEST_CASES.each_pair do |asciimath, mathml|
143
+ TEST_CASES.each_pair do |asciimath, output|
69
144
  it "should produce identical output to asciimathml.js for '#{asciimath}'" do
70
- expect_mathml(asciimath, mathml)
145
+ expect_mathml(asciimath, output[:mathml])
146
+ end
147
+ if output[:html] != "Unsupported"
148
+ it "should produce html that looks like the output from asciimathml.js for '#{asciimath}'" do
149
+ expect_html(asciimath, output[:html])
150
+ end
71
151
  end
72
152
  end
73
153
 
@@ -0,0 +1,67 @@
1
+ .math-fraction {
2
+ display: table;
3
+ border-collapse: collapse;
4
+ border-style: hidden;
5
+ }
6
+ .math-fraction_row {
7
+ display: table-row;
8
+ }
9
+ .math-fraction_cell {
10
+ display: table-cell;
11
+ border: 0.5px solid black;
12
+ text-align: center;
13
+ }
14
+ .math-block {
15
+ font-family: serif;
16
+ display: flex;
17
+ justify-content: center;
18
+ }
19
+ .math-inline {
20
+ font-family: serif;
21
+ display: inline-flex;
22
+ align-content: center;
23
+ }
24
+ .math-underover {
25
+ display: flex;
26
+ flex-direction: column;
27
+ align-items: center;
28
+ justify-content: center;
29
+ line-height:60%;
30
+ }
31
+ .math-subsup {
32
+ display: flex;
33
+ flex-direction: column;
34
+ align-items: center;
35
+ justify-content: center;
36
+ }
37
+ .math-row {
38
+ display: flex;
39
+ flex-direction: row;
40
+ align-items: center;
41
+ justify-content: center;
42
+ }
43
+ .math-matrix {
44
+ display: grid;
45
+ align-items: center;
46
+ justify-items: center;
47
+ }
48
+
49
+ .math-identifier,
50
+ .math-operator,
51
+ .math-text,
52
+ .math-number {
53
+ margin-right: 0.1em;
54
+ margin-left: 0.1em;
55
+ }
56
+ .math-smaller {
57
+ font-size: 75%;
58
+ }
59
+ .math-identifier {
60
+ font-style: italic;
61
+ }
62
+ .math-brace {
63
+ transform: scale(0.5,1.0);
64
+ }
65
+ .math-blank {
66
+ align-self: center;
67
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciimath
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pepijn Van Eeckhoudt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-12 00:00:00.000000000 Z
11
+ date: 2018-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -71,10 +71,12 @@ files:
71
71
  - bin/asciimath
72
72
  - lib/asciimath.rb
73
73
  - lib/asciimath/cli.rb
74
+ - lib/asciimath/html.rb
74
75
  - lib/asciimath/mathml.rb
75
76
  - lib/asciimath/parser.rb
76
77
  - lib/asciimath/version.rb
77
78
  - spec/parser_spec.rb
79
+ - style/math.css
78
80
  homepage: ''
79
81
  licenses:
80
82
  - MIT
@@ -95,10 +97,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
97
  version: '0'
96
98
  requirements: []
97
99
  rubyforge_project:
98
- rubygems_version: 2.4.7
100
+ rubygems_version: 2.5.1
99
101
  signing_key:
100
102
  specification_version: 4
101
103
  summary: AsciiMath parser and converter
102
104
  test_files:
103
105
  - spec/parser_spec.rb
104
- has_rdoc: