Class: Plurimath::Math::Function::Table

Inherits:
Core
  • Object
show all
Includes:
Plurimath::Mathml::Utility
Defined in:
lib/plurimath/math/function/table.rb,
lib/plurimath/math/function/table/align.rb,
lib/plurimath/math/function/table/array.rb,
lib/plurimath/math/function/table/cases.rb,
lib/plurimath/math/function/table/split.rb,
lib/plurimath/math/function/table/matrix.rb,
lib/plurimath/math/function/table/bmatrix.rb,
lib/plurimath/math/function/table/eqarray.rb,
lib/plurimath/math/function/table/pmatrix.rb,
lib/plurimath/math/function/table/vmatrix.rb,
lib/plurimath/math/function/table/multline.rb

Direct Known Subclasses

Align, Array, Bmatrix, Cases, Eqarray, Matrix, Multline, Pmatrix, Split, Vmatrix

Defined Under Namespace

Classes: Align, Array, Bmatrix, Cases, Eqarray, Matrix, Multline, Pmatrix, Split, Vmatrix

Constant Summary collapse

SIMPLE_TABLES =
%w[array align split].freeze

Constants included from Plurimath::Mathml::Utility::FormulaTransformation

Plurimath::Mathml::Utility::FormulaTransformation::CONDITIONAL_COMMON_UNARY_FUNCTIONS, Plurimath::Mathml::Utility::FormulaTransformation::SYMBOL_UPDATABLE_FUNCTIONS

Constants inherited from Core

Core::ALL_PARAMETERS, Core::REPLACABLES

Instance Attribute Summary collapse

Attributes included from Plurimath::Mathml::Utility

#temp_mathml_order

Instance Method Summary collapse

Methods included from Plurimath::Mathml::Utility

#accent=, #accentunder=, #bevelled=, #clear_temp_order, #element_order=, #linebreak=, #linebreakstyle=, #linethickness=, #maligngroup_value=, #malignmark_value=, #mathvariant=, #menclose_value=, #merror_value=, #mfenced_value=, #mfrac_value=, #mfraction_value=, #mglyph_value=, #mi_value=, #mlongdiv_value=, #mmultiscripts_value=, #mn_value=, #mo_value=, #mover_value=, #mpadded_value=, #mphantom_value=, #mroot_value=, #mrow_value=, #ms_value=, #mscarries_value=, #mscarry_value=, #msgroup_value=, #msline_value=, #mspace_value=, #msqrt_value=, #msrow_value=, #mstack_value=, #mstyle_value=, #msub_value=, #msubsup_value=, #msup_value=, #mtable_value=, #mtext_value=, #munder_value=, #munderover_value=, #none_value=, #notation=, #semantics_value=

Methods included from Plurimath::Mathml::Utility::EmptyDefinedMethods

