rutex 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.travis.yml +6 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +40 -0
- data/Rakefile +14 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/rutex +5 -0
- data/lib/rutex/version.rb +3 -0
- data/lib/rutex.rb +111 -0
- data/rutex.gemspec +30 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ff3a8a86d346108ad932c9367a0f01d031d38cbe6bc55de111252bfbd5fa8d3b
|
4
|
+
data.tar.gz: b441037fc05ad507269ff5c4b8e8813316bc741598dbb4d4a9261c1350d07bba
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fb21635ec40a0790d89f9df4ab7cd072e0fc5dd796c4ed0a238a422e362603c881adabb5e8060e898f1dcf91db7aa6549a50df5e24d13a3db425cd6c04d6c3de
|
7
|
+
data.tar.gz: 2c3a8fa83ff9ad5323cb9fa57d0229a8ab5f5c72833b570a4a75b36cd483fc3c73667dfbb7e8d3f43fd524df85bf019c5cab03570320daf337d7fc816bdba304
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 sergioro
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# Rutex
|
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/rutex`. 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
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'rutex'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install rutex
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
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).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rutex.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/clean'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
CLEAN.include ['**/.*.sw?', '**/*.gem', 'test/test.log']
|
7
|
+
|
8
|
+
task default: %i[test package]
|
9
|
+
task package: :clean
|
10
|
+
|
11
|
+
Rake::TestTask.new do |t|
|
12
|
+
t.libs << 'lib' << 'test'
|
13
|
+
t.test_files = FileList['test/**/*_test.rb']
|
14
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rutex"
|
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
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/rutex
ADDED
data/lib/rutex.rb
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'rutex/version'
|
2
|
+
require 'tempfile'
|
3
|
+
require 'byebug'
|
4
|
+
|
5
|
+
class RutexError < StandardError; end
|
6
|
+
class PdfError < RutexError; end
|
7
|
+
class ConvertError < RutexError; end
|
8
|
+
|
9
|
+
module Rutex
|
10
|
+
extend self
|
11
|
+
|
12
|
+
|
13
|
+
def entry(args)
|
14
|
+
@args=args
|
15
|
+
|
16
|
+
if args.size<1 or !(args & %w(-h --help)).empty?
|
17
|
+
help
|
18
|
+
end
|
19
|
+
|
20
|
+
#byebug
|
21
|
+
|
22
|
+
parse_options
|
23
|
+
|
24
|
+
@color||='black'
|
25
|
+
@eqn=args.join
|
26
|
+
tex_file=make_tex
|
27
|
+
@outfile||=(tex_file.sub %r(.*/),'')+'.png'
|
28
|
+
puts "Generating #{outfile}"
|
29
|
+
convert_tex(tex_file)
|
30
|
+
end
|
31
|
+
|
32
|
+
def parse_options
|
33
|
+
opts=%w(c f)
|
34
|
+
|
35
|
+
opts_idx=args.map.with_index do |e,i|
|
36
|
+
e.match(/^-[#{opts}.join]/) ? i : nil
|
37
|
+
end.compact.reverse
|
38
|
+
|
39
|
+
return if opts_idx.empty?
|
40
|
+
|
41
|
+
opts_idx.each do |i|
|
42
|
+
opt,value=args.slice!(i,2)
|
43
|
+
if opt=='-f'
|
44
|
+
@outfile=value
|
45
|
+
elsif opt=='-c'
|
46
|
+
@color=value
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def help
|
52
|
+
puts <<~eof
|
53
|
+
Usage: rutex <equation> [options]
|
54
|
+
|
55
|
+
Options:
|
56
|
+
-c --color
|
57
|
+
set color of equation (default black)
|
58
|
+
-f --file
|
59
|
+
set output file
|
60
|
+
|
61
|
+
Examples:
|
62
|
+
rutex E = mc^2
|
63
|
+
rutex '2\\neq\\sqrt{9}'
|
64
|
+
rutex 3=\\\\sqrt{9} -c white -f myeqn.png
|
65
|
+
eof
|
66
|
+
exit
|
67
|
+
end
|
68
|
+
|
69
|
+
def texstr
|
70
|
+
<<~eof
|
71
|
+
\\documentclass[preview]{standalone}
|
72
|
+
\\usepackage{xcolor}
|
73
|
+
\\begin{document}
|
74
|
+
$\\color{#{color}}#{eqn}$
|
75
|
+
\\end{document}
|
76
|
+
eof
|
77
|
+
end
|
78
|
+
|
79
|
+
def make_tex
|
80
|
+
tmp=Tempfile.new('eqn')
|
81
|
+
tmp.write(texstr)
|
82
|
+
path=tmp.path
|
83
|
+
dir=path.sub(%r(.*\K/.*),'')
|
84
|
+
tmp.close
|
85
|
+
%x(pdflatex --output-directory=#{dir} #{path})
|
86
|
+
path
|
87
|
+
rescue => e
|
88
|
+
puts "pdflatex error: \n#{e.message}"
|
89
|
+
exit
|
90
|
+
end
|
91
|
+
|
92
|
+
def convert_tex(tex_file)
|
93
|
+
%x(convert -density 300 #{tex_file}.pdf #{outfile} 2>/dev/null)
|
94
|
+
end
|
95
|
+
|
96
|
+
def color
|
97
|
+
@color
|
98
|
+
end
|
99
|
+
|
100
|
+
def eqn
|
101
|
+
@eqn
|
102
|
+
end
|
103
|
+
|
104
|
+
def args
|
105
|
+
@args
|
106
|
+
end
|
107
|
+
|
108
|
+
def outfile
|
109
|
+
@outfile
|
110
|
+
end
|
111
|
+
end
|
data/rutex.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require_relative 'lib/rutex/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "rutex"
|
5
|
+
spec.version = Rutex::VERSION
|
6
|
+
spec.authors = ["sergioro"]
|
7
|
+
spec.email = ["yo@sergioro.com"]
|
8
|
+
|
9
|
+
spec.summary = %q{Generate images from TeX equations}
|
10
|
+
spec.description = %q{Generate images from TeX equations}
|
11
|
+
spec.license = "MIT"
|
12
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
13
|
+
|
14
|
+
spec.metadata["thanks"] = "Donald Knuth for creating TeX"
|
15
|
+
|
16
|
+
# Specify which files should be added to the gem when it is released.
|
17
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
end
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
spec.add_development_dependency "byebug", "~> 11.0.1"
|
25
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
26
|
+
spec.add_development_dependency "minitest-reporters", "~> 1.3.8"
|
27
|
+
spec.add_development_dependency "rake", "~> 13.0.1"
|
28
|
+
|
29
|
+
#spec.add_runtime_dependency "SOME_GEM", "~> VERSION"
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rutex
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- sergioro
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-02-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: byebug
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 11.0.1
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 11.0.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest-reporters
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.3.8
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.3.8
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 13.0.1
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 13.0.1
|
69
|
+
description: Generate images from TeX equations
|
70
|
+
email:
|
71
|
+
- yo@sergioro.com
|
72
|
+
executables:
|
73
|
+
- rutex
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/console
|
84
|
+
- bin/setup
|
85
|
+
- exe/rutex
|
86
|
+
- lib/rutex.rb
|
87
|
+
- lib/rutex/version.rb
|
88
|
+
- rutex.gemspec
|
89
|
+
homepage:
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata:
|
93
|
+
thanks: Donald Knuth for creating TeX
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 2.3.0
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubygems_version: 3.0.6
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Generate images from TeX equations
|
113
|
+
test_files: []
|