rutex 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2d1778f9c254e131282f0cb5edb930ac63e860341206494d0fcf7bc7f46c9846
4
- data.tar.gz: affe81dd3e2e234127477b301f8f721735cadd870e7b25e45c911f4db3d6598c
3
+ metadata.gz: 5712ce9901a3f2745b95543efa8a66bf04e18d587130757aed0eb3e3941b7af1
4
+ data.tar.gz: e54cebec6a18307e70f38d225ca5b65ae76ad9dcf9be6b4ed6f9d4f38b071519
5
5
  SHA512:
6
- metadata.gz: 16e40a9985a176feb0d32e9d46b1a5f4b2dadb27ffa5b84f518aa1b14b1ea732d4450df968a00b504e1eb65623509f82d2a5c4d7c5a8a676d6d11a619bb548ea
7
- data.tar.gz: 9af7dddadca679980a796f9b941add10ea33e21649325adcdfb95ace2fe7887ae4f3d0b36b933ffd444ea7ae416937e45ae372c46602fbc877652c4eff65ca9b
6
+ metadata.gz: 3deba6a6105dbffc38542ccaf8d8af01f9157d175cf399fc42750421c6e85c2d027ce2bc61b5bf25d91c100e1dcfff99eadb4adb854f7c9627c6ec76a4adb438
7
+ data.tar.gz: eaf8170625ef64237bc0283db9ff704d544245793118bbfe4ae061ca38068cb3b699c0eb7a8f413068d8c317870237361ffef495c6efb81a6a6b43818f05eaae
data/.gitignore CHANGED
@@ -12,3 +12,5 @@ TODO.md
12
12
  *.swp
13
13
  *.tex
14
14
  *.png
15
+ .byebug
16
+ mkmf.log
data/Gemfile.lock CHANGED
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rutex (0.1.4)
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
- class RutexError < StandardError; end # :nodoc:
6
- class PdfError < RutexError; end # :nodoc:
7
- class PackageError < RutexError; end # :nodoc:
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
- attr_accessor :color, :equation, :args, :output_file
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
- def entry(args)
15
- @args=args
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 binary from texlive package"
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.new(['equation','.png']).path
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
- puts "Generating #{output_file}"
40
- pdflatex_command
41
- #convert_tex(tex_file)
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
- %x(type -p pdflatex)
51
- $?.exitstatus==0 ? true : false
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=#{output_dir}"
74
+ def pdflatex_options # :nodoc:
75
+ "-halt-on-error -interaction=nonstopmode -output-directory=#{pdflatex_log_dir}"
56
76
  end
57
77
 
58
- def pdflatex_command
78
+ # run pdflatex command with +pdflatex_options+
79
+ def pdflatex_run
59
80
  %x(pdflatex #{pdflatex_options} #{tex_file})
60
- raise PdfError "Error logged in #{output_dir}" unless $?.exitstatus==0
81
+ raise PdfError "Errors logged in #{pdflatex_log_dir}" unless $?.exitstatus==0
61
82
  rescue PdfError => e
62
83
  puts "PdfError (#{e.message})"
63
- exit
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 set color of equation (default black)
77
- -f, --file set output file
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 tex_string
88
- end
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
- "#{output_dir}/#{File.basename(output_file,File.extname(output_file))}.tex"
122
+ def tex_file # :nodoc:
123
+ "#{output_file}.tex"
107
124
  end
108
125
 
109
- def convert_tex(tex_file)
110
- %x(convert -density 300 #{tex_file}.pdf #{output_file} 2>/dev/null)
111
- raise ConvertError unless $?.exitstatus==0
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
@@ -1,3 +1,3 @@
1
1
  module Rutex
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.6" # :nodoc:
3
3
  end
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
- #spec.add_runtime_dependency "SOME_GEM", "~> VERSION"
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
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-12 00:00:00.000000000 Z
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