Method: ReVIEW::HTMLBuilder#make_math_image

Defined in:
lib/review/htmlbuilder.rb

#make_math_image(str, path, fontsize = 12) ⇒ Object



1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
# File 'lib/review/htmlbuilder.rb', line 1215

def make_math_image(str, path, fontsize = 12)
  # Re:VIEW 2 compatibility
  fontsize2 = (fontsize * 1.2).round.to_i
  texsrc = <<-EOB
\\documentclass[12pt]{article}
\\usepackage[utf8]{inputenc}
\\usepackage{amsmath}
\\usepackage{amsthm}
\\usepackage{amssymb}
\\usepackage{amsfonts}
\\usepackage{anyfontsize}
\\usepackage{bm}
\\pagestyle{empty}

\\begin{document}
\\fontsize{#{fontsize}}{#{fontsize2}}\\selectfont #{str}
\\end{document}
  EOB
  Dir.mktmpdir do |tmpdir|
    tex_path = File.join(tmpdir, 'tmpmath.tex')
    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 #{path} #{dvi_path}"
    out, status = Open3.capture2e(cmd)
    unless status.success?
      error "latex compile error\n\nError log:\n" + out
    end
  end
end