#accent, #accentunder, #align, #align=, #alignmentscope, #alignmentscope=, #annotation, #background, #background=, #bevelled, #charalign, #charalign=, #charspacing, #charspacing=, #close, #close=, #color, #color=, #columnalign, #columnalign=, #columnlines, #columnspacing, #columnspacing=, #columnspan, #columnspan=, #columnwidth, #columnwidth=, #crossout, #crossout=, #decimalpoint, #decimalpoint=, #denomalign, #denomalign=, #depth, #depth=, #dir, #dir=, #displaystyle, #displaystyle=, #edge, #edge=, #equalcolumns, #equalcolumns=, #equalrows, #equalrows=, #fence, #fence=, #fontfamily, #fontfamily=, #fontsize, #fontsize=, #fontstyle, #fontstyle=, #fontweight, #fontweight=, #form, #form=, #frame, #framespacing, #framespacing=, #groupalign, #groupalign=, #height, #height=, #id, #indentalign, #indentalign=, #indentalignfirst, #indentalignfirst=, #indentalignlast, #indentalignlast=, #indentshift, #indentshift=, #indentshiftfirst, #indentshiftfirst=, #indentshiftlast, #indentshiftlast=, #indenttarget, #indenttarget=, #infixlinebreakstyle, #infixlinebreakstyle=, #intent, #intent=, #largeop, #largeop=, #leftoverhang, #leftoverhang=, #length, #length=, #linebreak, #linebreakmultchar, #linebreakmultchar=, #linebreakstyle, #lineleading, #lineleading=, #linethickness, #location, #location=, #longdivstyle, #longdivstyle=, #lquote, #lquote=, #lspace, #lspace=, #maligngroup_value, #malignmark, #malignmark=, #malignmark_value, #mathbackground, #mathbackground=, #mathbackgroundcolor, #mathbackgroundcolor=, #mathcolor, #mathcolor=, #mathsize, #mathsize=, #mathvariant, #maxsize, #maxsize=, #mediummathspace, #mediummathspace=, #menclose_value, #merror_value, #mfenced_value, #mfrac_value, #mfraction_value, #mglyph_value, #mi_value, #minlabelspacing, #minlabelspacing=, #minsize, #minsize=, #mlabeledtr_value, #mlongdiv_value, #mmultiscripts_value, #mn_value, #mo_value, #movablelimits, #movablelimits=, #mover_value, #mpadded_value, #mphantom_value, #mprescripts_value, #mprescripts_value=, #mroot_value, #mrow_value, #ms_value, #mscarries_value, #mscarry_value, #msgroup_value, #msline_value, #mslinethickness, #mslinethickness=, #mspace_value, #msqrt_value, #msrow_value, #mstack_value, #mstyle_value, #msub_value, #msubsup_value, #msup_value, #mtable_value, #mtd_value, #mtext_value, #mtr_value, #munder_value, #munderover_value, #none_value, #notation, #numalign, #numalign=, #open, #open=, #position, #position=, #rightoverhang, #rightoverhang=, #rowalign, #rowalign=, #rowlines, #rowspacing, #rowspacing=, #rowspan, #rowspan=, #rquote, #rquote=, #rspace, #rspace=, #scriptlevel, #scriptlevel=, #scriptminsize, #scriptminsize=, #scriptsizemultiplier, #scriptsizemultiplier=, #selection, #selection=, #semantics_value, #separator, #separator=, #separators, #separators=, #shift, #shift=, #side, #side=, #stackalign, #stackalign=, #stretchy, #stretchy=, #subscriptshift, #subscriptshift=, #superscriptshift, #superscriptshift=, #symmetric, #symmetric=, #thickmathspace, #thickmathspace=, #thinmathspace, #thinmathspace=, #valign, #valign=, #verythickmathspace, #verythickmathspace=, #verythinmathspace, #verythinmathspace=, #veryverythickmathspace, #veryverythickmathspace=, #veryverythinmathspace, #veryverythinmathspace=, #width, #width=

Methods inherited from Core

#ascii_fields_to_print, #class_name, #cloned_objects, #common_math_zone_conversion, descendants, #dump_mathml, #dump_nodes, #dump_omml, #dump_ox_nodes, #empty_tag, #extract_class_name_from_text, #extractable?, #filtered_values, #font_style_t_tag, #get, #gsub_spacing, inherited, #insert_t_tag, #invert_unicode_symbols, #is_binary_function?, #is_mrow?, #is_mstyle?, #is_nary_function?, #is_nary_symbol?, #is_ternary_function?, #is_unary?, #latex_fields_to_print, #line_breaking, #linebreak?, #mathml_fields_to_print, #mini_sized?, #nary_attr_value, #nary_intent_name, #omml_fields_to_print, #omml_nodes, #omml_parameter, #omml_tag_name, #ox_element, #paren?, #pretty_print_instance_variables, #prime_unicode?, #r_element, #replacable_values, #result, #separate_table, #set, #symbol?, #tag_name, #to_ms_value, #unicodemath_fields_to_print, #unicodemath_parens, #updated_object_values, #validate_function_formula, #validate_mathml_fields, #variable_value, #variables

Constructor Details

#initialize(value = nil, open_paren = nil, close_paren = nil, options = {}) ⇒ Table

Returns a new instance of Table.



15
16
17
18
19
20
21
22
23
# File 'lib/plurimath/math/function/table.rb', line 15

def initialize(value = nil,
               open_paren = nil,
               close_paren = nil,
               options = {})
  @value = value
  @open_paren = Utility.symbols_class(open_paren, lang: :unicodemath)
  @close_paren = Utility.symbols_class(close_paren, lang: :unicodemath)
  @options = options
end

Instance Attribute Details

