latexmath 0.1.0 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.editorconfig +14 -0
- data/.github/workflows/test.yml +80 -0
- data/.gitignore +11 -0
- data/.rubocop.yml +129 -0
- data/Gemfile +6 -3
- data/Gemfile.lock +44 -3
- data/README.adoc +28 -0
- data/Rakefile +93 -4
- data/bin/console +3 -3
- data/exe/latexmath +8 -0
- data/latexmath.gemspec +17 -14
- data/lib/latexmath.rb +76 -10
- data/lib/latexmath/aggregator.rb +351 -0
- data/lib/latexmath/constants/symbols.rb +3936 -0
- data/lib/latexmath/converter.rb +424 -0
- data/lib/latexmath/equation.rb +3 -30
- data/lib/latexmath/ext.rb +9 -0
- data/lib/latexmath/symbol.rb +21 -0
- data/lib/latexmath/tokenizer.rb +82 -0
- data/lib/latexmath/version.rb +1 -1
- data/lib/latexmath/xml/builder.rb +4 -0
- data/lib/latexmath/xml/element.rb +25 -0
- data/lib/unimathsymbols.js.erb +4 -0
- data/lib/unimathsymbols.txt +2864 -0
- data/opal/latexmath-opal.rb +40 -0
- data/opal/ox.rb +64 -0
- data/opal/pseudoenumerator.rb +19 -0
- metadata +74 -17
- data/.travis.yml +0 -6
- data/README.md +0 -40
- data/lib/latexmath/latexml_requirement.rb +0 -84
- data/lib/latexmath/requirement.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3dd210bb97aa808bf1bee45d595148730fd1e324917a7fe402c05dcda243357e
|
4
|
+
data.tar.gz: 2bf325bde0a31dee92da668bd985d11cbc43424aeb1a3e94397ffbe7b6803a95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0ee9acb802192c32b47f22a8563964efd6640d8d606cd622e9f152dd46fd4f1fbe7d2c017aa8f1cc0e769e3b69d20b3e111946be67faed4420f45a519078053
|
7
|
+
data.tar.gz: e3cf465915d734f68290aecb7d9b1c9747b9b8202b5c673536899f97356e0fef341428950c31782b228209e4ea4eeb06cb5e87a2b925478a3e05fbee4261f6b9
|
data/.editorconfig
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
name: test
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request:
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
build:
|
10
|
+
name: Run specs on ${{ matrix.os }} ruby ${{ matrix.ruby }}
|
11
|
+
runs-on: ${{ matrix.os }}
|
12
|
+
continue-on-error: ${{ matrix.experimental }}
|
13
|
+
strategy:
|
14
|
+
fail-fast: false
|
15
|
+
matrix:
|
16
|
+
os: [ubuntu-latest, macos-latest, windows-latest]
|
17
|
+
ruby: ['2.6', '2.5', '2.4']
|
18
|
+
experimental: [false]
|
19
|
+
include:
|
20
|
+
- ruby: '2.7'
|
21
|
+
os: ubuntu-latest
|
22
|
+
experimental: true
|
23
|
+
- ruby: '2.7'
|
24
|
+
os: macos-latest
|
25
|
+
experimental: true
|
26
|
+
- ruby: '2.7'
|
27
|
+
os: windows-latest
|
28
|
+
experimental: true
|
29
|
+
|
30
|
+
steps:
|
31
|
+
- name: Use Ruby
|
32
|
+
uses: actions/setup-ruby@v1
|
33
|
+
with:
|
34
|
+
ruby-version: ${{ matrix.ruby }}
|
35
|
+
|
36
|
+
- uses: actions/checkout@master
|
37
|
+
|
38
|
+
- name: Install gems
|
39
|
+
run: |
|
40
|
+
gem install bundler -v "~> 2"
|
41
|
+
bundle install --jobs 4 --retry 5
|
42
|
+
|
43
|
+
- name: Install LaTeXML on Ubuntu
|
44
|
+
if: matrix.os == 'ubuntu-latest'
|
45
|
+
run: |
|
46
|
+
sudo snap install latexml --edge
|
47
|
+
echo "::add-path::/snap/bin"
|
48
|
+
|
49
|
+
- name: Install LaTeXML on macOS
|
50
|
+
if: matrix.os == 'macos-latest'
|
51
|
+
run: |
|
52
|
+
brew install libxml2 cpanminus
|
53
|
+
env PATH=$(brew --prefix libxml2)/bin:$PATH \
|
54
|
+
cpanm --notest XML::LibXSLT@1.96 git://github.com/brucemiller/LaTeXML.git@9a0e7dc5
|
55
|
+
|
56
|
+
- name: Install LaTeXML on Windows
|
57
|
+
if: matrix.os == 'windows-latest'
|
58
|
+
shell: cmd
|
59
|
+
run: |
|
60
|
+
cinst -y latexml
|
61
|
+
refreshenv
|
62
|
+
set PATH=C:\Strawberry\c\bin;C:\Strawberry\perl\site\bin;C:\Strawberry\perl\bin;%PATH%
|
63
|
+
where latexmlmath
|
64
|
+
|
65
|
+
- name: Run RSpecs
|
66
|
+
if: matrix.os == 'ubuntu-latest'
|
67
|
+
run: |
|
68
|
+
bundle exec rake
|
69
|
+
|
70
|
+
- name: Run RSpecs
|
71
|
+
if: matrix.os == 'macos-latest'
|
72
|
+
run: |
|
73
|
+
env PATH=$(brew --prefix perl)/bin:$PATH bundle exec rake
|
74
|
+
|
75
|
+
- name: Run specs
|
76
|
+
if: matrix.os == 'windows-latest'
|
77
|
+
shell: pwsh
|
78
|
+
run: |
|
79
|
+
$env:Path = "C:\Strawberry\c\bin;C:\Strawberry\perl\site\bin;C:\Strawberry\perl\bin;$env:Path"
|
80
|
+
bundle exec rake
|
data/.gitignore
CHANGED
@@ -7,5 +7,16 @@
|
|
7
7
|
/spec/reports/
|
8
8
|
/tmp/
|
9
9
|
|
10
|
+
# ignore generated file via Rakefile
|
11
|
+
#/lib/latexmath/constants/symbols.rb
|
12
|
+
|
10
13
|
# rspec failure tracking
|
11
14
|
.rspec_status
|
15
|
+
|
16
|
+
# ignore byebug history
|
17
|
+
.byebug_history
|
18
|
+
|
19
|
+
# ignore MacOS system file
|
20
|
+
.DS_Store
|
21
|
+
|
22
|
+
/dist/
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
Layout/EndAlignment:
|
2
|
+
Exclude:
|
3
|
+
- 'lib/latexmath/converter.rb'
|
4
|
+
- 'lib/latexmath/tokenizer.rb'
|
5
|
+
|
6
|
+
# Offense count: 1
|
7
|
+
# Configuration parameters: AllowSafeAssignment.
|
8
|
+
Lint/AssignmentInCondition:
|
9
|
+
Exclude:
|
10
|
+
- 'lib/latexmath/tokenizer.rb'
|
11
|
+
|
12
|
+
# Offense count: 2
|
13
|
+
Lint/ImplicitStringConcatenation:
|
14
|
+
Exclude:
|
15
|
+
- 'spec/tokenizer_spec.rb'
|
16
|
+
|
17
|
+
# Offense count: 1
|
18
|
+
# Configuration parameters: AllowKeywordBlockArguments.
|
19
|
+
Lint/UnderscorePrefixedVariableName:
|
20
|
+
Exclude:
|
21
|
+
- 'lib/latexmath/converter.rb'
|
22
|
+
|
23
|
+
# Offense count: 2
|
24
|
+
Lint/UselessAssignment:
|
25
|
+
Exclude:
|
26
|
+
- 'lib/latexmath/converter.rb'
|
27
|
+
|
28
|
+
# Offense count: 7
|
29
|
+
# Configuration parameters: IgnoredMethods.
|
30
|
+
Metrics/AbcSize:
|
31
|
+
Max: 32
|
32
|
+
|
33
|
+
# Offense count: 1
|
34
|
+
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods.
|
35
|
+
# ExcludedMethods: refine
|
36
|
+
Metrics/BlockLength:
|
37
|
+
Max: 35
|
38
|
+
|
39
|
+
# Offense count: 1
|
40
|
+
# Configuration parameters: CountBlocks.
|
41
|
+
Metrics/BlockNesting:
|
42
|
+
Max: 4
|
43
|
+
|
44
|
+
# Offense count: 1
|
45
|
+
# Configuration parameters: CountComments, CountAsOne.
|
46
|
+
Metrics/ClassLength:
|
47
|
+
Max: 157
|
48
|
+
|
49
|
+
# Offense count: 6
|
50
|
+
# Configuration parameters: IgnoredMethods.
|
51
|
+
Metrics/CyclomaticComplexity:
|
52
|
+
Max: 13
|
53
|
+
|
54
|
+
# Offense count: 9
|
55
|
+
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods.
|
56
|
+
Metrics/MethodLength:
|
57
|
+
Max: 39
|
58
|
+
|
59
|
+
# Offense count: 6
|
60
|
+
# Configuration parameters: IgnoredMethods.
|
61
|
+
Metrics/PerceivedComplexity:
|
62
|
+
Max: 14
|
63
|
+
|
64
|
+
# Offense count: 1
|
65
|
+
Naming/ConstantName:
|
66
|
+
Exclude:
|
67
|
+
- 'lib/latexmath.rb'
|
68
|
+
|
69
|
+
# Offense count: 2
|
70
|
+
# Cop supports --auto-correct.
|
71
|
+
# Configuration parameters: AutoCorrect, EnforcedStyle.
|
72
|
+
# SupportedStyles: nested, compact
|
73
|
+
Style/ClassAndModuleChildren:
|
74
|
+
Exclude:
|
75
|
+
- 'lib/latexmath/xml/builder.rb'
|
76
|
+
- 'lib/latexmath/xml/element.rb'
|
77
|
+
|
78
|
+
# Offense count: 7
|
79
|
+
Style/Documentation:
|
80
|
+
Exclude:
|
81
|
+
- 'spec/**/*'
|
82
|
+
- 'test/**/*'
|
83
|
+
- 'lib/latexmath.rb'
|
84
|
+
- 'lib/latexmath/aggregator.rb'
|
85
|
+
- 'lib/latexmath/converter.rb'
|
86
|
+
- 'lib/latexmath/equation.rb'
|
87
|
+
- 'lib/latexmath/tokenizer.rb'
|
88
|
+
|
89
|
+
# Offense count: 18
|
90
|
+
# Cop supports --auto-correct.
|
91
|
+
# Configuration parameters: EnforcedStyle.
|
92
|
+
# SupportedStyles: always, always_true, never
|
93
|
+
Style/FrozenStringLiteralComment:
|
94
|
+
Enabled: false
|
95
|
+
|
96
|
+
# Offense count: 2
|
97
|
+
# Configuration parameters: MinBodyLength.
|
98
|
+
Style/GuardClause:
|
99
|
+
Exclude:
|
100
|
+
- 'lib/latexmath/aggregator.rb'
|
101
|
+
|
102
|
+
# Offense count: 5
|
103
|
+
Style/IdenticalConditionalBranches:
|
104
|
+
Exclude:
|
105
|
+
- 'lib/latexmath/converter.rb'
|
106
|
+
|
107
|
+
# Offense count: 1
|
108
|
+
# Cop supports --auto-correct.
|
109
|
+
Style/LineEndConcatenation:
|
110
|
+
Exclude:
|
111
|
+
- 'spec/tokenizer_spec.rb'
|
112
|
+
|
113
|
+
# Offense count: 5
|
114
|
+
# Cop supports --auto-correct.
|
115
|
+
# Configuration parameters: AutoCorrect, EnforcedStyle, IgnoredMethods.
|
116
|
+
# SupportedStyles: predicate, comparison
|
117
|
+
Style/NumericPredicate:
|
118
|
+
Exclude:
|
119
|
+
- 'spec/**/*'
|
120
|
+
- 'lib/latexmath/aggregator.rb'
|
121
|
+
- 'lib/latexmath/converter.rb'
|
122
|
+
|
123
|
+
# Offense count: 2
|
124
|
+
# Cop supports --auto-correct.
|
125
|
+
Style/ZeroLengthPredicate:
|
126
|
+
Exclude:
|
127
|
+
- 'lib/latexmath/converter.rb'
|
128
|
+
|
129
|
+
|
data/Gemfile
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
# Specify your gem's dependencies in latexmath.gemspec
|
4
4
|
gemspec
|
5
5
|
|
6
|
-
gem
|
7
|
-
gem
|
6
|
+
gem 'byebug'
|
7
|
+
gem 'pry'
|
8
|
+
gem 'rake', '~> 12.0'
|
9
|
+
gem 'rspec', '~> 3.0'
|
10
|
+
gem 'rubocop'
|
data/Gemfile.lock
CHANGED
@@ -1,16 +1,39 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
latexmath (0.1.
|
4
|
+
latexmath (0.1.5)
|
5
5
|
htmlentities (~> 4.3)
|
6
|
-
|
6
|
+
ox (~> 2.13)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
+
ast (2.4.1)
|
12
|
+
byebug (11.1.3)
|
13
|
+
coderay (1.1.3)
|
11
14
|
diff-lcs (1.4.4)
|
15
|
+
equivalent-xml (0.6.0)
|
16
|
+
nokogiri (>= 1.4.3)
|
17
|
+
execjs (2.7.0)
|
12
18
|
htmlentities (4.3.4)
|
19
|
+
method_source (1.0.0)
|
20
|
+
mini_portile2 (2.4.0)
|
21
|
+
nokogiri (1.10.10)
|
22
|
+
mini_portile2 (~> 2.4.0)
|
23
|
+
opal (1.0.3)
|
24
|
+
ast (>= 2.3.0)
|
25
|
+
parser (~> 2.6)
|
26
|
+
ox (2.13.3)
|
27
|
+
parallel (1.19.2)
|
28
|
+
parser (2.7.1.4)
|
29
|
+
ast (~> 2.4.1)
|
30
|
+
pry (0.13.1)
|
31
|
+
coderay (~> 1.1)
|
32
|
+
method_source (~> 1.0)
|
33
|
+
rainbow (3.0.0)
|
13
34
|
rake (12.3.3)
|
35
|
+
regexp_parser (1.7.1)
|
36
|
+
rexml (3.2.4)
|
14
37
|
rspec (3.9.0)
|
15
38
|
rspec-core (~> 3.9.0)
|
16
39
|
rspec-expectations (~> 3.9.0)
|
@@ -24,15 +47,33 @@ GEM
|
|
24
47
|
diff-lcs (>= 1.2.0, < 2.0)
|
25
48
|
rspec-support (~> 3.9.0)
|
26
49
|
rspec-support (3.9.3)
|
27
|
-
|
50
|
+
rubocop (0.90.0)
|
51
|
+
parallel (~> 1.10)
|
52
|
+
parser (>= 2.7.1.1)
|
53
|
+
rainbow (>= 2.2.2, < 4.0)
|
54
|
+
regexp_parser (>= 1.7)
|
55
|
+
rexml
|
56
|
+
rubocop-ast (>= 0.3.0, < 1.0)
|
57
|
+
ruby-progressbar (~> 1.7)
|
58
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
59
|
+
rubocop-ast (0.3.0)
|
60
|
+
parser (>= 2.7.1.4)
|
61
|
+
ruby-progressbar (1.10.1)
|
62
|
+
unicode-display_width (1.7.0)
|
28
63
|
|
29
64
|
PLATFORMS
|
30
65
|
ruby
|
31
66
|
|
32
67
|
DEPENDENCIES
|
68
|
+
byebug
|
69
|
+
equivalent-xml
|
70
|
+
execjs
|
33
71
|
latexmath!
|
72
|
+
opal
|
73
|
+
pry
|
34
74
|
rake (~> 12.0)
|
35
75
|
rspec (~> 3.0)
|
76
|
+
rubocop
|
36
77
|
|
37
78
|
BUNDLED WITH
|
38
79
|
2.1.4
|
data/README.adoc
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
= latexmath
|
2
|
+
|
3
|
+
image:https://img.shields.io/gem/v/latexmath.svg["Gem Version", link="https://rubygems.org/gems/latexmath"]
|
4
|
+
image:https://github.com/metanorma/latexmath/workflows/test/badge.svg["Build Status", link="https://github.com/metanorma/latexmath/actions?workflow=test"]
|
5
|
+
image:https://codeclimate.com/github/metanorma/latexmath/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/metanorma/latexmath"]
|
6
|
+
image:https://img.shields.io/github/issues-pr-raw/metanorma/latexmath.svg["Pull Requests", link="https://github.com/metanorma/latexmath/pulls"]
|
7
|
+
image:https://img.shields.io/github/commits-since/metanorma/latexmath/latest.svg["Commits since latest",link="https://github.com/metanorma/latexmath/releases"]
|
8
|
+
|
9
|
+
== Purpose
|
10
|
+
|
11
|
+
Ruby gem to translate LaTeX math into MathML.
|
12
|
+
The MathML is supposed to be compliant with output of LaTeXML.
|
13
|
+
|
14
|
+
It also works in reverse by translating MathML into LaTeX code.
|
15
|
+
|
16
|
+
The LaTeX math syntax supports `amsmath`, `array`, `split` and `pmatrix` packages.
|
17
|
+
|
18
|
+
NOTE: Bolding, symbols like `\backepsilon`, equation alignment, are all supported.
|
19
|
+
|
20
|
+
== Usage
|
21
|
+
|
22
|
+
[source,ruby]
|
23
|
+
-------------
|
24
|
+
require "latexmath"
|
25
|
+
|
26
|
+
latex = "$$f_i = \sum_{j=1}^2 s_{ij} n_j \quad {\rm for} \quad i = 1,2$$"
|
27
|
+
mathml = Latexmath.parse(latex).to_mathml
|
28
|
+
-------------
|
data/Rakefile
CHANGED
@@ -1,6 +1,95 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
require 'rspec/core/rake_task'
|
4
4
|
RSpec::Core::RakeTask.new(:spec)
|
5
5
|
|
6
|
-
task
|
6
|
+
task 'build-opal' do
|
7
|
+
require 'opal'
|
8
|
+
require 'erb'
|
9
|
+
require 'json'
|
10
|
+
|
11
|
+
b = Opal::Builder.new
|
12
|
+
|
13
|
+
b.append_paths __dir__ + '/lib'
|
14
|
+
b.append_paths __dir__ + '/opal'
|
15
|
+
b.use_gem 'htmlentities'
|
16
|
+
|
17
|
+
build = b.build('latexmath-opal').to_s
|
18
|
+
# This is a hack intended for ExecJS to work properly.
|
19
|
+
build = build.gsub('Object freezing is not supported by Opal', '')
|
20
|
+
|
21
|
+
FileUtils.mkdir_p 'dist'
|
22
|
+
File.write('dist/latexmath.js', build)
|
23
|
+
end
|
24
|
+
|
25
|
+
task 'spec-opal' => 'build-opal' do
|
26
|
+
ENV['TEST_OPAL'] = '1'
|
27
|
+
Rake::Task['spec'].execute
|
28
|
+
ENV.delete 'TEST_OPAL'
|
29
|
+
end
|
30
|
+
|
31
|
+
def read_symbols(input)
|
32
|
+
@symbols = {}
|
33
|
+
File.readlines(input).each do |line|
|
34
|
+
next if line.start_with?('#')
|
35
|
+
|
36
|
+
columns = line.chop.split('^')
|
37
|
+
_unicode = columns[0]
|
38
|
+
latex = columns[2]
|
39
|
+
unicode_math = columns[3]
|
40
|
+
|
41
|
+
@symbols[latex] = _unicode if latex && !@symbols.include?(latex)
|
42
|
+
@symbols[unicode_math] = _unicode if unicode_math && !@symbols.include?(unicode_math)
|
43
|
+
|
44
|
+
matches = columns[-1].match(/=\s+(\\[^,^ ]+),?/)
|
45
|
+
if matches
|
46
|
+
@symbols[matches[1]] = _unicode unless @symbols[matches[1]]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
@symbols
|
50
|
+
end
|
51
|
+
|
52
|
+
directory 'lib/latexmath/constants'
|
53
|
+
file 'lib/latexmath/constants/symbols.rb' => [
|
54
|
+
'lib/latexmath/constants',
|
55
|
+
'lib/unimathsymbols.txt'
|
56
|
+
] do |file|
|
57
|
+
symbols = read_symbols(file.prerequisites.last)
|
58
|
+
|
59
|
+
File.open(file.name, "w+") do |f|
|
60
|
+
f.puts <<~HERE
|
61
|
+
module Latexmath
|
62
|
+
module Constants
|
63
|
+
SYMBOLS = {
|
64
|
+
HERE
|
65
|
+
|
66
|
+
@symbols.each_pair do |k,v|
|
67
|
+
f.puts(" '#{k.to_s}' => '#{v}',")
|
68
|
+
end
|
69
|
+
|
70
|
+
f.puts <<~HERE
|
71
|
+
}.freeze
|
72
|
+
end
|
73
|
+
end
|
74
|
+
HERE
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
Rake::Task['build'].enhance ['lib/latexmath/constants/symbols.rb']
|
79
|
+
Rake::Task[:spec].enhance ['lib/latexmath/constants/symbols.rb']
|
80
|
+
|
81
|
+
desc 'Generate and write MathML fixtures'
|
82
|
+
task 'create-mathml-fixtures' do
|
83
|
+
require_relative 'lib/latexmath'
|
84
|
+
records = Dir.glob('spec/fixtures/*/*.tex')
|
85
|
+
|
86
|
+
records.each do |file|
|
87
|
+
tex = File.read("./#{file}")
|
88
|
+
tokens = Latexmath::Tokenizer.new(tex).tokenize
|
89
|
+
aggr = Latexmath::Aggregator.new(tokens).aggregate
|
90
|
+
|
91
|
+
File.write("./#{file.chomp('.tex')}.html", Latexmath::Converter.new(aggr).convert)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
task default: [:spec, 'spec-opal']
|