Sha256: 9f44a128b9ae62f894f614c2d81f1524c1b4eff20e1e2db67c6e808114b6dc38

Contents?: true

Size: 1.54 KB

Versions: 4

Compression:

Stored size: 1.54 KB

Contents

# frozen_string_literal: true

require_relative "../table"

module Plurimath
  module Math
    module Function
      class Table
        class Matrix < Table
          def initialize(value = [],
                         open_paren = "(",
                         close_paren = ")",
                         options = {})
            super
          end

          def to_asciimath
            "{:#{value.map(&:to_asciimath).join(", ")}:}"
          end

          def to_latex
            "\\begin#{opening}#{latex_content}\\end#{matrix_class}"
          end

          def to_mathml_without_math_tag(intent)
            table_tag = Utility.update_nodes(
              ox_element("mtable", attributes: table_attribute),
              value&.map { |object| object&.to_mathml_without_math_tag(intent) }
            )
            return table_tag if table_tag_only?

            Utility.update_nodes(
              ox_element("mrow"),
              [mo_tag(open_paren), table_tag, mo_tag(close_paren)]
            )
          end

          def to_unicodemath
            first_value = value.map(&:to_unicodemath).join("@")
            "#{open_paren&.to_unicodemath}■(#{first_value})#{close_paren&.to_unicodemath}"
          end

          protected

          def mo_tag(paren)
            (ox_element("mo") << paren) unless validate_paren(paren)
          end

          def table_tag_only?
            (open_paren&.class_name == "lround" && close_paren&.class_name == "rround") ||
              !(open_paren && close_paren)
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
plurimath-0.8.14 lib/plurimath/math/function/table/matrix.rb
plurimath-0.8.13 lib/plurimath/math/function/table/matrix.rb
plurimath-0.8.12 lib/plurimath/math/function/table/matrix.rb
plurimath-0.8.11 lib/plurimath/math/function/table/matrix.rb