plurimath 0.2.0 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +13 -0
  3. data/.github/workflows/release.yml +22 -0
  4. data/.gitignore +1 -0
  5. data/.hound.yml +5 -0
  6. data/.rubocop.yml +8 -0
  7. data/AsciiMath-Supported-Data.adoc +2000 -0
  8. data/Gemfile +3 -0
  9. data/Latex-Supported-Data.adoc +1879 -0
  10. data/MathML-Supported-Data.adoc +287 -0
  11. data/README.adoc +96 -0
  12. data/lib/plurimath/asciimath/constants.rb +267 -229
  13. data/lib/plurimath/asciimath/parse.rb +125 -26
  14. data/lib/plurimath/asciimath/parser.rb +6 -3
  15. data/lib/plurimath/asciimath/transform.rb +1135 -208
  16. data/lib/plurimath/asciimath.rb +1 -1
  17. data/lib/plurimath/html/constants.rb +50 -0
  18. data/lib/plurimath/html/parse.rb +149 -0
  19. data/lib/plurimath/html/parser.rb +26 -0
  20. data/lib/plurimath/html/transform.rb +363 -0
  21. data/lib/plurimath/html.rb +1 -1
  22. data/lib/plurimath/latex/constants.rb +3729 -1906
  23. data/lib/plurimath/latex/parse.rb +167 -51
  24. data/lib/plurimath/latex/parser.rb +12 -4
  25. data/lib/plurimath/latex/transform.rb +598 -183
  26. data/lib/plurimath/math/base.rb +15 -0
  27. data/lib/plurimath/math/formula.rb +96 -11
  28. data/lib/plurimath/math/function/bar.rb +34 -0
  29. data/lib/plurimath/math/function/base.rb +32 -5
  30. data/lib/plurimath/math/function/binary_function.rb +104 -17
  31. data/lib/plurimath/math/function/cancel.rb +8 -0
  32. data/lib/plurimath/math/function/ceil.rb +3 -0
  33. data/lib/plurimath/math/function/color.rb +16 -6
  34. data/lib/plurimath/math/function/f.rb +8 -0
  35. data/lib/plurimath/math/function/fenced.rb +95 -3
  36. data/lib/plurimath/math/function/floor.rb +15 -0
  37. data/lib/plurimath/math/function/font_style/bold.rb +37 -0
  38. data/lib/plurimath/math/function/font_style/double_struck.rb +37 -0
  39. data/lib/plurimath/math/function/font_style/fraktur.rb +37 -0
  40. data/lib/plurimath/math/function/font_style/italic.rb +37 -0
  41. data/lib/plurimath/math/function/font_style/monospace.rb +37 -0
  42. data/lib/plurimath/math/function/font_style/normal.rb +37 -0
  43. data/lib/plurimath/math/function/font_style/sans-serif.rb +37 -0
  44. data/lib/plurimath/math/function/font_style/script.rb +37 -0
  45. data/lib/plurimath/math/function/font_style.rb +18 -25
  46. data/lib/plurimath/math/function/frac.rb +35 -5
  47. data/lib/plurimath/math/function/g.rb +7 -0
  48. data/lib/plurimath/math/function/hat.rb +12 -0
  49. data/lib/plurimath/math/function/inf.rb +21 -1
  50. data/lib/plurimath/math/function/int.rb +23 -2
  51. data/lib/plurimath/math/function/left.rb +25 -4
  52. data/lib/plurimath/math/function/lim.rb +40 -2
  53. data/lib/plurimath/math/function/limits.rb +8 -0
  54. data/lib/plurimath/math/function/log.rb +61 -4
  55. data/lib/plurimath/math/function/longdiv.rb +12 -0
  56. data/lib/plurimath/math/function/mbox.rb +31 -0
  57. data/lib/plurimath/math/function/menclose.rb +46 -0
  58. data/lib/plurimath/math/function/merror.rb +12 -0
  59. data/lib/plurimath/math/function/mod.rb +25 -4
  60. data/lib/plurimath/math/function/msgroup.rb +37 -0
  61. data/lib/plurimath/math/function/msline.rb +12 -0
  62. data/lib/plurimath/math/function/multiscript.rb +30 -0
  63. data/lib/plurimath/math/function/norm.rb +18 -1
  64. data/lib/plurimath/math/function/obrace.rb +17 -0
  65. data/lib/plurimath/math/function/oint.rb +2 -2
  66. data/lib/plurimath/math/function/over.rb +36 -0
  67. data/lib/plurimath/math/function/overset.rb +36 -7
  68. data/lib/plurimath/math/function/phantom.rb +28 -0
  69. data/lib/plurimath/math/function/power.rb +33 -9
  70. data/lib/plurimath/math/function/power_base.rb +110 -5
  71. data/lib/plurimath/math/function/prod.rb +29 -2
  72. data/lib/plurimath/math/function/right.rb +44 -0
  73. data/lib/plurimath/math/function/root.rb +27 -4
  74. data/lib/plurimath/math/function/rule.rb +33 -0
  75. data/lib/plurimath/math/function/scarries.rb +12 -0
  76. data/lib/plurimath/math/function/scarry.rb +12 -0
  77. data/lib/plurimath/math/function/sqrt.rb +24 -2
  78. data/lib/plurimath/math/function/stackrel.rb +27 -0
  79. data/lib/plurimath/math/function/substack.rb +7 -1
  80. data/lib/plurimath/math/function/sum.rb +56 -2
  81. data/lib/plurimath/math/function/sup.rb +3 -0
  82. data/lib/plurimath/math/function/table/align.rb +24 -0
  83. data/lib/plurimath/math/function/table/array.rb +44 -0
  84. data/lib/plurimath/math/function/table/bmatrix.rb +37 -0
  85. data/lib/plurimath/math/function/table/matrix.rb +32 -0
  86. data/lib/plurimath/math/function/table/multline.rb +24 -0
  87. data/lib/plurimath/math/function/table/pmatrix.rb +24 -0
  88. data/lib/plurimath/math/function/table/split.rb +24 -0
  89. data/lib/plurimath/math/function/table/vmatrix.rb +24 -0
  90. data/lib/plurimath/math/function/table.rb +190 -20
  91. data/lib/plurimath/math/function/td.rb +27 -9
  92. data/lib/plurimath/math/function/ternary_function.rb +83 -8
  93. data/lib/plurimath/math/function/text.rb +45 -8
  94. data/lib/plurimath/math/function/tr.rb +28 -4
  95. data/lib/plurimath/math/function/ubrace.rb +17 -0
  96. data/lib/plurimath/math/function/ul.rb +29 -0
  97. data/lib/plurimath/math/function/unary_function.rb +85 -7
  98. data/lib/plurimath/math/function/underline.rb +12 -0
  99. data/lib/plurimath/math/function/underover.rb +107 -0
  100. data/lib/plurimath/math/function/underset.rb +39 -0
  101. data/lib/plurimath/math/function/vec.rb +10 -0
  102. data/lib/plurimath/math/function.rb +13 -2
  103. data/lib/plurimath/math/number.rb +11 -3
  104. data/lib/plurimath/math/symbol.rb +57 -9
  105. data/lib/plurimath/math/unicode.rb +11 -0
  106. data/lib/plurimath/math.rb +15 -6
  107. data/lib/plurimath/mathml/constants.rb +224 -179
  108. data/lib/plurimath/mathml/parser.rb +24 -7
  109. data/lib/plurimath/mathml/transform.rb +249 -148
  110. data/lib/plurimath/mathml.rb +1 -1
  111. data/lib/plurimath/omml/parser.rb +42 -0
  112. data/lib/plurimath/omml/transform.rb +278 -0
  113. data/lib/plurimath/omml.rb +1 -1
  114. data/lib/plurimath/unitsml.rb +4 -0
  115. data/lib/plurimath/utility.rb +395 -0
  116. data/lib/plurimath/version.rb +1 -1
  117. data/plurimath.gemspec +1 -0
  118. metadata +66 -9
  119. data/.github/workflows/test.yml +0 -36
  120. data/README.md +0 -40
  121. data/lib/plurimath/mathml/parse.rb +0 -63
