latexmath 0.1.3 → 0.1.4

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
2
  SHA256:
3
- metadata.gz: 81fc79f8e8badb13f6f9a8010b81fa23cc6d610ecb2f5b61d88c5c4ef2c48e52
4
- data.tar.gz: adc01e90660d4b963a5ed955bc10e5972a399b37a94fd72eed607c48bd5cc5fa
3
+ metadata.gz: 7e751a24bfc7b92e3df8e1af211b838f679acaa888236d34b12853f43614891e
4
+ data.tar.gz: 10f0770286d862f60da92690bc316a6f1926b1e11c95fe8f4249fe3a96a6e5bf
5
5
  SHA512:
6
- metadata.gz: 4cd75a8fcf7e4eac4cf4b29fffa12ac0d75f178c9e3307e4f8b5d31dc993bc903ceefda271c747e9206f081fc7c62cd0ddb3b28c480e40e7f0cbc85bd06dc814
7
- data.tar.gz: 19714d6f9fdfbdd5c1bb90764ae4c7590e386b895042b27f671bb306137f03efa133ac2e37edd63cfd680e08b1edfed9fdee1446922f5fa2eeef8f89b1e71e75
6
+ metadata.gz: 2e3ff4b0ca14dad864a356f98e4d9f805fcdc182b58359396963724f62d9f9da433249c0f2471b36503189fdf351fab4693ee916fb82e708a675568a0267cce9
7
+ data.tar.gz: e8b4bfd444e139005535f183769a8721a8b7bfea8ffde74c14028f4bd79398c0684dc0f2b515c353127eb8a4fd6df61b969e33d8c41b41451fe4abea56b85fab
data/.gitignore CHANGED
@@ -7,6 +7,9 @@
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
12
15
 
@@ -16,6 +19,4 @@
16
19
  # ignore MacOS system file
17
20
  .DS_Store
18
21
 
19
- *.tex.html
20
-
21
22
  /dist/
@@ -84,8 +84,6 @@ Style/Documentation:
84
84
  - 'lib/latexmath/aggregator.rb'
85
85
  - 'lib/latexmath/converter.rb'
86
86
  - 'lib/latexmath/equation.rb'
87
- - 'lib/latexmath/latexml_requirement.rb'
88
- - 'lib/latexmath/requirement.rb'
89
87
  - 'lib/latexmath/tokenizer.rb'
90
88
 
91
89
  # Offense count: 18
@@ -121,7 +119,6 @@ Style/NumericPredicate:
121
119
  - 'spec/**/*'
122
120
  - 'lib/latexmath/aggregator.rb'
123
121
  - 'lib/latexmath/converter.rb'
124
- - 'lib/latexmath/latexml_requirement.rb'
125
122
 
126
123
  # Offense count: 2
127
124
  # Cop supports --auto-correct.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- latexmath (0.1.3)
4
+ latexmath (0.1.4)
5
5
  htmlentities (~> 4.3)
6
6
  ox (~> 2.13)
7
7
 
data/Rakefile CHANGED
@@ -1,7 +1,6 @@
1
1
  require 'bundler/setup'
2
2
  require 'bundler/gem_tasks'
3
3
  require 'rspec/core/rake_task'
4
-
5
4
  RSpec::Core::RakeTask.new(:spec)
6
5
 
7
6
  task 'build-opal' do
@@ -29,4 +28,68 @@ task 'spec-opal' => 'build-opal' do
29
28
  ENV.delete 'TEST_OPAL'
30
29
  end
31
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
+
32
95
  task default: [:spec, 'spec-opal']
@@ -1,10 +1,10 @@
1
- require 'byebug' unless RUBY_ENGINE == 'opal'
1
+ #require 'byebug' unless RUBY_ENGINE == 'opal'
2
2
  require 'json'
3
3
  require 'htmlentities'
4
4
  require 'ox'
5
5
  require_relative 'latexmath/ext'
6
6
  require_relative 'latexmath/version'
7
- #require_relative 'latexmath/latexml_requirement'
7
+ require_relative 'latexmath/constants/symbols'
8
8
  require_relative 'latexmath/aggregator'
9
9
  require_relative 'latexmath/converter'
10
10
  require_relative 'latexmath/symbol'
@@ -77,10 +77,6 @@ module Latexmath
77
77
  COMMANDS[limit] = [1, 'munder', {}]
78
78
  end
79
79
 
80
- Requirements = {
81
- #latexml: LatexmlRequirement.new
82
- }.freeze
83
-
84
80
  def self.parse(string)
