rutex 0.1.3 → 0.1.4
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 +4 -4
- data/.gitignore +2 -0
- data/Gemfile.lock +1 -1
- data/exe/rutex +2 -0
- data/lib/rutex/version.rb +1 -1
- data/lib/rutex.rb +69 -71
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d1778f9c254e131282f0cb5edb930ac63e860341206494d0fcf7bc7f46c9846
|
4
|
+
data.tar.gz: affe81dd3e2e234127477b301f8f721735cadd870e7b25e45c911f4db3d6598c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16e40a9985a176feb0d32e9d46b1a5f4b2dadb27ffa5b84f518aa1b14b1ea732d4450df968a00b504e1eb65623509f82d2a5c4d7c5a8a676d6d11a619bb548ea
|
7
|
+
data.tar.gz: 9af7dddadca679980a796f9b941add10ea33e21649325adcdfb95ace2fe7887ae4f3d0b36b933ffd444ea7ae416937e45ae372c46602fbc877652c4eff65ca9b
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/exe/rutex
CHANGED
data/lib/rutex/version.rb
CHANGED
data/lib/rutex.rb
CHANGED
@@ -1,99 +1,113 @@
|
|
1
|
+
$LOAD_PATH.unshift __dir__
|
1
2
|
require 'rutex/version'
|
2
3
|
require 'tempfile'
|
3
4
|
|
4
|
-
class RutexError < StandardError; end
|
5
|
-
class PdfError < RutexError; end
|
6
|
-
class
|
5
|
+
class RutexError < StandardError; end # :nodoc:
|
6
|
+
class PdfError < RutexError; end # :nodoc:
|
7
|
+
class PackageError < RutexError; end # :nodoc:
|
7
8
|
|
8
9
|
module Rutex
|
9
10
|
extend self
|
10
11
|
|
12
|
+
attr_accessor :color, :equation, :args, :output_file
|
13
|
+
|
11
14
|
def entry(args)
|
12
15
|
@args=args
|
13
16
|
|
14
|
-
|
15
|
-
|
17
|
+
unless pdflatex
|
18
|
+
raise PdfError "Missing pdflatex binary from texlive package"
|
16
19
|
end
|
17
20
|
|
18
|
-
|
21
|
+
help if (args.include?('-h') or args.include?('--help'))
|
22
|
+
|
23
|
+
version if args.include?('-v')
|
19
24
|
|
25
|
+
if args.include?('-f')
|
26
|
+
_, @output_file = args.slice!(args.index('-f'),2)
|
27
|
+
end
|
28
|
+
@output_file||=Tempfile.new(['equation','.png']).path
|
29
|
+
|
30
|
+
if args.include?('-c')
|
31
|
+
_, @color = args.slice!(args.index('-c'),2)
|
32
|
+
end
|
20
33
|
@color||='black'
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
34
|
+
|
35
|
+
help if args.empty?
|
36
|
+
|
37
|
+
@equation=args.join
|
38
|
+
make_tex_file
|
39
|
+
puts "Generating #{output_file}"
|
40
|
+
pdflatex_command
|
41
|
+
#convert_tex(tex_file)
|
26
42
|
end
|
27
43
|
|
28
|
-
def
|
29
|
-
|
44
|
+
def version
|
45
|
+
puts "rutex #{VERSION}"
|
46
|
+
exit
|
47
|
+
end
|
30
48
|
|
31
|
-
|
32
|
-
|
33
|
-
|
49
|
+
def pdflatex
|
50
|
+
%x(type -p pdflatex)
|
51
|
+
$?.exitstatus==0 ? true : false
|
52
|
+
end
|
34
53
|
|
35
|
-
|
54
|
+
def pdflatex_options
|
55
|
+
"-halt-on-error -interaction=nonstopmode -output-directory=#{output_dir}"
|
56
|
+
end
|
36
57
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
58
|
+
def pdflatex_command
|
59
|
+
%x(pdflatex #{pdflatex_options} #{tex_file})
|
60
|
+
raise PdfError "Error logged in #{output_dir}" unless $?.exitstatus==0
|
61
|
+
rescue PdfError => e
|
62
|
+
puts "PdfError (#{e.message})"
|
63
|
+
exit
|
64
|
+
end
|
65
|
+
|
66
|
+
def install_standalone_package
|
67
|
+
'http://mirrors.ctan.org/macros/latex/contrib/standalone.zip'
|
45
68
|
end
|
46
69
|
|
47
70
|
def help
|
48
71
|
puts <<~eof
|
49
|
-
Usage:
|
72
|
+
Usage:
|
73
|
+
rutex <equation> [options]
|
50
74
|
|
51
75
|
Options:
|
52
|
-
-c --color
|
53
|
-
|
54
|
-
-f --file
|
55
|
-
set output file
|
76
|
+
-c, --color set color of equation (default black)
|
77
|
+
-f, --file set output file
|
56
78
|
|
57
79
|
Examples:
|
58
80
|
rutex E = mc^2
|
59
81
|
rutex '2\\neq\\sqrt{9}'
|
60
|
-
rutex 3=\\\\sqrt{9} -c white -f
|
82
|
+
rutex 3=\\\\sqrt{9} -c white -f myequation.png
|
61
83
|
eof
|
62
84
|
exit
|
63
85
|
end
|
64
86
|
|
65
|
-
def
|
66
|
-
|
87
|
+
def tex_string
|
88
|
+
end
|
89
|
+
|
90
|
+
def output_dir
|
91
|
+
File.dirname(File.expand_path(output_file))
|
92
|
+
end
|
93
|
+
|
94
|
+
def make_tex_file
|
95
|
+
tex_string = <<~str
|
67
96
|
\\documentclass[preview]{standalone}
|
68
97
|
\\usepackage{xcolor}
|
69
98
|
\\begin{document}
|
70
|
-
$\\color{#{color}}#{
|
99
|
+
$\\color{#{color}}#{equation}$
|
71
100
|
\\end{document}
|
72
|
-
|
101
|
+
str
|
102
|
+
File.write(tex_file, tex_string)
|
73
103
|
end
|
74
104
|
|
75
|
-
def
|
76
|
-
|
77
|
-
tmp.write(texstr)
|
78
|
-
path=tmp.path
|
79
|
-
dir=path.sub(%r(.*\K/.*),'')
|
80
|
-
tmp.close
|
81
|
-
|
82
|
-
unless has_pdflatex
|
83
|
-
"Cannot proceed: RuTeX depends on pdflatex"
|
84
|
-
exit
|
85
|
-
end
|
86
|
-
|
87
|
-
%x(pdflatex --halt-on-error --output-directory=#{dir} #{path})
|
88
|
-
raise PdfError unless $?.exitstatus==0
|
89
|
-
path
|
90
|
-
rescue => e
|
91
|
-
puts "#{e.message}:\nError logged in #{path}.log"
|
92
|
-
exit
|
105
|
+
def tex_file
|
106
|
+
"#{output_dir}/#{File.basename(output_file,File.extname(output_file))}.tex"
|
93
107
|
end
|
94
108
|
|
95
109
|
def convert_tex(tex_file)
|
96
|
-
%x(convert -density 300 #{tex_file}.pdf #{
|
110
|
+
%x(convert -density 300 #{tex_file}.pdf #{output_file} 2>/dev/null)
|
97
111
|
raise ConvertError unless $?.exitstatus==0
|
98
112
|
rescue => e
|
99
113
|
puts "#{e.message}"
|
@@ -101,22 +115,6 @@ module Rutex
|
|
101
115
|
end
|
102
116
|
|
103
117
|
def has_pdflatex
|
104
|
-
system('type','-p', 'pdflatex', out
|
105
|
-
end
|
106
|
-
|
107
|
-
def color
|
108
|
-
@color
|
109
|
-
end
|
110
|
-
|
111
|
-
def eqn
|
112
|
-
@eqn
|
113
|
-
end
|
114
|
-
|
115
|
-
def args
|
116
|
-
@args
|
117
|
-
end
|
118
|
-
|
119
|
-
def outfile
|
120
|
-
@outfile
|
118
|
+
system('type','-p', 'pdflatex', [:out, :err] => File::NULL)
|
121
119
|
end
|
122
120
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sergioro
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|