Class: RubyDocx::Elements::Equation

Inherits:
Element
  • Object
show all
Defined in:
lib/ruby_docx/elements/equation.rb

Instance Attribute Summary collapse

Attributes inherited from Element

#doc, #grid, #node, #style

Instance Method Summary collapse

Methods inherited from Element

#elements, #initialize, #inspect, #to_xml

Constructor Details

This class inherits a constructor from RubyDocx::Elements::Element

Instance Attribute Details

Returns the value of attribute link.



7
8
9
# File 'lib/ruby_docx/elements/equation.rb', line 7

def link
  @link
end

Instance Method Details

#base64_dataObject



38
39
40
# File 'lib/ruby_docx/elements/equation.rb', line 38

def base64_data
  "data:image/png;base64,#{Base64.strict_encode64(self.to_png)}"
end

#dataObject



34
35
36
# File 'lib/ruby_docx/elements/equation.rb', line 34

def data
  self.to_png
end

#replace(lnk) ⇒ Object



48
49
50
# File 'lib/ruby_docx/elements/equation.rb', line 48

def replace(lnk)
  @link = lnk
end

#replace_with_latex(txt) ⇒ Object



26
27
# File 'lib/ruby_docx/elements/equation.rb', line 26

def replace_with_latex(txt)
end

#replace_with_mathml(txt) ⇒ Object



23
24
# File 'lib/ruby_docx/elements/equation.rb', line 23

def replace_with_mathml(txt)
end

#save(path) ⇒ Object



42
43
44
45
46
# File 'lib/ruby_docx/elements/equation.rb', line 42

def save(path)
  file = File.new(path, "wb")
  file.write(self.to_png)
  file.close
end

#to_htmlObject



52
53
54
55
56
57
58
# File 'lib/ruby_docx/elements/equation.rb', line 52

def to_html
  if @link
    "<img src='#{@link}' data-latex=\"#{self.to_latex}\" data-mathml=\"#{self.to_mathml}\" style='height: 13px;' />"
  else
    "<img src='#{self.base64_data}' data-latex=\"#{self.to_latex}\" data-mathml=\"#{self.to_mathml}\" style='height: 13px;' />"
  end
end

#to_latexObject



14
15
16
# File 'lib/ruby_docx/elements/equation.rb', line 14

def to_latex
   TeXMath.convert("#{self.to_omml}", :from => :omml, :to => :tex)
end

#to_mathmlObject



18
19
20
# File 'lib/ruby_docx/elements/equation.rb', line 18

def to_mathml
   TeXMath.convert("#{self.to_omml}", :from => :omml, :to => :mathml)
end

#to_ommlObject



9
10
11
12
# File 'lib/ruby_docx/elements/equation.rb', line 9

def to_omml
  ele = @node.xpath(".//m:oMath").first
  ele.to_s
end

#to_pngObject



29
30
31
32
# File 'lib/ruby_docx/elements/equation.rb', line 29

def to_png
  @path ||= Calculus::Expression.new("#{self.to_latex}", :parse => false).to_png
  File.read(@path)
end

#to_sObject



60
61
62
# File 'lib/ruby_docx/elements/equation.rb', line 60

def to_s
  self.to_latex.to_s
end