Better tex errors
This commit is contained in:
+12
-6
@@ -4,6 +4,8 @@ require 'tmpdir'
|
|||||||
|
|
||||||
module Gollum
|
module Gollum
|
||||||
module Tex
|
module Tex
|
||||||
|
class Error < StandardError; end
|
||||||
|
|
||||||
Template = <<-EOS
|
Template = <<-EOS
|
||||||
\\documentclass[12pt]{article}
|
\\documentclass[12pt]{article}
|
||||||
\\usepackage{color}
|
\\usepackage{color}
|
||||||
@@ -28,15 +30,15 @@ module Gollum
|
|||||||
|
|
||||||
def self.check_dependencies!
|
def self.check_dependencies!
|
||||||
if `which latex` == ""
|
if `which latex` == ""
|
||||||
raise "`latex` command not found"
|
raise Error, "`latex` command not found"
|
||||||
end
|
end
|
||||||
|
|
||||||
if `which dvips` == ""
|
if `which dvips` == ""
|
||||||
raise "`dvips` command not found"
|
raise Error, "`dvips` command not found"
|
||||||
end
|
end
|
||||||
|
|
||||||
if `which convert` == ""
|
if `which convert` == ""
|
||||||
raise "`convert` command not found"
|
raise Error, "`convert` command not found"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -51,13 +53,17 @@ module Gollum
|
|||||||
|
|
||||||
::File.open(tex_path, 'w') { |f| f.write(Template % formula) }
|
::File.open(tex_path, 'w') { |f| f.write(Template % formula) }
|
||||||
|
|
||||||
sh latex_path, '-interaction=batchmode', 'formula.tex', :cwd => path
|
result = sh latex_path, '-interaction=batchmode', 'formula.tex', :cwd => path
|
||||||
sh dvips_path, '-o', eps_path, '-E', dvi_path
|
raise "`latex` command failed: #{result}" unless ::File.exist?(eps_path)
|
||||||
sh convert_path, '+adjoin',
|
|
||||||
|
result = sh dvips_path, '-o', eps_path, '-E', dvi_path
|
||||||
|
raise "`dvips` command failed: #{result}" unless ::File.exist?(dvi_path)
|
||||||
|
result = sh convert_path, '+adjoin',
|
||||||
'-antialias',
|
'-antialias',
|
||||||
'-transparent', 'white',
|
'-transparent', 'white',
|
||||||
'-density', '150x150',
|
'-density', '150x150',
|
||||||
eps_path, png_path
|
eps_path, png_path
|
||||||
|
raise "`convert` command failed: #{result}" unless ::File.exist?(png_path)
|
||||||
|
|
||||||
::File.read(png_path)
|
::File.read(png_path)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user