plurimath 0.1.0 → 0.2.0

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.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +36 -0
  3. data/.rubocop.yml +2 -0
  4. data/lib/plurimath/asciimath/constants.rb +308 -0
  5. data/lib/plurimath/asciimath/parse.rb +87 -0
  6. data/lib/plurimath/asciimath/parser.rb +24 -0
  7. data/lib/plurimath/asciimath/transform.rb +304 -0
  8. data/lib/plurimath/asciimath.rb +16 -0
  9. data/lib/plurimath/html.rb +15 -0
  10. data/lib/plurimath/latex/constants.rb +1963 -0
  11. data/lib/plurimath/latex/parse.rb +105 -0
  12. data/lib/plurimath/latex/parser.rb +24 -0
  13. data/lib/plurimath/latex/transform.rb +298 -0
  14. data/lib/plurimath/latex.rb +15 -0
  15. data/lib/plurimath/math/formula.rb +43 -0
  16. data/lib/plurimath/math/function/abs.rb +12 -0
  17. data/lib/plurimath/math/function/arccos.rb +12 -0
  18. data/lib/plurimath/math/function/arcsin.rb +12 -0
  19. data/lib/plurimath/math/function/arctan.rb +12 -0
  20. data/lib/plurimath/math/function/bar.rb +16 -0
  21. data/lib/plurimath/math/function/base.rb +30 -0
  22. data/lib/plurimath/math/function/binary_function.rb +53 -0
  23. data/lib/plurimath/math/function/cancel.rb +12 -0
  24. data/lib/plurimath/math/function/ceil.rb +12 -0
  25. data/lib/plurimath/math/function/color.rb +23 -0
  26. data/lib/plurimath/math/function/cos.rb +12 -0
  27. data/lib/plurimath/math/function/cosh.rb +12 -0
  28. data/lib/plurimath/math/function/cot.rb +12 -0
  29. data/lib/plurimath/math/function/coth.rb +12 -0
  30. data/lib/plurimath/math/function/csc.rb +12 -0
  31. data/lib/plurimath/math/function/csch.rb +12 -0
  32. data/lib/plurimath/math/function/ddot.rb +12 -0
  33. data/lib/plurimath/math/function/deg.rb +12 -0
  34. data/lib/plurimath/math/function/det.rb +12 -0
  35. data/lib/plurimath/math/function/dim.rb +12 -0
  36. data/lib/plurimath/math/function/dot.rb +12 -0
  37. data/lib/plurimath/math/function/exp.rb +12 -0
  38. data/lib/plurimath/math/function/f.rb +12 -0
  39. data/lib/plurimath/math/function/fenced.rb +22 -0
  40. data/lib/plurimath/math/function/floor.rb +12 -0
  41. data/lib/plurimath/math/function/font_style.rb +45 -0
  42. data/lib/plurimath/math/function/frac.rb +23 -0
  43. data/lib/plurimath/math/function/g.rb +12 -0
  44. data/lib/plurimath/math/function/gcd.rb +12 -0
  45. data/lib/plurimath/math/function/glb.rb +12 -0
  46. data/lib/plurimath/math/function/hat.rb +12 -0
  47. data/lib/plurimath/math/function/hom.rb +12 -0
  48. data/lib/plurimath/math/function/inf.rb +18 -0
  49. data/lib/plurimath/math/function/int.rb +17 -0
  50. data/lib/plurimath/math/function/ker.rb +12 -0
  51. data/lib/plurimath/math/function/lcm.rb +12 -0
  52. data/lib/plurimath/math/function/left.rb +23 -0
  53. data/lib/plurimath/math/function/lg.rb +12 -0
  54. data/lib/plurimath/math/function/lim.rb +23 -0
  55. data/lib/plurimath/math/function/liminf.rb +12 -0
  56. data/lib/plurimath/math/function/limits.rb +19 -0
  57. data/lib/plurimath/math/function/limsup.rb +12 -0
  58. data/lib/plurimath/math/function/ln.rb +12 -0
  59. data/lib/plurimath/math/function/log.rb +23 -0
  60. data/lib/plurimath/math/function/lub.rb +12 -0
  61. data/lib/plurimath/math/function/max.rb +12 -0
  62. data/lib/plurimath/math/function/min.rb +12 -0
  63. data/lib/plurimath/math/function/mod.rb +23 -0
  64. data/lib/plurimath/math/function/norm.rb +15 -0
  65. data/lib/plurimath/math/function/obrace.rb +12 -0
  66. data/lib/plurimath/math/function/oint.rb +17 -0
  67. data/lib/plurimath/math/function/overset.rb +23 -0
  68. data/lib/plurimath/math/function/power.rb +30 -0
  69. data/lib/plurimath/math/function/power_base.rb +26 -0
  70. data/lib/plurimath/math/function/prod.rb +23 -0
  71. data/lib/plurimath/math/function/root.rb +22 -0
  72. data/lib/plurimath/math/function/sec.rb +12 -0
  73. data/lib/plurimath/math/function/sech.rb +12 -0
  74. data/lib/plurimath/math/function/sin.rb +12 -0
  75. data/lib/plurimath/math/function/sinh.rb +12 -0
  76. data/lib/plurimath/math/function/sqrt.rb +16 -0
  77. data/lib/plurimath/math/function/stackrel.rb +12 -0
  78. data/lib/plurimath/math/function/substack.rb +18 -0
  79. data/lib/plurimath/math/function/sum.rb +23 -0
  80. data/lib/plurimath/math/function/sup.rb +12 -0
  81. data/lib/plurimath/math/function/table.rb +42 -0
  82. data/lib/plurimath/math/function/tan.rb +12 -0
  83. data/lib/plurimath/math/function/tanh.rb +12 -0
  84. data/lib/plurimath/math/function/td.rb +27 -0
  85. data/lib/plurimath/math/function/ternary_function.rb +42 -0
  86. data/lib/plurimath/math/function/text.rb +32 -0
  87. data/lib/plurimath/math/function/tilde.rb +12 -0
  88. data/lib/plurimath/math/function/tr.rb +25 -0
  89. data/lib/plurimath/math/function/ubrace.rb +12 -0
  90. data/lib/plurimath/math/function/ul.rb +12 -0
  91. data/lib/plurimath/math/function/unary_function.rb +41 -0
  92. data/lib/plurimath/math/function/underover.rb +12 -0
  93. data/lib/plurimath/math/function/underset.rb +12 -0
  94. data/lib/plurimath/math/function/vec.rb +12 -0
  95. data/lib/plurimath/math/function.rb +3 -0
  96. data/lib/plurimath/math/number.rb +29 -0
  97. data/lib/plurimath/math/symbol.rb +34 -0
  98. data/lib/plurimath/math.rb +51 -0
  99. data/lib/plurimath/mathml/constants.rb +327 -0
  100. data/lib/plurimath/mathml/parse.rb +63 -0
  101. data/lib/plurimath/mathml/parser.rb +25 -0
  102. data/lib/plurimath/mathml/transform.rb +195 -0
  103. data/lib/plurimath/mathml.rb +16 -0
  104. data/lib/plurimath/omml.rb +15 -0
  105. data/lib/plurimath/unicode.rb +15 -0
  106. data/lib/plurimath/unitsml.rb +11 -0
  107. data/lib/plurimath/version.rb +3 -1
  108. data/lib/plurimath.rb +3 -5
  109. data/plurimath.gemspec +3 -3
  110. metadata +129 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9d753ecd87f98bee9b8ce86a97c884f6faf5d80054779b0e614b81cee83f122c
