Class: RubyDocx::Elements::Equation
- Inherits:
-
Element
- Object
- Element
- RubyDocx::Elements::Equation
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
Instance Attribute Details
#link ⇒ Object
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_data ⇒ Object
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
|
#data ⇒ Object
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_html ⇒ Object
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_latex ⇒ Object
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_mathml ⇒ Object
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_omml ⇒ Object
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_png ⇒ Object
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_s ⇒ Object
60
61
62
|
# File 'lib/ruby_docx/elements/equation.rb', line 60
def to_s
self.to_latex.to_s
end
|