mathematical 0.6.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +48 -12
  3. data/Rakefile +3 -2
  4. data/ext/mathematical/cairo_callbacks.c +25 -0
  5. data/ext/mathematical/cairo_callbacks.h +7 -0
  6. data/ext/mathematical/extconf.rb +11 -11
  7. data/ext/mathematical/lasem/src/lsmmathmldocument.c +3 -0
  8. data/ext/mathematical/lasem/src/lsmmathmlencloseelement.c +142 -0
  9. data/ext/mathematical/lasem/src/lsmmathmlencloseelement.h +64 -0
  10. data/ext/mathematical/lasem/src/lsmmathmlenums.c +35 -0
  11. data/ext/mathematical/lasem/src/lsmmathmlenums.h +25 -1
  12. data/ext/mathematical/lasem/src/lsmmathmlpaddedelement.c +79 -0
  13. data/ext/mathematical/lasem/src/lsmmathmlpaddedelement.h +5 -0
  14. data/ext/mathematical/lasem/src/lsmmathmlstyleelement.c +6 -0
  15. data/ext/mathematical/lasem/src/lsmmathmltableelement.c +5 -5
  16. data/ext/mathematical/lasem/src/lsmmathmltraits.c +24 -0
  17. data/ext/mathematical/lasem/src/lsmmathmltraits.h +1 -0
  18. data/ext/mathematical/lasem/src/lsmmathmltypes.h +1 -0
  19. data/ext/mathematical/lasem/src/lsmmathmlutils.h +9 -2
  20. data/ext/mathematical/lasem/src/lsmmathmlview.c +283 -11
  21. data/ext/mathematical/lasem/src/lsmmathmlview.h +13 -0
  22. data/ext/mathematical/lasem_overrides.c +40 -0
  23. data/ext/mathematical/lasem_overrides.h +23 -0
  24. data/ext/mathematical/mathematical.c +119 -127
  25. data/ext/mathematical/mathematical.h +24 -0
  26. data/ext/mathematical/mtex2MML/ext/extconf.rb +1 -1
  27. data/ext/mathematical/mtex2MML/src/lex.yy.c +4488 -4032
  28. data/ext/mathematical/mtex2MML/src/mtex2MML.h +3 -0
  29. data/ext/mathematical/mtex2MML/src/parse_extras.c +14 -5
  30. data/ext/mathematical/mtex2MML/src/parse_extras.h +3 -1
  31. data/ext/mathematical/mtex2MML/src/string_extras.c +39 -0
  32. data/ext/mathematical/mtex2MML/src/string_extras.h +7 -0
  33. data/ext/mathematical/mtex2MML/src/y.tab.c +4408 -3175
  34. data/ext/mathematical/mtex2MML/src/y.tab.h +500 -422
  35. data/lib/mathematical.rb +112 -2
  36. data/lib/mathematical/corrections.rb +2 -2
  37. data/lib/mathematical/version.rb +2 -2
  38. data/mathematical.gemspec +4 -4
  39. data/test/mathematical/basic_test.rb +1 -1
  40. data/test/mathematical/corrections_test.rb +1 -1
  41. data/test/mathematical/fixtures/png/numeric_test_1.png +0 -0
  42. data/test/mathematical/fixtures/png/numeric_test_2.png +0 -0
  43. data/test/mathematical/fixtures/png/numeric_test_3.png +0 -0
  44. data/test/mathematical/fixtures_test.rb +7 -7
  45. data/test/mathematical/maliciousness_test.rb +44 -17
  46. data/test/mathematical/mathjax_test.rb +5 -13
  47. data/test/mathematical/mathml_test.rb +3 -3
  48. data/test/mathematical/multiples_test.rb +68 -0
  49. data/test/mathematical/performance_test.rb +2 -2
  50. data/test/mathematical/png_test.rb +5 -5
  51. data/test/test_helper.rb +36 -1
  52. metadata +26 -11
  53. data/lib/mathematical/render.rb +0 -74
@@ -1,4 +1,4 @@
1
- require "test_helper"
1
+ require 'test_helper'
2
2
  require 'benchmark'
