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
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
6 7 8 |
# File 'lib/tex2png/converter.rb', line 6 def base @base end |
#density ⇒ Object (readonly)
Returns the value of attribute density.
6 7 8 |
# File 'lib/tex2png/converter.rb', line 6 def density @density end |
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
6 7 8 |
# File 'lib/tex2png/converter.rb', line 6 def dir @dir end |
#formula ⇒ Object (readonly)
Returns the value of attribute formula.
6 7 8 |
# File 'lib/tex2png/converter.rb', line 6 def formula @formula end |
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
6 7 8 |
# File 'lib/tex2png/converter.rb', line 6 def hash @hash end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/tex2png/converter.rb', line 6 def name @name end |
Instance Method Details
#content ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/tex2png/converter.rb', line 15 def content @content ||= <<-END.gsub(/^ {6}/, "") \\documentclass[12pt]{article} \\usepackage[utf8]{inputenc} \\usepackage{#{LATEX_PACKAGES.join(", ")}} \\begin{document} \\pagestyle{empty} \\begin{displaymath} #{formula} \\end{displaymath} \\end{document} END end |
#data ⇒ Object
29 30 31 32 33 |
# File 'lib/tex2png/converter.rb', line 29 def data @data ||= png do |io| "data:image/png;base64, #{Base64.encode64(io.read)}" end end |
#png(&block) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/tex2png/converter.rb', line 35 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 |