texrack 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- checksums.yaml.gz.asc +13 -13
- data.tar.gz.asc +13 -13
- data/README.md +1 -2
- data/config.ru +1 -1
- data/lib/texrack.rb +6 -0
- data/lib/texrack/endpoint.rb +32 -6
- data/lib/texrack/latex_to_pdf.rb +15 -7
- data/lib/texrack/pdf_to_png.rb +12 -8
- data/lib/texrack/static/latex-failed.png +0 -0
- data/lib/texrack/static/missing-convert.png +0 -0
- data/lib/texrack/static/missing-pdflatex.png +0 -0
- data/lib/texrack/version.rb +1 -1
- data/lib/texrack/views/form.erb +28 -28
- data/texrack.gemspec +1 -1
- metadata +8 -5
- metadata.gz.asc +13 -13
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NGIyZDVhOGRjYzc0MzQ5ZGQwMzlhMmE0MTdkYWE4MDZmODRlMTUwYw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NTkwNWQ1MTI3ZjkzZTljMGI1NjU0ZmU3MGMwMTE2NTljM2EyNjE2Nw==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
M2Q2NTQ0ZDRjMTg3NjE5OTM5MmExM2U5ZmM2MzdhMDg4ZDQxNDczZmI0YTcz
|
10
|
+
OTY1MzQ1ZGU0ZTZiOGU5MjIyNTgwNzMwOGEwZmNjMTI0Mjc2N2UxN2RjZmNl
|
11
|
+
MDU0NjBlZTFkN2Q2NTIzYmI4MTM5YzNlZmY0NDM0NWExODQ5ZWQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OTIyYzU4NTA2YmIyMzViODEwMDQ5NjNlNTFhZjFjNjVhMGVhYTdmMGE5YWQ5
|
14
|
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LCZIYHfR
|
15
|
+
JmmalIU9ZoGdRoUXmr8A9MwDIQKu2rlogaFSkaM/ZKjYovfIwyYgFi+PVOX9wa8l
|
16
|
+
FzBRzW44gnLsWCjrSieU
|
17
|
+
=LOQB
|
18
18
|
-----END PGP SIGNATURE-----
|
data.tar.gz.asc
CHANGED
@@ -2,17 +2,17 @@
|
|
2
2
|
Version: GnuPG/MacGPG2 v2.0.20 (Darwin)
|
3
3
|
Comment: GPGTools - http://gpgtools.org
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
=
|
5
|
+
iQIcBAABAgAGBQJSc3n3AAoJEH1ncb0Txu7XMcwP/1S6Ixhnzw6oKq/8hiJ6T1bA
|
6
|
+
tHf5Ip8nB0BZP2vIioAeEOJxZDr3YnbRJ+d4nJy4MltqlYZtE4ZV64umNKqRnSHT
|
7
|
+
JtwHK7my38kA9H7pM6GKJq19VojZU7RxDAmp/RHkLbZfh9pC8su09lshOX7EX09f
|
8
|
+
jIIo1PhZUT9yhXiuPczNHa6fI/z4c942a8KCAIftrF3xDCA9ahY63QeYarr3LVrf
|
9
|
+
0QwvAORKQ9tv16M/BxArhF36mnVF64wFYa7mkqrczCkXXGwWlBXH0D1fv/GEvvZz
|
10
|
+
OQzWGCsOEdH8IKup8bwKtAnXxuZlvLkct1DQgiCv7N8PDhTdcu73JJW9XPXBDL81
|
11
|
+
eI7bSAJMGYbBNaU3g22tFVV8kf7rS6YoscUMiugC+1swv8EBltgR0B9U/dHtt7yQ
|
12
|
+
UtdSw8ZdlMPat+lJH+vXeY8z5IZp3GaR8arIrIFt8JWECut1vN2zx3GJmEhGo+ip
|
13
|
+
1jJg196cqkeP1T2lxSWnG+qTjSL0WXo5tg3KKzaltyUrYVgJONm9gAy0I85Jqavm
|
14
|
+
fk7XBNyBTpCs1+qrDiEcoN8Pe1+7xIT9MFfgV5g9wabyu7URE9oJvwnFW5A1Z+b7
|
15
|
+
tm0Ap7yKpJDK07WWOv38CdFaEn1bczneKq98sJV++94VWCt4d9Cgi+KZdqtpVf4X
|
16
|
+
lyxazvcPqMp5oPiQY+nl
|
17
|
+
=dGL3
|
18
18
|
-----END PGP SIGNATURE-----
|
data/README.md
CHANGED
@@ -5,8 +5,7 @@ Simple Rack middleware to render LaTeX to PNGs on the fly.
|
|
5
5
|
## Requirements
|
6
6
|
|
7
7
|
* `pdflatex` must exist in `$PATH`
|
8
|
-
*
|
9
|
-
installed and available.
|
8
|
+
* `convert` (from ImageMagick) must exist in `$PATH`
|
10
9
|
|
11
10
|
## Configuration
|
12
11
|
|
data/config.ru
CHANGED
data/lib/texrack.rb
CHANGED
@@ -2,3 +2,9 @@ require 'texrack/version'
|
|
2
2
|
require 'texrack/latex_to_pdf'
|
3
3
|
require 'texrack/pdf_to_png'
|
4
4
|
require 'texrack/endpoint'
|
5
|
+
|
6
|
+
module Texrack
|
7
|
+
class LatexNotFoundError < StandardError; end
|
8
|
+
class ConvertNotFoundError < StandardError; end
|
9
|
+
class LatexFailedError < StandardError; end
|
10
|
+
end
|
data/lib/texrack/endpoint.rb
CHANGED
@@ -4,6 +4,7 @@ require 'erb'
|
|
4
4
|
module Texrack
|
5
5
|
class Endpoint < Sinatra::Base
|
6
6
|
enable :logging
|
7
|
+
set :public_folder, File.dirname(__FILE__) + '/static'
|
7
8
|
|
8
9
|
get '/' do
|
9
10
|
if params[:data].to_s.strip != ""
|
@@ -19,12 +20,33 @@ module Texrack
|
|
19
20
|
|
20
21
|
def render_png(source)
|
21
22
|
content_type 'image/png'
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
begin
|
24
|
+
@data = source
|
25
|
+
output = Tempfile.new(["texrack-output", ".png"])
|
26
|
+
pdf_source = erb :latex
|
27
|
+
pdf = Texrack::LatexToPdf.new(pdf_source, logger).generate_pdf
|
28
|
+
png = Texrack::PdfToPng.new(pdf, logger).to_file(output)
|
29
|
+
send_file png, {
|
30
|
+
disposition: :inline
|
31
|
+
}
|
32
|
+
rescue Texrack::LatexFailedError
|
33
|
+
send_file File.join(settings.public_folder, "latex-failed.png"), {
|
34
|
+
disposition: :inline,
|
35
|
+
status: 500
|
36
|
+
}
|
37
|
+
rescue Texrack::LatexNotFoundError
|
38
|
+
logger.error "Could not find pdflatex in #{ENV['PATH']}"
|
39
|
+
send_file File.join(settings.public_folder, "missing-pdflatex.png"), {
|
40
|
+
disposition: :inline,
|
41
|
+
status: 500
|
42
|
+
}
|
43
|
+
rescue Texrack::ConvertNotFoundError
|
44
|
+
logger.error "Could not find convert (ImageMagick) in #{ENV['PATH']}"
|
45
|
+
send_file File.join(settings.public_folder, "missing-convert.png"), {
|
46
|
+
disposition: :inline,
|
47
|
+
status: 500
|
48
|
+
}
|
49
|
+
end
|
28
50
|
end
|
29
51
|
|
30
52
|
helpers do
|
@@ -32,6 +54,10 @@ module Texrack
|
|
32
54
|
params[:math] != "0"
|
33
55
|
end
|
34
56
|
|
57
|
+
def root_path
|
58
|
+
"#{env['SCRIPT_NAME']}/"
|
59
|
+
end
|
60
|
+
|
35
61
|
def packages
|
36
62
|
found = {}
|
37
63
|
params[:packages].to_s.split("|").each do |package|
|
data/lib/texrack/latex_to_pdf.rb
CHANGED
@@ -15,6 +15,8 @@ class Texrack::LatexToPdf
|
|
15
15
|
#
|
16
16
|
# pdflatex is used to convert the file.
|
17
17
|
def generate_pdf
|
18
|
+
raise Texrack::LatexNotFoundError unless has_pdflatex?
|
19
|
+
|
18
20
|
logger.debug "Generating PDF from #{latex}"
|
19
21
|
input = Tempfile.new(["texrack-input", ".tex"])
|
20
22
|
input.binmode
|
@@ -41,15 +43,21 @@ class Texrack::LatexToPdf
|
|
41
43
|
end
|
42
44
|
end)
|
43
45
|
|
44
|
-
output
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
logger.
|
49
|
-
|
46
|
+
output = input.path.sub(/\.tex$/, '.pdf')
|
47
|
+
logfile = input.path.sub(/\.tex$/, '.log')
|
48
|
+
if !File.exist?(output)
|
49
|
+
loglines = File.read(logfile)
|
50
|
+
logger.error "Unable to find file #{output}"
|
51
|
+
logger.error "LaTeX output: #{loglines}"
|
52
|
+
raise Texrack::LatexFailedError
|
50
53
|
end
|
51
54
|
|
52
55
|
input.close
|
53
|
-
|
56
|
+
output
|
57
|
+
end
|
58
|
+
|
59
|
+
def has_pdflatex?
|
60
|
+
ENV["PATH"].split(':').any? {|x| FileTest.executable? "#{x}/pdflatex" }
|
54
61
|
end
|
62
|
+
private :has_pdflatex?
|
55
63
|
end
|
data/lib/texrack/pdf_to_png.rb
CHANGED
@@ -1,15 +1,19 @@
|
|
1
|
-
require '
|
1
|
+
require 'cocaine'
|
2
2
|
|
3
3
|
class Texrack::PdfToPng
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
attr_reader :pdf_path, :logger, :line
|
5
|
+
|
6
|
+
def initialize(pdf_path, logger)
|
7
|
+
@pdf_path = pdf_path
|
8
|
+
@logger = logger
|
9
|
+
@line = Cocaine::CommandLine.new("convert",
|
10
|
+
"-density 300x300 -quality 90 :in :out", logger: logger)
|
9
11
|
end
|
10
12
|
|
11
13
|
def to_file(file)
|
12
|
-
|
13
|
-
file
|
14
|
+
line.run(in: pdf_path, out: file.path)
|
15
|
+
file.path
|
16
|
+
rescue Cocaine::CommandNotFoundError => e
|
17
|
+
raise Texrack::ConvertNotFoundError
|
14
18
|
end
|
15
19
|
end
|
Binary file
|
Binary file
|
Binary file
|
data/lib/texrack/version.rb
CHANGED
data/lib/texrack/views/form.erb
CHANGED
@@ -1,38 +1,38 @@
|
|
1
1
|
<!DOCTYPE html>
|
2
2
|
<html>
|
3
3
|
<head>
|
4
|
-
<title>Texrack</title>
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
-
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
|
4
|
+
<title>Texrack</title>
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
+
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
|
7
7
|
</head>
|
8
8
|
<body>
|
9
|
-
<div class="container">
|
10
|
-
<h1 class="page-header">Render <img src="
|
9
|
+
<div class="container">
|
10
|
+
<h1 class="page-header">Render <img src="<%= root_path %>?data=\LaTeX&math=0" alt="LaTeX"> as a PNG</h1>
|
11
11
|
|
12
|
-
<form role="form" action="
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
12
|
+
<form role="form" action="<%= root_path %>" method="POST">
|
13
|
+
<div class="form-group">
|
14
|
+
<label for="data">LaTeX to render</label>
|
15
|
+
<textarea class="form-control" id="data" name="data" rows="5"></textarea>
|
16
|
+
</div>
|
17
|
+
<div class="checkbox">
|
18
|
+
<label>
|
19
|
+
<input type="hidden" name="math" value="0">
|
20
|
+
<input type="checkbox" checked name="math" value="1"> Render in math mode?
|
21
|
+
</label>
|
22
|
+
</div>
|
23
|
+
<div class="form-group">
|
24
|
+
<label for="packages">Extra packages to include</label>
|
25
|
+
<input type="text" class="form-control" id="packages" name="packages">
|
26
|
+
<p class="help-block">
|
27
|
+
Separate packages with a pipe (|).
|
28
|
+
Arguments are also supported. Example: "[english]babel|amsmath"
|
29
|
+
</p>
|
30
|
+
</div>
|
31
31
|
|
32
|
-
|
33
|
-
|
32
|
+
<div class="form-actions">
|
33
|
+
<input type="submit" class="btn btn-primary" value="Render PNG">
|
34
|
+
</div>
|
35
|
+
</form>
|
34
36
|
</div>
|
35
|
-
</form>
|
36
|
-
</div>
|
37
37
|
</body>
|
38
38
|
</html>
|
data/texrack.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: texrack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Per Christian B. Viken
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -29,15 +29,15 @@ dependencies:
|
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
32
|
+
version: 0.5.3
|
33
33
|
version_requirements: !ruby/object:Gem::Requirement
|
34
34
|
requirements:
|
35
35
|
- - ~>
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version:
|
37
|
+
version: 0.5.3
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
|
-
name:
|
40
|
+
name: cocaine
|
41
41
|
description: texrack is a microservice that renders LaTeX as PNG files. Can be mounted
|
42
42
|
in a Rack app
|
43
43
|
email:
|
@@ -55,6 +55,9 @@ files:
|
|
55
55
|
- lib/texrack/endpoint.rb
|
56
56
|
- lib/texrack/latex_to_pdf.rb
|
57
57
|
- lib/texrack/pdf_to_png.rb
|
58
|
+
- lib/texrack/static/latex-failed.png
|
59
|
+
- lib/texrack/static/missing-convert.png
|
60
|
+
- lib/texrack/static/missing-pdflatex.png
|
58
61
|
- lib/texrack/version.rb
|
59
62
|
- lib/texrack/views/form.erb
|
60
63
|
- lib/texrack/views/latex.erb
|
metadata.gz.asc
CHANGED
@@ -2,17 +2,17 @@
|
|
2
2
|
Version: GnuPG/MacGPG2 v2.0.20 (Darwin)
|
3
3
|
Comment: GPGTools -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