#close_parenObject

Returns the value of attribute close_paren.



11
12
13
# File 'lib/plurimath/math/function/table.rb', line 11

def close_paren
  @close_paren
end

#open_parenObject

Returns the value of attribute open_paren.



11
12
13
# File 'lib/plurimath/math/function/table.rb', line 11

def open_paren
  @open_paren
end

#optionsObject

Returns the value of attribute options.



11
12
13
# File 'lib/plurimath/math/function/table.rb', line 11

def options
  @options
end

#valueObject

Returns the value of attribute value.



11
12
13
# File 'lib/plurimath/math/function/table.rb', line 11

def value
  @value
end

Instance Method Details

#==(object) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/plurimath/math/function/table.rb', line 25

def ==(object)
  object.class == self.class &&
    object.value == value &&
    object.options == options &&
    object.open_paren == open_paren &&
    object.close_paren == close_paren
end

#columnlines=(value) ⇒ Object



176
177
178
179
180
181
182
183
184
185
# File 'lib/plurimath/math/function/table.rb', line 176

def columnlines=(value)
  return if value.nil? || value.empty?
  return if value.split.all? { |val| val.include?("none") }

  Plurimath::Utility.table_separator(
    value.split,
    @value,
  )
  set_option(:columnlines, value)
end

#frame=(value) ⇒ Object



164
165
166
167
168
# File 'lib/plurimath/math/function/table.rb', line 164

def frame=(value)
  return if value.nil? || value.empty?

  set_option(:frame, value)
end

#intent_namesObject



132
133
134
135
136
137
138
139
140
141
142
# File 'lib/plurimath/math/function/table.rb', line 132

def intent_names
  {
    curly_braced_matrix: ":curly-braced-matrix",
    parenthesized_matrix: ":parenthesized-matrix",
    bracketed_matrix: ":bracketed-matrix",
    normed_matrix: ":normed-matrix",
    determinant: ":determinant",
    equations: ":equations",
    cases: ":cases",
  }
end

#mlabeledtr_value=(value) ⇒ Object



154
155
156
157
158
159
160
161
162
# File 'lib/plurimath/math/function/table.rb', line 154

def mlabeledtr_value=(value)
  return if value.nil? || value.empty?

  self.value = replace_order_with_value(
    clear_temp_order,
    update_temp_mathml_values(value),
    "mlabeledtr"
  )
end

#mtr_value=(value) ⇒ Object



144
145
146
147
148
149
150
151
152
# File 'lib/plurimath/math/function/table.rb', line 144

def mtr_value=(value)
  return if value.nil? || value.empty?

  self.value = replace_order_with_value(
    clear_temp_order,
    update_temp_mathml_values(value),
    "mtr"
  )
end

#rowlines=(value) ⇒ Object



170
171
172
173
174
# File 'lib/plurimath/math/function/table.rb', line 170

def rowlines=(value)
  return if value.nil? || value.empty?

  set_option(:rowlines, value)
end

#to_asciimath(options:) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/plurimath/math/function/table.rb', line 33

def to_asciimath(options:)
  return parentheless_table(options: options) if SIMPLE_TABLES.include?(class_name)

  parenthesis = Asciimath::Constants::TABLE_PARENTHESIS
  first_value = value&.map { |val| val&.to_asciimath(options: options) }&.join(", ")
  lparen = open_paren.nil? ? "[" : open_paren.to_asciimath(options: options)
  rparen = close_paren.nil? ? parenthesis[lparen.to_sym] : close_paren.to_asciimath(options: options)
  "#{lparen}#{first_value}#{rparen}"
end

#to_asciimath_math_zone(spacing, last = false, indent = true, options:) ⇒ Object



97
98
99
100
101
102
# File 'lib/plurimath/math/function/table.rb', line 97

def to_asciimath_math_zone(spacing, last = false, indent = true, options:)
  [
    "#{spacing}\"table\" function apply\n",
    Formula.new(value).to_asciimath_math_zone(gsub_spacing(spacing, last), last, indent, options: options),
  ]
end

#to_html(options:) ⇒ Object



74
75
76
77
# File 'lib/plurimath/math/function/table.rb', line 74

def to_html(options:)
  first_value = value.map { |val| val.to_html(options: options) }.join
  "<table>#{first_value}</table>"