4
- data.tar.gz: 48e00ea65c235d43ec0acf12dc89a6491bc3bea261bfdc2930c54f6772b8e684
3
+ metadata.gz: b38da6a872ab566412690e3f08859d3ba4935409fad521a74f36a5fb972eaf90
4
+ data.tar.gz: e4f009d832c64605123611924b34ee3f794ebf57fc2296e8cb3f4d0fd522b76f
5
5
  SHA512:
6
- metadata.gz: '08c01a96cc02476603a6a0cece4703fdd096ea166eb4e2117e185ff8a5dfc2dcb05a6a8a6f2f6526a208763ad2129bfd22d63a1121e347554cfb042deb171798'
7
- data.tar.gz: 5893839b6b1523b2a6610f32e0af5cf67a15340542d031b909aa03b04487f4482fb61f5c33e8ebf3538013d661561c0f0888028bc036937bf1f1a240f5d2b91f
6
+ metadata.gz: 28c3682a4a1c8132213cdfddbca0c463d822811fe396b77d5062bea96148ba880970ae2d5c4e255eea4666c7b34a8b9b0854ef27896dfb7443b56088d26fc793
7
+ data.tar.gz: e4e135b39e22960e2a3d7841bcc15ec82a3aad9c3f3876d648d24b608b2baae450b42a30c799813e57506e01216ba4038bca7d7cd0fac2b32d15fec3e899827b
@@ -0,0 +1,36 @@
1
+ name: test
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ tags:
7
+ - '*'
8
+ pull_request:
9
+ paths-ignore:
10
+ - .github/workflows/macos.yml
11
+ - .github/workflows/windows.yml
12
+
13
+ jobs:
14
+ test-linux:
15
+ name: Test on Ruby ${{ matrix.ruby }} ${{ matrix.os }}
16
+ runs-on: ${{ matrix.os }}
17
+ continue-on-error: ${{ matrix.experimental }}
18
+ strategy:
19
+ fail-fast: false
20
+ matrix:
21
+ ruby: [ '2.6', '2.7', '3.0' ]
22
+ os: [ 'macos-latest', 'ubuntu-latest', 'windows-latest']
23
+ experimental: [false]
24
+ steps:
25
+ - uses: actions/checkout@master
26
+ - name: Use Ruby
27
+ uses: ruby/setup-ruby@v1
28
+ with:
29
+ ruby-version: ${{ matrix.ruby }}
30
+ - name: Update gems
31
+ run: |
32
+ gem install bundler
33
+ bundle install --jobs 4 --retry 3
34
+ - name: Run specs
35
+ run: |
36
+ bundle exec rake
data/.rubocop.yml ADDED
@@ -0,0 +1,2 @@
1
+ inherit_from:
2
+ - https://raw.githubusercontent.com/riboseinc/oss-guides/master/ci/rubocop.yml
@@ -0,0 +1,308 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Plurimath
4
+ class Asciimath
5
+ class Constants
6
+ PARENTHESIS = {
7
+ "(": ")",
8
+ "(:": ":)",
9
+ "{": "}",
10
+ "{:": ":}",
11
+ "[": "]",
12
+ }.freeze
13
+ SYMBOLS = %i[
14
+ twoheadrightarrowtail
15
+ twoheadrightarrow
16
+ rightarrowtail
17
+ Leftrightarrow
18
+ leftrightarrow
19
+ varepsilon
20
+ Rightarrow
21
+ rightarrow
22
+ Leftarrow
23
+ leftarrow
24
+ backslash
25
+ downarrow
26
+ therefore
27
+ triangle
28
+ vartheta
29
+ bigwedge
30
+ rceiling
31
+ lceiling
32
+ setminus
33
+ supseteq
34
+ subseteq
35
+ emptyset
36
+ "|\\ |"
37
+ upsilon
38
+ diamond
39
+ uparrow
40
+ implies
41
+ partial
42
+ epsilon
43
+ because
44
+ |cdots|
45
+ |ldots|
46
+ bigcap
47
+ bigvee
48
+ propto
49
+ approx
50
+ exists
51
+ forall
52
+ otimes
53
+ ltimes
54
+ bowtie
55
+ rtimes
56
+ models
57
+ mapsto
58
+ bigcup
59
+ lambda
60
+ Lambda
61
+ "(x:}"
62
+ "{:x)"
63
+ succeq
64
+ preceq
65
+ varphi
66
+ rfloor
67
+ lfloor
68
+ square
69
+ |quad|
70
+ supset
71
+ subset
72
+ vdash
73
+ times
74
+ wedge
75
+ oplus
76
+ alpha
77
+ nabla
78
+ delta
79
+ theta
80
+ gamma
81
+ Gamma
82
+ Delta
83
+ Theta
84
+ kappa
85
+ ddots
86
+ vdots
87
+ |...|
88
+ equiv
89
+ Sigma
90
+ Omega
91
+ omega
92
+ aleph
93
+ infty
94
+ sigma
95
+ frown
96
+ notin
97
+ angle
98
+ succ
99
+ prec
100
+ cong
101
+ \\\\
102
+ star
103
+ odot
104
+ cdot
105
+ rarr
106
+ darr
107
+ prop
108
+ lArr
109
+ rArr
110
+ uarr
111
+ beta
112
+ hArr
113
+ harr
114
+ larr
115
+ grad
116
+ circ
117
+ >->>
118
+ zeta
119
+ iota
120
+ /_\\
121
+ sube
122
+ sup
123
+ sub
124
+ !in
125
+ eta
126
+ top
127
+ |><|
128
+ __|
129
+ |__
130
+ ":'"
131
+ Phi
132
+ supe
133
+ Psi
134
+ psi
135
+ chi
136
+ >-=
137
+ -<=
138
+ mgt
139
+ mlt
140
+ ><|
141
+ |==
142
+ |--
143
+ vvv
144
+ vee
145
+ nnn
146
+ cap
147
+ ^^^
148
+ div
149
+ ast
150
+ bot
151
+ del
152
+ and
153
+ neg
154
+ not
155
+ uuu
156
+ cup
157
+ iff
158
+ phi
159
+ rho
160
+ tau
161
+ |->
162
+ >->
163
+ <=>
164
+ ->>
165
+ ^^
166
+ nn
167
+ vv
168
+ TT
169
+ EE
170
+ ox
171
+ xx
172
+ o+
173
+ o.
174
+ |><
175
+ _|_
176
+ ***
177
+ **
178
+ -:
179
+ ~~
180
+ //
181
+ pm
182
+ O/
183
+ ->
184
+ =>
185
+ +-
186
+ to
187
+ Xi
188
+ AA
189
+ if
190
+ uu
191
+ or
192
+ lt
193
+ ne
194
+ nu
195
+ mu
196
+ ZZ
197
+ RR
198
+ QQ
199
+ NN
200
+ CC
201
+ >>
202
+ <<
203
+ ~|
204
+ !=
205
+ >-
206
+ -<
207
+ ~=
208
+ -=
209
+ pi
210
+ xi
211
+ oo
212
+ Pi
213
+ :.
214
+ gg
215
+ ll
216
+ ge
217
+ >=
218
+ le
219
+ <=
220
+ gt
221
+ |~
222
+ in
223
+ /_
224
+ >
225
+ @
226
+ /
227
+ *
228
+ -
229
+ <
230
+ =
231
+ +
232
+ ].freeze
233
+ UNARY_CLASSES = %i[
234
+ arccos
235
+ arcsin
236
+ arctan
237
+ ubrace
238
+ obrace
239
+ cancel
240
+ tilde
241
+ floor
242
+ ceil
243
+ ddot
244
+ coth
245
+ csch
246
+ sech
247
+ sinh
248
+ tanh
249
+ cosh
250
+ sqrt
251
+ norm
252
+ text
253
+ sec
254
+ sin
255
+ tan
256
+ cos
257
+ exp
258
+ gcd
259
+ glb
260
+ lcm
261
+ lub
262
+ cot
263
+ csc
264
+ det
265
+ dim
266
+ max
267
+ min
268
+ abs
269
+ bar
270
+ dot
271
+ hat
272
+ vec
273
+ ul
274
+ ln
275
+ f
276
+ g
277
+ ].freeze
278
+ BINARY_CLASSES = %i[
279
+ underset
280
+ stackrel
281
+ overset
282
+ color
283
+ prod
284
+ frac
285
+ root
286
+ oint
287
+ int
288
+ sum
289
+ mod
290
+ log
291
+ ].freeze
292
+ FONT_STYLES = %i[
293
+ mathfrak
294
+ mathcal
295
+ mathbb
296
+ mathsf
297
+ mathtt
298
+ mathbf
299
+ bbb
300
+ bb
301
+ fr
302
+ cc
303
+ sf
304
+ tt
305
+ ].freeze
306
+ end
307
+ end
308
+ end
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "parslet"
4
+ module Plurimath
5
+ class Asciimath
6
+ class Parse < Parslet::Parser
7
+ rule(:base) { str("_").as(:_) }
8
+
9
+ rule(:power) { str("^").as(:^) }
10
+
11
+ rule(:symbols) { arr_to_expression(Constants::SYMBOLS, :symbol) }
12
+
13
+ rule(:unary_functions) { arr_to_expression(Constants::UNARY_CLASSES) }
14
+
15
+ rule(:font_style) { arr_to_expression(Constants::FONT_STYLES, :fonts) }
16
+
17
+ rule(:binary_functions) { arr_to_expression(Constants::BINARY_CLASSES) }
18
+
19
+ rule(:lparen) do
20
+ Constants::PARENTHESIS.keys.reduce do |expression, parenthesis|
21
+ expression = str(expression) if expression.is_a?(Symbol)
22
+ expression | str(parenthesis)
23
+ end
24
+ end
25
+
26
+ rule(:rparen) do
27
+ Constants::PARENTHESIS.values.reduce do |expression, parenthesis|
28
+ expression = str(expression) if expression.is_a?(String)
29
+ expression | str(parenthesis)
30
+ end
31
+ end
32
+
33
+ rule(:quoted_text) do
34
+ str('"') >> match("[^\"]").repeat.as(:text) >> str('"')
35
+ end
36
+
37
+ rule(:symbol_text_or_integer) do
38
+ binary_functions |
39
+ unary_functions |
40
+ symbols |
41
+ quoted_text |
42
+ match["a-zA-Z"].as(:symbol) |
43
+ match("[0-9]").repeat(1).as(:number)
44
+ end
45
+
46
+ rule(:sequence) do
47
+ (lparen >> expression >> rparen).as(:intermediate_exp) |
48
+ (binary_functions >> sequence.as(:base) >> sequence.maybe.as(:exponent)).as(:binary) |
49
+ (str("text") >> lparen.capture(:paren) >> read_text >> rparen) |
50
+ (unary_functions >> sequence).as(:unary) |
51
+ (font_style >> sequence).as(:fonts) |
52
+ symbol_text_or_integer
53
+ end
54
+
55
+ rule(:iteration) do
56
+ (sequence.as(:dividend) >> str("mod").as(:mod) >> sequence.as(:divisor)).as(:mod) |
57
+ (sequence >> base >> sequence.as(:base) >> power >> sequence.as(:exponent)).as(:power_base) |
58
+ (sequence >> base >> sequence).as(:base) |
59
+ (sequence >> power >> sequence).as(:power) |
60
+ sequence.as(:sequence) |
61
+ str(" ")
62
+ end
63
+
64
+ rule(:expression) do
65
+ (iteration >> expression).as(:expr) |
66
+ (iteration >> str("/").as(:/) >> iteration).as(:expr) |
67
+ str("")
68
+ end
69
+
70
+ root :expression
71
+
72
+ def arr_to_expression(arr, name = nil)
73
+ arr.reduce do |expression, expr_string|
74
+ expression = str(expression).as(name || expression) if expression.is_a?(Symbol)
75
+ expression | str(expr_string).as(name || expr_string)
76
+ end
77
+ end
78
+
79
+ def read_text
80
+ dynamic do |_sour, context|
81
+ rparen = Constants::PARENTHESIS[context.captures[:paren].to_sym]
82
+ match("[^#{rparen}]").repeat.as(:text)
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "parse"
4
+ require_relative "constants"
5
+ require_relative "transform"
6
+ module Plurimath
7
+ class Asciimath
8
+ class Parser
9
+ attr_accessor :text
10
+
11
+ def initialize(text)
12
+ @text = text
13
+ end
14
+
15
+ def parse
16
+ nodes = Parse.new.parse(text)
17
+ transformed_tree = Plurimath::Asciimath::Transform.new.apply(nodes)
18
+ return transformed_tree if transformed_tree.is_a?(Plurimath::Math::Formula)
19
+
20
+ Plurimath::Math::Formula.new(transformed_tree)
21
+ end
22
+ end
23
+ end
24
+ end