Class: Coradoc::Docx::Transform::Rules::MathRule

Inherits:
Coradoc::Docx::Transform::Rule show all
Defined in:
lib/coradoc/docx/transform/rules/math_rule.rb

Overview

Transforms OMML math elements to CoreModel.

Display math (m:oMathPara) → CoreModel::Block (stem) Inline math (m:oMath) → CoreModel::InlineElement (stem)

Uses Plurimath for OMML → LaTeX conversion when available. Falls back to raw XML string when Plurimath is not loaded.

Instance Method Summary collapse

Methods inherited from Coradoc::Docx::Transform::Rule

#priority

Instance Method Details

#apply(element, _context) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/coradoc/docx/transform/rules/math_rule.rb', line 22

def apply(element, _context)
  latex = omml_to_latex(element)

  if display_math?(element)
    CoreModel::Block.new(
      element_type: 'block',
      delimiter_type: '++++',
      language: 'latexmath',
      content: latex
    )
  else
    CoreModel::InlineElement.new(
      format_type: 'stem',
      content: latex
    )
  end
end

#matches?(element) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
# File 'lib/coradoc/docx/transform/rules/math_rule.rb', line 15

def matches?(element)
  return false unless defined?(Uniword::Math)

  element.is_a?(Uniword::Math::OMathPara) ||
    element.is_a?(Uniword::Math::OMath)
end