lib/review/img_math.rb in review-5.1.1 vs lib/review/img_math.rb in review-5.2.0

- old
+ new

@@ -1,10 +1,13 @@ require 'fileutils' require 'shellwords' +require 'review/loggable' module ReVIEW class ImgMath + include Loggable + def initialize(config, path_name: '_review_math') @config = config @logger = ReVIEW.logger @math_dir = File.join(@config['imagedir'], path_name) @math_maps = {} @@ -48,11 +51,11 @@ dvi_path = File.join(tmpdir, 'tmpmath.dvi') File.write(tex_path, texsrc) cmd = "latex --interaction=nonstopmode --output-directory=#{tmpdir} #{tex_path} && dvipng -T tight -z9 -o #{img_path} #{dvi_path}" out, status = Open3.capture2e(cmd) unless status.success? - raise ApplicationError, "latex compile error\n\nError log:\n" + out + raise ApplicationError, "latex compile error\n\nError log:\n#{out}" end img_path end end @@ -95,34 +98,24 @@ when 'pdfcrop' make_math_images_pdfcrop(tmpdir, tex_path, math_real_dir) when 'dvipng' make_math_images_dvipng(tmpdir, tex_path, math_real_dir) else - error "unknown math converter error. imgmath_options/converter parameter should be 'pdfcrop' or 'dvipng'." - exit 1 + error! "unknown math converter error. imgmath_options/converter parameter should be 'pdfcrop' or 'dvipng'." end rescue CompileError FileUtils.cp([tex_path, File.join(File.dirname(tex_path), '__IMGMATH__.log')], math_real_dir) - error "LaTeX math compile error. See #{math_real_dir}/__IMGMATH__.log for details." - exit 1 + error! "LaTeX math compile error. See #{math_real_dir}/__IMGMATH__.log for details." end end @math_maps.clear end private - def error(msg) - @logger.error msg - end - - def warn(msg) - @logger.warn msg - end - def default_imgmath_preamble <<-EOB \\documentclass[uplatex,a3paper,landscape]{jsarticle} \\usepackage[deluxe,uplatex]{otf} \\usepackage[T1]{fontenc} @@ -154,22 +147,22 @@ end if File.exist?(dvi_path) out, status = Open3.capture2e(*[@config['dvicommand'], @config['dvioptions'].shellsplit, dvi_path].flatten.compact) if !status.success? || !File.exist?(pdf_path) - warn "error in #{@config['dvicommand']}. Error log:\n#{out}" + @logger.error "error in #{@config['dvicommand']}. Error log:\n#{out}" raise CompileError end end args = @config['imgmath_options']['pdfcrop_cmd'].shellsplit args.map! do |m| m.sub('%i', pdf_path). sub('%o', '__IMGMATH__pdfcrop.pdf') end out, status = Open3.capture2e(*args) unless status.success? - warn "error in pdfcrop. Error log:\n#{out}" + @logger.error "error in pdfcrop. Error log:\n#{out}" raise CompileError end pdf_path = '__IMGMATH__pdfcrop.pdf' pdf_path2 = pdf_path @@ -190,11 +183,11 @@ sub('%O', "__IMGMATH__pdfcrop_p#{page}"). sub('%p', page.to_s) end out, status = Open3.capture2e(*args) unless status.success? - warn "error in pdf extracting. Error log:\n#{out}" + @logger.error "error in pdf extracting. Error log:\n#{out}" raise CompileError end pdf_path2 = "__IMGMATH__pdfcrop_p#{page}.pdf" end @@ -207,11 +200,11 @@ sub('%O', File.join(math_real_dir, "_gen_#{key}")). sub('%p', page.to_s) end out, status = Open3.capture2e(*args) unless status.success? - warn "error in pdf pixelizing. Error log:\n#{out}" + @logger.error "error in pdf pixelizing. Error log:\n#{out}" raise CompileError end end end end @@ -233,10 +226,10 @@ sub('%O', File.join(math_real_dir, "_gen_#{key}")). sub('%p', page.to_s) end out, status = Open3.capture2e(*args) unless status.success? - warn "error in dvipng. Error log:\n#{out}" + @logger.error "error in dvipng. Error log:\n#{out}" raise CompileError end end end end