math-to-itex 0.2.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: f05a939cba1dbfa2747fd5c6693f796eb17bec31
4
- data.tar.gz: 30d01cfd7e0f33cb1ac0923331b1b5ac44c8e645
2
+ SHA256:
3
+ metadata.gz: a0c69c903e672a4eca3caabc18d23eb78d927f56b5503514a830f8c216b76810
4
+ data.tar.gz: a84b98f126d570ece86dcfdf38dc406f4558c5c55f0ef481a4529047116ef041
5
5
  SHA512:
6
- metadata.gz: 6838353e1d7abd41c25a40177e3d13717ec55056cb67a648204f828fa3b52bf427134c60c44dd11a979ffa7f81fc2967dda7648ef965fe900bf726eb06786883
7
- data.tar.gz: 63dfc3d77457092d46078c8860dde0a2c6d1d367bfc592b685d6585cb2d92894a9608ef5855f6d647f5d410c9d0b8cbbaba2886a10f437aa17184ce7f2e002cf
6
+ metadata.gz: ef8b104005f0e3e04125a2e442ef70d6a555af985a3deab1af6d08e815ba0eb979ccb8ffd548f283fd6324748b56ebba885a2baa36f19fbdd502ae1dc1c45603
7
+ data.tar.gz: 90a6ef1d7c7df5750481e68201c3a3b53bfc7e8f4716df9a106671943a5a1ef9be0530efc58330cd0b94602aaf872d4aa33e0478237fae294b4b7a814b90e8af
data/README.md CHANGED
@@ -57,7 +57,7 @@ Currently, the following formats are supported:
57
57
  | inline formulas | display formulas |
58
58
  | ------------- |-------------|
59
59
  | `$...$` | `$$...$$`
60
- | `(...)` | `[...]`
60
+ | `\(...\)` | `\[...\]`
61
61
  |   | `\begin{equation}...\end{equation}`
62
62
 
63
63
  ## More math stuff
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,43 +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(?!\\begin)/
27
- just_maths = maths[16..-15]
28
- type = :display
29
- end
40
+ # this is the format itex2MML expects
41
+ all_maths = if type == :inline
42
+ "$#{just_maths}$"
43
+ else
44
+ "$$#{just_maths}$$"
45
+ end
30
46
 
31
- # this is the format itex2MML expects
32
- if type == :inline
33
- just_maths = "$#{just_maths}$"
34
- else
35
- just_maths = "$$#{just_maths}$$"
36
- end
47
+ next(all_maths) if block.nil?
37
48
 
38
- next(just_maths) if block.nil?
39
-
40
- yield just_maths, type
49
+ yield all_maths, type, just_maths
50
+ end
41
51
  end
42
52
  end
43
53
  end
54
+
55
+ def MathToItex(string)
56
+ MathToItex::Math.new(string)
57
+ end
@@ -1,5 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module MathToItex
2
4
  class Parser
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
6
+ JOINED_ENVIRONMENTS = ENVIRONMENTS.join('|')
3
7
  # https://stackoverflow.com/questions/14182879/regex-to-match-latex-equations
4
8
  REGEX = /
5
9
  (?<!\\) # negative look-behind to make sure start is not escaped
@@ -12,19 +16,19 @@ module MathToItex
12
16
  # group 3, match escaped bracket
13
17
  (\\\[)|
14
18
  # group 4, match begin equation
15
- (\\begin\{equation\})
19
+ \\begin\{(#{JOINED_ENVIRONMENTS})\}
16
20
  )
17
21
  (.*?(\g<1>)?.*?) # match everything in between including nested LaTeX equations
18
22
  (?<!\\) # negative look-behind to make sure end is not escaped
19
23
  # if group 1 was start, match \1
20
- (?(1)(?<!\$)\1(?!\$)|
24
+ (?(1)(?<!\$)\1(?!\$|\d)|
21
25
  # if group 2 was start, escaped parenthesis is end
22
26
  (?(2)\\\)|
23
27
  # if group 3 was start, escaped bracket is end
24
28
  (?(3)\\\]|
25
29
  # otherwise group 4 was start, match end equation
26
- \\end\{equation\}
30
+ \\end\{\4\}
27
31
  )))
28
- /x
32
+ /xm.freeze
29
33
  end
30
34
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module MathToItex
2
- VERSION = "0.2.0"
4
+ VERSION = '0.6.1'
3
5
  end
@@ -1,24 +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 'rake'
25
+ spec.add_development_dependency 'rubocop'
26
+ spec.add_development_dependency 'rubocop-standard'
27
+ spec.add_development_dependency 'test-unit'
24
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.2.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: 2014-05-08 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,48 @@ 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'
55
+ - !ruby/object:Gem::Dependency
56
+ name: test-unit
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'
27
69
  description: Pass in a string and turn all math equations into itex equations. Or,
28
70
  pass in a block manipulate multiple matches.
29
71
  email:
@@ -37,7 +79,6 @@ files:
37
79
  - Rakefile
38
80
  - lib/math-to-itex.rb
39
81
  - lib/math-to-itex/parser.rb
40
- - lib/math-to-itex/support_parens.rb
41
82
  - lib/math-to-itex/version.rb
42
83
  - math-to-itex.gemspec
43
84
  homepage: https://github.com/gjtorikian/math-to-itex
@@ -59,8 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
100
  - !ruby/object:Gem::Version
60
101
  version: '0'
61
102
  requirements: []
62
- rubyforge_project:
63
- rubygems_version: 2.2.2
103
+ rubygems_version: 3.1.2
64
104
  signing_key:
65
105
  specification_version: 4
66
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