plurimath 0.10.0 → 0.10.2
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/.rspec-opal +1 -1
- data/.rubocop.yml +9 -5
- data/.rubocop_todo.yml +0 -0
- data/Gemfile +7 -5
- data/README.adoc +57 -1
- data/Rakefile +11 -0
- data/lib/plurimath/asciimath/parse.rb +0 -1
- data/lib/plurimath/asciimath/parser.rb +0 -3
- data/lib/plurimath/asciimath.rb +5 -0
- data/lib/plurimath/cli.rb +28 -1
- data/lib/plurimath/errors.rb +0 -4
- data/lib/plurimath/formatter/numbers.rb +12 -0
- data/lib/plurimath/formatter/numeric_formatter.rb +4 -1
- data/lib/plurimath/formatter/standard.rb +0 -1
- data/lib/plurimath/formatter.rb +6 -9
- data/lib/plurimath/html/parse.rb +0 -1
- data/lib/plurimath/html/parser.rb +0 -3
- data/lib/plurimath/html.rb +5 -0
- data/lib/plurimath/latex/parse.rb +0 -1
- data/lib/plurimath/latex/parser.rb +2 -5
- data/lib/plurimath/latex.rb +5 -0
- data/lib/plurimath/math/core.rb +6 -2
- data/lib/plurimath/math/formula/mrow.rb +2 -41
- data/lib/plurimath/math/formula/mstyle.rb +6 -0
- data/lib/plurimath/math/formula.rb +59 -301
- data/lib/plurimath/math/function/abs.rb +0 -1
- data/lib/plurimath/math/function/arccos.rb +0 -1
- data/lib/plurimath/math/function/arcsin.rb +0 -1
- data/lib/plurimath/math/function/arctan.rb +0 -1
- data/lib/plurimath/math/function/arg.rb +0 -1
- data/lib/plurimath/math/function/bar.rb +0 -1
- data/lib/plurimath/math/function/base.rb +0 -3
- data/lib/plurimath/math/function/binary_function.rb +5 -3
- data/lib/plurimath/math/function/cancel.rb +0 -1
- data/lib/plurimath/math/function/ceil.rb +0 -1
- data/lib/plurimath/math/function/color.rb +0 -1
- data/lib/plurimath/math/function/cos.rb +0 -1
- data/lib/plurimath/math/function/cosh.rb +0 -1
- data/lib/plurimath/math/function/cot.rb +0 -1
- data/lib/plurimath/math/function/coth.rb +0 -1
- data/lib/plurimath/math/function/csc.rb +0 -1
- data/lib/plurimath/math/function/csch.rb +0 -1
- data/lib/plurimath/math/function/ddot.rb +0 -1
- data/lib/plurimath/math/function/deg.rb +0 -1
- data/lib/plurimath/math/function/det.rb +0 -1
- data/lib/plurimath/math/function/dim.rb +0 -1
- data/lib/plurimath/math/function/dot.rb +0 -1
- data/lib/plurimath/math/function/exp.rb +0 -1
- data/lib/plurimath/math/function/fenced.rb +1 -197
- data/lib/plurimath/math/function/floor.rb +0 -1
- data/lib/plurimath/math/function/font_style/bold-fraktur.rb +0 -1
- data/lib/plurimath/math/function/font_style/bold-italic.rb +0 -1
- data/lib/plurimath/math/function/font_style/bold-sans-serif.rb +0 -1
- data/lib/plurimath/math/function/font_style/bold-script.rb +0 -1
- data/lib/plurimath/math/function/font_style/bold.rb +0 -1
- data/lib/plurimath/math/function/font_style/double_struck.rb +0 -1
- data/lib/plurimath/math/function/font_style/fraktur.rb +0 -1
- data/lib/plurimath/math/function/font_style/italic.rb +0 -1
- data/lib/plurimath/math/function/font_style/monospace.rb +0 -1
- data/lib/plurimath/math/function/font_style/normal.rb +0 -1
- data/lib/plurimath/math/function/font_style/sans-serif-bold-italic.rb +0 -1
- data/lib/plurimath/math/function/font_style/sans-serif-italic.rb +0 -1
- data/lib/plurimath/math/function/font_style/sans-serif.rb +0 -1
- data/lib/plurimath/math/function/font_style/script.rb +0 -1
- data/lib/plurimath/math/function/font_style.rb +29 -2
- data/lib/plurimath/math/function/frac.rb +0 -3
- data/lib/plurimath/math/function/gcd.rb +0 -1
- data/lib/plurimath/math/function/glb.rb +0 -1
- data/lib/plurimath/math/function/hat.rb +0 -1
- data/lib/plurimath/math/function/hom.rb +0 -1
- data/lib/plurimath/math/function/inf.rb +1 -2
- data/lib/plurimath/math/function/int.rb +2 -3
- data/lib/plurimath/math/function/intent.rb +0 -1
- data/lib/plurimath/math/function/ker.rb +0 -1
- data/lib/plurimath/math/function/lcm.rb +0 -1
- data/lib/plurimath/math/function/left.rb +0 -1
- data/lib/plurimath/math/function/lg.rb +0 -1
- data/lib/plurimath/math/function/lim.rb +1 -2
- data/lib/plurimath/math/function/liminf.rb +0 -1
- data/lib/plurimath/math/function/limits.rb +0 -1
- data/lib/plurimath/math/function/limsup.rb +0 -1
- data/lib/plurimath/math/function/linebreak.rb +0 -1
- data/lib/plurimath/math/function/ln.rb +0 -1
- data/lib/plurimath/math/function/log.rb +1 -2
- data/lib/plurimath/math/function/longdiv.rb +0 -3
- data/lib/plurimath/math/function/lub.rb +0 -1
- data/lib/plurimath/math/function/max.rb +0 -1
- data/lib/plurimath/math/function/mbox.rb +0 -1
- data/lib/plurimath/math/function/menclose.rb +0 -3
- data/lib/plurimath/math/function/merror.rb +0 -3
- data/lib/plurimath/math/function/mglyph.rb +0 -3
- data/lib/plurimath/math/function/min.rb +0 -1
- data/lib/plurimath/math/function/mlabeledtr.rb +0 -20
- data/lib/plurimath/math/function/mod.rb +0 -1
- data/lib/plurimath/math/function/mpadded.rb +0 -3
- data/lib/plurimath/math/function/ms.rb +1 -77
- data/lib/plurimath/math/function/msgroup.rb +0 -27
- data/lib/plurimath/math/function/msline.rb +0 -3
- data/lib/plurimath/math/function/multiscript.rb +0 -14
- data/lib/plurimath/math/function/nary.rb +4 -0
- data/lib/plurimath/math/function/none.rb +1 -4
- data/lib/plurimath/math/function/norm.rb +0 -1
- data/lib/plurimath/math/function/obrace.rb +0 -1
- data/lib/plurimath/math/function/oint.rb +2 -3
- data/lib/plurimath/math/function/over.rb +0 -3
- data/lib/plurimath/math/function/overset.rb +3 -3
- data/lib/plurimath/math/function/phantom.rb +0 -3
- data/lib/plurimath/math/function/power.rb +0 -3
- data/lib/plurimath/math/function/power_base.rb +0 -3
- data/lib/plurimath/math/function/prod.rb +2 -3
- data/lib/plurimath/math/function/right.rb +0 -1
- data/lib/plurimath/math/function/root.rb +0 -3
- data/lib/plurimath/math/function/rule.rb +0 -1
- data/lib/plurimath/math/function/scarries.rb +0 -3
- data/lib/plurimath/math/function/scarry.rb +22 -0
- data/lib/plurimath/math/function/sec.rb +0 -1
- data/lib/plurimath/math/function/sech.rb +0 -1
- data/lib/plurimath/math/function/semantics.rb +0 -15
- data/lib/plurimath/math/function/sin.rb +0 -1
- data/lib/plurimath/math/function/sinh.rb +0 -1
- data/lib/plurimath/math/function/sqrt.rb +0 -3
- data/lib/plurimath/math/function/stackrel.rb +0 -3
- data/lib/plurimath/math/function/substack.rb +0 -1
- data/lib/plurimath/math/function/sum.rb +2 -3
- data/lib/plurimath/math/function/sup.rb +0 -1
- data/lib/plurimath/math/function/table/align.rb +0 -1
- data/lib/plurimath/math/function/table/array.rb +0 -1
- data/lib/plurimath/math/function/table/bmatrix.rb +0 -1
- data/lib/plurimath/math/function/table/cases.rb +0 -1
- data/lib/plurimath/math/function/table/eqarray.rb +0 -1
- data/lib/plurimath/math/function/table/matrix.rb +0 -1
- data/lib/plurimath/math/function/table/multline.rb +0 -1
- data/lib/plurimath/math/function/table/pmatrix.rb +0 -1
- data/lib/plurimath/math/function/table/split.rb +0 -1
- data/lib/plurimath/math/function/table/vmatrix.rb +0 -1
- data/lib/plurimath/math/function/table.rb +10 -23
- data/lib/plurimath/math/function/tan.rb +0 -1
- data/lib/plurimath/math/function/tanh.rb +0 -1
- data/lib/plurimath/math/function/td.rb +0 -4
- data/lib/plurimath/math/function/ternary_function.rb +6 -2
- data/lib/plurimath/math/function/text.rb +1 -6
- data/lib/plurimath/math/function/tilde.rb +4 -1
- data/lib/plurimath/math/function/tr.rb +0 -13
- data/lib/plurimath/math/function/ubrace.rb +0 -1
- data/lib/plurimath/math/function/ul.rb +4 -1
- data/lib/plurimath/math/function/underover.rb +0 -3
- data/lib/plurimath/math/function/underset.rb +22 -45
- data/lib/plurimath/math/function/unitsml.rb +2 -1
- data/lib/plurimath/math/function/vec.rb +4 -1
- data/lib/plurimath/math/function.rb +107 -10
- data/lib/plurimath/math/number.rb +9 -7
- data/lib/plurimath/math/symbols/comma.rb +1 -1
- data/lib/plurimath/math/symbols/plus.rb +1 -1
- data/lib/plurimath/math/symbols/symbol.rb +17 -4
- data/lib/plurimath/math.rb +8 -26
- data/lib/plurimath/mathml/constants.rb +1 -0
- data/lib/plurimath/mathml/formula_transformation.rb +442 -0
- data/lib/plurimath/mathml/parser.rb +11 -50
- data/lib/plurimath/mathml/translator.rb +584 -0
- data/lib/plurimath/mathml/utility/formula_transformation.rb +2 -341
- data/lib/plurimath/mathml.rb +5 -0
- data/lib/plurimath/number_formatter.rb +2 -1
- data/lib/plurimath/omml/parser.rb +10 -7
- data/lib/plurimath/omml/transform.rb +17 -5
- data/lib/plurimath/omml.rb +3 -0
- data/lib/plurimath/setup/opal.rb.erb +3 -4
- data/lib/plurimath/unicode_math/parse.rb +0 -5
- data/lib/plurimath/unicode_math/parser.rb +1 -6
- data/lib/plurimath/unicode_math/parsing_rules/absence_rules.rb +0 -1
- data/lib/plurimath/unicode_math/parsing_rules/common_rules.rb +0 -1
- data/lib/plurimath/unicode_math/parsing_rules/constants_rules.rb +0 -1
- data/lib/plurimath/unicode_math/parsing_rules/masked.rb +0 -1
- data/lib/plurimath/unicode_math/parsing_rules/sub_sup.rb +0 -1
- data/lib/plurimath/unicode_math/parsing_rules.rb +14 -0
- data/lib/plurimath/unicode_math.rb +6 -0
- data/lib/plurimath/utility.rb +1 -1
- data/lib/plurimath/version.rb +1 -1
- data/lib/plurimath/xml_engine/oga.rb +6 -6
- data/lib/plurimath/xml_engine/ox_engine.rb +2 -2
- data/lib/plurimath/xml_engine.rb +2 -0
- data/lib/plurimath.rb +43 -18
- data/plurimath.gemspec +5 -4
- metadata +33 -15
- data/lib/plurimath/mathml/utility/empty_defined_methods.rb +0 -483
- data/lib/plurimath/mathml/utility.rb +0 -369
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a2ce7ef29dd4032b83c86b06d92276325630994243ef48e193aa8d3092e2fe22
|
|
4
|
+
data.tar.gz: ebaec8740845b7f1cb76e690f95f349d98d18a0b1342528463d8af3187138d1c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a80a5ad2febd36bad53adc58c6a3d6406ee04bd78c05c2e3ea7eeecf0f924818798de20c745995ee38b161ffc3758389bb80d6ad6487de16183abdc12e88f166
|
|
7
|
+
data.tar.gz: 2f1258c3745a73a0c1d4336f489d1908cfc4691a19b093dc2d0a4bcd19612ad4d449a6f452ff963a27ca01aba6eada160be778e22f7705129fc44f43ad092985
|
data/.rspec-opal
CHANGED
data/.rubocop.yml
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
# Auto-generated by Cimas: Do not edit it manually!
|
|
2
|
-
# See https://github.com/metanorma/cimas
|
|
3
1
|
inherit_from:
|
|
4
2
|
- https://raw.githubusercontent.com/riboseinc/oss-guides/master/ci/rubocop.yml
|
|
3
|
+
- .rubocop_todo.yml
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
plugins:
|
|
6
|
+
- rubocop-performance
|
|
7
|
+
- rubocop-rake
|
|
8
|
+
- rubocop-rspec
|
|
8
9
|
|
|
9
10
|
AllCops:
|
|
10
|
-
TargetRubyVersion:
|
|
11
|
+
TargetRubyVersion: 3.0
|
|
12
|
+
NewCops: enable
|
|
13
|
+
Exclude:
|
|
14
|
+
- 'vendor/**/*'
|
data/.rubocop_todo.yml
ADDED
|
File without changes
|
data/Gemfile
CHANGED
|
@@ -3,12 +3,14 @@ source "https://rubygems.org"
|
|
|
3
3
|
# Specify your gem's dependencies in plurimath.gemspec
|
|
4
4
|
gemspec
|
|
5
5
|
|
|
6
|
+
gem 'lutaml-model', github: "lutaml/lutaml-model", branch: "main"
|
|
7
|
+
gem 'canon'
|
|
6
8
|
gem "rake", "~> 12.0"
|
|
7
9
|
gem "rspec", "~> 3.0"
|
|
8
|
-
gem
|
|
9
|
-
gem
|
|
10
|
-
gem
|
|
11
|
-
gem 'opal-rspec', "~> 1.1.0a"
|
|
10
|
+
gem "rubocop-performance"
|
|
11
|
+
gem "rubocop-rake"
|
|
12
|
+
gem "rubocop-rspec"
|
|
12
13
|
gem 'oga'
|
|
14
|
+
gem 'opal-rspec', "~> 1.1.0a"
|
|
13
15
|
gem 'ox'
|
|
14
|
-
gem
|
|
16
|
+
gem 'simplecov', require: false, group: :test
|
data/README.adoc
CHANGED
|
@@ -1135,7 +1135,9 @@ method using a `formatter` option, which serializes the formula into an math
|
|
|
1135
1135
|
representation language.
|
|
1136
1136
|
|
|
1137
1137
|
The formatter should be an instance of `Plurimath::NumberFormatter` or a custom
|
|
1138
|
-
formatter derived from `Plurimath::Formatter::Standard`.
|
|
1138
|
+
formatter derived from `Plurimath::Formatter::Standard`. Custom formatters can
|
|
1139
|
+
define a `format(formula, number)` method to make context-aware formatting
|
|
1140
|
+
decisions based on the surrounding formula (see <<Contextual number formatting>>).
|
|
1139
1141
|
|
|
1140
1142
|
The quick example below demonstrates how to format a number in a formula.
|
|
1141
1143
|
|
|
@@ -1346,6 +1348,60 @@ end
|
|
|
1346
1348
|
====
|
|
1347
1349
|
|
|
1348
1350
|
|
|
1351
|
+
==== Contextual number formatting
|
|
1352
|
+
|
|
1353
|
+
In some cases, certain numbers within a formula should be formatted differently
|
|
1354
|
+
depending on their context. For example, a year like "2024" should not have digit
|
|
1355
|
+
grouping applied, while other numbers in the same formula should.
|
|
1356
|
+
|
|
1357
|
+
The `format` method on the formatter receives both the root
|
|
1358
|
+
`Plurimath::Math::Formula` tree and the current `Plurimath::Math::Number` node
|
|
1359
|
+
being processed, allowing context-aware formatting decisions.
|
|
1360
|
+
|
|
1361
|
+
.Signature of the `format` method
|
|
1362
|
+
[source,ruby]
|
|
1363
|
+
----
|
|
1364
|
+
def format(formula, number)
|
|
1365
|
+
# formula: the root Plurimath::Math::Formula containing the full equation
|
|
1366
|
+
# number: the Plurimath::Math::Number node currently being formatted
|
|
1367
|
+
# returns: a formatted string
|
|
1368
|
+
end
|
|
1369
|
+
----
|
|
1370
|
+
|
|
1371
|
+
Formatters that do not define `format` will fall back to `localized_number`, so
|
|
1372
|
+
existing formatters continue to work without changes.
|
|
1373
|
+
|
|
1374
|
+
To implement contextual formatting, define a `format` method in a custom
|
|
1375
|
+
formatter subclass.
|
|
1376
|
+
|
|
1377
|
+
.Creating a year-aware formatter that skips digit grouping for year-like numbers
|
|
1378
|
+
[example]
|
|
1379
|
+
====
|
|
1380
|
+
[source,ruby]
|
|
1381
|
+
----
|
|
1382
|
+
class YearFormatter < Plurimath::Formatter::Standard
|
|
1383
|
+
def format(formula, number) <1>
|
|
1384
|
+
int_value = Integer(number.value, exception: false)
|
|
1385
|
+
if int_value && int_value > 1800 && int_value < 2200 <2>
|
|
1386
|
+
number.value.to_s
|
|
1387
|
+
else
|
|
1388
|
+
localized_number(number.value.to_s) <3>
|
|
1389
|
+
end
|
|
1390
|
+
end
|
|
1391
|
+
end
|
|
1392
|
+
|
|
1393
|
+
formatter = YearFormatter.new
|
|
1394
|
+
formula = Plurimath::Math.parse("2024 + 1000000", :asciimath)
|
|
1395
|
+
formula.to_latex(formatter: formatter)
|
|
1396
|
+
# => "2024 + 1,000,000" <4>
|
|
1397
|
+
----
|
|
1398
|
+
<1> Define `format` to receive the formula tree and number node.
|
|
1399
|
+
<2> Detect year-like numbers and return them unformatted.
|
|
1400
|
+
<3> Call `localized_number` to apply locale-based formatting for other numbers.
|
|
1401
|
+
<4> "2024" is left as-is, while "1000000" is formatted with digit grouping.
|
|
1402
|
+
====
|
|
1403
|
+
|
|
1404
|
+
|
|
1349
1405
|
[[standard_configuration]]
|
|
1350
1406
|
=== Default number formatting configuration
|
|
1351
1407
|
|
data/Rakefile
CHANGED
|
@@ -105,7 +105,18 @@ def write_intent_doc_file(file)
|
|
|
105
105
|
file.write("\nIntent for unary classes like, sin, cos, tan, etc. will be `Function`.\n")
|
|
106
106
|
end
|
|
107
107
|
|
|
108
|
+
def require_math_function_files
|
|
109
|
+
(
|
|
110
|
+
Dir.glob(File.join(__dir__, "lib/plurimath/math/function", "*.rb")) +
|
|
111
|
+
Dir.glob(File.join(__dir__, "lib/plurimath/math/function", "*", "*.rb"))
|
|
112
|
+
).each do |file|
|
|
113
|
+
require file
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
108
117
|
def intent_classes
|
|
118
|
+
require_math_function_files
|
|
119
|
+
|
|
109
120
|
intent_classes = [
|
|
110
121
|
Plurimath::Math::Function::TernaryFunction.descendants,
|
|
111
122
|
Plurimath::Math::Function::BinaryFunction.descendants,
|
data/lib/plurimath/asciimath.rb
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
module Plurimath
|
|
4
4
|
class Asciimath
|
|
5
|
+
autoload :Constants, "#{__dir__}/asciimath/constants"
|
|
6
|
+
autoload :Parse, "#{__dir__}/asciimath/parse"
|
|
7
|
+
autoload :Parser, "#{__dir__}/asciimath/parser"
|
|
8
|
+
autoload :Transform, "#{__dir__}/asciimath/transform"
|
|
9
|
+
|
|
5
10
|
attr_accessor :text
|
|
6
11
|
|
|
7
12
|
def initialize(text)
|
data/lib/plurimath/cli.rb
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "thor"
|
|
4
|
+
require_relative "../plurimath"
|
|
4
5
|
|
|
5
6
|
module Plurimath
|
|
6
|
-
self.autoload :Math, "plurimath/math"
|
|
7
7
|
|
|
8
8
|
class Cli < Thor
|
|
9
9
|
desc "convert", "Convert between math formats"
|
|
@@ -43,6 +43,11 @@ module Plurimath
|
|
|
43
43
|
desc: "Splits only MathML and OMML equations into multiple equations, Boolean only",
|
|
44
44
|
force: :boolean
|
|
45
45
|
|
|
46
|
+
option :xml_engine,
|
|
47
|
+
aliases: "-e",
|
|
48
|
+
default: "ox",
|
|
49
|
+
desc: "XML engine to use for parsing and rendering (ox or oga)"
|
|
50
|
+
|
|
46
51
|
def convert
|
|
47
52
|
input = options[:input]
|
|
48
53
|
input_string = options[:file_path] ? File.read(options[:file_path]) : input
|
|
@@ -50,6 +55,7 @@ module Plurimath
|
|
|
50
55
|
|
|
51
56
|
input_format = options[:input_format]
|
|
52
57
|
output_format = options[:output_format]
|
|
58
|
+
configure_xml_engine(input_format, output_format)
|
|
53
59
|
formula = Plurimath::Math.parse(input_string, input_format)
|
|
54
60
|
return puts formula.to_display(output_format.to_sym) if YAML.safe_load(options[:math_rendering])
|
|
55
61
|
|
|
@@ -75,6 +81,27 @@ module Plurimath
|
|
|
75
81
|
end
|
|
76
82
|
|
|
77
83
|
no_commands do
|
|
84
|
+
def configure_xml_engine(input_format, output_format)
|
|
85
|
+
xml_formats = %w[mathml omml]
|
|
86
|
+
return unless xml_formats.include?(input_format) || xml_formats.include?(output_format)
|
|
87
|
+
|
|
88
|
+
set_xml_engine(options[:xml_engine])
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def set_xml_engine(engine)
|
|
92
|
+
engine_class = case engine
|
|
93
|
+
when "ox"
|
|
94
|
+
require_relative "setup/ox_engine"
|
|
95
|
+
Plurimath::XmlEngine::OxEngine
|
|
96
|
+
when "oga"
|
|
97
|
+
require_relative "setup/oga"
|
|
98
|
+
Plurimath::XmlEngine::Oga
|
|
99
|
+
else
|
|
100
|
+
warn_and_exit("Invalid XML engine: #{engine}. Use 'ox' or 'oga'.")
|
|
101
|
+
end
|
|
102
|
+
Plurimath.xml_engine = engine_class
|
|
103
|
+
end
|
|
104
|
+
|
|
78
105
|
def warn_and_exit(message)
|
|
79
106
|
warn(message)
|
|
80
107
|
abort
|
data/lib/plurimath/errors.rb
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Plurimath
|
|
4
|
+
module Formatter
|
|
5
|
+
module Numbers
|
|
6
|
+
autoload :Base, "#{__dir__}/numbers/base"
|
|
7
|
+
autoload :Fraction, "#{__dir__}/numbers/fraction"
|
|
8
|
+
autoload :Integer, "#{__dir__}/numbers/integer"
|
|
9
|
+
autoload :Significant, "#{__dir__}/numbers/significant"
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -78,7 +78,10 @@ module Plurimath
|
|
|
78
78
|
end
|
|
79
79
|
|
|
80
80
|
def notation_chars(num_str)
|
|
81
|
-
|
|
81
|
+
bd = BigDecimal(num_str)
|
|
82
|
+
return [num_str, 0] if bd.zero?
|
|
83
|
+
|
|
84
|
+
notation_array = bd.to_s("e").split("e")
|
|
82
85
|
notation_array[1] = update_exponent_value(notation_array[1])
|
|
83
86
|
number_str = notation_array[0]
|
|
84
87
|
number_str = number_str.gsub(/0\.(\d)/, '\1.')
|
data/lib/plurimath/formatter.rb
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative "errors/formatter/unsupported_base"
|
|
4
|
-
require_relative "formatter/numeric_formatter"
|
|
5
|
-
require_relative "formatter/supported_locales"
|
|
6
|
-
require_relative "formatter/numbers/base"
|
|
7
|
-
require_relative "formatter/numbers/integer"
|
|
8
|
-
require_relative "formatter/numbers/fraction"
|
|
9
|
-
require_relative "formatter/numbers/significant"
|
|
10
|
-
require_relative "formatter/number_formatter"
|
|
11
|
-
|
|
12
3
|
module Plurimath
|
|
13
4
|
module Formatter
|
|
5
|
+
autoload :NumericFormatter, "#{__dir__}/formatter/numeric_formatter"
|
|
6
|
+
autoload :NumberFormatter, "#{__dir__}/formatter/number_formatter"
|
|
7
|
+
autoload :SupportedLocales, "#{__dir__}/formatter/supported_locales"
|
|
8
|
+
autoload :UnsupportedBase, "#{__dir__}/errors/formatter/unsupported_base"
|
|
9
|
+
autoload :Numbers, "#{__dir__}/formatter/numbers"
|
|
10
|
+
autoload :Standard, "#{__dir__}/formatter/standard"
|
|
14
11
|
end
|
|
15
12
|
end
|
data/lib/plurimath/html/parse.rb
CHANGED
data/lib/plurimath/html.rb
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
module Plurimath
|
|
4
4
|
class Html
|
|
5
|
+
autoload :Constants, "#{__dir__}/html/constants"
|
|
6
|
+
autoload :Parse, "#{__dir__}/html/parse"
|
|
7
|
+
autoload :Parser, "#{__dir__}/html/parser"
|
|
8
|
+
autoload :Transform, "#{__dir__}/html/transform"
|
|
9
|
+
|
|
5
10
|
attr_accessor :text
|
|
6
11
|
|
|
7
12
|
def initialize(text)
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative "parse"
|
|
4
|
-
require_relative "constants"
|
|
5
|
-
require_relative "transform"
|
|
6
3
|
module Plurimath
|
|
7
4
|
class Latex
|
|
8
5
|
class Parser
|
|
@@ -11,6 +8,7 @@ module Plurimath
|
|
|
11
8
|
TEXT_REGEX = %r(\\(?:mbox|text)\{[^\}]+\})
|
|
12
9
|
|
|
13
10
|
def initialize(text)
|
|
11
|
+
@enti = ::HTMLEntities.new
|
|
14
12
|
@text = pre_processing(text)
|
|
15
13
|
end
|
|
16
14
|
|
|
@@ -26,8 +24,7 @@ module Plurimath
|
|
|
26
24
|
|
|
27
25
|
def pre_processing(text)
|
|
28
26
|
text_functions = text.scan(TEXT_REGEX)
|
|
29
|
-
|
|
30
|
-
text = enti.encode(enti.decode(text), :hexadecimal)
|
|
27
|
+
text = @enti.encode(@enti.decode(text), :hexadecimal)
|
|
31
28
|
text = gsub_space_and_unicodes(text)
|
|
32
29
|
text.gsub(TEXT_REGEX) { |str| text_functions.shift }
|
|
33
30
|
end
|
data/lib/plurimath/latex.rb
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
module Plurimath
|
|
4
4
|
class Latex
|
|
5
|
+
autoload :Constants, "#{__dir__}/latex/constants"
|
|
6
|
+
autoload :Parse, "#{__dir__}/latex/parse"
|
|
7
|
+
autoload :Parser, "#{__dir__}/latex/parser"
|
|
8
|
+
autoload :Transform, "#{__dir__}/latex/transform"
|
|
9
|
+
|
|
5
10
|
attr_accessor :text
|
|
6
11
|
|
|
7
12
|
def initialize(text)
|
data/lib/plurimath/math/core.rb
CHANGED
|
@@ -285,7 +285,12 @@ module Plurimath
|
|
|
285
285
|
end
|
|
286
286
|
|
|
287
287
|
def variables
|
|
288
|
-
instance_variables
|
|
288
|
+
instance_variables.reject do |var|
|
|
289
|
+
name = var.to_s
|
|
290
|
+
name.start_with?("@__") ||
|
|
291
|
+
name.start_with?("@lutaml") ||
|
|
292
|
+
name == "@using_default"
|
|
293
|
+
end
|
|
289
294
|
end
|
|
290
295
|
|
|
291
296
|
def ox_element(node, attributes: [], namespace: "")
|
|
@@ -348,7 +353,6 @@ module Plurimath
|
|
|
348
353
|
def pretty_print_instance_variables
|
|
349
354
|
excluded_vars = [
|
|
350
355
|
:@left_right_wrapper,
|
|
351
|
-
:@temp_mathml_order,
|
|
352
356
|
:@using_default,
|
|
353
357
|
:@displaystyle,
|
|
354
358
|
:@__encoding,
|
|
@@ -16,30 +16,10 @@ module Plurimath
|
|
|
16
16
|
@is_mrow = true
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
def element_order=(value)
|
|
20
|
-
@value = validated_order(value&.map(&:name), rejectable_array: ["comment"])
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def content; end
|
|
24
|
-
|
|
25
|
-
def content=(value)
|
|
26
|
-
arr_value = Array(value)
|
|
27
|
-
if no_content_in?(arr_value)
|
|
28
|
-
delete_all_text
|
|
29
|
-
else
|
|
30
|
-
validate_text_order(
|
|
31
|
-
arr_value.map { |val| validate_symbols(val) unless val.strip.empty? }
|
|
32
|
-
)
|
|
33
|
-
end
|
|
34
|
-
organize_value
|
|
35
|
-
end
|
|
36
|
-
|
|
37
19
|
def is_mrow?
|
|
38
20
|
@is_mrow
|
|
39
21
|
end
|
|
40
22
|
|
|
41
|
-
private
|
|
42
|
-
|
|
43
23
|
def organize_value
|
|
44
24
|
return if value.any?(String)
|
|
45
25
|
return unless is_mrow
|
|
@@ -62,6 +42,8 @@ module Plurimath
|
|
|
62
42
|
end
|
|
63
43
|
end
|
|
64
44
|
|
|
45
|
+
private
|
|
46
|
+
|
|
65
47
|
def update_current_element(element, value, index)
|
|
66
48
|
if first_and_last_values_nil?(value)
|
|
67
49
|
replace_symbols_with_parens(value)
|
|
@@ -70,27 +52,6 @@ module Plurimath
|
|
|
70
52
|
end
|
|
71
53
|
end
|
|
72
54
|
|
|
73
|
-
def validate_text_order(value)
|
|
74
|
-
@value.each_with_index do |item, index|
|
|
75
|
-
next unless item == "text"
|
|
76
|
-
|
|
77
|
-
if value.first
|
|
78
|
-
@value[index] = value.shift
|
|
79
|
-
else
|
|
80
|
-
value.shift
|
|
81
|
-
@value.delete_at(index)
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
def delete_all_text
|
|
87
|
-
@value.delete("text")
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
def no_content_in?(value)
|
|
91
|
-
value.nil? || value.empty? || value&.all? { |val| val.strip.empty? }
|
|
92
|
-
end
|
|
93
|
-
|
|
94
55
|
def first_and_last_values_nil?(value)
|
|
95
56
|
value.first.class_name == "symbol" &&
|
|
96
57
|
value.first.value.nil? &&
|
|
@@ -11,6 +11,12 @@ module Plurimath
|
|
|
11
11
|
def is_mstyle?
|
|
12
12
|
true
|
|
13
13
|
end
|
|
14
|
+
|
|
15
|
+
def omml_content(display_style, options:)
|
|
16
|
+
# Use Mstyle's own @displaystyle, not the passed-in display_style
|
|
17
|
+
effective_display = @displaystyle.nil? ? display_style : @displaystyle
|
|
18
|
+
value&.map { |val| val.insert_t_tag(effective_display, options: options) }
|
|
19
|
+
end
|
|
14
20
|
end
|
|
15
21
|
end
|
|
16
22
|
end
|