3
3
 
4
4
  class Mathematical::BasicTest < Test::Unit::TestCase
@@ -6,7 +6,7 @@ class Mathematical::BasicTest < Test::Unit::TestCase
6
6
  assert_nothing_raised do
7
7
  big_file = File.read('test/mathematical/fixtures/performance/big_file.text')
8
8
  speed = Benchmark.realtime do
9
- MathToItex(big_file).convert { |equation| Mathematical::Render.new.render(equation) }
9
+ MathToItex(big_file).convert { |equation| Mathematical.new.render(equation) }
10
10
  end
11
11
 
12
12
  assert_operator speed, :<=, 5
@@ -2,7 +2,7 @@ require "test_helper"
2
2
 
3
3
  class Mathematical::PNGTest < Test::Unit::TestCase
4
4
  def before
5
- File.delete("#{fixtures_dir}/png/pmatrix.png") if File.exists?("#{fixtures_dir}/png/pmatrix.png")
5
+ File.delete("#{fixtures_dir}/png/pmatrix.png") if File.exist?("#{fixtures_dir}/png/pmatrix.png")
6
6
  end
7
7
 
8
8
  def test_it_creates_a_png
@@ -16,10 +16,10 @@ class Mathematical::PNGTest < Test::Unit::TestCase
16
16
  \end{pmatrix}
17
17
  $$
