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
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'opal'
|
2
|
+
require 'corelib/string/unpack'
|
3
|
+
require 'pseudoenumerator'
|
4
|
+
require 'htmlentities'
|
5
|
+
require 'htmlentities/mappings/html4' # Dynamic require
|
6
|
+
require 'htmlentities/mappings/xhtml1' # Dynamic require
|
7
|
+
require 'htmlentities/mappings/expanded' # Dynamic require
|
8
|
+
require 'latexmath'
|
9
|
+
|
10
|
+
# Override 2 methods that use dynamic execution so we don't need to require a parser
|
11
|
+
class HTMLEntities
|
12
|
+
class Encoder
|
13
|
+
def build_basic_entity_encoder(instructions)
|
14
|
+
if instructions.include?(:basic) || instructions.include?(:named)
|
15
|
+
method = :encode_named
|
16
|
+
elsif instructions.include?(:decimal)
|
17
|
+
method = :encode_decimal
|
18
|
+
elsif instructions.include?(:hexadecimal)
|
19
|
+
method = :encode_hexadecimal
|
20
|
+
end
|
21
|
+
self.class.define_method :encode_basic do |char|
|
22
|
+
send(method, char)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def build_extended_entity_encoder(instructions)
|
27
|
+
operations = [:named, :decimal, :hexadecimal] & instructions
|
28
|
+
|
29
|
+
self.class.define_method :encode_extended do |char|
|
30
|
+
|
31
|
+
operations.each do |encoder|
|
32
|
+
encoded = send(:"encode_#{encoder}", char)
|
33
|
+
return encoded if encoded
|
34
|
+
end
|
35
|
+
|
36
|
+
char
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/opal/ox.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# A minimal Ox implementation for Opal
|
2
|
+
|
3
|
+
module Ox
|
4
|
+
CODER = HTMLEntities.new
|
5
|
+
|
6
|
+
class Document
|
7
|
+
def initialize
|
8
|
+
@root = nil
|
9
|
+
end
|
10
|
+
|
11
|
+
def << child
|
12
|
+
@root = child
|
13
|
+
end
|
14
|
+
|
15
|
+
def dump
|
16
|
+
@root.dump
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class Element
|
21
|
+
def initialize tag_name
|
22
|
+
@tag_name = tag_name
|
23
|
+
@attrs = {}
|
24
|
+
@children = []
|
25
|
+
end
|
26
|
+
|
27
|
+
def []= key, value
|
28
|
+
@attrs[key] = value
|
29
|
+
end
|
30
|
+
|
31
|
+
def << child
|
32
|
+
@children << child
|
33
|
+
self
|
34
|
+
end
|
35
|
+
|
36
|
+
def value= value
|
37
|
+
@tag_name = value
|
38
|
+
end
|
39
|
+
|
40
|
+
def dump
|
41
|
+
attrs = @attrs.map do |k,v|
|
42
|
+
%Q< #{k}="#{CODER.encode(v)}">
|
43
|
+
end.join("")
|
44
|
+
"<#{@tag_name}#{attrs}>"+
|
45
|
+
@children.map(&:dump).join("")+
|
46
|
+
"</#{@tag_name}>"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class Raw
|
51
|
+
def initialize value
|
52
|
+
@value = value
|
53
|
+
end
|
54
|
+
|
55
|
+
def dump
|
56
|
+
#CODER.encode(@value)
|
57
|
+
@value
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.dump doc
|
62
|
+
doc.dump
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Opal doesn't support Enumerator's #next and #peek extended methods. This tries
|
2
|
+
# to emulate them.
|
3
|
+
|
4
|
+
class Pseudoenumerator
|
5
|
+
def initialize obj
|
6
|
+
@obj = obj.to_a.reverse
|
7
|
+
end
|
8
|
+
|
9
|
+
def next
|
10
|
+
out = peek
|
11
|
+
@obj.pop
|
12
|
+
out
|
13
|
+
end
|
14
|
+
|
15
|
+
def peek
|
16
|
+
raise StopIteration if @obj.length == 0
|
17
|
+
@obj.last
|
18
|
+
end
|
19
|
+
end
|
metadata
CHANGED
@@ -1,73 +1,130 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: latexmath
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: htmlentities
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '4.3'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '4.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: ox
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '2.13'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '2.13'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: equivalent-xml
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: execjs
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: opal
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
41
83
|
description: Converts LaTeX math into MathML.
|
42
84
|
email:
|
43
85
|
- open.source@ribose.com
|
44
|
-
executables:
|
86
|
+
executables:
|
87
|
+
- latexmath
|
45
88
|
extensions: []
|
46
89
|
extra_rdoc_files: []
|
47
90
|
files:
|
91
|
+
- ".editorconfig"
|
92
|
+
- ".github/workflows/test.yml"
|
48
93
|
- ".gitignore"
|
49
94
|
- ".rspec"
|
50
|
-
- ".
|
95
|
+
- ".rubocop.yml"
|
51
96
|
- CODE_OF_CONDUCT.md
|
52
97
|
- Gemfile
|
53
98
|
- Gemfile.lock
|
54
|
-
- README.
|
99
|
+
- README.adoc
|
55
100
|
- Rakefile
|
56
101
|
- bin/console
|
57
102
|
- bin/setup
|
103
|
+
- exe/latexmath
|
58
104
|
- latexmath.gemspec
|
59
105
|
- lib/latexmath.rb
|
106
|
+
- lib/latexmath/aggregator.rb
|
107
|
+
- lib/latexmath/constants/symbols.rb
|
108
|
+
- lib/latexmath/converter.rb
|
60
109
|
- lib/latexmath/equation.rb
|
61
|
-
- lib/latexmath/
|
62
|
-
- lib/latexmath/
|
110
|
+
- lib/latexmath/ext.rb
|
111
|
+
- lib/latexmath/symbol.rb
|
112
|
+
- lib/latexmath/tokenizer.rb
|
63
113
|
- lib/latexmath/version.rb
|
64
|
-
|
114
|
+
- lib/latexmath/xml/builder.rb
|
115
|
+
- lib/latexmath/xml/element.rb
|
116
|
+
- lib/unimathsymbols.js.erb
|
117
|
+
- lib/unimathsymbols.txt
|
118
|
+
- opal/latexmath-opal.rb
|
119
|
+
- opal/ox.rb
|
120
|
+
- opal/pseudoenumerator.rb
|
121
|
+
homepage: https://github.com/plurimath/latexmath
|
65
122
|
licenses:
|
66
123
|
- BSD-2-Clause
|
67
124
|
metadata:
|
68
|
-
homepage_uri: https://github.com/
|
69
|
-
source_code_uri: https://github.com/
|
70
|
-
changelog_uri: https://github.com/
|
125
|
+
homepage_uri: https://github.com/plurimath/latexmath
|
126
|
+
source_code_uri: https://github.com/plurimath/latexmath
|
127
|
+
changelog_uri: https://github.com/plurimath/latexmath/blob/master/CHANGELOG.md.
|
71
128
|
post_install_message:
|
72
129
|
rdoc_options: []
|
73
130
|
require_paths:
|
data/.travis.yml
DELETED
data/README.md
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
# Latexmath
|
2
|
-
|
3
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/latexmath`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
6
|
-
|
7
|
-
## Installation
|
8
|
-
|
9
|
-
Add this line to your application's Gemfile:
|
10
|
-
|
11
|
-
```ruby
|
12
|
-
gem 'latexmath'
|
13
|
-
```
|
14
|
-
|
15
|
-
And then execute:
|
16
|
-
|
17
|
-
$ bundle install
|
18
|
-
|
19
|
-
Or install it yourself as:
|
20
|
-
|
21
|
-
$ gem install latexmath
|
22
|
-
|
23
|
-
## Usage
|
24
|
-
|
25
|
-
TODO: Write usage instructions here
|
26
|
-
|
27
|
-
## Development
|
28
|
-
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
-
|
31
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
-
|
33
|
-
## Contributing
|
34
|
-
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/latexmath. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/latexmath/blob/master/CODE_OF_CONDUCT.md).
|
36
|
-
|
37
|
-
|
38
|
-
## Code of Conduct
|
39
|
-
|
40
|
-
Everyone interacting in the Latexmath project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/latexmath/blob/master/CODE_OF_CONDUCT.md).
|
@@ -1,84 +0,0 @@
|
|
1
|
-
require_relative "./requirement"
|
2
|
-
require 'open3'
|
3
|
-
|
4
|
-
module Latexmath
|
5
|
-
class LatexmlRequirement < Requirement
|
6
|
-
@recommended_version = '0.8.4'
|
7
|
-
@minimal_version = '0.8.0'
|
8
|
-
|
9
|
-
def initialize
|
10
|
-
version_output, = Open3.capture2e("latexml --VERSION")
|
11
|
-
version = version_output&.match(%r{\d+(.\d+)*})
|
12
|
-
puts version_output
|
13
|
-
if version.to_s.empty?
|
14
|
-
@error_message = "LaTeXML is not available. (Or is PATH not setup properly?)"\
|
15
|
-
" You must upgrade/install LaTeXML to a version higher than `#{@recommended_version}`"
|
16
|
-
|
17
|
-
elsif Gem::Version.new(version) < Gem::Version.new(@minimal_version)
|
18
|
-
@error_message = "Minimal supported LaTeXML version is `#{@minimal_version}` "\
|
19
|
-
"Version `#{version}` found; recommended version is `#{@recommended_version}`"
|
20
|
-
|
21
|
-
elsif Gem::Version.new(version) < Gem::Version.new(@recommended_version)
|
22
|
-
version = "unknown" if version.to_s.empty?
|
23
|
-
header_msg = "latexmlmath version `#{version}` below `#{@recommended_version}`!"
|
24
|
-
suggestion = if Gem.win_platform?
|
25
|
-
"cmd encoding is set to UTF-8 with `chcp 65001`"
|
26
|
-
else
|
27
|
-
"terminal encoding is set to UTF-8 with `export LANG=en_US.UTF-8`"
|
28
|
-
end
|
29
|
-
|
30
|
-
@error_message = "WARNING #{header_msg} Please sure that #{suggestion} command."
|
31
|
-
|
32
|
-
@cmd = 'latexmlmath --strict --preload=amsmath -- -'
|
33
|
-
@cmd2 = 'latexmlmath --strict -- -'
|
34
|
-
else
|
35
|
-
@cmd = 'latexmlmath --strict --preload=amsmath --inputencoding=UTF-8 -- -'
|
36
|
-
@cmd2 = 'latexmlmath --strict --inputencoding=UTF-8 -- -'
|
37
|
-
end
|
38
|
-
rescue
|
39
|
-
@error_message = "LaTeXML is not available. (Or is PATH not setup properly?)"\
|
40
|
-
" You must upgrade/install LaTeXML to a version higher than `#{@recommended_version}`"
|
41
|
-
end
|
42
|
-
|
43
|
-
def satisfied(abort = false)
|
44
|
-
unless @error_message.nil?
|
45
|
-
if abort
|
46
|
-
abort @error_message
|
47
|
-
else
|
48
|
-
warn @error_message
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
@error_message.nil?
|
53
|
-
end
|
54
|
-
|
55
|
-
def cmd
|
56
|
-
abort @error_message unless @error_message.nil?
|
57
|
-
|
58
|
-
[@cmd, @cmd2]
|
59
|
-
end
|
60
|
-
|
61
|
-
def run(input, command)
|
62
|
-
puts command
|
63
|
-
IO.popen(command, "r+", external_encoding: "UTF-8") do |io|
|
64
|
-
io.write(input)
|
65
|
-
io.close_write
|
66
|
-
io.read
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def convert(input)
|
71
|
-
results = nil
|
72
|
-
cmd.each_with_index do |cmd, i|
|
73
|
-
warn "Retrying with #{cmd}" if i > 0
|
74
|
-
results = run(input, cmd)
|
75
|
-
if $CHILD_STATUS.to_i.zero?
|
76
|
-
warn "Success!" if i > 0
|
77
|
-
break
|
78
|
-
end
|
79
|
-
end
|
80
|
-
$CHILD_STATUS.to_i.zero? ? results : nil
|
81
|
-
end
|
82
|
-
|
83
|
-
end
|
84
|
-
end
|