math_ml 0.9 → 0.10
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.
- data/Rakefile +17 -6
- data/Rakefile.utirake +62 -24
- data/lib/math_ml/latex/builtin/symbol.rb +549 -0
- data/lib/math_ml/latex/builtin.rb +5 -0
- data/lib/math_ml/latex.rb +20 -14
- data/lib/math_ml/symbol/character_reference.rb +2107 -0
- data/lib/math_ml/symbol/entity_reference.rb +2106 -0
- data/lib/math_ml/symbol/utf8.rb +2107 -0
- data/lib/math_ml.rb +2 -2
- data/spec/{math_ml_element_spec.rb → math_ml/element_spec.rb} +0 -0
- data/spec/{math_ml_latex_macro_spec.rb → math_ml/latex/macro_spec.rb} +0 -0
- data/spec/{math_ml_latex_parser_spec.rb → math_ml/latex/parser_spec.rb} +85 -1
- data/spec/{math_ml_latex_scanner_spec.rb → math_ml/latex/scanner_spec.rb} +0 -0
- data/spec/{math_ml_string_spec.rb → math_ml/string_spec.rb} +0 -0
- data/spec/{math_ml_util_spec.rb → math_ml/util_spec.rb} +0 -0
- data/spec/util.rb +13 -7
- metadata +20 -16
- data/lib/math_ml/latex/builtin_commands.rb +0 -547
data/lib/math_ml.rb
CHANGED
@@ -14,12 +14,12 @@ module MathML
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def self.pcstring(s, encoded=false)
|
17
|
-
EimXML::PCString.new(s, encoded)
|
17
|
+
s.is_a?(EimXML::PCString) ? s : EimXML::PCString.new(s, encoded)
|
18
18
|
end
|
19
19
|
|
20
20
|
class Error < StandardError; end
|
21
21
|
end
|
22
22
|
|
23
23
|
require "math_ml/element"
|
24
|
+
require "math_ml/symbol/entity_reference"
|
24
25
|
require "math_ml/latex"
|
25
|
-
require "math_ml/latex/builtin_commands"
|
File without changes
|
File without changes
|
@@ -2,6 +2,8 @@ require "eim_xml/parser"
|
|
2
2
|
require "eim_xml/dsl"
|
3
3
|
require "math_ml"
|
4
4
|
require "spec/util"
|
5
|
+
require "math_ml/symbol/character_reference"
|
6
|
+
require "math_ml/symbol/utf8"
|
5
7
|
|
6
8
|
describe MathML::LaTeX::Parser do
|
7
9
|
include MathML::Spec::Util
|
@@ -473,7 +475,89 @@ EOS
|
|
473
475
|
end
|
474
476
|
|
475
477
|
it "should parse symbols" do
|
476
|
-
smml('\precneqq').should == "<mo
|
478
|
+
smml('\precneqq').should == "<mo>⪵</mo>"
|
479
|
+
end
|
480
|
+
end
|
481
|
+
|
482
|
+
context ".new should accept symbol table" do
|
483
|
+
it "character reference" do
|
484
|
+
@parser = MathML::LaTeX::Parser.new(:symbol=>MathML::Symbol::CharacterReference)
|
485
|
+
smml('\alpha').should == "<mi>α</mi>"
|
486
|
+
smml('\mathbb{abcABC}').should == "<mrow><mrow><mi>𝕒</mi><mi>𝕓</mi><mi>𝕔</mi><mi>𝔸</mi><mi>𝔹</mi><mi>ℂ</mi></mrow></mrow>"
|
487
|
+
smml('\mathscr{abcABC}').should == "<mrow><mrow><mi>𝒶</mi><mi>𝒷</mi><mi>𝒸</mi><mi>𝒜</mi><mi>ℬ</mi><mi>𝒞</mi></mrow></mrow>"
|
488
|
+
smml('\mathfrak{abcABC}').should == "<mrow><mrow><mi>𝔞</mi><mi>𝔟</mi><mi>𝔠</mi><mi>𝔄</mi><mi>𝔅</mi><mi>ℭ</mi></mrow></mrow>"
|
489
|
+
end
|
490
|
+
|
491
|
+
it "utf8" do
|
492
|
+
@parser = MathML::LaTeX::Parser.new(:symbol=>MathML::Symbol::UTF8)
|
493
|
+
smml('\alpha').should == "<mi>α</mi>"
|
494
|
+
smml('\mathbb{abcABC}').should == "<mrow><mrow><mi>𝕒</mi><mi>𝕓</mi><mi>𝕔</mi><mi>𝔸</mi><mi>𝔹</mi><mi>ℂ</mi></mrow></mrow>"
|
495
|
+
smml('\mathscr{abcABC}').should == "<mrow><mrow><mi>𝒶</mi><mi>𝒷</mi><mi>𝒸</mi><mi>𝒜</mi><mi>ℬ</mi><mi>𝒞</mi></mrow></mrow>"
|
496
|
+
smml('\mathfrak{abcABC}').should == "<mrow><mrow><mi>𝔞</mi><mi>𝔟</mi><mi>𝔠</mi><mi>𝔄</mi><mi>𝔅</mi><mi>ℭ</mi></mrow></mrow>"
|
497
|
+
end
|
498
|
+
end
|
499
|
+
|
500
|
+
context "#symbol_table" do
|
501
|
+
it "should return when .new was given name of symbol-module" do
|
502
|
+
ps = MathML::LaTeX::Parser
|
503
|
+
symbol = MathML::Symbol
|
504
|
+
|
505
|
+
ps.new(:symbol=>symbol::UTF8).symbol_table.should == symbol::UTF8
|
506
|
+
ps.new(:symbol=>symbol::EntityReference).symbol_table.should == symbol::EntityReference
|
507
|
+
ps.new(:symbol=>symbol::CharacterReference).symbol_table.should == symbol::CharacterReference
|
508
|
+
|
509
|
+
ps.new(:symbol=>:utf8).symbol_table.should == symbol::UTF8
|
510
|
+
ps.new(:symbol=>:entity).symbol_table.should == symbol::EntityReference
|
511
|
+
ps.new(:symbol=>:character).symbol_table.should == symbol::CharacterReference
|
512
|
+
|
513
|
+
ps.new.symbol_table.should == symbol::EntityReference
|
514
|
+
ps.new(:symbol=>nil).symbol_table.should == symbol::EntityReference
|
515
|
+
end
|
516
|
+
|
517
|
+
context "should return default symbol module" do
|
518
|
+
before do
|
519
|
+
@loaded_features = $LOADED_FEATURES.dup
|
520
|
+
$LOADED_FEATURES.delete_if{|i| i=~/math_ml/}
|
521
|
+
if ::Object.const_defined?(:MathML)
|
522
|
+
@MathML = ::Object.const_get(:MathML)
|
523
|
+
::Object.module_eval{remove_const(:MathML)}
|
524
|
+
end
|
525
|
+
end
|
526
|
+
|
527
|
+
after do
|
528
|
+
$LOADED_FEATURES.clear
|
529
|
+
$LOADED_FEATURES.push(@loaded_features.shift) until @loaded_features.empty?
|
530
|
+
if @MathML
|
531
|
+
::Object.module_eval{remove_const(:MathML)}
|
532
|
+
::Object.const_set(:MathML, @MathML)
|
533
|
+
end
|
534
|
+
end
|
535
|
+
|
536
|
+
it "character entity reference version by default" do
|
537
|
+
require("math_ml").should be_true
|
538
|
+
MathML::LaTeX::Parser.new.symbol_table.should == MathML::Symbol::EntityReference
|
539
|
+
end
|
540
|
+
|
541
|
+
describe "character entity reference version when set by requiring" do
|
542
|
+
it do
|
543
|
+
require("math_ml/symbol/entity_reference").should be_true
|
544
|
+
MathML::LaTeX::Parser.new.symbol_table.should == MathML::Symbol::EntityReference
|
545
|
+
end
|
546
|
+
end
|
547
|
+
|
548
|
+
describe "utf8 version when set by requiring" do
|
549
|
+
it do
|
550
|
+
require("math_ml/symbol/utf8").should be_true
|
551
|
+
MathML::LaTeX::Parser.new.symbol_table.should == MathML::Symbol::UTF8
|
552
|
+
end
|
553
|
+
end
|
554
|
+
|
555
|
+
describe "numeric character reference version when set by requiring" do
|
556
|
+
it do
|
557
|
+
require("math_ml/symbol/character_reference").should be_true
|
558
|
+
MathML::LaTeX::Parser.new.symbol_table.should == MathML::Symbol::CharacterReference
|
559
|
+
end
|
560
|
+
end
|
477
561
|
end
|
478
562
|
end
|
479
563
|
end
|
File without changes
|
File without changes
|
File without changes
|
data/spec/util.rb
CHANGED
@@ -1,13 +1,19 @@
|
|
1
|
+
require "rspec"
|
1
2
|
module MathML
|
2
3
|
module Spec
|
3
4
|
module Util
|
4
5
|
def raise_parse_error(message, done, rest)
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
RSpec::Matchers::Matcher.new(:raise_parse_error) do
|
7
|
+
match do |given|
|
8
|
+
begin
|
9
|
+
given.call
|
10
|
+
@error = nil
|
11
|
+
rescue Exception
|
12
|
+
@error = $!
|
13
|
+
end
|
14
|
+
@error.is_a?(MathML::LaTeX::ParseError) &&
|
15
|
+
[@error.message, @error.done, @error.rest] == [message, done, rest]
|
16
|
+
end
|
11
17
|
end
|
12
18
|
end
|
13
19
|
|
@@ -16,7 +22,7 @@ module MathML
|
|
16
22
|
end
|
17
23
|
|
18
24
|
def math_ml(src, display_style=false, parser=nil)
|
19
|
-
parser ||= new_parser
|
25
|
+
parser ||= @parser || new_parser
|
20
26
|
parser.parse(src, display_style)
|
21
27
|
end
|
22
28
|
|
metadata
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: math_ml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: "0.
|
8
|
+
- 10
|
9
|
+
version: "0.10"
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- KURODA Hiraku
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-12-12 00:00:00 +09:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -40,22 +40,26 @@ extensions: []
|
|
40
40
|
extra_rdoc_files: []
|
41
41
|
|
42
42
|
files:
|
43
|
-
- Rakefile.utirake
|
44
43
|
- Rakefile
|
45
|
-
-
|
46
|
-
- lib/math_ml/
|
44
|
+
- Rakefile.utirake
|
45
|
+
- lib/math_ml/element.rb
|
46
|
+
- lib/math_ml/string.rb
|
47
47
|
- lib/math_ml/util.rb
|
48
48
|
- lib/math_ml/latex.rb
|
49
|
-
- lib/math_ml/
|
50
|
-
- lib/math_ml/
|
51
|
-
-
|
52
|
-
-
|
53
|
-
-
|
54
|
-
-
|
55
|
-
- spec/math_ml_latex_macro_spec.rb
|
56
|
-
- spec/math_ml_util_spec.rb
|
49
|
+
- lib/math_ml/latex/builtin.rb
|
50
|
+
- lib/math_ml/latex/builtin/symbol.rb
|
51
|
+
- lib/math_ml/symbol/character_reference.rb
|
52
|
+
- lib/math_ml/symbol/entity_reference.rb
|
53
|
+
- lib/math_ml/symbol/utf8.rb
|
54
|
+
- lib/math_ml.rb
|
57
55
|
- spec/math_ml_spec.rb
|
58
|
-
- spec/
|
56
|
+
- spec/math_ml/element_spec.rb
|
57
|
+
- spec/math_ml/util_spec.rb
|
58
|
+
- spec/math_ml/string_spec.rb
|
59
|
+
- spec/math_ml/latex/macro_spec.rb
|
60
|
+
- spec/math_ml/latex/scanner_spec.rb
|
61
|
+
- spec/math_ml/latex/parser_spec.rb
|
62
|
+
- spec/util.rb
|
59
63
|
has_rdoc: true
|
60
64
|
homepage: http://mathml.rubyforge.org/
|
61
65
|
licenses: []
|