Class: Imaginator::LaTeX
- Inherits:
-
Object
- Object
- Imaginator::LaTeX
- Defined in:
- lib/imaginator.rb
Instance Method Summary collapse
- #format ⇒ Object
-
#initialize(opts = {}) ⇒ LaTeX
constructor
A new instance of LaTeX.
- #process(code) ⇒ Object
- #render(code, file) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ LaTeX
Returns a new instance of LaTeX.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/imaginator.rb', line 12 def initialize(opts = {}) @opts = { :convert_opts => '-trim -density 120', :format => 'png', :debug => false } @opts[:blacklist] = %w{ include def command loop repeat open toks output input catcode name \\every \\errhelp \\errorstopmode \\scrollmode \\nonstopmode \\batchmode \\read \\write csname \\newhelp \\uppercase \\lowercase \\relax \\aftergroup \\afterassignment \\expandafter \\noexpand \\special $$ } @opts.update(opts) end |
Instance Method Details
#format ⇒ Object
28 29 30 |
# File 'lib/imaginator.rb', line 28 def format @opts[:format] end |
#process(code) ⇒ Object
45 46 47 48 49 |
# File 'lib/imaginator.rb', line 45 def process(code) errors = @opts[:blacklist].select { |cmd| code.include?(cmd) } errors.empty? || raise(ArgumentError.new("Invalid LaTeX commands #{errors.join(', ')}")) code.strip end |
#render(code, file) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/imaginator.rb', line 32 def render(code, file) begin temp_dir = create_temp_dir(file) latex2dvi(temp_dir, code) dvi2ps(temp_dir) ps2image(temp_dir, file) rescue FileUtils.rm_rf(temp_dir) if !@opts[:debug] else FileUtils.rm_rf(temp_dir) end end |