18
18
  '''
19
- render = Mathematical::Render.new({:format => "png"})
19
+ render = Mathematical.new({:format => :png})
20
20
  data_hash = render.render(string)
21
- header = data_hash["png"].unpack('H*').first.slice(0, 18)
22
- File.open("#{fixtures_dir}/png/pmatrix.png", "w") { |f| f.write(data_hash["png"])}
23
- assert_equal header, "89504e470d0a1a0a00"
21
+ header = data_hash['png'].unpack('H*').first.slice(0, 18)
22
+ File.open("#{fixtures_dir}/png/pmatrix.png", 'w') { |f| f.write(data_hash['png'])}
23
+ assert_equal header, '89504e470d0a1a0a00'
24
24
  end
25
25
  end
data/test/test_helper.rb CHANGED
@@ -3,9 +3,10 @@ require 'mathematical'
3
3
  require 'test/unit'
4
4
  require 'mocha/test_unit'
5
5
  require 'math-to-itex'
6
+ require 'pp'
6
7
 
7
8
  def fixtures_dir
8
- "test/mathematical/fixtures"
9
+ 'test/mathematical/fixtures'
9
10
  end
10
11
 
11
12
  def capture_stderr(&blk)
@@ -16,3 +17,37 @@ def capture_stderr(&blk)
16
17
  ensure
17
18
  $stderr = old
18
19
  end
20
+
21
+ def write_base64svg_to_test_file(converted)
22
+
23
+ text = """
24
+ <html>
25
+
26
+ <body>
27
+
28
+ <img class=\"display-math\" data-math-type=\"display-math\" src=\"#{converted}\"/>
29
+
30
+ </body>
31
+
32
+ </html>
33
+ """
34
+
35
+ File.open('test.html', 'w') { |f| f.write(text) }
36
+ end
37
+
38
+ def write_svg_to_test_file(converted)
39
+
40
+ text = """
41
+ <html>
42
+
43
+ <body>
44
+
45
+ #{converted}
46
+
47
+ </body>
48
+
49
+ </html>
50
+ """
51
+
52
+ File.open('test.html', 'w') { |f| f.write(text) }
53
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mathematical
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garen Torikian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-17 00:00:00.000000000 Z
11
+ date: 2015-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -70,16 +70,16 @@ dependencies:
70
70
  name: math-to-itex
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - '='
74
74
  - !ruby/object:Gem::Version
75
- version: '0.3'
75
+ version: 0.3.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - '='
81
81
  - !ruby/object:Gem::Version
82
- version: '0.3'
82
+ version: 0.3.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: nokogiri
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -94,9 +94,10 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '1.6'
97
- description: 'A very fast way to turn itex math equations into beautifully rendered
98
- SVGs, to embed on the web. This library is mostly written in C and is a general
99
- purpose wrapper to GNOME''s Lasem. '
97
+ description: '["A", "very", "fast", "way", "to", "turn", "LaTeX", "math", "equations",
98
+ "into", "beautifully", "rendered", "SVGs,", "to", "embed", "on", "the", "web.",
99
+ "This", "library", "is", "mostly", "written", "in", "C", "and", "is", "a", "general",
100
+ "purpose", "wrapper", "to", "GNOME''s", "Lasem."]'
100
101
  email:
101
102
  - gjtorikian@gmail.com
102
103
  executables: []
@@ -107,6 +108,8 @@ files:
107
108
  - LICENSE.txt
108
109
  - README.md
109
110
  - Rakefile
111
+ - ext/mathematical/cairo_callbacks.c
112
+ - ext/mathematical/cairo_callbacks.h
110
113
  - ext/mathematical/extconf.rb
111
114
  - ext/mathematical/lasem/itex2mml/itex2MML.h
112
115
  - ext/mathematical/lasem/src/lasemrender.c
@@ -159,6 +162,8 @@ files:
159
162
  - ext/mathematical/lasem/src/lsmmathmldocument.h
160
163
  - ext/mathematical/lasem/src/lsmmathmlelement.c
161
164
  - ext/mathematical/lasem/src/lsmmathmlelement.h
165
+ - ext/mathematical/lasem/src/lsmmathmlencloseelement.c
166
+ - ext/mathematical/lasem/src/lsmmathmlencloseelement.h
162
167
  - ext/mathematical/lasem/src/lsmmathmlenums.c
163
168
  - ext/mathematical/lasem/src/lsmmathmlenums.h
164
169
  - ext/mathematical/lasem/src/lsmmathmlerrorelement.c
@@ -329,7 +334,10 @@ files:
329
334
  - ext/mathematical/lasem/tests/str.c
330
335
  - ext/mathematical/lasem/tests/suite.c
331
336
  - ext/mathematical/lasem/tools/generate-entity-array.c
337
+ - ext/mathematical/lasem_overrides.c
338
+ - ext/mathematical/lasem_overrides.h
332
339
  - ext/mathematical/mathematical.c
340
+ - ext/mathematical/mathematical.h
333
341
  - ext/mathematical/mtex2MML/ext/extconf.rb
334
342
  - ext/mathematical/mtex2MML/src/color_definitions.c
335
343
  - ext/mathematical/mtex2MML/src/deps/uthash/utarray.h
@@ -346,7 +354,6 @@ files:
346
354
  - ext/mathematical/mtex2MML/src/y.tab.h
347
355
  - lib/mathematical.rb
348
356
  - lib/mathematical/corrections.rb
349
- - lib/mathematical/render.rb
350
357
  - lib/mathematical/version.rb
351
358
  - mathematical.gemspec
352
359
  - test/mathematical/basic_test.rb
@@ -378,11 +385,15 @@ files:
378
385
  - test/mathematical/fixtures/before/multiple_dollar_inline.text
379
386
  - test/mathematical/fixtures/before/parens_inline.text
380
387
  - test/mathematical/fixtures/performance/big_file.text
388
+ - test/mathematical/fixtures/png/numeric_test_1.png
389
+ - test/mathematical/fixtures/png/numeric_test_2.png
390
+ - test/mathematical/fixtures/png/numeric_test_3.png
381
391
  - test/mathematical/fixtures/png/pmatrix.png
382
392
  - test/mathematical/fixtures_test.rb
383
393
  - test/mathematical/maliciousness_test.rb
384
394
  - test/mathematical/mathjax_test.rb
385
395
  - test/mathematical/mathml_test.rb
396
+ - test/mathematical/multiples_test.rb
386
397
  - test/mathematical/performance_test.rb
387
398
  - test/mathematical/png_test.rb
388
399
  - test/test_helper.rb
@@ -410,7 +421,7 @@ rubyforge_project:
410
421
  rubygems_version: 2.2.2
411
422
  signing_key:
412
423
  specification_version: 4
413
- summary: Quickly convert math equations into beautiful SVGs/PNGs/MathML.
424
+ summary: '["Quickly", "convert", "math", "equations", "into", "beautiful", "SVGs/PNGs/MathML."]'
414
425
  test_files:
415
426
  - test/mathematical/basic_test.rb
416
427
  - test/mathematical/corrections_test.rb
@@ -441,11 +452,15 @@ test_files:
441
452
  - test/mathematical/fixtures/before/multiple_dollar_inline.text
442
453
  - test/mathematical/fixtures/before/parens_inline.text
443
454
  - test/mathematical/fixtures/performance/big_file.text
455
+ - test/mathematical/fixtures/png/numeric_test_1.png
456
+ - test/mathematical/fixtures/png/numeric_test_2.png
457
+ - test/mathematical/fixtures/png/numeric_test_3.png
444
458
  - test/mathematical/fixtures/png/pmatrix.png
445
459
  - test/mathematical/fixtures_test.rb
446
460
  - test/mathematical/maliciousness_test.rb
447
461
  - test/mathematical/mathjax_test.rb
448
462
  - test/mathematical/mathml_test.rb
463
+ - test/mathematical/multiples_test.rb
449
464
  - test/mathematical/performance_test.rb
450
465
  - test/mathematical/png_test.rb
451
466
  - test/test_helper.rb
@@ -1,74 +0,0 @@
1
- require 'fileutils'
2
- require 'base64'
3
- require 'tempfile'
4
-
5
- module Mathematical
6
- class Render
7
- include Corrections
8
-
9
- FORMAT_TYPES = %w(svg png mathml)
10
-
11
- DEFAULT_OPTS = {
12
- ppi: 72.0,
13
- zoom: 1.0,
14
- base64: false,
15
- maxsize: 0,
16
- format: 'svg'
17
- }
18
-
19
- XML_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
20
-
21
- def initialize(opts = {})
22
- @config = DEFAULT_OPTS.merge(opts)
23
-
24
- validate_config
25
-
26
- @config[:formatInt] = FORMAT_TYPES.index(@config[:format])
27
-
28
- @processer = Mathematical::Process.new(@config)
29
- end
30
-
31
- def validate_config
32
- fail(TypeError, 'maxsize must be an integer!') unless @config[:maxsize].is_a? Fixnum
33
- fail(TypeError, 'maxsize cannot be less than 0!') if @config[:maxsize] < 0
34
- fail(TypeError, 'format must be a string!') unless @config[:format].is_a? String
35
- fail(TypeError, "format type must be one of the following formats: #{FORMAT_TYPES.join(', ')}") unless FORMAT_TYPES.include?(@config[:format])
36
- end
37
-
38
- def render(maths)
39
- maths = validate_content(maths)
40
-
41
- begin
42
- data_hash = @processer.process(maths)
43
- fail RuntimeError unless data_hash
44
-
45
- case @config[:format]
46
- when 'svg'
47
- # remove starting <?xml...> tag
48
- data_hash['svg'] = data_hash['svg'][XML_HEADER.length..-1]
49
- data_hash['svg'] = svg_to_base64(data_hash['svg']) if @config[:base64]
50
- data_hash
51
- when 'png', 'mathml'
52
- data_hash
53
- end
54
- rescue ParseError, DocumentCreationError, DocumentReadError => e
55
- # an error in the C code, probably a bad TeX parse
56
- $stderr.puts "#{e.message}: #{maths}"
57
- maths
58
- end
59
- end
60
-
61
- def validate_content(maths)
62
- fail(TypeError, 'text must be a string!') unless maths.is_a? String
63
- maths = maths.strip
64
- fail(ArgumentError, 'text must be in tex format (`$...$` or `$$...$$`)!') unless maths =~ /\A\${1,2}/
65
- apply_corrections(maths)
66
- end
67
-
68
- private
69
-
70
- def svg_to_base64(contents)
71
- "data:image/svg+xml;base64,#{Base64.strict_encode64(contents)}"
72
- end
73
- end
74
- end