@@ -3,234 +3,247 @@
3
3
  module Plurimath
4
4
  class Asciimath
5
5
  class Constants
6
- PARENTHESIS = {
6
+ TABLE_PARENTHESIS = {
7
+ "(:": ":)",
8
+ "ℒ": "ℛ",
9
+ "[": "]",
7
10
  "(": ")",
11
+ }.freeze
12
+ PARENTHESIS = {
8
13
  "(:": ":)",
14
+ "ℒ": "ℛ",
15
+ "(": ")",
9
16
  "{": "}",
10
- "{:": ":}",
11
17
  "[": "]",
12
18
  }.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
19
+ SYMBOLS = {
20
+ twoheadrightarrowtail: :"&#x2916;",
21
+ twoheadrightarrow: :"&#x21a0;",
22
+ rightarrowtail: :"&#x21a3;",
23
+ Leftrightarrow: :"&#x21d4;",
24
+ leftrightarrow: :"&#x2194;",
25
+ Rightarrow: :"&#x21d2;",
26
+ rightarrow: :"&#x2192;",
27
+ varepsilon: :"&#x25b;",
28
+ Leftarrow: :"&#x21d0;",
29
+ leftarrow: :"&#x2190;",
30
+ downarrow: :"&#x2193;",
31
+ therefore: :"&#x2234;",
32
+ backslash: :"&#x5c;",
33
+ setminus: :"&#x29f5;",
34
+ triangle: :"&#x25b3;",
35
+ bigwedge: :"&#x22c0;",
36
+ rceiling: :"&#x2309;",
37
+ lceiling: :"&#x2308;",
38
+ supseteq: :"&#x2287;",
39
+ subseteq: :"&#x2286;",
40
+ vartheta: :"&#x3d1;",
41
+ emptyset: :"&#x2205;",
42
+ diamond: :"&#x22c4;",
43
+ uparrow: :"&#x2191;",
44
+ implies: :"&#x21d2;",
45
+ partial: :"&#x2202;",
46
+ because: :"&#x2235;",
47
+ upsilon: :"&#x3c5;",
48
+ epsilon: :"&#x3b5;",
49
+ bigcap: :"&#x22c2;",
50
+ bigvee: :"&#x22c1;",
51
+ propto: :"&#x221d;",
52
+ approx: :"&#x2248;",
53
+ exists: :"&#x2203;",
54
+ forall: :"&#x2200;",
55
+ otimes: :"&#x2297;",
56
+ ltimes: :"&#x22c9;",
57
+ bowtie: :"&#x22c8;",
58
+ rtimes: :"&#x22ca;",
59
+ models: :"&#x22a8;",
60
+ mapsto: :"&#x21a6;",
61
+ bigcup: :"&#x22c3;",
62
+ succeq: :"&#x2ab0;",
63
+ preceq: :"&#x2aaf;",
64
+ rfloor: :"&#x230b;",
65
+ lfloor: :"&#x230a;",
66
+ square: :"&#x25a1;",
67
+ supset: :"&#x2283;",
68
+ subset: :"&#x2282;",
69
+ lambda: :"&#x3bb;",
70
+ Lambda: :"&#x39b;",
71
+ varphi: :"&#x3c6;",
72
+ rangle: :"&#x232a;",
73
+ langle: :"&#x2329;",
74
+ ">->>": :"&#x2916;",
75
+ "/_\\": :"&#x25b3;",
76
+ "|><|": :"&#x22c8;",
77
+ kappa: :"&#x3ba;",
78
+ Delta: :"&#x394;",
79
+ delta: :"&#x3b4;",
80
+ gamma: :"&#x3b3;",
81
+ Gamma: :"&#x393;",
82
+ Theta: :"&#x398;",
83
+ theta: :"&#x3b8;",
84
+ alpha: :"&#x3b1;",
85
+ aleph: :"&#x2135;",
86
+ infty: :"&#x221e;",
87
+ equiv: :"&#x2261;",
88
+ frown: :"&#x2322;",
89
+ notin: :"&#x2209;",
90
+ angle: :"&#x2220;",
91
+ prime: :"&#x2032;",
92
+ "!in": :"&#x2209;",
93
+ cdots: :"&#x22ef;",
94
+ vdash: :"&#x22a2;",
95
+ wedge: :"&#x2227;",
96
+ oplus: :"&#x2295;",
97
+ nabla: :"&#x2207;",
98
+ ddots: :"&#x22f1;",
99
+ vdots: :"&#x22ee;",
100
+ Sigma: :"&#x3a3;",
101
+ Omega: :"&#x3a9;",
102
+ omega: :"&#x3c9;",
103
+ sigma: :"&#x3c3;",
104
+ times: :"&#xd7;",
105
+ ldots: :"&#x2026;",
106
+ ">-=": :"&#x2ab0;",
107
+ "-<=": :"&#x2aaf;",
108
+ "><|": :"&#x22ca;",
109
+ "|==": :"&#x22a8;",
110
+ "|--": :"&#x22a2;",
111
+ "^^^": :"&#x22c0;",
112
+ "|->": :"&#x21a6;",
113
+ ">->": :"&#x21a3;",
114
+ "->>": :"&#x21a0;",
115
+ "__|": :"&#x230b;",
116
+ "|__": :"&#x230a;",
117
+ "|><": :"&#x22c9;",
118
+ "_|_": :"&#x22a5;",
119
+ "***": :"&#x22c6;",
120
+ "<=>": :"&#x21d4;",
121
+ "...": :"&#x2026;",
122
+ "(:": :"&#x2329;",
123
+ ":)": :"&#x232a;",
124
+ quad: :"&#x2001;",
125
+ star: :"&#x22c6;",
126
+ odot: :"&#x2299;",
127
+ cdot: :"&#x22c5;",
128
+ rarr: :"&#x2192;",
129
+ darr: :"&#x2193;",
130
+ prop: :"&#x221d;",
131
+ lArr: :"&#x21d0;",
132
+ rArr: :"&#x21d2;",
133
+ uarr: :"&#x2191;",
134
+ hArr: :"&#x21d4;",
135
+ harr: :"&#x2194;",
136
+ larr: :"&#x2190;",
137
+ grad: :"&#x2207;",
138
+ circ: :"&#x2218;",
139
+ sube: :"&#x2286;",
140
+ supe: :"&#x2287;",
141
+ succ: :"&#x227b;",
142
+ prec: :"&#x227a;",
143
+ cong: :"&#x2245;",
144
+ beta: :"&#x3b2;",
145
+ zeta: :"&#x3b6;",
146
+ iota: :"&#x3b9;",
147
+ ":'": :"&#x2235;",
148
+ "^^": :"&#x2227;",
149
+ "o+": :"&#x2295;",
150
+ "o.": :"&#x2299;",
151
+ "**": :"&#x2217;",
152
+ "~~": :"&#x2248;",
153
+ "O/": :"&#x2205;",
154
+ "->": :"&#x2192;",
155
+ "=>": :"&#x21d2;",
156
+ ">>": :"&#x232a;",
157
+ "<<": :"&#x2329;",
158
+ "~|": :"&#x2309;",
159
+ "!=": :"&#x2260;",
160
+ ">-": :"&#x227b;",
161
+ "-<": :"&#x227a;",
162
+ "~=": :"&#x2245;",
163
+ "-=": :"&#x2261;",
164
+ ":.": :"&#x2234;",
165
+ ">=": :"&#x2265;",
166
+ "<=": :"&#x2264;",
167
+ "|~": :"&#x2308;",
168
+ "/_": :"&#x2220;",
169
+ "+-": :"&#xb1;",
170
+ "-:": :"&#xf7;",
171
+ "\\ ": :"&#xa0;",
172
+ "\\": :"\\",
173
+ "//": :/,
174
+ sup: :"&#x2283;",
175
+ sub: :"&#x2282;",
176
+ top: :"&#x22a4;",
177
+ vvv: :"&#x22c1;",
178
+ vee: :"&#x2228;",
179
+ nnn: :"&#x22c2;",
180
+ cap: :"&#x2229;",
181
+ ast: :"&#x2217;",
182
+ bot: :"&#x22a5;",
183
+ del: :"&#x2202;",
184
+ uuu: :"&#x22c3;",
185
+ cup: :"&#x222a;",
186
+ iff: :"&#x21d4;",
187
+ eta: :"&#x3b7;",
188
+ Phi: :"&#x3a6;",
189
+ Psi: :"&#x3a8;",
190
+ psi: :"&#x3c8;",
191
+ chi: :"&#x3c7;",
192
+ phi: :"&#x3d5;",
193
+ rho: :"&#x3c1;",
194
+ tau: :"&#x3c4;",
195
+ div: :"&#xf7;",
196
+ neg: :"&#xac;",
197
+ not: :"&#xac;",
198
+ "*": :"&#x22c5;",
199
+ "@": :"&#x40;",
200
+ "<": :"&#x3c;",
201
+ ">": :"&#x3e;",
202
+ "/": :"&#x2f;",
203
+ ":": :"&#x3a;",
204
+ "!": :"&#x21;",
205
+ ",": :"&#x2c;",
206
+ ";": :"&#x3b;",
207
+ "?": :"&#x3f;",
208
+ "$": :"&#x24;",
209
+ "~": :"&#x7e;",
210
+ "|": :"&#x7c;",
211
+ "%": :"&#x25;",
212
+ "'": :"&#x27;",
213
+ "&": :"&#x26;",
214
+ "#": :"&#x23;",
215
+ "=": :"=",
216
+ "-": :"-",
217
+ "+": :"+",
218
+ nn: :"&#x2229;",
219
+ vv: :"&#x2228;",
220
+ TT: :"&#x22a4;",
221
+ EE: :"&#x2203;",
222
+ ox: :"&#x2297;",
223
+ to: :"&#x2192;",
224
+ AA: :"&#x2200;",
225
+ uu: :"&#x222a;",
226
+ ne: :"&#x2260;",
227
+ oo: :"&#x221e;",
228
+ ge: :"&#x2265;",
229
+ le: :"&#x2264;",
230
+ in: :"&#x2208;",
231
+ nu: :"&#x3bd;",
232
+ mu: :"&#x3bc;",
233
+ pi: :"&#x3c0;",
234
+ Pi: :"&#x3a0;",
235
+ xi: :"&#x3be;",
236
+ Xi: :"&#x39e;",
237
+ xx: :"&#xd7;",
238
+ pm: :"&#xb1;",
239
+ gt: :"&#x3e;",
240
+ lt: :"&#x3c;",
241
+ if: :if,
242
+ }.freeze
233
243
  UNARY_CLASSES = %i[
244
+ underbrace
245
+ overbrace
246
+ underline
234
247
  arccos
235
248
  arcsin
236
249
  arctan
@@ -279,15 +292,8 @@ module Plurimath
279
292
  underset
280
293
  stackrel
281
294
  overset
282
- color
283
- prod
284
295
  frac
285
296
  root
286
- oint
287
- int
288
- sum
289
- mod
290
- log
291
297
  ].freeze
292
298
  FONT_STYLES = %i[
293
299
  mathfrak
@@ -298,11 +304,43 @@ module Plurimath
298
304
  mathbf
299
305
  bbb
300
306
  bb
307
+ rm
301
308
  fr
302
309
  cc
303
310
  sf
304
311
  tt
312
+ ii
313
+ ].freeze
314
+ SUB_SUP_CLASSES = %w[
315
+ prod
316
+ oint
317
+ lim
318
+ sum
319
+ log
320
+ int
305
321
  ].freeze
322
+ SPECIAL_BOLD_ALPHABETS = %w[
323
+ ZZ
324
+ RR
325
+ QQ
326
+ NN
327
+ CC
328
+ ].freeze
329
+
330
+ class << self
331
+ def precompile_constants
332
+ @values ||=
333
+ named_hash(UNARY_CLASSES, :unary_class)
334
+ .merge(named_hash(SYMBOLS.keys, :symbol))
335
+ .merge(named_hash(FONT_STYLES, :fonts))
336
+ .merge(named_hash(SPECIAL_BOLD_ALPHABETS, :special_fonts))
337
+ @values.sort_by { |v, _| -v.length }.to_h
338
+ end
339
+
340
+ def named_hash(hash_or_array, name_key)
341
+ hash_or_array.each_with_object({}) { |d, i| i[d] = name_key }
342
+ end
343
+ end
306
344
  end
307
345
  end
308
346
  end