# frozen_string_literal: true require_relative "binary_function" module Plurimath module Math module Function class Underset < BinaryFunction attr_accessor :options FUNCTION = { name: "underscript", first_value: "underscript value", second_value: "base expression", }.freeze def initialize( parameter_one = nil, parameter_two = nil, options = {}) super(parameter_one, parameter_two) @options = options unless options.empty? end def to_mathml_without_math_tag value_array = [ validate_mathml_fields(parameter_two), validate_mathml_fields(parameter_one), ] Utility.update_nodes(ox_element("munder", attributes: options), value_array) end def to_omml_without_math_tag(display_style) if !display_style base = Base.new(parameter_one, parameter_two) return base.to_omml_without_math_tag(display_style) end limlow = Utility.ox_element("limLow", namespace: "m") limlowpr = Utility.ox_element("limLowPr", namespace: "m") limlowpr << Utility.pr_element("ctrl", true, namespace: "m") Utility.update_nodes( limlow, [ limlowpr, omml_parameter(parameter_one, display_style, tag_name: "e"), omml_parameter(parameter_two, display_style, tag_name: "lim"), ], ) [limlow] end def to_unicodemath return "#{parameter_one.to_unicodemath}#{unicodemath_parens(parameter_two)}" if horizontal_brackets? return "#{parameter_two.to_unicodemath}_#{unicodemath_parens(parameter_one)}" if unicode_classes_accent?(parameter_two) return "#{unicodemath_parens(parameter_two)}#{unicodemath_field_value(parameter_one)}" if unicode_accent?(parameter_one) "#{unicodemath_parens(parameter_two)}┬#{parameter_one.to_unicodemath}" end def line_breaking(obj) parameter_one&.line_breaking(obj) if obj.value_exist? obj.update(self.class.new(Utility.filter_values(obj.value), parameter_two)) self.parameter_two = nil return end parameter_two&.line_breaking(obj) if obj.value_exist? obj.update(self.class.new(nil, Utility.filter_values(obj.value))) end end def new_nary_function(fourth_value) Nary.new(parameter_two, parameter_one, nil, fourth_value, { type: "undOvr" }) end def is_nary_function? parameter_two.is_nary_function? || parameter_two.is_nary_symbol? end protected def unicode_accent?(field) return unless field.is_a?(Math::Symbols::Symbol) match_unicode?(unicodemath_field_value(field)) end def horizontal_brackets? return unless parameter_one.is_a?(Math::Symbols::Symbol) UnicodeMath::Constants::HORIZONTAL_BRACKETS.value?(unicodemath_field_value(parameter_one)) end def unicode_classes_accent?(field) (field.is_a?(Math::Function::Obrace) || field.is_a?(Math::Function::Ubrace)) end def match_unicode?(unicode) UnicodeMath::Constants::DIACRITIC_BELOWS.include?(unicode) || UnicodeMath::Constants::ACCENT_SYMBOLS.has_value?(unicode) end end end end end