mathml2asciimath 0.0.9 → 0.0.13
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/.github/workflows/rake.yml +32 -0
- data/.gitignore +1 -0
- data/.hound.yml +3 -1
- data/.rubocop.yml +7 -7
- data/Gemfile +1 -2
- data/README.adoc +6 -6
- data/Rakefile +1 -1
- data/bin/m2a.rb +5 -7
- data/bin/rspec +1 -1
- data/lib/mathml2asciimath/m2a.rb +208 -210
- data/lib/mathml2asciimath/version.rb +1 -2
- data/mathml2asciimath.gemspec +7 -7
- data/spec/mathml_spec.rb +329 -327
- data/spec/spec_helper.rb +6 -7
- metadata +37 -41
- data/.github/workflows/macos.yml +0 -31
- data/.github/workflows/ubuntu.yml +0 -43
- data/.github/workflows/windows.yml +0 -34
- data/.rubocop.ribose.yml +0 -65
- data/.rubocop.tb.yml +0 -650
- data/Gemfile.lock +0 -106
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a11fa790b22436b9f9d06a40d90264a67e2bef3fd08f02538daa01a16a4818f8
|
4
|
+
data.tar.gz: c017afbd1e64bb121517f6a508193d37d2157326b4aca00953d9764ca4920731
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b1371dffc46a011741a9d0544860327e2ce5ef275b7f0461bf00bc50d84d443af8c10760e2db75f32d7a1a3c6f57edfa986ea57df66065fc96ed5964c4fc545
|
7
|
+
data.tar.gz: 37ad642dd7ef784027a713433abdccf1d273d469dc3b24fcb1d74e0ef05e27f8c92eb4911605ca9d91fe14ba55c20e8366a056ba94eb54276b0ad6c4f36d4f84
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# Auto-generated by Cimas: Do not edit it manually!
|
2
|
+
# See https://github.com/metanorma/cimas
|
3
|
+
name: rake
|
4
|
+
|
5
|
+
on:
|
6
|
+
push:
|
7
|
+
branches: [ master, main ]
|
8
|
+
tags: [ v* ]
|
9
|
+
pull_request:
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
rake:
|
13
|
+
name: Test on Ruby ${{ matrix.ruby }} ${{ matrix.os }}
|
14
|
+
runs-on: ${{ matrix.os }}
|
15
|
+
continue-on-error: ${{ matrix.experimental }}
|
16
|
+
strategy:
|
17
|
+
fail-fast: false
|
18
|
+
matrix:
|
19
|
+
ruby: [ '3.0', '2.7', '2.6', '2.5' ]
|
20
|
+
os: [ ubuntu-latest, windows-latest, macos-latest ]
|
21
|
+
experimental: [ false ]
|
22
|
+
steps:
|
23
|
+
- uses: actions/checkout@v2
|
24
|
+
with:
|
25
|
+
submodules: true
|
26
|
+
|
27
|
+
- uses: ruby/setup-ruby@v1
|
28
|
+
with:
|
29
|
+
ruby-version: ${{ matrix.ruby }}
|
30
|
+
bundler-cache: true
|
31
|
+
|
32
|
+
- run: bundle exec rake
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
.rubocop-https--*
|
data/.hound.yml
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
#
|
2
|
-
# https://github.com/
|
3
|
-
# All project-specific additions and overrides should be specified in this file.
|
4
|
-
|
1
|
+
# Auto-generated by Cimas: Do not edit it manually!
|
2
|
+
# See https://github.com/metanorma/cimas
|
5
3
|
inherit_from:
|
6
4
|
- https://raw.githubusercontent.com/riboseinc/oss-guides/master/ci/rubocop.yml
|
5
|
+
|
6
|
+
# local repo-specific modifications
|
7
|
+
# ...
|
8
|
+
|
7
9
|
AllCops:
|
8
|
-
TargetRubyVersion: 2.
|
9
|
-
Rails:
|
10
|
-
Enabled: true
|
10
|
+
TargetRubyVersion: 2.5
|
data/Gemfile
CHANGED
data/README.adoc
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
= mathml2asciimath
|
2
2
|
|
3
3
|
image:https://img.shields.io/gem/v/mathml2asciimath.svg["Gem Version", link="https://rubygems.org/gems/mathml2asciimath"]
|
4
|
-
image:https://github.com/
|
5
|
-
image:https://github.com/
|
6
|
-
image:https://github.com/
|
7
|
-
image:https://codeclimate.com/github/
|
8
|
-
image:https://img.shields.io/github/issues-pr-raw/
|
9
|
-
image:https://img.shields.io/github/commits-since/
|
4
|
+
image:https://github.com/plurimath/mathml2asciimath/workflows/ubuntu/badge.svg["Ubuntu Build Status", link="https://github.com/plurimath/mathml2asciimath/actions?query=workflow%3Aubuntu"]
|
5
|
+
image:https://github.com/plurimath/mathml2asciimath/workflows/macos/badge.svg["OSX Build Status", link="https://github.com/plurimath/mathml2asciimath/actions?query=workflow%3Amacos"]
|
6
|
+
image:https://github.com/plurimath/mathml2asciimath/workflows/windows/badge.svg["Windows Build Status", link="https://github.com/plurimath/mathml2asciimath/actions?query=workflow%3Awindows"]
|
7
|
+
image:https://codeclimate.com/github/plurimath/mathml2asciimath/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/plurimath/mathml2asciimath"]
|
8
|
+
image:https://img.shields.io/github/issues-pr-raw/plurimath/mathml2asciimath.svg["Pull Requests", link="https://github.com/plurimath/mathml2asciimath/pulls"]
|
9
|
+
image:https://img.shields.io/github/commits-since/plurimath/mathml2asciimath/latest.svg["Commits since latest",link="https://github.com/plurimath/mathml2asciimath/releases"]
|
10
10
|
|
11
11
|
Ruby gem to convert MathML into AsciiMath
|
12
12
|
|
data/Rakefile
CHANGED
data/bin/m2a.rb
CHANGED
@@ -5,13 +5,11 @@ while a = gets
|
|
5
5
|
matches = a.split(%r{(<math.*?</math>)})
|
6
6
|
out = ""
|
7
7
|
matches.each do |x|
|
8
|
-
if /<math/.match x
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
out += if /<math/.match? x
|
9
|
+
MathML2AsciiMath.m2a(x)
|
10
|
+
else
|
11
|
+
x
|
12
|
+
end
|
13
13
|
end
|
14
14
|
print out
|
15
15
|
end
|
16
|
-
|
17
|
-
|
data/bin/rspec
CHANGED
data/lib/mathml2asciimath/m2a.rb
CHANGED
@@ -3,161 +3,172 @@ require "htmlentities"
|
|
3
3
|
require "pp"
|
4
4
|
|
5
5
|
module MathML2AsciiMath
|
6
|
+
def self.m2a(xml)
|
7
|
+
normalized = xml
|
6
8
|
|
7
|
-
|
8
|
-
docxml = Nokogiri::XML(
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
# &:noblanks skips non-significant whitespaces in MathML
|
10
|
+
docxml = Nokogiri::XML.parse(normalized, &:noblanks)
|
11
|
+
|
12
|
+
# Get rid of things like
|
13
|
+
# <mtext> </mtext>
|
14
|
+
parse(docxml.root).gsub(/[[:blank:]]/, " ").unicode_normalize.squeeze(" ")
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.encodechars(xml)
|
18
|
+
xml.gsub(/\u03b1/, "alpha")
|
19
|
+
.gsub(/\u03b2/, "beta")
|
20
|
+
.gsub(/\u03b3/, "gamma")
|
21
|
+
.gsub(/\u0393/, "Gamma")
|
22
|
+
.gsub(/\u03b4/, "delta")
|
23
|
+
.gsub(/\u0394/, "Delta")
|
24
|
+
.gsub(/\u2206/, "Delta")
|
25
|
+
.gsub(/\u03b5/, "epsilon")
|
26
|
+
.gsub(/\u025b/, "varepsilon")
|
27
|
+
.gsub(/\u03b6/, "zeta")
|
28
|
+
.gsub(/\u03b7/, "eta")
|
29
|
+
.gsub(/\u03b8/, "theta")
|
30
|
+
.gsub(/\u0398/, "Theta")
|
31
|
+
.gsub(/\u03d1/, "vartheta")
|
32
|
+
.gsub(/\u03b9/, "iota")
|
33
|
+
.gsub(/\u03ba/, "kappa")
|
34
|
+
.gsub(/\u03bb/, "lambda")
|
35
|
+
.gsub(/\u039b/, "Lambda")
|
36
|
+
.gsub(/\u03bc/, "mu")
|
37
|
+
.gsub(/\u03bd/, "nu")
|
38
|
+
.gsub(/\u03be/, "xi")
|
39
|
+
.gsub(/\u039e/, "Xi")
|
40
|
+
.gsub(/\u03c0/, "pi")
|
41
|
+
.gsub(/\u03a0/, "Pi")
|
42
|
+
.gsub(/\u03c1/, "rho")
|
43
|
+
.gsub(/\u03c2/, "beta")
|
44
|
+
.gsub(/\u03c3/, "sigma")
|
45
|
+
.gsub(/\u03a3/, "Sigma")
|
46
|
+
.gsub(/\u03c4/, "tau")
|
47
|
+
.gsub(/\u03c5/, "upsilon")
|
48
|
+
.gsub(/\u03c6/, "phi")
|
49
|
+
.gsub(/\u03a6/, "Phi")
|
50
|
+
.gsub(/\u03d5/, "varphi")
|
51
|
+
.gsub(/\u03c7/, "chi")
|
52
|
+
.gsub(/\u03c8/, "psi")
|
53
|
+
.gsub(/\u03a8/, "Psi")
|
54
|
+
.gsub(/\u03c9/, "omega")
|
55
|
+
.gsub(/\u03a9/, "omega")
|
56
|
+
.gsub(/\u22c5/, "*")
|
57
|
+
.gsub(/\u2219/, "*")
|
58
|
+
.gsub(/\u00b7/, "*")
|
59
|
+
.gsub(/\u2217/, "**")
|
60
|
+
.gsub(/\u22c6/, "***")
|
61
|
+
.gsub(/\//, "//")
|
62
|
+
.gsub(/\\/, "\\\\")
|
63
|
+
.gsub(/\u00d7/, "xx")
|
64
|
+
.gsub(/\u22c9/, "|><")
|
65
|
+
.gsub(/\u22ca/, "><|")
|
66
|
+
.gsub(/\u22c8/, "|><|")
|
67
|
+
.gsub(/\u00f7/, "-:")
|
68
|
+
.gsub(/\u2218/, "@")
|
69
|
+
.gsub(/\u2295/, "o+")
|
70
|
+
.gsub(/\u2a01/, "o+")
|
71
|
+
.gsub(/\u2297/, "ox")
|
72
|
+
.gsub(/\u2299/, "o.")
|
73
|
+
.gsub(/\u2211/, "sum")
|
74
|
+
.gsub(/\u220f/, "prod")
|
75
|
+
.gsub(/\u2227/, "^^")
|
76
|
+
.gsub(/\u22c0/, "^^^")
|
77
|
+
.gsub(/\u2228/, "vv")
|
78
|
+
.gsub(/\u22c1/, "vvv")
|
79
|
+
.gsub(/\u2229/, "nn")
|
80
|
+
.gsub(/\u22c2/, "nnn")
|
81
|
+
.gsub(/\u222a/, "uu")
|
82
|
+
.gsub(/\u22c3/, "uuu")
|
83
|
+
.gsub(/\u2260/, "!=")
|
84
|
+
.gsub(/\u2264/, "<=")
|
85
|
+
.gsub(/\u2265/, ">=")
|
86
|
+
.gsub(/\u227a/, "-<")
|
87
|
+
.gsub(/\u227b/, ">-")
|
88
|
+
.gsub(/\u2aaf/, "-<=")
|
89
|
+
.gsub(/\u2ab0/, ">-=")
|
90
|
+
.gsub(/\u2208/, "in")
|
91
|
+
.gsub(/\u2209/, "!in")
|
92
|
+
.gsub(/\u2282/, "sub")
|
93
|
+
.gsub(/\u2283/, "sup")
|
94
|
+
.gsub(/\u2286/, "sube")
|
95
|
+
.gsub(/\u2287/, "supe")
|
96
|
+
.gsub(/\u2261/, "-=")
|
97
|
+
.gsub(/\u2245/, "~=")
|
98
|
+
.gsub(/\u2248/, "~~")
|
99
|
+
.gsub(/\u221d/, "prop")
|
100
|
+
.gsub(/\u00ac/, "not")
|
101
|
+
.gsub(/\u21d2/, "=>")
|
102
|
+
.gsub(/\u21d4/, "<=>")
|
103
|
+
.gsub(/\u2200/, "AA")
|
104
|
+
.gsub(/\u2203/, "EE")
|
105
|
+
.gsub(/\u22a5/, "_|_")
|
106
|
+
.gsub(/\u22a4/, "TT")
|
107
|
+
.gsub(/\u22a2/, "|--")
|
108
|
+
.gsub(/\u22a8/, "|==")
|
109
|
+
.gsub(/\u22a8/, "|==")
|
110
|
+
.gsub(/\u2329/, "(:")
|
111
|
+
.gsub(/\u232a/, ":)")
|
112
|
+
.gsub(/\u2329/, "<<")
|
113
|
+
.gsub(/\u27e8/, "<<")
|
114
|
+
.gsub(/\u232a/, ">>")
|
115
|
+
.gsub(/\u27e9/, ">>")
|
116
|
+
.gsub(/\u222b/, "int")
|
117
|
+
.gsub(/\u222e/, "oint")
|
118
|
+
.gsub(/\u2202/, "del")
|
119
|
+
.gsub(/\u2207/, "grad")
|
120
|
+
.gsub(/\u00b1/, "+-")
|
121
|
+
.gsub(/\u2205/, "O/")
|
122
|
+
.gsub(/\u221e/, "oo")
|
123
|
+
.gsub(/\u2135/, "aleph")
|
124
|
+
.gsub(/\u2234/, ":.")
|
125
|
+
.gsub(/\u2235/, ":'")
|
126
|
+
.gsub(/\u2220/, "/_")
|
127
|
+
.gsub(/\u25b3/, "/_\\")
|
128
|
+
.gsub(/\u2032/, "'")
|
129
|
+
.gsub(/~/, "tilde")
|
130
|
+
.gsub(/\u00a0\u00a0\u00a0\u00a0/, "qquad")
|
131
|
+
.gsub(/\u00a0\u00a0/, "quad")
|
132
|
+
.gsub(/\u00a0/, "\\ ")
|
133
|
+
.gsub(/\u2322/, "frown")
|
134
|
+
.gsub(/\u00a0/, "quad")
|
135
|
+
.gsub(/\u22ef/, "cdots")
|
136
|
+
.gsub(/\u22ee/, "vdots")
|
137
|
+
.gsub(/\u22f1/, "ddots")
|
138
|
+
.gsub(/\u22c4/, "diamond")
|
139
|
+
.gsub(/\u25a1/, "square")
|
140
|
+
.gsub(/\u230a/, "|__")
|
141
|
+
.gsub(/\u230b/, "__|")
|
142
|
+
.gsub(/\u2308/, "|~")
|
143
|
+
.gsub(/\u2309/, "~|")
|
144
|
+
.gsub(/\u2102/, "CC")
|
145
|
+
.gsub(/\u2115/, "NN")
|
146
|
+
.gsub(/\u211a/, "QQ")
|
147
|
+
.gsub(/\u211d/, "RR")
|
148
|
+
.gsub(/\u2124/, "ZZ")
|
149
|
+
.gsub(/\u2191/, "uarr")
|
150
|
+
.gsub(/\u2193/, "darr")
|
151
|
+
.gsub(/\u2190/, "larr")
|
152
|
+
.gsub(/\u2194/, "harr")
|
153
|
+
.gsub(/\u21d2/, "rArr")
|
154
|
+
.gsub(/\u21d0/, "lArr")
|
155
|
+
.gsub(/\u21d4/, "hArr")
|
156
|
+
.gsub(/\u2192/, "->")
|
157
|
+
.gsub(/\u21a3/, ">->")
|
158
|
+
.gsub(/\u21a0/, "->>")
|
159
|
+
.gsub(/\u2916/, ">->>")
|
160
|
+
.gsub(/\u21a6/, "|->")
|
161
|
+
.gsub(/\u2026/, "...")
|
162
|
+
.gsub(/\u2212/, "-")
|
163
|
+
.gsub(/\u2061/, "") # function application
|
164
|
+
.gsub(/\u2751/, "square")
|
165
|
+
.gsub(/[\u2028\u2029]/, " ") # normalize thin spaces like \u2009, \u2008
|
12
166
|
end
|
13
167
|
|
14
|
-
def self.
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
gsub(/\u0393/, "Gamma").
|
19
|
-
gsub(/\u03b4/, "delta").
|
20
|
-
gsub(/\u0394/, "Delta").
|
21
|
-
gsub(/\u2206/, "Delta").
|
22
|
-
gsub(/\u03b5/, "epsilon").
|
23
|
-
gsub(/\u025b/, "varepsilon").
|
24
|
-
gsub(/\u03b6/, "zeta").
|
25
|
-
gsub(/\u03b7/, "eta").
|
26
|
-
gsub(/\u03b8/, "theta").
|
27
|
-
gsub(/\u0398/, "Theta").
|
28
|
-
gsub(/\u03d1/, "vartheta").
|
29
|
-
gsub(/\u03b9/, "iota").
|
30
|
-
gsub(/\u03ba/, "kappa").
|
31
|
-
gsub(/\u03bb/, "lambda").
|
32
|
-
gsub(/\u039b/, "Lambda").
|
33
|
-
gsub(/\u03bc/, "mu").
|
34
|
-
gsub(/\u03bd/, "nu").
|
35
|
-
gsub(/\u03be/, "xi").
|
36
|
-
gsub(/\u039e/, "Xi").
|
37
|
-
gsub(/\u03c0/, "pi").
|
38
|
-
gsub(/\u03a0/, "Pi").
|
39
|
-
gsub(/\u03c1/, "rho").
|
40
|
-
gsub(/\u03c2/, "beta").
|
41
|
-
gsub(/\u03c3/, "sigma").
|
42
|
-
gsub(/\u03a3/, "Sigma").
|
43
|
-
gsub(/\u03c4/, "tau").
|
44
|
-
gsub(/\u03c5/, "upsilon").
|
45
|
-
gsub(/\u03c6/, "phi").
|
46
|
-
gsub(/\u03a6/, "Phi").
|
47
|
-
gsub(/\u03d5/, "varphi").
|
48
|
-
gsub(/\u03c7/, "chi").
|
49
|
-
gsub(/\u03c8/, "psi").
|
50
|
-
gsub(/\u03a8/, "Psi").
|
51
|
-
gsub(/\u03c9/, "omega").
|
52
|
-
gsub(/\u03a9/, "omega").
|
53
|
-
gsub(/\u22c5/, "*").
|
54
|
-
gsub(/\u2219/, "*").
|
55
|
-
gsub(/\u00b7/, "*").
|
56
|
-
gsub(/\u2217/, "**").
|
57
|
-
gsub(/\u22c6/, "***").
|
58
|
-
gsub(/\//, "//").
|
59
|
-
gsub(/\\/, "\\\\").
|
60
|
-
gsub(/\u00d7/, "xx").
|
61
|
-
gsub(/\u22c9/, "|><").
|
62
|
-
gsub(/\u22ca/, "><|").
|
63
|
-
gsub(/\u22c8/, "|><|").
|
64
|
-
gsub(/\u00f7/, "-:").
|
65
|
-
gsub(/\u2218/, "@").
|
66
|
-
gsub(/\u2295/, "o+").
|
67
|
-
gsub(/\u2a01/, "o+").
|
68
|
-
gsub(/\u2297/, "ox").
|
69
|
-
gsub(/\u2299/, "o.").
|
70
|
-
gsub(/\u2211/, "sum").
|
71
|
-
gsub(/\u220f/, "prod").
|
72
|
-
gsub(/\u2227/, "^^").
|
73
|
-
gsub(/\u22c0/, "^^^").
|
74
|
-
gsub(/\u2228/, "vv").
|
75
|
-
gsub(/\u22c1/, "vvv").
|
76
|
-
gsub(/\u2229/, "nn").
|
77
|
-
gsub(/\u22c2/, "nnn").
|
78
|
-
gsub(/\u222a/, "uu").
|
79
|
-
gsub(/\u22c3/, "uuu").
|
80
|
-
gsub(/\u2260/, "!=").
|
81
|
-
gsub(/\u2264/, "<=").
|
82
|
-
gsub(/\u2265/, ">=").
|
83
|
-
gsub(/\u227a/, "-<").
|
84
|
-
gsub(/\u227b/, ">-").
|
85
|
-
gsub(/\u2aaf/, "-<=").
|
86
|
-
gsub(/\u2ab0/, ">-=").
|
87
|
-
gsub(/\u2208/, "in").
|
88
|
-
gsub(/\u2209/, "!in").
|
89
|
-
gsub(/\u2282/, "sub").
|
90
|
-
gsub(/\u2283/, "sup").
|
91
|
-
gsub(/\u2286/, "sube").
|
92
|
-
gsub(/\u2287/, "supe").
|
93
|
-
gsub(/\u2261/, "-=").
|
94
|
-
gsub(/\u2245/, "~=").
|
95
|
-
gsub(/\u2248/, "~~").
|
96
|
-
gsub(/\u221d/, "prop").
|
97
|
-
gsub(/\u00ac/, "not").
|
98
|
-
gsub(/\u21d2/, "=>").
|
99
|
-
gsub(/\u21d4/, "<=>").
|
100
|
-
gsub(/\u2200/, "AA").
|
101
|
-
gsub(/\u2203/, "EE").
|
102
|
-
gsub(/\u22a5/, "_|_").
|
103
|
-
gsub(/\u22a4/, "TT").
|
104
|
-
gsub(/\u22a2/, "|--").
|
105
|
-
gsub(/\u22a8/, "|==").
|
106
|
-
gsub(/\u22a8/, "|==").
|
107
|
-
gsub(/\u2329/, "(:").
|
108
|
-
gsub(/\u232a/, ":)").
|
109
|
-
gsub(/\u2329/, "<<").
|
110
|
-
gsub(/\u27e8/, "<<").
|
111
|
-
gsub(/\u232a/, ">>").
|
112
|
-
gsub(/\u27e9/, ">>").
|
113
|
-
gsub(/\u222e/, "oint").
|
114
|
-
gsub(/\u2202/, "del").
|
115
|
-
gsub(/\u2207/, "grad").
|
116
|
-
gsub(/\u00b1/, "+-").
|
117
|
-
gsub(/\u2205/, "O/").
|
118
|
-
gsub(/\u221e/, "oo").
|
119
|
-
gsub(/\u2135/, "aleph").
|
120
|
-
gsub(/\u2234/, ":.").
|
121
|
-
gsub(/\u2235/, ":'").
|
122
|
-
gsub(/\u2220/, "/_").
|
123
|
-
gsub(/\u25b3/, "/_\\").
|
124
|
-
gsub(/\u2032/, "'").
|
125
|
-
gsub(/~/, "tilde").
|
126
|
-
gsub(/\u00a0\u00a0\u00a0\u00a0/, "qquad").
|
127
|
-
gsub(/\u00a0\u00a0/, "quad").
|
128
|
-
gsub(/\u00a0/, "\\ ").
|
129
|
-
gsub(/\u2322/, "frown").
|
130
|
-
gsub(/\u00a0/, "quad").
|
131
|
-
gsub(/\u22ef/, "cdots").
|
132
|
-
gsub(/\u22ee/, "vdots").
|
133
|
-
gsub(/\u22f1/, "ddots").
|
134
|
-
gsub(/\u22c4/, "diamond").
|
135
|
-
gsub(/\u25a1/, "square").
|
136
|
-
gsub(/\u230a/, "|__").
|
137
|
-
gsub(/\u230b/, "__|").
|
138
|
-
gsub(/\u2308/, "|~").
|
139
|
-
gsub(/\u2309/, "~|").
|
140
|
-
gsub(/\u2102/, "CC").
|
141
|
-
gsub(/\u2115/, "NN").
|
142
|
-
gsub(/\u211a/, "QQ").
|
143
|
-
gsub(/\u211d/, "RR").
|
144
|
-
gsub(/\u2124/, "ZZ").
|
145
|
-
gsub(/\u2191/, "uarr").
|
146
|
-
gsub(/\u2193/, "darr").
|
147
|
-
gsub(/\u2190/, "larr").
|
148
|
-
gsub(/\u2194/, "harr").
|
149
|
-
gsub(/\u21d2/, "rArr").
|
150
|
-
gsub(/\u21d0/, "lArr").
|
151
|
-
gsub(/\u21d4/, "hArr").
|
152
|
-
gsub(/\u2192/, "->").
|
153
|
-
gsub(/\u21a3/, ">->").
|
154
|
-
gsub(/\u21a0/, "->>").
|
155
|
-
gsub(/\u2916/, ">->>").
|
156
|
-
gsub(/\u21a6/, "|->").
|
157
|
-
gsub(/\u2026/, "...").
|
158
|
-
gsub(/\u2212/, "-").
|
159
|
-
gsub(/\u2061/, ""). # function application
|
160
|
-
gsub(/\u2751/, "square")
|
168
|
+
def self.join_parsed_children(children, delimiter = " ")
|
169
|
+
children.map do |n|
|
170
|
+
parse(n).strip
|
171
|
+
end.join(delimiter)
|
161
172
|
end
|
162
173
|
|
163
174
|
def self.parse(node)
|
@@ -168,55 +179,47 @@ module MathML2AsciiMath
|
|
168
179
|
|
169
180
|
case node.name.sub(/^[^:]*:/, "")
|
170
181
|
when "math"
|
171
|
-
|
172
|
-
node.elements.each { |n| outarr << parse(n).strip }
|
173
|
-
return outarr.join(" ")
|
182
|
+
join_parsed_children(node.elements)
|
174
183
|
|
175
184
|
when "annotation"
|
176
|
-
|
185
|
+
""
|
177
186
|
|
178
187
|
when "semantics"
|
179
|
-
|
180
|
-
node.elements.each { |n| outarr << parse(n).strip }
|
181
|
-
return outarr.join(" ")
|
188
|
+
join_parsed_children(node.elements)
|
182
189
|
|
183
190
|
when "mrow"
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
if %w{mfrac msub munder munderover}.include? node.parent.name.sub(/^[^:]*:/, "")
|
191
|
+
out = join_parsed_children(node.elements)
|
192
|
+
if %w[mfrac msub munder munderover]
|
193
|
+
.include? node.parent.name.sub(/^[^:]*:/, "")
|
188
194
|
out = "(#{out})"
|
189
195
|
end
|
190
|
-
|
196
|
+
out
|
191
197
|
|
192
198
|
when "mfenced"
|
193
|
-
|
194
|
-
|
195
|
-
|
199
|
+
sym_open = node["open"] || "("
|
200
|
+
sym_close = node["close"] || ")"
|
201
|
+
|
196
202
|
separator = "," # TODO currently ignore the supplied separators
|
197
|
-
node.elements
|
198
|
-
out
|
199
|
-
return "#{open}#{out}#{close}"
|
203
|
+
out = join_parsed_children(node.elements, separator)
|
204
|
+
"#{sym_open}#{out}#{sym_close}"
|
200
205
|
|
201
206
|
when "msqrt"
|
202
|
-
|
203
|
-
node.elements.each { |n| outarr << parse(n).strip }
|
204
|
-
return "sqrt(#{outarr.join(" ")})"
|
207
|
+
"sqrt(#{join_parsed_children(node.elements)})"
|
205
208
|
|
206
209
|
when "mfrac"
|
207
|
-
|
210
|
+
"(#{parse(node.elements[0])})/(#{parse(node.elements[1])})"
|
208
211
|
|
209
212
|
when "msup"
|
210
213
|
sup = parse(node.elements[1])
|
211
214
|
sup = "(#{sup})" unless sup.length == 1
|
212
215
|
op = parse(node.elements[0]).gsub(/ $/, "")
|
213
|
-
|
216
|
+
"#{op}^#{sup}"
|
214
217
|
|
215
218
|
when "msub"
|
216
219
|
sub = parse(node.elements[1])
|
217
220
|
sub = "(#{sub})" unless sub.length == 1
|
218
221
|
op = parse(node.elements[0]).gsub(/ $/, "")
|
219
|
-
|
222
|
+
"#{op}_#{sub}"
|
220
223
|
|
221
224
|
when "munderover", "msubsup"
|
222
225
|
sub = parse(node.elements[1])
|
@@ -224,27 +227,29 @@ module MathML2AsciiMath
|
|
224
227
|
sup = parse(node.elements[2])
|
225
228
|
sup = "(#{sup})" unless sup.length == 1
|
226
229
|
op = parse(node.elements[0]).gsub(/ $/, "")
|
227
|
-
|
230
|
+
"#{op}_#{sub}^#{sup}"
|
228
231
|
|
229
232
|
when "munder"
|
230
|
-
elem1 = parse(node.elements[1]).
|
233
|
+
elem1 = parse(node.elements[1]).strip
|
231
234
|
accent = case elem1
|
232
235
|
when "\u0332" then "ul"
|
233
236
|
when "\u23df" then "ubrace"
|
234
237
|
else
|
235
238
|
"underset"
|
236
239
|
end
|
240
|
+
|
237
241
|
if accent == "underset"
|
238
|
-
|
242
|
+
"underset(#{elem1})(#{parse(node.elements[0])})"
|
239
243
|
else
|
240
|
-
|
244
|
+
"#{accent} #{parse(node.elements[0])}"
|
241
245
|
end
|
246
|
+
|
242
247
|
when "mover"
|
243
|
-
elem1 = parse(node.elements[1]).
|
248
|
+
elem1 = parse(node.elements[1]).strip
|
244
249
|
accent = case elem1
|
245
250
|
when "\u005e" then "hat"
|
246
251
|
when "\u00af" then "bar"
|
247
|
-
#when "\u2192" then "vec"
|
252
|
+
# when "\u2192" then "vec"
|
248
253
|
when "->" then "vec"
|
249
254
|
when "." then "dot"
|
250
255
|
when ".." then "ddot"
|
@@ -252,53 +257,46 @@ module MathML2AsciiMath
|
|
252
257
|
else
|
253
258
|
"overset"
|
254
259
|
end
|
260
|
+
|
255
261
|
if accent == "overset"
|
256
|
-
|
262
|
+
"overset(#{elem1})(#{parse(node.elements[0])})"
|
257
263
|
else
|
258
|
-
|
264
|
+
"#{accent} #{parse(node.elements[0])}"
|
259
265
|
end
|
260
266
|
|
261
267
|
when "mtable"
|
262
|
-
|
263
|
-
node.elements.each { |n| outarr << parse(n).strip }
|
264
|
-
return "[#{outarr.join(",")}]"
|
268
|
+
"[#{join_parsed_children(node.elements, ',')}]"
|
265
269
|
|
266
270
|
when "mtr"
|
267
|
-
|
268
|
-
node.elements.each { |n| outarr << parse(n).strip }
|
269
|
-
return "[#{outarr.join(",")}]"
|
271
|
+
"[#{join_parsed_children(node.elements, ',')}]"
|
270
272
|
|
271
273
|
when "mtd"
|
272
|
-
|
273
|
-
node.elements.each { |n| outarr << parse(n).strip }
|
274
|
-
return "#{outarr.join(",")}"
|
274
|
+
join_parsed_children(node.elements, ",")
|
275
275
|
|
276
276
|
when "mn", "mtext"
|
277
|
-
|
278
|
-
node.children.each { |n| outarr << parse(n).strip }
|
279
|
-
return "#{outarr.join("")}"
|
277
|
+
join_parsed_children(node.children, "")
|
280
278
|
|
281
279
|
when "mi"
|
282
|
-
#
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
280
|
+
# FIXME: What does this comment have to do with Word?
|
281
|
+
# mi is not meant to have space around it,
|
282
|
+
# but Word is conflating operators and operands
|
283
|
+
join_parsed_children(node.children)
|
284
|
+
|
285
|
+
# FIXME: Why do we need to add extra spaces?
|
286
|
+
# out = " #{out} " if /[^a-zA-Z0-9',]|[a-z][a-z]/.match out
|
288
287
|
|
289
288
|
when "mo"
|
290
|
-
|
291
|
-
node.children.each { |n| outarr << parse(n).strip }
|
292
|
-
out = outarr.join(" ")
|
289
|
+
out = join_parsed_children(node.children)
|
293
290
|
out = " #{out} " unless node["fence"]
|
294
|
-
|
291
|
+
out
|
295
292
|
|
296
293
|
when "mstyle"
|
297
|
-
|
298
|
-
|
299
|
-
out = outarr.join(" ")
|
294
|
+
join_parsed_children(node.children)
|
295
|
+
|
300
296
|
else
|
301
|
-
|
297
|
+
"<math xmlns=\"http://www.w3.org/1998/Math/MathML\">" +
|
298
|
+
node.to_xml +
|
299
|
+
"</math>"
|
302
300
|
|
303
301
|
end
|
304
302
|
end
|