Class: Plurimath::Math::Symbol

Inherits:
Core
  • Object
show all
Defined in:
lib/plurimath/math/symbol.rb

Direct Known Subclasses

Unicode

Constant Summary

Constants inherited from Core

Core::REPLACABLES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Core

#ascii_fields_to_print, #class_name, #cloned_objects, #common_math_zone_conversion, #dump_mathml, #dump_nodes, #dump_omml, #dump_ox_nodes, #empty_tag, #extract_class_name_from_text, #extractable?, #filtered_values, #get, #gsub_spacing, #invert_unicode_symbols, #is_binary_function?, #is_nary_function?, #is_ternary_function?, #is_unary?, #latex_fields_to_print, #line_breaking, #mathml_fields_to_print, #omml_fields_to_print, #omml_parameter, #ox_element, #r_element, #replacable_values, #result, #set, #unicodemath_parens, #updated_object_values, #validate_mathml_fields, #variable_value, #variables

Constructor Details

#initialize(sym = nil, slashed = nil, mini_sub_sized: false, mini_sup_sized: false, options: {}) ⇒ Symbol

Returns a new instance of Symbol.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/plurimath/math/symbol.rb', line 8

def initialize(sym = nil,
               slashed = nil,
               mini_sub_sized: false,
               mini_sup_sized: false,
               options: {})
  @value = sym.is_a?(Parslet::Slice) ? sym.to_s : sym
  @slashed = slashed if slashed
  @mini_sub_sized = mini_sub_sized if mini_sub_sized
  @mini_sup_sized = mini_sup_sized if mini_sup_sized
  @options = options unless options.empty?
end

Instance Attribute Details

#mini_sub_sizedObject

Returns the value of attribute mini_sub_sized.



6
7
8
# File 'lib/plurimath/math/symbol.rb', line 6

def mini_sub_sized
  @mini_sub_sized
end

#mini_sup_sizedObject

Returns the value of attribute mini_sup_sized.



6
7
8
# File 'lib/plurimath/math/symbol.rb', line 6

def mini_sup_sized
  @mini_sup_sized
end

#optionsObject

Returns the value of attribute options.



6
7
8
# File 'lib/plurimath/math/symbol.rb', line 6

def options
  @options
end

#slashedObject

Returns the value of attribute slashed.



6
7
8
# File 'lib/plurimath/math/symbol.rb', line 6

def slashed
  @slashed
end

#valueObject

Returns the value of attribute value.



6
7
8
# File 'lib/plurimath/math/symbol.rb', line 6

def value
  @value
end

Instance Method Details

#==(object) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/plurimath/math/symbol.rb', line 20

def ==(object)
  object.respond_to?(:value) &&
    object.value == value &&
    object.slashed == slashed &&
    object.mini_sub_sized == mini_sub_sized &&
    object.mini_sup_sized == mini_sup_sized &&
    object.options == options
end

#font_style_t_tag(_) ⇒ Object



100
101
102
# File 'lib/plurimath/math/symbol.rb', line 100

def font_style_t_tag(_)
  t_tag
end

#insert_t_tag(_) ⇒ Object



84
85
86
# File 'lib/plurimath/math/symbol.rb', line 84

def insert_t_tag(_)
  [(Utility.ox_element("r", namespace: "m") << t_tag)]
end

#is_nary_symbol?Boolean

Returns:

  • (Boolean)


128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/plurimath/math/symbol.rb', line 128

def is_nary_symbol?
  %w[
    &#x222c;
    &#x222d;
    &#x222f;
    &#x2230;
    &#x2232;
    &#x2233;
    &#x2231;
    &#x2229;
    &#x222a;
    &#x2210;
  ].include?(value)
end

#linebreakObject



124
125
126
# File 'lib/plurimath/math/symbol.rb', line 124

def linebreak
  value == "\\\\"
end

#mini_sized?Boolean

Returns:

  • (Boolean)


143
144
145
# File 'lib/plurimath/math/symbol.rb', line 143

def mini_sized?
  mini_sub_sized || mini_sup_sized
end

#nary_attr_valueObject



104
105
106
# File 'lib/plurimath/math/symbol.rb', line 104

def nary_attr_value
  value
end

#omml_nodes(_) ⇒ Object



112
113
114
# File 'lib/plurimath/math/symbol.rb', line 112

def omml_nodes(_)
  Array(t_tag)
end

#omml_tag_nameObject



92
93
94
95
96
97
98
# File 'lib/plurimath/math/symbol.rb', line 92

def omml_tag_name
  if ["&#x22c0;", "&#x22c1;", "&#x22c2;", "&#x22c3;", "&#x22c3;", "&#x2211;", "&#x220f;"].include?(value)
    return "undOvr"
  end

  "subSup"
end

#separate_tableObject



120
121
122
# File 'lib/plurimath/math/symbol.rb', line 120

def separate_table
  ["&", "\\\\"].include?(value)
end

#t_tagObject



116
117
118
# File 'lib/plurimath/math/symbol.rb', line 116

def t_tag
  Utility.ox_element("t", namespace: "m") << value
end

#tag_nameObject



88
89
90
# File 'lib/plurimath/math/symbol.rb', line 88

def tag_name
  ["&#x22c0;", "&#x22c1;", "&#x22c2;", "&#x22c3;"].include?(value) ? "underover" : "subsup"
end

#to_asciimathObject



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/plurimath/math/symbol.rb', line 29

def to_asciimath
  return "" if value.nil?

  symbol = Asciimath::Constants::SYMBOLS.invert[value.strip.to_sym]
  unicodes = Latex::Constants::UNICODE_SYMBOLS.invert
  if value.match?(/&#x[0-9\w]+;/) && symbol.nil? && unicodes[value]
    return unicodes[value].to_s
  end

  symbol ? symbol.to_s : value
end

#to_htmlObject



68
69
70
# File 'lib/plurimath/math/symbol.rb', line 68

def to_html
  value
end

#to_latexObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/plurimath/math/symbol.rb', line 53

def to_latex
  returned = specific_values
  return returned if returned

  special_char = %w[&#x26; &#x23;]
  symbols = Latex::Constants::UNICODE_SYMBOLS.invert

  symbol = symbols[value]
  if Latex::Constants::SYMBOLS[symbol] == :operant
    special_char.include?(value) ? "\\#{symbol}" : symbol
  else
    symbols.key?(value) ? "\\#{symbol}" : value
  end
end

#to_mathml_without_math_tagObject



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/plurimath/math/symbol.rb', line 41

def to_mathml_without_math_tag
  mi_tag = Utility.ox_element("mi")
  return mi_tag if ["{:", ":}"].include?(value)

  unicode = Mathml::Constants::UNICODE_SYMBOLS.invert[value]
  if operator?(unicode) || unicode || explicit_checks(unicode)
    return Utility.ox_element("mo") << (unicode || value).to_s
  end

  mi_tag << value
end

#to_omml_without_math_tag(_, _) ⇒ Object



72
73
74
# File 'lib/plurimath/math/symbol.rb', line 72

def to_omml_without_math_tag(_, _)
  value
end

#to_unicodemathObject



76
77
78
79
80
81
82
# File 'lib/plurimath/math/symbol.rb', line 76

def to_unicodemath
  return "\\#{value}" if slashed || special_chars
  return mini_sub if mini_sub_sized
  return mini_sup if mini_sup_sized

  value
end

#validate_function_formulaObject



108
109
110
# File 'lib/plurimath/math/symbol.rb', line 108

def validate_function_formula
  false
end