asciimath 1.0.3 → 1.0.4
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 +4 -4
- data/CHANGELOG.adoc +31 -0
- data/{README.md → README.adoc} +21 -16
- data/lib/asciimath/mathml.rb +6 -1
- data/lib/asciimath/parser.rb +9 -2
- data/lib/asciimath/version.rb +1 -1
- data/spec/parser_spec.rb +3 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae64f8f21a57a2628a5e8ca6c04aaa15a7d6cae4
|
4
|
+
data.tar.gz: 88ffb4452dd16e56a9fc72876ecb0321f6724d82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d53d55278be758c46d356214fd764b07839a2e64eac67e333b1de409b3a29ff3e1341adeb4eb8d9db084617f3f686dc19b069fe3cc15795938fa9a257f96144
|
7
|
+
data.tar.gz: 4a8f1ac5d07d7776a232d763cd6b435274916319783bfb356a668db96af99f9b6892e3ace5445222cc9c3f6eee604628d9a0476a0c42c61601b9cfbe7c0e810e
|
data/CHANGELOG.adoc
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
= Asciimath Changelog
|
2
|
+
|
3
|
+
== 1.0.4
|
4
|
+
|
5
|
+
Enhancements::
|
6
|
+
|
7
|
+
* Add support for AsciiMath font commands
|
8
|
+
|
9
|
+
== 1.0.3
|
10
|
+
|
11
|
+
Bug Fixes::
|
12
|
+
|
13
|
+
* Issue #2: Correctly parse input strings containing multi-byte characters.
|
14
|
+
|
15
|
+
== 1.0.2
|
16
|
+
|
17
|
+
Bug Fixes::
|
18
|
+
|
19
|
+
* Issue #1: Resolve uninitialized instance variable warning
|
20
|
+
|
21
|
+
== 1.0.1
|
22
|
+
|
23
|
+
Enhancements::
|
24
|
+
|
25
|
+
* Make AsciiMath compatible with Ruby 1.8
|
26
|
+
|
27
|
+
== 1.0.0
|
28
|
+
|
29
|
+
Initial release::
|
30
|
+
|
31
|
+
* An AsciiMath parser and MathML converter written in Ruby
|
data/{README.md → README.adoc}
RENAMED
@@ -1,14 +1,15 @@
|
|
1
1
|
# AsciiMath
|
2
2
|
|
3
|
-
An
|
3
|
+
An http://asciimath.org[AsciiMath] parser and MathML generator written in pure Ruby.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
|
-
|
9
|
+
[source,ruby]
|
10
|
+
----
|
10
11
|
gem 'asciimath'
|
11
|
-
|
12
|
+
----
|
12
13
|
|
13
14
|
And then execute:
|
14
15
|
|
@@ -24,23 +25,26 @@ Or install it yourself as:
|
|
24
25
|
|
25
26
|
First require the library.
|
26
27
|
|
27
|
-
|
28
|
+
[source,ruby]
|
29
|
+
----
|
28
30
|
require 'asciimath'
|
29
|
-
|
31
|
+
----
|
30
32
|
|
31
33
|
Then parse an AsciiMath string.
|
32
34
|
|
33
|
-
|
35
|
+
[source,ruby]
|
36
|
+
----
|
34
37
|
parsed_expression = AsciiMath.parse(asciimath)
|
35
|
-
|
38
|
+
----
|
36
39
|
|
37
40
|
The parsed expression is a set of nested Array and Hash objects.
|
38
41
|
|
39
42
|
This expression can then be converted to MathML.
|
40
43
|
|
41
|
-
|
44
|
+
[source,ruby]
|
45
|
+
----
|
42
46
|
math_ml = parsed_expression.to_mathml
|
43
|
-
|
47
|
+
----
|
44
48
|
|
45
49
|
The MathML code is returned as a String.
|
46
50
|
|
@@ -48,16 +52,17 @@ The MathML code is returned as a String.
|
|
48
52
|
|
49
53
|
The AsciiMath parser and MathML converter can be invoked via the command line as follows:
|
50
54
|
|
51
|
-
|
55
|
+
[source]
|
56
|
+
----
|
52
57
|
asciimath "an asciimath string"
|
53
|
-
|
58
|
+
----
|
54
59
|
|
55
60
|
This command will print out the generated MathML code on stdout.
|
56
61
|
|
57
62
|
## Contributing
|
58
63
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
+
. Fork it (https://github.com/pepijnve/asciimath/fork)
|
65
|
+
. Create your feature branch (`git checkout -b my-new-feature`)
|
66
|
+
. Commit your changes (`git commit -am 'Add some feature'`)
|
67
|
+
. Push to the branch (`git push origin my-new-feature`)
|
68
|
+
. Create a new Pull Request
|
data/lib/asciimath/mathml.rb
CHANGED
@@ -54,6 +54,11 @@ module AsciiMath
|
|
54
54
|
else
|
55
55
|
append(expression[:e])
|
56
56
|
end
|
57
|
+
when :font
|
58
|
+
style = expression[:operator]
|
59
|
+
tag("mstyle", :mathvariant => style.to_s.gsub('_', '-')) do
|
60
|
+
append(expression[:s], :single_child => true, :strip_paren => true)
|
61
|
+
end
|
57
62
|
when :unary
|
58
63
|
operator = expression[:operator]
|
59
64
|
tag("m#{operator}") do
|
@@ -103,7 +108,7 @@ module AsciiMath
|
|
103
108
|
@mathml << '<' << @prefix << tag.to_s
|
104
109
|
|
105
110
|
attrs.each_pair do |key, value|
|
106
|
-
@mathml << ' ' << key << '="' << value << '"'
|
111
|
+
@mathml << ' ' << key.to_s << '="' << value.to_s << '"'
|
107
112
|
end
|
108
113
|
|
109
114
|
|
data/lib/asciimath/parser.rb
CHANGED
@@ -38,6 +38,7 @@ module AsciiMath
|
|
38
38
|
# - :number a number
|
39
39
|
# - :operator a mathematical operator symbol
|
40
40
|
# - :unary a unary operator (e.g., sqrt, text, ...)
|
41
|
+
# - :font a unary font command (e.g., bb, cc, ...)
|
41
42
|
# - :infix an infix operator (e.g, /, _, ^, ...)
|
42
43
|
# - :binary a binary operator (e.g., frac, root, ...)
|
43
44
|
# - :accent an accent character
|
@@ -350,6 +351,12 @@ module AsciiMath
|
|
350
351
|
# Other
|
351
352
|
'sqrt' => {:value => :sqrt, :type => :unary},
|
352
353
|
'text' => {:value => :text, :type => :unary},
|
354
|
+
'bb' => {:value => :bold, :type => :font},
|
355
|
+
'bbb' => {:value => :double_struck, :type => :font},
|
356
|
+
'cc' => {:value => :script, :type => :font},
|
357
|
+
'tt' => {:value => :monospace, :type => :font},
|
358
|
+
'fr' => {:value => :fraktur, :type => :font},
|
359
|
+
'sf' => {:value => :sans_serif, :type => :font},
|
353
360
|
'frac' => {:value => :frac, :type => :binary},
|
354
361
|
'root' => {:value => :root, :type => :binary},
|
355
362
|
'stackrel' => {:value => :over, :type => :binary},
|
@@ -481,9 +488,9 @@ module AsciiMath
|
|
481
488
|
when :accent
|
482
489
|
s = parse_simple_expression(tok, depth)
|
483
490
|
{:type => :binary, :s1 => s, :s2 => {:type => :operator, :c => t1[:value]}, :operator => t1[:position]}
|
484
|
-
when :unary
|
491
|
+
when :unary, :font
|
485
492
|
s = parse_simple_expression(tok, depth)
|
486
|
-
{:type => :
|
493
|
+
{:type => t1[:type], :s => s, :operator => t1[:value]}
|
487
494
|
when :binary
|
488
495
|
s1 = parse_simple_expression(tok, depth)
|
489
496
|
s2 = parse_simple_expression(tok, depth)
|
data/lib/asciimath/version.rb
CHANGED
data/spec/parser_spec.rb
CHANGED
@@ -43,7 +43,9 @@ TEST_CASES = {
|
|
43
43
|
'sum_(k=1)^n k = 1+2+ cdots +n=(n(n+1))/2' =>
|
44
44
|
'<math><munderover><mo>∑</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>⋯</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>',
|
45
45
|
'"Скорость"=("Расстояние")/("Время")' =>
|
46
|
-
'<math><mtext>Скорость</mtext><mo>=</mo><mfrac><mtext>Расстояние</mtext><mtext>Время</mtext></mfrac></math>'
|
46
|
+
'<math><mtext>Скорость</mtext><mo>=</mo><mfrac><mtext>Расстояние</mtext><mtext>Время</mtext></mfrac></math>',
|
47
|
+
'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>'
|
47
49
|
}
|
48
50
|
|
49
51
|
version = RUBY_VERSION.split('.').map { |s| s.to_i }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asciimath
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pepijn Van Eeckhoudt
|
@@ -62,9 +62,10 @@ extra_rdoc_files: []
|
|
62
62
|
files:
|
63
63
|
- ".gitignore"
|
64
64
|
- ".travis.yml"
|
65
|
+
- CHANGELOG.adoc
|
65
66
|
- Gemfile
|
66
67
|
- LICENSE.txt
|
67
|
-
- README.
|
68
|
+
- README.adoc
|
68
69
|
- Rakefile
|
69
70
|
- asciimath.gemspec
|
70
71
|
- bin/asciimath
|