end

#to_latex(options:) ⇒ Object



63
64
65
66
67
68
69
70
71
72
# File 'lib/plurimath/math/function/table.rb', line 63

def to_latex(options:)
  return "\\begin{Vmatrix}#{latex_content(options: options)}\\end{Vmatrix}" if open_paren.is_a?(Math::Symbols::Paren::Norm)

  separator = "{#{table_attribute(:latex)}}" if environment&.include?("array")
  left_paren = open_paren&.to_latex(options: options) || "."
  right_paren = close_paren&.to_latex(options: options) || "."
  left = "\\left #{left_paren}\\begin{matrix}"
  right = "\\end{matrix}\\right #{right_paren.delete_prefix("\\right")}"
  "#{left}#{separator}#{latex_content(options: options)}#{right}"
end

#to_latex_math_zone(spacing, last = false, indent = true, options:) ⇒ Object



104
105
106
107
108
109
# File 'lib/plurimath/math/function/table.rb', line 104

def to_latex_math_zone(spacing, last = false, indent = true, options:)
  [
    "#{spacing}\"table\" function apply\n",
    Formula.new(value).to_latex_math_zone(gsub_spacing(spacing, last), last, indent, options: options),
  ]
end

#to_mathml_math_zone(spacing, last = false, indent = true, options:) ⇒ Object



111
112
113
114
115
116
# File 'lib/plurimath/math/function/table.rb', line 111

def to_mathml_math_zone(spacing, last = false, indent = true, options:)
  [
    "#{spacing}\"table\" function apply\n",
    Formula.new(value).to_mathml_math_zone(gsub_spacing(spacing, last), last, indent, options: options),
  ]
end

#to_mathml_without_math_tag(intent, options:) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/plurimath/math/function/table.rb', line 43

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) },
  )
  return norm_table(table_tag) if open_paren.is_a?(Math::Symbols::Paren::Norm)

  if mathml_paren_present?(open_paren, intent, options: options) || mathml_paren_present?(close_paren, intent, options: options)
    first_paren = mo_element(mathml_parenthesis(open_paren, intent, options: options))
    second_paren = mo_element(mathml_parenthesis(close_paren, intent, options: options))
    attributes = { intent: ":fenced" } if intent
    mrow = ox_element("mrow", attributes: attributes)
    return Utility.update_nodes(mrow, [first_paren, table_tag, second_paren])
  end

  table_tag
end

#to_omml_math_zone(spacing, last = false, indent = true, display_style:, options:) ⇒ Object



118
119
120
121
122
123
# File 'lib/plurimath/math/function/table.rb', line 118

def to_omml_math_zone(spacing, last = false, indent = true, display_style:, options:)
  [
    "#{spacing}\"table\" function apply\n",
    Formula.new(value).to_omml_math_zone(gsub_spacing(spacing, last), last, indent, display_style: display_style, options: options),
  ]
end

#to_omml_without_math_tag(display_style, options:) ⇒ Object



79
80
81
82
83
84
85
86
# File 'lib/plurimath/math/function/table.rb', line 79

def to_omml_without_math_tag(display_style, options:)
  ox_table = if single_table?
               single_td_table(display_style, options: options)
             else
               multiple_td_table(display_style, options: options)
             end
  fenced_table(ox_table)
end

#to_unicodemath(options:) ⇒ Object



88
89
90
91
92
93
94
95
# File 'lib/plurimath/math/function/table.rb', line 88

def to_unicodemath(options:)
  table_values = value&.map { |val| val&.to_unicodemath(options: options) }&.join("@")
  if unicodemath_table_class?
    "#{unicodemath_class_name}(#{table_values})"
  else
    "#{open_paren&.to_unicodemath(options: options)}■(#{table_values})#{close_paren&.to_unicodemath(options: options)}"
  end
end

#to_unicodemath_math_zone(spacing, last = false, indent = true, options:) ⇒ Object



125
126
127
128
129
130
# File 'lib/plurimath/math/function/table.rb', line 125

def to_unicodemath_math_zone(spacing, last = false, indent = true, options:)
  [
    "#{spacing}\"table\" function apply\n",
    Formula.new(value).to_unicodemath_math_zone(gsub_spacing(spacing, last), last, indent, options: options),
  ]
end