math-to-itex 0.6.0 → 0.6.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ad9eb19885894425d7140a3eea899a84ec499c35
4
- data.tar.gz: 7653c1957f9b7296bcc4925e06b59cff9b69dffe
2
+ SHA256:
3
+ metadata.gz: a0c69c903e672a4eca3caabc18d23eb78d927f56b5503514a830f8c216b76810
4
+ data.tar.gz: a84b98f126d570ece86dcfdf38dc406f4558c5c55f0ef481a4529047116ef041
5
5
  SHA512:
6
- metadata.gz: 2bdd032b1d6876f01df7f3a6a4fdd37346c983d734b985b60d93c13f92695f8e972b89b3a8be648bc3732c9a2d2ac3084055510b859ad09777a0b96226148a38
7
- data.tar.gz: 9f068d67aa84fa0a1f84e441251a5647aa12c1a7420687b97ff24c9126dbb908a598c2de821ce98833ea07ddefd03825e3a16603083cce1f01e55695e45391b6
6
+ metadata.gz: ef8b104005f0e3e04125a2e442ef70d6a555af985a3deab1af6d08e815ba0eb979ccb8ffd548f283fd6324748b56ebba885a2baa36f19fbdd502ae1dc1c45603
7
+ data.tar.gz: 90a6ef1d7c7df5750481e68201c3a3b53bfc7e8f4716df9a106671943a5a1ef9be0530efc58330cd0b94602aaf872d4aa33e0478237fae294b4b7a814b90e8af
data/Rakefile CHANGED
@@ -1,11 +1,17 @@
1
1
  #!/usr/bin/env rake
2
- require "bundler/gem_tasks"
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/gem_tasks'
3
5
  require 'rake/testtask'
4
6
 
5
7
  Rake::TestTask.new do |t|
6
- t.libs << "test"
8
+ t.libs << 'test'
7
9
  t.test_files = FileList['test/**/*_test.rb']
8
10
  t.verbose = true
9
11
  end
10
12
 
11
- task :default => [:test]
13
+ task default: [:test]
14
+
15
+ require 'rubocop/rake_task'
16
+
17
+ RuboCop::RakeTask.new(:rubocop)
@@ -1,52 +1,57 @@
1
- require "math-to-itex/parser"
2
- require "math-to-itex/support_parens"
3
- require "math-to-itex/version"
1
+ # frozen_string_literal: true
2
+
3
+ require 'math-to-itex/parser'
4
+ require 'math-to-itex/version'
4
5
 
5
6
  module MathToItex
7
+ class Math
8
+ def initialize(string)
9
+ @string = string
10
+ end
6
11
 
