Method: Lcms::Engine::EmbedEquations.tex_to_svg

Defined in:
app/services/lcms/engine/embed_equations.rb

.tex_to_svg(tex, custom_color: nil, preserve_color: false) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/services/lcms/engine/embed_equations.rb', line 35

def tex_to_svg(tex, custom_color: nil, preserve_color: false)
  return if tex.blank?

  key = "#{REDIS_KEY_SVG}#{tex}#{preserve_color}#{custom_color}"
  if (svg = redis.get(key)).blank?
    if custom_color.present?
      tex = "\\require{color}\\definecolor{math}{RGB}{#{custom_color}}\\color{math}{#{tex}}"
    end
    svg = `tex2svg -- '#{tex}'`

    #
    # Should make that change only for Web view.
    # Settings color to `initial` prevents it from customization
    #
    svg = fix_color(svg, preserve_color) unless custom_color.present?

    redis.set key, svg
  end

  svg
end