latex2image 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8850f4a329ff8e8fcf96dcaffac6e83cb4013107
4
+ data.tar.gz: a58359beecd6831099dd726e4026f6eea2d7b784
5
+ SHA512:
6
+ metadata.gz: 31b8cdfb9313fe0cc1aec5dbdfbaf70f5ee5aecbec593b197cd9691e7976715e5ea41bffc2288ea53909c627b680ae4cb541e8cbe8a9a5711becdd952aab2568
7
+ data.tar.gz: b14c768c40e99daa7584c18f73173babbedce431cc7a3aea333e4bbbc6fb04b876d8b37857e01f0339051a93f0e475e42368ef49a60ae284b46dc0d38c7e5bb4
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /output/
11
+ /.vagrant/
12
+ .DS_Store
13
+ *.dvi
14
+ *.aux
15
+ *.log
16
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
4
+ before_install: gem install bundler -v 1.10.5
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in latex2image.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Joao Fraga
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,62 @@
1
+ # Latex2Image
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/latex2image`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Dependencies
8
+
9
+ That gem require a `LaTeX` distribution and `dvipng`. The shell-script will only work in a Linux distribution, e.g. **Ubuntu**.
10
+
11
+ To install a `LaTeX` distribution in **Ubuntu** type in a terminal:
12
+
13
+ sudo apt-get install texlive-full
14
+
15
+ To install `dvipng` in **Ubuntu** type in a terminal:
16
+
17
+ sudo apt-get install dvipng
18
+
19
+
20
+ ## Installation
21
+
22
+ Add this line to your application's Gemfile:
23
+
24
+ ```ruby
25
+ gem 'latex2image'
26
+ ```
27
+
28
+ And then execute:
29
+
30
+ $ bundle
31
+
32
+ Or install it yourself as:
33
+
34
+ $ gem install latex2image
35
+
36
+ ## Usage
37
+
38
+ To convert LaTeX formules to PNG, just add to your code:
39
+
40
+ ``` ruby
41
+ image = Latex2Image.convert '\int \ln{x} dx = |x| \ln{|x|} - x +c'
42
+ image.output
43
+ # => #<File:/tmp/latex2image20151102-4025-9tmj0upng>
44
+ ```
45
+
46
+ ###
47
+
48
+ ## Development
49
+
50
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
51
+
52
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
53
+
54
+ ## Contributing
55
+
56
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/latex2image. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
57
+
58
+
59
+ ## License
60
+
61
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
62
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,72 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ # All Vagrant configuration is done below. The "2" in Vagrant.configure
5
+ # configures the configuration version (we support older styles for
6
+ # backwards compatibility). Please don't change it unless you know what
7
+ # you're doing.
8
+ Vagrant.configure(2) do |config|
9
+ # The most common configuration options are documented and commented below.
10
+ # For a complete reference, please see the online documentation at
11
+ # https://docs.vagrantup.com.
12
+
13
+ # Every Vagrant development environment requires a box. You can search for
14
+ # boxes at https://atlas.hashicorp.com/search.
15
+ config.vm.box = "fnando/hellobits-trusty64"
16
+
17
+ # Disable automatic box update checking. If you disable this, then
18
+ # boxes will only be checked for updates when the user runs
19
+ # `vagrant box outdated`. This is not recommended.
20
+ # config.vm.box_check_update = false
21
+
22
+ # Create a forwarded port mapping which allows access to a specific port
23
+ # within the machine from a port on the host machine. In the example below,
24
+ # accessing "localhost:8080" will access port 80 on the guest machine.
25
+ # config.vm.network "forwarded_port", guest: 80, host: 8080
26
+
27
+ # Create a private network, which allows host-only access to the machine
28
+ # using a specific IP.
29
+ # config.vm.network "private_network", ip: "192.168.33.10"
30
+
31
+ # Create a public network, which generally matched to bridged network.
32
+ # Bridged networks make the machine appear as another physical device on
33
+ # your network.
34
+ # config.vm.network "public_network"
35
+
36
+ # Share an additional folder to the guest VM. The first argument is
37
+ # the path on the host to the actual folder. The second argument is
38
+ # the path on the guest to mount the folder. And the optional third
39
+ # argument is a set of non-required options.
40
+ config.vm.synced_folder ".", "/vagrant"
41
+
42
+ # Provider-specific configuration so you can fine-tune various
43
+ # backing providers for Vagrant. These expose provider-specific options.
44
+ # Example for VirtualBox:
45
+ #
46
+ # config.vm.provider "virtualbox" do |vb|
47
+ # # Display the VirtualBox GUI when booting the machine
48
+ # vb.gui = true
49
+ #
50
+ # # Customize the amount of memory on the VM:
51
+ # vb.memory = "1024"
52
+ # end
53
+ #
54
+ # View the documentation for the provider you are using for more
55
+ # information on available options.
56
+
57
+ # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
58
+ # such as FTP and Heroku are also available. See the documentation at
59
+ # https://docs.vagrantup.com/v2/push/atlas.html for more information.
60
+ # config.push.define "atlas" do |push|
61
+ # push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
62
+ # end
63
+
64
+ # Enable provisioning with a shell script. Additional provisioners such as
65
+ # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
66
+ # documentation for more information about their specific syntax and use.
67
+ config.vm.provision "shell", inline: <<-SHELL
68
+ sudo apt-get update
69
+ sudo apt-get install texlive-full
70
+ sudo apt-get install dvipng
71
+ SHELL
72
+ end
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "latex2image"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # Using pry
10
+ require "pry"
11
+ Pry.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'latex2image/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "latex2image"
8
+ spec.version = Latex2Image::VERSION
9
+ spec.authors = ["Joao Fraga"]
10
+ spec.email = ["jgfraga@gmail.com"]
11
+
12
+ spec.summary = %q{Generate PNG images from Latex formules}
13
+ spec.description = %q{Generate PNG images from Latex formules on your ruby projects}
14
+ spec.homepage = "https://github.com/joaofraga/latex2image"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency 'rspec', '~> 0'
25
+ spec.add_development_dependency "pry", '~> 0'
26
+ end
@@ -0,0 +1,12 @@
1
+ require "latex2image/available_formats"
2
+ require "latex2image/generator"
3
+ require "latex2image/latex"
4
+ require "latex2image/version"
5
+
6
+ module Latex2Image
7
+ def self.convert(formule, output=nil)
8
+ latex = Latex.new(formule)
9
+
10
+ Generator.new(latex, output).generate
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module Latex2Image
2
+ AVAILABLE_FORMATS = ["png"]
3
+ end
@@ -0,0 +1,32 @@
1
+ module Latex2Image
2
+ class Generator
3
+ attr_reader :output
4
+
5
+ def initialize(latex, output=nil)
6
+ @latex = latex
7
+ @output = output.nil? ? Tempfile.new(%w(latex2image png)) : File.new(output, 'w+')
8
+ end
9
+
10
+ def generate
11
+ generate_dvi
12
+ generate_png
13
+
14
+ self
15
+ end
16
+
17
+ private
18
+
19
+ def generate_dvi
20
+ system "latex -output-directory=#{temp_dir} -interaction=nonstopmode #{@latex.file.path} .tex"
21
+ @dvi_file = "#{temp_dir}/#{File.basename(@latex.file.path, '.tex')}.dvi"
22
+ end
23
+
24
+ def generate_png
25
+ system "dvipng -q -T tight -bg transparent -D 300 #{@dvi_file} -o #{@output.path}"
26
+ end
27
+
28
+ def temp_dir
29
+ @temp_dir ||= Dir.mktmpdir
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,43 @@
1
+ require 'digest'
2
+
3
+ module Latex2Image
4
+ class Latex
5
+ attr_reader :formule, :file
6
+
7
+ def initialize(formule)
8
+ @formule = formule
9
+ @file = write_file
10
+ end
11
+
12
+ def to_tex
13
+ %{
14
+ \\documentclass[fleqn]{article}
15
+ \\DeclareMathSizes{20}{20}{20}{20}
16
+ \\usepackage{amssymb,amsmath,bm}
17
+ \\usepackage[latin1]{inputenc}
18
+ \\begin{document}
19
+ \\thispagestyle{empty}
20
+ \\begin{equation*}
21
+ #{@formule}
22
+ \\end{equation*}
23
+ \\end{document}
24
+ }
25
+ end
26
+
27
+ private
28
+
29
+ def write_file
30
+ file = Tempfile.new([file_name, '.tex'])
31
+ file.write to_tex
32
+ file.close
33
+
34
+ file
35
+ end
36
+
37
+ def file_name
38
+ md5 = Digest::MD5.new
39
+ md5.update @formule
40
+ md5.hexdigest
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ module Latex2Image
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: latex2image
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Joao Fraga
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-11-02 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
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: pry
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'
69
+ description: Generate PNG images from Latex formules on your ruby projects
70
+ email:
71
+ - jgfraga@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - Vagrantfile
85
+ - bin/console
86
+ - bin/setup
87
+ - latex2image.gemspec
88
+ - lib/latex2image.rb
89
+ - lib/latex2image/available_formats.rb
90
+ - lib/latex2image/generator.rb
91
+ - lib/latex2image/latex.rb
92
+ - lib/latex2image/version.rb
93
+ homepage: https://github.com/joaofraga/latex2image
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.4.8
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Generate PNG images from Latex formules
117
+ test_files: []