7
- def self.parens(string)
8
- @string = string
9
- self
10
- end
12
+ def convert(&block)
13
+ @string.gsub(MathToItex::Parser::REGEX) do |maths|
14
+ if /\A\$(?!\$)/.match?(maths)
15
+ just_maths = maths[1..-2]
16
+ type = :inline
17
+ elsif /^\\\((?!\\\()/.match?(maths)
18
+ just_maths = maths[2..-3]
19
+ type = :inline
20
+ elsif /\A\$\$/.match?(maths)
21
+ just_maths = maths[2..-3]
22
+ type = :display
23
+ elsif /\A\\\[(?!\\\[)/.match?(maths)
24
+ just_maths = maths[2..-3]
25
+ type = :display
26
+ elsif /\A\\begin{equation}(?!\\begin{equation})/.match?(maths)
27
+ just_maths = maths[16..-15]
28
+ type = :display
29
+ elsif /\A\\begin{math}(?!\\begin{math})/.match?(maths)
30
+ just_maths = maths[12..-11]
31
+ type = :inline
32
+ elsif /\A\\begin{displaymath}(?!\\begin{displaymath})/.match?(maths)
33
+ just_maths = maths[19..-18]
34
+ type = :display
35
+ elsif /\A\\begin{#{MathToItex::Parser::JOINED_ENVIRONMENTS}}(?!\\begin{#{MathToItex::Parser::JOINED_ENVIRONMENTS}})/.match?(maths)
36
+ just_maths = maths
37
+ type = :display
38
+ end
11
39
 
12
- def self.convert(&block)
13
- @string.gsub(MathToItex::Parser::REGEX) do |maths|
14
- if maths =~ /\A\$(?!\$)/
15
- just_maths = maths[1..-2]
16
- type = :inline
17
- elsif maths =~ /^\\\((?!\\\()/
18
- just_maths = maths[2..-3]
19
- type = :inline
20
- elsif maths =~ /\A\$\$/
21
- just_maths = maths[2..-3]
22
- type = :display
23
- elsif maths =~ /\A\\\[(?!\\\[)/
24
- just_maths = maths[2..-3]
25
- type = :display
26
- elsif maths =~ /\A\\begin{equation}(?!\\begin{equation})/
27
- just_maths = maths[16..-15]
28
- type = :display
29
- elsif maths =~ /\A\\begin{math}(?!\\begin{math})/
30
- just_maths = maths[12..-11]
31
- type = :inline
32
- elsif maths =~ /\A\\begin{displaymath}(?!\\begin{displaymath})/
33
- just_maths = maths[19..-18]
34
- type = :display
35
- elsif maths =~ /\A\\begin{#{MathToItex::Parser::JOINED_ENVIRONMENTS}}(?!\\begin{#{MathToItex::Parser::JOINED_ENVIRONMENTS}})/
36
- just_maths = maths
37
- type = :display
38
- end
40
+ # this is the format itex2MML expects
41
+ all_maths = if type == :inline
42
+ "$#{just_maths}$"
43
+ else
44
+ "$$#{just_maths}$$"
45
+ end
39
46
 
40
- # this is the format itex2MML expects
41
- if type == :inline
42
- all_maths = "$#{just_maths}$"
43
- else
44
- all_maths = "$$#{just_maths}$$"
45
- end
47
+ next(all_maths) if block.nil?
46
48
 
47
- next(all_maths) if block.nil?
48
-
49
- yield all_maths, type, just_maths
49
+ yield all_maths, type, just_maths
50
+ end
50
51
  end
51
52
  end
52
53
  end
54
+
55
+ def MathToItex(string)
56
+ MathToItex::Math.new(string)
57
+ end
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module MathToItex
2
4
  class Parser
3
- ENVIRONMENTS = %w(align align\* alignat alignat\* aligned alignedat array Bmatrix bmatrix cases displaymath eqnarray eqnarray\* equation equation\* gather gather\* gathered math matrix multline multline\* pmatrix smallmatrix split subarray svg Vmatrix vmatrix)
5
+ ENVIRONMENTS = %w[align align\* alignat alignat\* aligned alignedat array Bmatrix bmatrix cases displaymath eqnarray eqnarray\* equation equation\* gather gather\* gathered math matrix multline multline\* pmatrix smallmatrix split subarray svg Vmatrix vmatrix].freeze
4
6
  JOINED_ENVIRONMENTS = ENVIRONMENTS.join('|')
5
7
  # https://stackoverflow.com/questions/14182879/regex-to-match-latex-equations
6
8
  REGEX = /
@@ -27,6 +29,6 @@ module MathToItex
27
29
  # otherwise group 4 was start, match end equation
28
30
  \\end\{\4\}
29
31
  )))
30
- /xm
32
+ /xm.freeze
31
33
  end
32
34
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module MathToItex
2
- VERSION = '0.6.0'
4
+ VERSION = '0.6.1'
3
5
  end
@@ -1,25 +1,28 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'math-to-itex/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = "math-to-itex"
8
+ spec.name = 'math-to-itex'
8
9
  spec.version = MathToItex::VERSION
9
- spec.authors = ["Garen Torikian"]
10
- spec.email = ["gjtorikian@gmail.com"]
11
- spec.summary = %q{Turn math syntaxes into itex equations.}
12
- spec.description = %q{Pass in a string and turn all math equations into itex equations. Or, pass in a block manipulate multiple matches.}
13
- spec.homepage = "https://github.com/gjtorikian/math-to-itex"
14
- spec.license = "MIT"
10
+ spec.authors = ['Garen Torikian']
11
+ spec.email = ['gjtorikian@gmail.com']
12
+ spec.summary = 'Turn math syntaxes into itex equations.'
13
+ spec.description = 'Pass in a string and turn all math equations into itex equations. Or, pass in a block manipulate multiple matches.'
14
+ spec.homepage = 'https://github.com/gjtorikian/math-to-itex'
15
+ spec.license = 'MIT'
15
16
  spec.required_ruby_version = '>= 2.0'
16
17
 
17
- spec.files = %w(LICENSE.txt README.md Rakefile math-to-itex.gemspec)
18
- spec.files += Dir.glob("lib/**/*")
18
+ spec.files = %w[LICENSE.txt README.md Rakefile math-to-itex.gemspec]
19
+ spec.files += Dir.glob('lib/**/*')
19
20
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
21
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
- spec.require_paths = ["lib"]
22
+ spec.require_paths = ['lib']
22
23
 
23
- spec.add_development_dependency "rake"
24
- spec.add_development_dependency "test-unit"
24
+ spec.add_development_dependency 'rake'
25
+ spec.add_development_dependency 'rubocop'
26
+ spec.add_development_dependency 'rubocop-standard'
27
+ spec.add_development_dependency 'test-unit'
25
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: math-to-itex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garen Torikian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-25 00:00:00.000000000 Z
11
+ date: 2020-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -24,6 +24,34 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop-standard
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'
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: test-unit
29
57
  requirement: !ruby/object:Gem::Requirement
@@ -51,7 +79,6 @@ files:
51
79
  - Rakefile
52
80
  - lib/math-to-itex.rb
53
81
  - lib/math-to-itex/parser.rb
54
- - lib/math-to-itex/support_parens.rb
55
82
  - lib/math-to-itex/version.rb
56
83
  - math-to-itex.gemspec
57
84
  homepage: https://github.com/gjtorikian/math-to-itex
@@ -73,8 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
100
  - !ruby/object:Gem::Version
74
101
  version: '0'
75
102
  requirements: []
76
- rubyforge_project:
77
- rubygems_version: 2.4.5.1
103
+ rubygems_version: 3.1.2
78
104
  signing_key:
79
105
  specification_version: 4
80
106
  summary: Turn math syntaxes into itex equations.
@@ -1,15 +0,0 @@
1
- # from http://coderrr.wordpress.com/2008/11/30/overloading-the-parenthesis-operator-in-ruby/
2
-
3
- class Object
4
- alias_method :orig_method_missing, :method_missing
5
-
6
- def method_missing(m, *a, &b)
7
- klass = begin
8
- (self.is_a?(Module) ? self : self.class).const_get(m)
9
- rescue NameError
10
- end
11
-
12
- return klass.send(:parens, *a, &b) if klass.respond_to? :parens
13
- orig_method_missing m, *a, &b
14
- end
15
- end