class RubyDocx::Elements::Equation

Attributes

Public Instance Methods

base64_data() click to toggle source
# File lib/ruby_docx/elements/equation.rb, line 58
def base64_data
  "data:image/png;base64,#{Base64.strict_encode64(self.to_png)}"
end
data() click to toggle source
# File lib/ruby_docx/elements/equation.rb, line 54
def data
  self.to_png
end
replace(lnk) click to toggle source
# File lib/ruby_docx/elements/equation.rb, line 68
def replace(lnk)
  @link = lnk
end
replace_with_latex(txt) click to toggle source
# File lib/ruby_docx/elements/equation.rb, line 27
def replace_with_latex(txt)
end
replace_with_mathml(txt) click to toggle source
# File lib/ruby_docx/elements/equation.rb, line 24
def replace_with_mathml(txt)
end
save(path) click to toggle source
# File lib/ruby_docx/elements/equation.rb, line 62
def save(path)
  file = File.new(path, "wb")
  file.write(self.to_png)
  file.close
end
size() click to toggle source
# File lib/ruby_docx/elements/equation.rb, line 35
def size
  return @size if @size

  sz = ImageSize.new(self.data)

  @size = [sz.width/7.2, sz.height/7.2]
rescue
  nil
end
style() click to toggle source
# File lib/ruby_docx/elements/equation.rb, line 45
def style
  if self.size
    "width: #{self.size[0]}px; height: #{self.size[1]}px;"
  else
    ""
  end
end
to_html() click to toggle source
# File lib/ruby_docx/elements/equation.rb, line 72
def to_html
  if @link
    "<img class=\"Wirisformula\" role='math' src='#{@link}' data-latex=\"#{self.to_latex}\" data-mathml=\"#{self.to_mathml.gsub("\n", "").gsub("<", "«").gsub(">", "»").gsub("\"", "¨")}\" style='#{self.style}' />"
  else
    "<img class=\"Wirisformula\" role='math' src='#{self.base64_data}' data-latex=\"#{self.to_latex}\" data-mathml=\"#{self.to_mathml.gsub("\n", "").gsub("<", "«").gsub(">", "»").gsub("\"", "¨")}\" style='#{self.style}' />"
  end
end
to_latex() click to toggle source
# File lib/ruby_docx/elements/equation.rb, line 15
def to_latex
   TeXMath.convert("#{self.to_omml}", :from => :omml, :to => :tex)
end
to_mathml() click to toggle source
# File lib/ruby_docx/elements/equation.rb, line 19
def to_mathml
   TeXMath.convert("#{self.to_omml}", :from => :omml, :to => :mathml)
end
to_omml() click to toggle source
# File lib/ruby_docx/elements/equation.rb, line 10
def to_omml
  ele = @node.xpath(".//m:oMath").first
  ele.to_s
end
to_png() click to toggle source
# File lib/ruby_docx/elements/equation.rb, line 30
def to_png
  @path ||= Calculus::Expression.new("#{self.to_latex}", :parse => false).to_png
  File.read(@path)
end
to_s() click to toggle source
# File lib/ruby_docx/elements/equation.rb, line 80
def to_s
  self.to_latex.to_s
end