rutex 0.1.4 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/Gemfile.lock +3 -1
- data/README.md +3 -0
- data/lib/rutex.rb +70 -40
- data/lib/rutex/version.rb +1 -1
- data/rutex.gemspec +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5712ce9901a3f2745b95543efa8a66bf04e18d587130757aed0eb3e3941b7af1
|
4
|
+
data.tar.gz: e54cebec6a18307e70f38d225ca5b65ae76ad9dcf9be6b4ed6f9d4f38b071519
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3deba6a6105dbffc38542ccaf8d8af01f9157d175cf399fc42750421c6e85c2d027ce2bc61b5bf25d91c100e1dcfff99eadb4adb854f7c9627c6ec76a4adb438
|
7
|
+
data.tar.gz: eaf8170625ef64237bc0283db9ff704d544245793118bbfe4ae061ca38068cb3b699c0eb7a8f413068d8c317870237361ffef495c6efb81a6a6b43818f05eaae
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rutex (0.1.
|
4
|
+
rutex (0.1.6)
|
5
|
+
mini_magick (~> 4.10.1)
|
5
6
|
|
6
7
|
GEM
|
7
8
|
remote: https://rubygems.org/
|
@@ -9,6 +10,7 @@ GEM
|
|
9
10
|
ansi (1.5.0)
|
10
11
|
builder (3.2.4)
|
11
12
|
byebug (11.0.1)
|
13
|
+
mini_magick (4.10.1)
|
12
14
|
minitest (5.14.0)
|
13
15
|
minitest-reporters (1.3.8)
|
14
16
|
ansi
|
data/README.md
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
[ ] study mkmf source. specifically the line with the wird parenthesis syntax
|
2
|
+
do |msg, (pre, noun)|
|
3
|
+
|
1
4
|
# Rutex
|
2
5
|
|
3
6
|
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.
|
data/lib/rutex.rb
CHANGED
@@ -1,21 +1,38 @@
|
|
1
1
|
$LOAD_PATH.unshift __dir__
|
2
2
|
require 'rutex/version'
|
3
3
|
require 'tempfile'
|
4
|
+
require 'mkmf'
|
5
|
+
require 'mini_magick'
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
|
7
|
+
module MakeMakefile
|
8
|
+
module Logging
|
9
|
+
@logfile = File::NULL
|
10
|
+
end
|
11
|
+
end
|
8
12
|
|
13
|
+
# Generate images from TeX equations
|
9
14
|
module Rutex
|
15
|
+
class RutexError < StandardError; end # :nodoc:
|
16
|
+
class PdfError < RutexError; end # :nodoc:
|
17
|
+
class PackageError < RutexError; end # :nodoc:
|
18
|
+
|
10
19
|
extend self
|
11
20
|
|
12
|
-
|
21
|
+
# input equation
|
22
|
+
attr_accessor :equation
|
23
|
+
|
24
|
+
# color of equation
|
25
|
+
attr_accessor :color
|
26
|
+
|
27
|
+
attr_accessor :output_file # :nodoc:
|
13
28
|
|
14
|
-
|
15
|
-
|
29
|
+
PNG_TRANSPARENT=true
|
30
|
+
PNG_DENSITY=600
|
31
|
+
PNG_QUALITY=100
|
16
32
|
|
33
|
+
def entry(args) # :nodoc:
|
17
34
|
unless pdflatex
|
18
|
-
raise PdfError "Missing pdflatex
|
35
|
+
raise PdfError, "Missing pdflatex. Install texlive package"
|
19
36
|
end
|
20
37
|
|
21
38
|
help if (args.include?('-h') or args.include?('--help'))
|
@@ -25,7 +42,7 @@ module Rutex
|
|
25
42
|
if args.include?('-f')
|
26
43
|
_, @output_file = args.slice!(args.index('-f'),2)
|
27
44
|
end
|
28
|
-
@output_file||=Tempfile.
|
45
|
+
@output_file||=Tempfile.open('equation') {|f| f.path}
|
29
46
|
|
30
47
|
if args.include?('-c')
|
31
48
|
_, @color = args.slice!(args.index('-c'),2)
|
@@ -36,45 +53,47 @@ module Rutex
|
|
36
53
|
|
37
54
|
@equation=args.join
|
38
55
|
make_tex_file
|
39
|
-
|
40
|
-
|
41
|
-
|
56
|
+
pdflatex_run
|
57
|
+
puts "Generating #{png_file}"
|
58
|
+
pdf_to_png
|
59
|
+
rescue => e
|
60
|
+
abort e.message
|
42
61
|
end
|
43
62
|
|
44
|
-
def version
|
63
|
+
def version # :nodoc:
|
45
64
|
puts "rutex #{VERSION}"
|
46
65
|
exit
|
47
66
|
end
|
48
67
|
|
68
|
+
# returns location of pdflatex binary
|
49
69
|
def pdflatex
|
50
|
-
|
51
|
-
|
70
|
+
Logging.quiet=true
|
71
|
+
find_executable 'pdflatex'
|
52
72
|
end
|
53
73
|
|
54
|
-
def pdflatex_options
|
55
|
-
"-halt-on-error -interaction=nonstopmode -output-directory=#{
|
74
|
+
def pdflatex_options # :nodoc:
|
75
|
+
"-halt-on-error -interaction=nonstopmode -output-directory=#{pdflatex_log_dir}"
|
56
76
|
end
|
57
77
|
|
58
|
-
|
78
|
+
# run pdflatex command with +pdflatex_options+
|
79
|
+
def pdflatex_run
|
59
80
|
%x(pdflatex #{pdflatex_options} #{tex_file})
|
60
|
-
raise PdfError "
|
81
|
+
raise PdfError "Errors logged in #{pdflatex_log_dir}" unless $?.exitstatus==0
|
61
82
|
rescue PdfError => e
|
62
83
|
puts "PdfError (#{e.message})"
|
63
|
-
|
64
|
-
end
|
65
|
-
|
66
|
-
def install_standalone_package
|
67
|
-
'http://mirrors.ctan.org/macros/latex/contrib/standalone.zip'
|
84
|
+
abort "Try installing standalone package https://www.ctan.org/pkg/standalone"
|
68
85
|
end
|
69
86
|
|
70
|
-
def help
|
87
|
+
def help # :nodoc:
|
71
88
|
puts <<~eof
|
72
89
|
Usage:
|
73
90
|
rutex <equation> [options]
|
74
91
|
|
75
92
|
Options:
|
76
|
-
-c, --color
|
77
|
-
-f,
|
93
|
+
-c, --color set color of equation (default black)
|
94
|
+
-f, --file set output file
|
95
|
+
-h, --help print this help message
|
96
|
+
-v, --version print rutex version
|
78
97
|
|
79
98
|
Examples:
|
80
99
|
rutex E = mc^2
|
@@ -84,13 +103,11 @@ module Rutex
|
|
84
103
|
exit
|
85
104
|
end
|
86
105
|
|
87
|
-
def
|
88
|
-
|
89
|
-
|
90
|
-
def output_dir
|
91
|
-
File.dirname(File.expand_path(output_file))
|
106
|
+
def pdflatex_log_dir # :nodoc:
|
107
|
+
File.dirname(Tempfile.new)
|
92
108
|
end
|
93
109
|
|
110
|
+
# create tex file containing the +equation+
|
94
111
|
def make_tex_file
|
95
112
|
tex_string = <<~str
|
96
113
|
\\documentclass[preview]{standalone}
|
@@ -102,19 +119,32 @@ module Rutex
|
|
102
119
|
File.write(tex_file, tex_string)
|
103
120
|
end
|
104
121
|
|
105
|
-
def tex_file
|
106
|
-
"#{
|
122
|
+
def tex_file # :nodoc:
|
123
|
+
"#{output_file}.tex"
|
107
124
|
end
|
108
125
|
|
109
|
-
def
|
110
|
-
|
111
|
-
|
126
|
+
def png_file
|
127
|
+
"#{output_file}.png"
|
128
|
+
end
|
129
|
+
|
130
|
+
def pdf_file
|
131
|
+
"#{output_file}.pdf"
|
132
|
+
end
|
133
|
+
|
134
|
+
def pdf_to_png
|
135
|
+
pdf = MiniMagick::Image.open pdf_file
|
136
|
+
MiniMagick::Tool::Convert.new do |convert|
|
137
|
+
unless PNG_TRANSPARENT
|
138
|
+
convert.background "white"
|
139
|
+
convert.flatten
|
140
|
+
end
|
141
|
+
convert.density PNG_DENSITY
|
142
|
+
convert.quality PNG_QUALITY
|
143
|
+
convert << pdf.pages.first.path
|
144
|
+
convert << "png8:#{png_file}"
|
145
|
+
end
|
112
146
|
rescue => e
|
113
147
|
puts "#{e.message}"
|
114
148
|
exit
|
115
149
|
end
|
116
|
-
|
117
|
-
def has_pdflatex
|
118
|
-
system('type','-p', 'pdflatex', [:out, :err] => File::NULL)
|
119
|
-
end
|
120
150
|
end
|
data/lib/rutex/version.rb
CHANGED
data/rutex.gemspec
CHANGED
@@ -26,5 +26,5 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_development_dependency "minitest-reporters", "~> 1.3.8"
|
27
27
|
spec.add_development_dependency "rake", "~> 13.0.1"
|
28
28
|
|
29
|
-
|
29
|
+
spec.add_runtime_dependency "mini_magick", "~> 4.10.1"
|
30
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rutex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sergioro
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04-
|
11
|
+
date: 2020-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 13.0.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: mini_magick
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 4.10.1
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 4.10.1
|
69
83
|
description: Generate images from TeX equations
|
70
84
|
email:
|
71
85
|
- yo@sergioro.com
|