latex_to_png 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7ec7822ae92fb0f98e532fa72737330791bc9a24
4
+ data.tar.gz: 9e3f2a3593321336d06d88e70ff675a789a007bc
5
+ SHA512:
6
+ metadata.gz: b6e673221153c9fc1142e2dccfa91e44014f7a4515c6f57b978330e6f00ba0c33c45b05a45d1331c0d34eb4853e02540cc17c4677e490ea8d9bfcb817e846cc1
7
+ data.tar.gz: 925fa8fea6b554c5148fd8099a77e996f19bca10c7f15e8195bc4608998daf21933983f094c545f6ac71a6f04ed0072f95da41b58050d93392f355776a749d60
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in latex_to_png.gemspec
4
+ gemspec
5
+
6
+
7
+ gem 'byebug'
8
+ gem 'rspec'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 luizamboni
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # LatexToPng
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'latex_to_png'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install latex_to_png
18
+
19
+ ## External Dependencies
20
+
21
+ sudo apt-get install imagemagick libmagickcore-dev
22
+
23
+ sudo apt-get install texlive texlive-latex-extra
24
+
25
+ sudo apt-get install texinfo
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'latex_to_png/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "latex_to_png"
8
+ spec.version = LatexToPng::VERSION
9
+ spec.authors = ["luizamboni"]
10
+ spec.email = ["luizamboni2002@hotmail.com"]
11
+ spec.summary = %q{Conversor de documentos Latex em imagens}
12
+ spec.description = %q{Conversor de documentos Latex em imagens, via shell script}
13
+ spec.homepage = "https://github.com/luizamboni/latex_to_png"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.requirements << "latex"
22
+ spec.requirements << "dvips"
23
+ spec.requirements << "imageMagik"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.6"
26
+ spec.add_development_dependency "rake"
27
+ end
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,28 @@
1
+ module LatexToPng
2
+ Sizes = {
3
+ '6pt' => '8px',
4
+ '7pt' => '9px',
5
+ '8pt' => '11px',
6
+ '9pt' => '12px',
7
+ '10pt' => '13px',
8
+ '11pt' => '15px',
9
+ '12pt' => '16px',
10
+ '13pt' => '17px',
11
+ '14pt' => '19px',
12
+ '15pt' => '21px',
13
+ '16pt' => '22px',
14
+ '17pt' => '23px',
15
+ '18pt' => '24px',
16
+ '20pt' => '26px',
17
+ '22pt' => '29px',
18
+ '24pt' => '32px',
19
+ '26pt' => '35px',
20
+ '27pt' => '36px',
21
+ '28pt' => '37px',
22
+ '29pt' => '38px',
23
+ '30pt' => '40px',
24
+ '32pt' => '42px',
25
+ '34pt' => '45px',
26
+ '36pt' => '48px'
27
+ }
28
+ end
@@ -0,0 +1,3 @@
1
+ module LatexToPng
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,107 @@
1
+ require "latex_to_png/version"
2
+ require 'tempfile'
3
+ require "erb"
4
+ require 'ostruct'
5
+
6
+
7
+
8
+ #precisa do programa texi2dvi
9
+ #sudo apt-get install texinfo
10
+ #e depois o Latex
11
+ #sudo apt-get install texlive
12
+ # e depois iamgeMagik com extensão para dev, para a gem rmagik
13
+ #sudo apt-get install imagemagick libmagickcore-dev
14
+ begin
15
+ if %x(hash convert 2>/dev/null || { echo >&2 "I require ImageMagick but it's not installed."; exit 1; })
16
+ raise RuntimeError,"You need install ImageMagick dependency. Run 'sudo apt-get install imagemagick libmagickcore-dev'"
17
+ end
18
+ if %x(hash latex 2>/dev/null || { echo >&2 "I require latex but it's not installed."; exit 1; })
19
+ raise RuntimeError,"You need install latex dependency. Run 'sudo apt-get install texlive texlive-latex-extra'"
20
+ end
21
+ if %x(hash dvips 2>/dev/null || { echo >&2 "I require dvips but it's not installed."; exit 1; })
22
+ raise RuntimeError,"You need install dvips dependency. Run 'sudo apt-get install texinfo'"
23
+ end
24
+ rescue Exception => e
25
+ puts e
26
+ # raise Gem::Installer::ExtensionBuildError
27
+ end
28
+
29
+ require "latex_to_png/sizes"
30
+
31
+ module LatexToPng
32
+
33
+
34
+
35
+ ROOT_LIB = File.dirname __FILE__
36
+
37
+
38
+ class Convert
39
+
40
+ attr_accessor :dirname , :filename, :basename, :png_file, :template_path
41
+
42
+ def size_in_points size_in_pixels
43
+ size = Sizes.invert[size_in_pixels]
44
+ if size.nil?
45
+ size_in_points "#{size_in_pixels.to_i + 1}px"
46
+
47
+ else
48
+ size
49
+ end
50
+ end
51
+
52
+ def initialize opts={ filename: nil, formula: nil, template_path: nil, size: nil }
53
+
54
+ @filename = opts[:filename] if opts[:filename]
55
+ @basename = File.basename opts[:filename].split(".")[0] if opts[:filename]
56
+ @dirname = File.dirname opts[:filename] if opts[:filename]
57
+
58
+ @size = (opts[:size] || 10).to_i
59
+ @template_path = opts[:template_path] if opts[:template_path]
60
+ @formula = opts[:formula] if opts[:formula]
61
+ end
62
+
63
+ def to_png
64
+ if @formula
65
+ doc = ERB.new(File.read("#{ROOT_LIB}/templates/equation.erb"))
66
+ infos = OpenStruct.new({formula: @formula })
67
+ doc = doc.result(infos.instance_eval { binding })
68
+
69
+ tmp_file = Tempfile.new("formula")
70
+ tmp_file.write doc
71
+ tmp_file.close
72
+ # debugger
73
+ @filename = tmp_file.path
74
+ else
75
+ @filename
76
+ end
77
+
78
+ name = @filename.split("/").last.split(".").first
79
+ dirname = File.dirname @filename
80
+ basename = @filename.gsub( /.tex$/,'')
81
+ density = ((300/10)*@size).to_i
82
+
83
+ %x(cd #{dirname}; latex -halt-on-error #{@filename} >> convert_#{name}.log)
84
+ %x(cd #{dirname}; dvips -q* -E #{name}.dvi >> convert_#{name}.log)
85
+ %x(cd #{dirname}; convert -density #{density}x#{density} #{name}.ps #{name}.png >> convert_#{name}.log)
86
+ %x(cd #{dirname}; rm -f #{name}.dvi #{name}.log #{name}.aux #{name}.ps)
87
+ png_path = "#{@filename.gsub(/.tex$/,"")}.png"
88
+
89
+ if File.exist? png_path
90
+ %x(cd #{dirname}; rm -f convert_#{name}.log)
91
+ @png_file = open(png_path)
92
+ else
93
+ %x(cp #{tmp_file.path} #{dirname}/origin_#{name}.log)
94
+ raise StandardError
95
+ end
96
+
97
+ end
98
+
99
+ private
100
+
101
+ def move_to_dir
102
+ "cd #{@dirname}"
103
+ end
104
+
105
+ end
106
+ end
107
+
@@ -0,0 +1,11 @@
1
+ \documentclass{article}
2
+ \usepackage{amsmath}
3
+ \usepackage{cancel}
4
+ \usepackage{amsfonts}
5
+ \usepackage{amssymb}
6
+ \usepackage{amsthm}
7
+ \usepackage{mathtools}
8
+ \pagestyle{empty}
9
+ \begin{document}
10
+ $$<%= formula %>$$
11
+ \end{document}
@@ -0,0 +1,123 @@
1
+ require "spec_helper"
2
+
3
+ describe "" do
4
+
5
+ after(:each) do
6
+ # %x(rm #{ROOT_DIR_SPEC}/support/*.png)
7
+ end
8
+
9
+ context "convert.size_in_points" do
10
+ it "com valor exato" do
11
+
12
+ image = LatexToPng::Convert.new(filename: "#{ROOT_DIR_SPEC}/support/flux.tex")
13
+
14
+ expect(image.size_in_points("12px")).to eq "9pt"
15
+
16
+ end
17
+
18
+ it "com valor inexato pontos arredondadndo" do
19
+
20
+ image = LatexToPng::Convert.new(filename: "#{ROOT_DIR_SPEC}/support/flux.tex")
21
+
22
+ expect(image.size_in_points("18px")).to eq "14pt"
23
+
24
+ end
25
+
26
+
27
+ end
28
+
29
+
30
+ it "dirname do arquivo" do
31
+
32
+ image = LatexToPng::Convert.new(filename: "#{ROOT_DIR_SPEC}/support/flux.tex")
33
+
34
+ expect(image.dirname).to eq "#{ROOT_DIR_SPEC}/support"
35
+ expect(image.basename).to eq "flux"
36
+
37
+
38
+ end
39
+
40
+ it "dirname do arquivo" do
41
+
42
+ image = LatexToPng::Convert.new(filename: "#{ROOT_DIR_SPEC}/support/flux.tex")
43
+ image = image.to_png
44
+ expect(image.class).to eq File
45
+
46
+ File.delete image.path
47
+ end
48
+
49
+ it "dirname do arquivo com \\cancel" do
50
+
51
+ image = LatexToPng::Convert.new(filename: "#{ROOT_DIR_SPEC}/support/cancel_example.tex")
52
+ image = image.to_png
53
+
54
+ expect(image.class).to eq File
55
+ File.delete image.path
56
+
57
+ end
58
+
59
+ context "formula com usando template" do
60
+
61
+ it "fração simples" do
62
+
63
+ image = LatexToPng::Convert.new(formula: "\\frac{a}{b}")
64
+ image = image.to_png
65
+
66
+ expect(image.class).to eq File
67
+ expect(File.exist? image).to eq true
68
+
69
+ File.delete image.path
70
+ end
71
+
72
+ it "fração com \\cdot" do
73
+
74
+ image = LatexToPng::Convert.new(formula: "\\frac{a}{b}\\cdot\\frac{b}{a}")
75
+ image = image.to_png
76
+
77
+ expect(image.class).to eq File
78
+ expect(File.exist? image).to eq true
79
+
80
+ File.delete image.path
81
+ end
82
+
83
+ it "fração com \\cdot e espaços" do
84
+
85
+ image = LatexToPng::Convert.new(formula: "\\frac{a}{b} \\cdot \\frac{b}{a}")
86
+ image = image.to_png
87
+
88
+ expect(image.class).to eq File
89
+ expect(File.exist? image).to eq true
90
+
91
+ File.delete image.path
92
+ end
93
+
94
+ it "fração com \\cdot e espaços e tab" do
95
+
96
+ image = LatexToPng::Convert.new(formula: "\\frac{a}{b} \\cdot \\frac{b}{a}")
97
+ image = image.to_png
98
+
99
+ expect(image.class).to eq File
100
+ expect(File.exist? image).to eq true
101
+
102
+ File.delete image.path
103
+ end
104
+
105
+ it "fração com tamanho de fonte" do
106
+
107
+ image = LatexToPng::Convert.new(formula: "\\frac{a}{b}", size_in_pixels: "19px")
108
+ image = image.to_png
109
+
110
+ expect(image.class).to eq File
111
+ expect(File.exist? image).to eq true
112
+
113
+ # File.delete image.path
114
+ end
115
+
116
+ it "insstrução inexistente como \\blabla" do
117
+
118
+ image = LatexToPng::Convert.new(formula: "\\blabla")
119
+ expect{image.to_png}.to raise_error
120
+ end
121
+
122
+ end
123
+ end
@@ -0,0 +1,12 @@
1
+ require "latex_to_png"
2
+ require "byebug"
3
+ require 'bundler/setup'
4
+
5
+ Bundler.setup
6
+
7
+ ROOT_DIR_SPEC = File.dirname __FILE__
8
+
9
+ RSpec.configure do |config|
10
+
11
+
12
+ end
@@ -0,0 +1,9 @@
1
+ \documentclass{article}
2
+ \usepackage{amsmath}
3
+ \usepackage{cancel}
4
+ \pagestyle{empty}
5
+ \begin{document}
6
+ \begin{equation}
7
+ \cancel{a}
8
+ \end{equation}
9
+ \end{document}
@@ -0,0 +1,8 @@
1
+ \documentclass{article}
2
+ \usepackage{amsmath}
3
+ \pagestyle{empty}
4
+ \begin{document}
5
+ \begin{equation}
6
+ 60=a_{1}+(n-1)\cdot 2
7
+ \end{equation}
8
+ \end{document}
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: latex_to_png
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - luizamboni
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
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
+ description: Conversor de documentos Latex em imagens, via shell script
42
+ email:
43
+ - luizamboni2002@hotmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".rspec"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - latex_to_png.gemspec
55
+ - lib/fonts/STIX-Bold.otf
56
+ - lib/fonts/STIX-BoldItalic.otf
57
+ - lib/fonts/STIX-Italic.otf
58
+ - lib/fonts/STIX-Regular.otf
59
+ - lib/fonts/STIXMath-Regular.otf
60
+ - lib/latex_to_png.rb
61
+ - lib/latex_to_png/sizes.rb
62
+ - lib/latex_to_png/version.rb
63
+ - lib/templates/equation.erb
64
+ - spec/convert_spec.rb
65
+ - spec/spec_helper.rb
66
+ - spec/support/cancel_example.tex
67
+ - spec/support/flux.tex
68
+ homepage: https://github.com/luizamboni/latex_to_png
69
+ licenses:
70
+ - MIT
71
+ metadata: {}
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements:
87
+ - latex
88
+ - dvips
89
+ - imageMagik
90
+ rubyforge_project:
91
+ rubygems_version: 2.4.6
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Conversor de documentos Latex em imagens
95
+ test_files:
96
+ - spec/convert_spec.rb
97
+ - spec/spec_helper.rb
98
+ - spec/support/cancel_example.tex
99
+ - spec/support/flux.tex