Class: Tex2png::Converter
- Inherits:
-
Object
- Object
- Tex2png::Converter
- Defined in:
- lib/tex2png/converter.rb
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#density ⇒ Object
readonly
Returns the value of attribute density.
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#formula ⇒ Object
readonly
Returns the value of attribute formula.
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #content ⇒ Object
- #data ⇒ Object
-
#initialize(formula, density: 155) ⇒ Converter
constructor
A new instance of Converter.
- #png(&block) ⇒ Object
Constructor Details
#initialize(formula, density: 155) ⇒ Converter
Returns a new instance of Converter.
7 8 9 10 11 12 |
# File 'lib/tex2png/converter.rb', line 7 def initialize(formula, density: 155) @formula = formula @density = density @hash = SecureRandom.hex(16) @base = File.join TEMP_DIR, hash end |
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
5 6 7 |
# File 'lib/tex2png/converter.rb', line 5 def base @base end |
#density ⇒ Object (readonly)
Returns the value of attribute density.
5 6 7 |
# File 'lib/tex2png/converter.rb', line 5 def density @density end |
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
5 6 7 |
# File 'lib/tex2png/converter.rb', line 5 def dir @dir end |
#formula ⇒ Object (readonly)
Returns the value of attribute formula.
5 6 7 |
# File 'lib/tex2png/converter.rb', line 5 def formula @formula end |
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
5 6 7 |
# File 'lib/tex2png/converter.rb', line 5 def hash @hash end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/tex2png/converter.rb', line 5 def name @name end |
Instance Method Details
#content ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/tex2png/converter.rb', line 14 def content @content ||= " \\\\documentclass[12pt]{article}\n \\\\usepackage[utf8]{inputenc}\n \\\\usepackage{\#{LATEX_PACKAGES.join(\", \")}}\n \\\\begin{document}\n \\\\pagestyle{empty}\n \\\\begin{displaymath}\n \#{formula}\n \\\\end{displaymath}\n \\\\end{document}\n END\nend\n".gsub(/^ {6}/, "") |
#data ⇒ Object
28 29 30 |
# File 'lib/tex2png/converter.rb', line 28 def data png {|io| "data:image/png;base64, #{io.read}"} end |
#png(&block) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/tex2png/converter.rb', line 32 def png(&block) @png ||= proc do args = [ "-q -T tight -D #{density}", "-o #{base}.png", "#{base}.dvi" ] tex dvi Tex2png::dvipng.run(*args).raise! clean! path(:png) end.call file(:png, &block) end |