Sha256: ce3b9984a9359bdfb9527b39656528e2bc4b45ab5cfe1f2af2267ec668ed4565

Contents?: true

Size: 1.85 KB

Versions: 8

Compression:

Stored size: 1.85 KB

Contents

# frozen_string_literal: true

require_relative "../table"

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

          def to_latex(options:)
            "\\begin#{opening}#{latex_content(options: options)}\\end#{matrix_class}"
          end

          def to_mathml_without_math_tag(intent, options:)
            table_tag = ox_element("mtable", attributes: table_attribute)
            table_tag["intent"] = ":matrix(#{value.length},#{td_count})" if intent
            Utility.update_nodes(
              table_tag,
              value&.map { |object| object&.to_mathml_without_math_tag(intent, options: options) },
            )
            Utility.update_nodes(
              ox_element("mrow", attributes: intent_attr(intent)),
              [
                mo_element(mathml_parenthesis(open_paren, intent, options: options)),
                table_tag,
                mo_element(mathml_parenthesis(close_paren, intent, options: options)),
              ],
            )
          end

          def to_unicodemath(options:)
            unicode_value = value.map { |val| val.to_unicodemath(options: options) }.join("@")
            "#{matrix_symbol}(#{unicode_value})"
          end

          private

          def matrix_symbol
            capital_bmatrix? ? "Ⓢ" : "ⓢ"
          end

          def capital_bmatrix?
            open_paren.is_a?(Math::Symbols::Paren::Lcurly)
          end

          def intent_attr(intent)
            return {} unless intent

            {
              intent: intent_names.dig(capital_bmatrix? ? :curly_braced_matrix : :bracketed_matrix)
            }
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
plurimath-0.8.24 lib/plurimath/math/function/table/bmatrix.rb
plurimath-0.8.23 lib/plurimath/math/function/table/bmatrix.rb
plurimath-0.8.22 lib/plurimath/math/function/table/bmatrix.rb
plurimath-0.8.21 lib/plurimath/math/function/table/bmatrix.rb
plurimath-0.8.20 lib/plurimath/math/function/table/bmatrix.rb
plurimath-0.8.19 lib/plurimath/math/function/table/bmatrix.rb
plurimath-0.8.18 lib/plurimath/math/function/table/bmatrix.rb
plurimath-0.8.17 lib/plurimath/math/function/table/bmatrix.rb