latexmath 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +38 -0
- data/README.md +40 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/latexmath.gemspec +31 -0
- data/lib/latexmath.rb +22 -0
- data/lib/latexmath/equation.rb +40 -0
- data/lib/latexmath/latexml_requirement.rb +84 -0
- data/lib/latexmath/requirement.rb +12 -0
- data/lib/latexmath/version.rb +3 -0
- metadata +90 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6e3ecc01756ec040a67e70289d15cf757b15c1b4b6f656a887ef991c15ae3852
|
4
|
+
data.tar.gz: 46341cdd12a8b4e84bbe14b69c1eae6b66eaa5e136c07bd55fae628fbcf028ac
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2f67278c0fe3acbacd04e3ba8449fbcb77f75d46f36d5268db8dd42e971fadbf47dabeb4fe1197d0e2b50517e55b0c6db4d37916bdf6267e76bb7fa100dcd535
|
7
|
+
data.tar.gz: 845366028db2233749cc57f5a18fb5b842953c4426b12e80b416bc0701ec70e3127b030b27de7491f80ff2c9ad233af4407de208a4e92df69e7e2accf3e1e8e4
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at ronald.tse@ribose.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
latexmath (0.1.0)
|
5
|
+
htmlentities (~> 4.3)
|
6
|
+
unicode2latex (~> 0.0.1)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
diff-lcs (1.4.4)
|
12
|
+
htmlentities (4.3.4)
|
13
|
+
rake (12.3.3)
|
14
|
+
rspec (3.9.0)
|
15
|
+
rspec-core (~> 3.9.0)
|
16
|
+
rspec-expectations (~> 3.9.0)
|
17
|
+
rspec-mocks (~> 3.9.0)
|
18
|
+
rspec-core (3.9.2)
|
19
|
+
rspec-support (~> 3.9.3)
|
20
|
+
rspec-expectations (3.9.2)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.9.0)
|
23
|
+
rspec-mocks (3.9.1)
|
24
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
25
|
+
rspec-support (~> 3.9.0)
|
26
|
+
rspec-support (3.9.3)
|
27
|
+
unicode2latex (0.0.4)
|
28
|
+
|
29
|
+
PLATFORMS
|
30
|
+
ruby
|
31
|
+
|
32
|
+
DEPENDENCIES
|
33
|
+
latexmath!
|
34
|
+
rake (~> 12.0)
|
35
|
+
rspec (~> 3.0)
|
36
|
+
|
37
|
+
BUNDLED WITH
|
38
|
+
2.1.4
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
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).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "latexmath"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/latexmath.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative 'lib/latexmath/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "latexmath"
|
5
|
+
spec.version = Latexmath::VERSION
|
6
|
+
spec.authors = ['Ribose Inc.']
|
7
|
+
spec.email = ['open.source@ribose.com']
|
8
|
+
|
9
|
+
spec.summary = %q{Converts LaTeX math into MathML.}
|
10
|
+
spec.description = %q{Converts LaTeX math into MathML.}
|
11
|
+
spec.homepage = "https://github.com/metanorma/latexmath"
|
12
|
+
spec.license = "BSD-2-Clause"
|
13
|
+
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
15
|
+
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
spec.metadata["source_code_uri"] = "https://github.com/metanorma/latexmath"
|
18
|
+
spec.metadata["changelog_uri"] = "https://github.com/metanorma/latexmath/blob/master/CHANGELOG.md."
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
end
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_dependency "unicode2latex", "~> 0.0.1"
|
30
|
+
spec.add_dependency "htmlentities", "~> 4.3"
|
31
|
+
end
|
data/lib/latexmath.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require "latexmath/version"
|
2
|
+
require "latexmath/latexml_requirement"
|
3
|
+
require "latexmath/equation"
|
4
|
+
require "htmlentities"
|
5
|
+
require "unicode2latex"
|
6
|
+
|
7
|
+
module Latexmath
|
8
|
+
class Error < StandardError; end
|
9
|
+
# Your code goes here...
|
10
|
+
|
11
|
+
Requirements = {
|
12
|
+
latexml: LatexmlRequirement.new
|
13
|
+
}
|
14
|
+
|
15
|
+
def self.parse(string)
|
16
|
+
lxm_input = Unicode2LaTeX.unicode2latex(HTMLEntities.new.decode(string))
|
17
|
+
|
18
|
+
# parse
|
19
|
+
Equation.new(lxm_input)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Latexmath
|
2
|
+
class Equation
|
3
|
+
|
4
|
+
def initialize(string)
|
5
|
+
@latex = string
|
6
|
+
end
|
7
|
+
|
8
|
+
def to_mathml
|
9
|
+
<<~'INPUT'
|
10
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
11
|
+
<math xmlns="http://www.w3.org/1998/Math/MathML" alttext="\varepsilon=\frac{1}{2}(J+J^{t})" display="block">
|
12
|
+
<mrow>
|
13
|
+
<mi>ε</mi>
|
14
|
+
<mo>=</mo>
|
15
|
+
<mrow>
|
16
|
+
<mfrac>
|
17
|
+
<mn>1</mn>
|
18
|
+
<mn>2</mn>
|
19
|
+
</mfrac>
|
20
|
+
<mo></mo>
|
21
|
+
<mrow>
|
22
|
+
<mo stretchy="false">(</mo>
|
23
|
+
<mrow>
|
24
|
+
<mi>J</mi>
|
25
|
+
<mo>+</mo>
|
26
|
+
<msup>
|
27
|
+
<mi>J</mi>
|
28
|
+
<mi>t</mi>
|
29
|
+
</msup>
|
30
|
+
</mrow>
|
31
|
+
<mo stretchy="false">)</mo>
|
32
|
+
</mrow>
|
33
|
+
</mrow>
|
34
|
+
</mrow>
|
35
|
+
</math>
|
36
|
+
INPUT
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,84 @@
|
|
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
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: latexmath
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ribose Inc.
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-07-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: unicode2latex
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.0.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.0.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: htmlentities
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.3'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.3'
|
41
|
+
description: Converts LaTeX math into MathML.
|
42
|
+
email:
|
43
|
+
- open.source@ribose.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".rspec"
|
50
|
+
- ".travis.yml"
|
51
|
+
- CODE_OF_CONDUCT.md
|
52
|
+
- Gemfile
|
53
|
+
- Gemfile.lock
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- bin/console
|
57
|
+
- bin/setup
|
58
|
+
- latexmath.gemspec
|
59
|
+
- lib/latexmath.rb
|
60
|
+
- lib/latexmath/equation.rb
|
61
|
+
- lib/latexmath/latexml_requirement.rb
|
62
|
+
- lib/latexmath/requirement.rb
|
63
|
+
- lib/latexmath/version.rb
|
64
|
+
homepage: https://github.com/metanorma/latexmath
|
65
|
+
licenses:
|
66
|
+
- BSD-2-Clause
|
67
|
+
metadata:
|
68
|
+
homepage_uri: https://github.com/metanorma/latexmath
|
69
|
+
source_code_uri: https://github.com/metanorma/latexmath
|
70
|
+
changelog_uri: https://github.com/metanorma/latexmath/blob/master/CHANGELOG.md.
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: 2.3.0
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubygems_version: 3.0.3
|
87
|
+
signing_key:
|
88
|
+
specification_version: 4
|
89
|
+
summary: Converts LaTeX math into MathML.
|
90
|
+
test_files: []
|