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_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, #updated_object_values, #validate_mathml_fields, #variable_value, #variables

Constructor Details

#initialize(sym = nil) ⇒ Symbol

Returns a new instance of Symbol.



8
9
10
# File 'lib/plurimath/math/symbol.rb', line 8

def initialize(sym = nil)
  @value = sym.is_a?(Parslet::Slice) ? sym.to_s : sym
end

Instance Attribute Details

#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



12
13
14
# File 'lib/plurimath/math/symbol.rb', line 12

def ==(object)
  object.respond_to?(:value) && object.value == value
end

#font_style_t_tag(_) ⇒ Object



79
80
81
# File 'lib/plurimath/math/symbol.rb', line 79

def font_style_t_tag(_)
  t_tag
end

#insert_t_tag(_) ⇒ Object



63
64
65
# File 'lib/plurimath/math/symbol.rb', line 63

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

#linebreakObject



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

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

#nary_attr_valueObject



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

def nary_attr_value
  value
end

#omml_nodes(_) ⇒ Object



91
92
93
# File 'lib/plurimath/math/symbol.rb', line 91

def omml_nodes(_)
  Array(t_tag)
end

#omml_tag_nameObject



71
72
73
74
75
76
77
# File 'lib/plurimath/math/symbol.rb', line 71

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

  "subSup"
end

#separate_tableObject



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

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

#t_tagObject



95
96
97
# File 'lib/plurimath/math/symbol.rb', line 95

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

#tag_nameObject



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

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

#to_asciimathObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/plurimath/math/symbol.rb', line 16

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



55
56
57
# File 'lib/plurimath/math/symbol.rb', line 55

def to_html
  value
end

#to_latexObject



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

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



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

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



59
60
61
# File 'lib/plurimath/math/symbol.rb', line 59

def to_omml_without_math_tag(_, _)
  value
end

#validate_function_formulaObject



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

def validate_function_formula
  false
end