Class: Uniword::MathEquation
- Defined in:
- lib/uniword/math_equation.rb
Overview
Represents a mathematical equation in a Word document Responsibility: Hold and manage Plurimath formula objects for math equations
Office Math Markup Language (OMML) is used in OOXML documents to represent mathematical equations. This class bridges between OMML and Plurimath, providing a model-based approach to math equation handling.
v4.0.0: Plurimath integration for math equation support
Instance Attribute Summary collapse
-
#formula ⇒ Plurimath::Math::Formula?
The Plurimath formula object representing the equation.
Class Method Summary collapse
-
.from_omml(omml_xml) ⇒ MathEquation
Create a MathEquation from OMML XML.
Instance Method Summary collapse
-
#accept(visitor) ⇒ Object
Visitor pattern support.
-
#alignment ⇒ Symbol
Alignment for block equations.
-
#block? ⇒ Boolean
Check if equation is block/display mode.
-
#break_enabled ⇒ Boolean
Whether equation should break across lines.
-
#display_type ⇒ Symbol
Display type for the equation.
-
#initialize(**attributes) ⇒ MathEquation
constructor
Initialize a new MathEquation.
-
#inline? ⇒ Boolean
Check if equation is inline (vs block/display).
-
#to_asciimath ⇒ String
Convert equation to AsciiMath.
-
#to_latex ⇒ String
Convert equation to LaTeX.
-
#to_mathml ⇒ String
Convert equation to MathML.
-
#to_omml(options = {}) ⇒ String
Convert equation to OMML XML.
-
#valid? ⇒ Boolean
Validate the equation.
Methods inherited from Element
Constructor Details
#initialize(**attributes) ⇒ MathEquation
Initialize a new MathEquation
48 49 50 51 |
# File 'lib/uniword/math_equation.rb', line 48 def initialize(**attributes) super @formula = attributes[:formula] end |
Instance Attribute Details
#formula ⇒ Plurimath::Math::Formula?
The Plurimath formula object representing the equation
27 28 29 |
# File 'lib/uniword/math_equation.rb', line 27 def formula @formula end |
Class Method Details
.from_omml(omml_xml) ⇒ MathEquation
Create a MathEquation from OMML XML
61 62 63 |
# File 'lib/uniword/math_equation.rb', line 61 def self.from_omml(omml_xml) Math::PlurimathAdapter.from_omml(omml_xml) end |
Instance Method Details
#accept(visitor) ⇒ Object
Visitor pattern support
134 135 136 |
# File 'lib/uniword/math_equation.rb', line 134 def accept(visitor) visitor.visit_math_equation(self) end |
#alignment ⇒ Symbol
Alignment for block equations
35 |
# File 'lib/uniword/math_equation.rb', line 35 attribute :alignment, :string |
#block? ⇒ Boolean
Check if equation is block/display mode
126 127 128 |
# File 'lib/uniword/math_equation.rb', line 126 def block? display_type.to_s == "block" end |
#break_enabled ⇒ Boolean
Whether equation should break across lines
39 |
# File 'lib/uniword/math_equation.rb', line 39 attribute :break_enabled, :boolean, default: -> { false } |
#display_type ⇒ Symbol
Display type for the equation
31 |
# File 'lib/uniword/math_equation.rb', line 31 attribute :display_type, :string, default: -> { "inline" } |
#inline? ⇒ Boolean
Check if equation is inline (vs block/display)
119 120 121 |
# File 'lib/uniword/math_equation.rb', line 119 def inline? display_type.to_s == "inline" end |
#to_asciimath ⇒ String
Convert equation to AsciiMath
110 111 112 113 114 |
# File 'lib/uniword/math_equation.rb', line 110 def to_asciimath return "" unless formula formula.to_asciimath end |
#to_latex ⇒ String
Convert equation to LaTeX
84 85 86 87 88 |
# File 'lib/uniword/math_equation.rb', line 84 def to_latex return "" unless formula formula.to_latex end |
#to_mathml ⇒ String
Convert equation to MathML
97 98 99 100 101 |
# File 'lib/uniword/math_equation.rb', line 97 def to_mathml return "" unless formula formula.to_mathml end |
#to_omml(options = {}) ⇒ String
Convert equation to OMML XML
73 74 75 |
# File 'lib/uniword/math_equation.rb', line 73 def to_omml( = {}) Math::PlurimathAdapter.to_omml(self, ) end |
#valid? ⇒ Boolean
Validate the equation
141 142 143 |
# File 'lib/uniword/math_equation.rb', line 141 def valid? super && formula_valid? end |