85
81
  lxm_input = HTMLEntities.new.decode(string)
86
82
 
@@ -301,6 +301,9 @@ module Latexmath
301
301
  if element == '_' && index == 1 && param == '\\sum'
302
302
  new_parent.tag = 'munder'
303
303
  classify(param, new_parent)
304
+ elsif element == '_^' && param == '\\sum'
305
+ new_parent.tag = 'munderover'
306
+ classify(param, new_parent)
304
307
  elsif element == '\\left' || element == '\\right'
305
308
  if param == '.'
306
309
 
@@ -13,31 +13,9 @@ module Latexmath
13
13
  require 'native'
14
14
  @symbols ||= Native::Object.new(`globalThis.unimathsymbols`)
15
15
  else
16
- @symbols ||= read_symbols
16
+ @symbols ||= Latexmath::Constants::SYMBOLS
17
17
  end
18
18
  end
19
19
 
20
- private
21
-
22
- def read_symbols
23
- @symbols = {}
24
- File.readlines(File.join(File.dirname(__FILE__), "..", 'unimathsymbols.txt')).each do |line|
25
- next if line.start_with?('#')
26
-
27
- columns = line.chop.split('^')
28
- _unicode = columns[0]
29
- latex = columns[2]
30
- unicode_math = columns[3]
31
-
32
- @symbols[latex] = _unicode if latex && !@symbols.include?(latex)
33
- @symbols[unicode_math] = _unicode if unicode_math && !@symbols.include?(unicode_math)
34
-
35
- matches = columns[-1].match(/=\s+(\\[^,^ ]+),?/)
36
- if matches
37
- @symbols[matches[1]] = _unicode unless @symbols[matches[1]]
38
- end
39
- end
40
- @symbols
41
- end
42
20
  end
43
21
  end
@@ -58,9 +58,7 @@ module Latexmath
58
58
  matched
59
59
  elsif scan(/\\\{/)
60
60
  matched
61
- elsif scan(/\\,/)
62
- matched
63
- elsif scan(/\\:/)
61
+ elsif scan(/\\[:;,]/)
64
62
  matched
65
63
  elsif scan(/\\/)
66
64
  matched
@@ -1,3 +1,3 @@
1
1
  module Latexmath
2
- VERSION = '0.1.3'.freeze
2
+ VERSION = '0.1.4'.freeze
3
3
  end
@@ -1,4 +1,4 @@
1
- <%# This preprocesses unimathsymbols.txt for Opal %>
2
- <% require_relative 'lib/latexmath/symbol' %>
1
+ <%# This preprocesses Latexmath::SYMBOLS constant for Opal %>
2
+ <% require_relative 'lib/latexmath/constants/symbols' %>
3
3
 
4
- globalThis.unimathsymbols = <%= Latexmath::Symbol.instance.symbols.to_json %>;
4
+ globalThis.unimathsymbols = <%= Latexmath::Constants::SYMBOLS.to_json %>;
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: latexmath
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-09-11 00:00:00.000000000 Z
11
+ date: 2020-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: htmlentities
@@ -107,8 +107,6 @@ files:
107
107
  - lib/latexmath/converter.rb
108
108
  - lib/latexmath/equation.rb
109
109
  - lib/latexmath/ext.rb
110
- - lib/latexmath/latexml_requirement.rb
111
- - lib/latexmath/requirement.rb
112
110
  - lib/latexmath/symbol.rb
113
111
  - lib/latexmath/tokenizer.rb
114
112
  - lib/latexmath/version.rb
@@ -126,7 +124,7 @@ metadata:
126
124
  homepage_uri: https://github.com/plurimath/latexmath
127
125
  source_code_uri: https://github.com/plurimath/latexmath
128
126
  changelog_uri: https://github.com/plurimath/latexmath/blob/master/CHANGELOG.md.
129
- post_install_message:
127
+ post_install_message:
130
128
  rdoc_options: []
131
129
  require_paths:
132
130
  - lib
@@ -142,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
140
  version: '0'
143
141
  requirements: []
144
142
  rubygems_version: 3.0.3
145
- signing_key:
143
+ signing_key:
146
144
  specification_version: 4
147
145
  summary: Converts LaTeX math into MathML.
148
146
  test_files: []
@@ -1,83 +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(/\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 StandardError
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
- end
83
- end
@@ -1,11 +0,0 @@
1
- module Latexmath
2
- class Requirement
3
- def satisfied
4
- raise NotImplementedError('abstract method')
5
- end
6
-
7
- def cmd
8
- raise NotImplementedError('abstract method')
9
- end
10
- end
11
- end