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
@@ -0,0 +1,287 @@
1
+ == MathML Support
2
+
3
+ == Classes
4
+
5
+ === Fonts
6
+
7
+ * `double-struck`
8
+ * `sans-serif`
9
+ * `monospace`
10
+ * `fraktur`
11
+ * `script`
12
+ * `bold`
13
+
14
+ === Functions
15
+
16
+ * `stackrel`
17
+ * `underset`
18
+ * `mathfrak`
19
+ * `mathcal`
20
+ * `overset`
21
+ * `cancel`
22
+ * `obrace`
23
+ * `ubrace`
24
+ * `mathtt`
25
+ * `mathbf`
26
+ * `mathbb`
27
+ * `mathsf`
28
+ * `arctan`
29
+ * `arcsin`
30
+ * `arccos`
31
+ * `color`
32
+ * `floor`
33
+ * `tilde`
34
+ * `prod`
35
+ * `text`
36
+ * `norm`
37
+ * `sqrt`
38
+ * `cosh`
39
+ * `tanh`
40
+ * `sinh`
41
+ * `sech`
42
+ * `csch`
43
+ * `coth`
44
+ * `ddot`
45
+ * `ceil`
46
+ * `oint`
47
+ * `root`
48
+ * `frac`
49
+ * `log`
50
+ * `mod`
51
+ * `vec`
52
+ * `hat`
53
+ * `dot`
54
+ * `bar`
55
+ * `abs`
56
+ * `min`
57
+ * `max`
58
+ * `dim`
59
+ * `det`
60
+ * `csc`
61
+ * `cot`
62
+ * `lub`
63
+ * `lcm`
64
+ * `glb`
65
+ * `gcd`
66
+ * `exp`
67
+ * `sum`
68
+ * `cos`
69
+ * `tan`
70
+ * `sin`
71
+ * `int`
72
+ * `sec`
73
+ * `ln`
74
+ * `ul`
75
+ * `g`
76
+ * `f`
77
+
78
+
79
+ === Tags
80
+
81
+ * `annotation_xml`
82
+ * `annotation-xml`
83
+ * `mmultiscripts`
84
+ * `maligngroup`
85
+ * `munderover`
86
+ * `annotation`
87
+ * `malignmark`
88
+ * `semantics`
89
+ * `mscarries`
90
+ * `menclose`
91
+ * `mlongdiv`
92
+ * `mphantom`
93
+ * `mfenced`
94
+ * `msgroup`
95
+ * `maction`
96
+ * `mpadded`
97
+ * `msubsup`
98
+ * `mscarry`
99
+ * `msline`
100
+ * `mspace`
101
+ * `mstack`
102
+ * `mstyle`
103
+ * `mtable`
104
+ * `munder`
105
+ * `merror`
106
+ * `msqrt`
107
+ * `mroot`
108
+ * `msrow`
109
+ * `mover`
110
+ * `mfrac`
111
+ * `math`
112
+ * `mrow`
113
+ * `msub`
114
+ * `msup`
115
+ * `mtd`
116
+ * `mtr`
117
+ * `mn`
118
+ * `mo`
119
+ * `mi`
120
+ * `ms`
121
+
122
+ === Unicode symbols
123
+
124
+ |===
125
+ | Symbol code | Rendered symbol
126
+
127
+ | `\α` | α
128
+ | `\β` | β
129
+ | `\γ` | γ
130
+ | `\Γ` | Γ
131
+ | `\δ` | δ
132
+ | `\Δ` | Δ
133
+ | `\∆` | ∆
134
+ | `\ε` | ε
135
+ | `\ɛ` | ɛ
136
+ | `\ζ` | ζ
137
+ | `\η` | η
138
+ | `\θ` | θ
139
+ | `\Θ` | Θ
140
+ | `\ϑ` | ϑ
141
+ | `\ι` | ι
142
+ | `\κ` | κ
143
+ | `\λ` | λ
144
+ | `\Λ` | Λ
145
+ | `\μ` | μ
146
+ | `\ν` | ν
147
+ | `\ξ` | ξ
148
+ | `\Ξ` | Ξ
149
+ | `\π` | π
150
+ | `\Π` | Π
151
+ | `\ρ` | ρ
152
+ | `\ς` | ς
153
+ | `\σ` | σ
154
+ | `\Σ` | Σ
155
+ | `\τ` | τ
156
+ | `\υ` | υ
157
+ | `\φ` | φ
158
+ | `\Φ` | Φ
159
+ | `\ϕ` | ϕ
160
+ | `\χ` | χ
161
+ | `\ψ` | ψ
162
+ | `\Ψ` | Ψ
163
+ | `\ω` | ω
164
+ | `\Ω` | Ω
165
+ | `\⋅` | ⋅
166
+ | `\∙` | ∙
167
+ | `\·` | ·
168
+ | `\∗` | ∗
169
+ | `\⋆` | ⋆
170
+ | `\×` | ×
171
+ | `\⋉` | ⋉
172
+ | `\⋊` | ⋊
173
+ | `\⋈` | ⋈
174
+ | `\÷` | ÷
175
+ | `\∘` | ∘
176
+ | `\⊕` | ⊕
177
+ | `\⨁` | ⨁
178
+ | `\⊗` | ⊗
179
+ | `\⊙` | ⊙
180
+ | `\∑` | ∑
181
+ | `\∏` | ∏
182
+ | `\∏` | ∏
183
+ | `\∧` | ∧
184
+ | `\⋀` | ⋀
185
+ | `\∨` | ∨
186
+ | `\⋁` | ⋁
187
+ | `\∩` | ∩
188
+ | `\⋂` | ⋂
189
+ | `\∪` | ∪
190
+ | `\⋃` | ⋃
191
+ | `\≠` | ≠
192
+ | `\≤` | ≤
193
+ | `\≥` | ≥
194
+ | `\≺` | ≺
195
+ | `\≻` | ≻
196
+ | `\⪯` | ⪯
197
+ | `\⪰` | ⪰
198
+ | `\∈` | ∈
199
+ | `\∉` | ∉
200
+ | `\⊂` | ⊂
201
+ | `\⊃` | ⊃
202
+ | `\⊆` | ⊆
203
+ | `\⊇` | ⊇
204
+ | `\≡` | ≡
205
+ | `\≅` | ≅
206
+ | `\≈` | ≈
207
+ | `\∝` | ∝
208
+ | `\¬` | ¬
209
+ | `\∀` | ∀
210
+ | `\∃` | ∃
211
+ | `\⊥` | ⊥
212
+ | `\⊤` | ⊤
213
+ | `\⊢` | ⊢
214
+ | `\⊨` | ⊨
215
+ | `\〈` | 〈
216
+ | `\〉` | 〉
217
+ | `\⟨` | ⟨
218
+ | `\⟩` | ⟩
219
+ | `\∫` | ∫
220
+ | `\∮` | ∮
221
+ | `\∂` | ∂
222
+ | `\∇` | ∇
223
+ | `\±` | ±
224
+ | `\∅` | ∅
225
+ | `\∞` | ∞
226
+ | `\ℵ` | ℵ
227
+ | `\∴` | ∴
228
+ | `\∵` | ∵
229
+ | `\∠` | ∠
230
+ | `\△` | △
231
+ | `\′` | ′
232
+ | `\ \ ` |   
233
+ | `\ \ \ \ ` |     
234
+ | `\⌢` | ⌢
235
+ | `\⋯` | ⋯
236
+ | `\⋮` | ⋮
237
+ | `\⋱` | ⋱
238
+ | `\⋄` | ⋄
239
+ | `\□` | □
240
+ | `\⌊` | ⌊
241
+ | `\⌋` | ⌋
242
+ | `\⌈` | ⌈
243
+ | `\⌉` | ⌉
244
+ | `\ℂ` | ℂ
245
+ | `\ℕ` | ℕ
246
+ | `\ℚ` | ℚ
247
+ | `\ℝ` | ℝ
248
+ | `\ℤ` | ℤ
249
+ | `\↑` | ↑
250
+ | `\↓` | ↓
251
+ | `\←` | ←
252
+ | `\↔` | ↔
253
+ | `\⇒` | ⇒
254
+ | `\⇐` | ⇐
255
+ | `\⇔` | ⇔
256
+ | `\→` | →
257
+ | `\↣` | ↣
258
+ | `\↠` | ↠
259
+ | `\⤖` | ⤖
260
+ | `\↦` | ↦
261
+ | `\…` | …
262
+ | `\−` | −
263
+ | `\⁡` | ⁡
264
+ | `\⏞` | ⏞
265
+ | `\⏟` | ⏟
266
+
267
+ |===
268
+
269
+ === Symbols
270
+
271
+ * `|`
272
+ * `/`
273
+ * `\`
274
+ * `~`
275
+ * `(`
276
+ * `)`
277
+ * `(:`
278
+ * `:)`
279
+ * `{`
280
+ * `}`
281
+ * `{:`
282
+ * `:}`
283
+ * `]`
284
+ * `[`
285
+ * `=`
286
+ * `+`
287
+ * `-`
data/README.adoc ADDED
@@ -0,0 +1,96 @@
1
+ = Plurimath
2
+
3
+ This gem implements a mechanism of conversion between Math languages mentioned below.
4
+
5
+ 1. **AsciiMath**
6
+ 2. **MathML**
7
+ 3. **Latex**
8
+
9
+ == Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem "plurimath"
15
+ ```
16
+ And then execute:
17
+ ```shell
18
+ $ bundle install
19
+ ```
20
+ Or install it yourself as:
21
+ ```shell
22
+ $ gem install plurimath
23
+ ```
24
+
25
+ == Usage
26
+
27
+ Pass the string you want to convert and Math type of the string provided, which will give you **Plurimath::Math::Formula** object as output, Let's see some examples below.
28
+
29
+ === *Conversion Examples*
30
+
31
+ ===== Asciimath Formula Example
32
+ [source, ruby, indent=2]
33
+ ----
34
+ asciimath = "sin(1)"
35
+ formula = Plurimath::Math.parse(asciimath, :asciimath)
36
+ ----
37
+ ===== MathML Formula Example
38
+ [source, ruby, indent=2]
39
+ ----
40
+ mathml = <<~MATHML
41
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
42
+ <mstyle displaystyle='true'>
43
+ <mi>sin</mi>
44
+ <mn>1</mn>
45
+ </mstyle>
46
+ </math>
47
+ MATHML
48
+ formula = Plurimath::Math.parse(mathml, "mathml")
49
+ ----
50
+ ===== Latex Formula Example
51
+ [source, ruby, indent=2]
52
+ ----
53
+ latex = "\\sin{1}"
54
+ formula = Plurimath::Math.parse(latex, "latex")
55
+ ----
56
+ ---
57
+ Since we have the object of **Plurimath::Formula**,We can generate **AsciiMath**, **MathMl** or **Latex** string from the formula object,All we have to do is call conversion function on formula object, see examples below.
58
+
59
+ ===== AsciiMath Output conversion
60
+ [source, ruby, indent=2]
61
+ ----
62
+ formula.to_asciimath
63
+ > sin(1)
64
+ ----
65
+ *Note:*
66
+ Asciimath doesn't support link:AsciiMath-Supported-Data.adoc#symbols-inherited-from-latex[*following symbols*] but Latex does.So from Latex to Asciimath conversion we are returning latex's supported symbols if it's not supported in Asciimath.
67
+
68
+ ===== Latex Output conversion
69
+ [source, ruby, indent=2]
70
+ ----
71
+ formula.to_latex
72
+ > \\sin1
73
+ ----
74
+ ===== MathML Output conversion
75
+ [source, ruby, indent=2]
76
+ ----
77
+ formula.to_mathml
78
+ > <math xmlns='http://www.w3.org/1998/Math/MathML'>
79
+ > <mstyle displaystyle='true'>
80
+ > <mi>sin</mi>
81
+ > <mn>1</mn>
82
+ > </mstyle>
83
+ > </math>
84
+ ----
85
+ === Supported Content
86
+ --
87
+ link:AsciiMath-Supported-Data.adoc[AsciiMath Supported Data, target="_blank"]
88
+ --
89
+
90
+ --
91
+ link:MathML-Supported-Data.adoc[MathML Supported Data, target="_blank"]
92
+ --
93
+
94
+ --
95
+ link:Latex-Supported-Data.adoc[Latex Supported Data, target="_blank"]
96
+ --