module Rutex
Generate images from TeX equations
Constants
- PNG_DENSITY
- PNG_QUALITY
- PNG_TRANSPARENT
Attributes
color[RW]
color of equation
equation[RW]
input equation
Public Instance Methods
make_tex_file()
click to toggle source
create tex file containing the equation
# File lib/rutex.rb, line 118 def make_tex_file tex_string = <<~str \\documentclass[preview]{standalone} \\usepackage{xcolor} \\begin{document} $\\color{#{color}}#{equation}$ \\end{document} str File.write(tex_file, tex_string) end
pdf_to_png()
click to toggle source
# File lib/rutex.rb, line 139 def pdf_to_png pdf = MiniMagick::Image.open pdf_file MiniMagick::Tool::Convert.new do |convert| unless PNG_TRANSPARENT convert.background "white" convert.flatten end convert.density PNG_DENSITY convert.quality PNG_QUALITY convert << pdf.pages.first.path convert << "png8:#{png_file}" end rescue => e puts "#{e.message}" exit end
pdflatex()
click to toggle source
returns location of pdflatex binary
# File lib/rutex.rb, line 76 def pdflatex Logging.quiet=true find_executable 'pdflatex' end
pdflatex_run()
click to toggle source
run pdflatex command with pdflatex_options
# File lib/rutex.rb, line 86 def pdflatex_run %x(pdflatex #{pdflatex_options} #{tex_file}) raise PdfError "Errors logged in #{tmp_dir}" unless $?.exitstatus==0 rescue PdfError => e puts "PdfError (#{e.message})" abort "Try installing standalone package https://www.ctan.org/pkg/standalone" end
png_file()
click to toggle source
# File lib/rutex.rb, line 135 def png_file "#{output_file}.png" end