---
- name: pause
  tag: "!*"
  match: "not(self::m:math) and not($MatchingPause) and @data-intent-property[contains(., ':pause')]"
  replace:
   - with:
      variables: [MatchingPause: "true()"]
      replace:
      - test:
        - if: "contains(@data-intent-property, ':pause-long')"
          then: [pause: long]
        - else_if: "contains(@data-intent-property, ':pause-short')"
          then: [pause: short]
          else: [pause: medium]
      - x: "."

- name: intent-literal-silent
  tag: [mi, mo, mn]
  match: "contains(@data-intent-property, ':silent:')"
  # say nothing
  replace: []

# handling of negative numbers that come from 'intent' is hard -- we do something that is close to right here 
- name: intent-literal-negative-number
  tag: mn
  match: "starts-with(text(), '-')"
  replace:
  - T: "mínusz"        # phrase(x 'minus' y)
  - x: "translate(text(), '-_', '')"

- name: default
  tag: square-root
  match: "."
  replace:
  - test:
      if: "$Verbosity!='Terse'"
      then: [T: "a"]    # phrase('the' square root of x)
  - T: "négyzetgyöke"      # phrase(the 'square root' of x)
  - test:
      if: "$Verbosity!='Terse'"
      then: [T: "ennek:"]   # phrase(the square root 'of' x)
      else: [pause: short]
  - x: "*[1]"
  - pause: short
  - test:
      if: "not(IsNode(*[1], 'leaf')) and $Impairment = 'Blindness'"
      then: [T: "gyök vége", pause: medium]  # phrase(start the square root of x 'end of root')

- name: default
  tag: root
  match: "."
  replace:
  - test:
      if: "$Verbosity!='Terse'"
      then: [T: "a"]
  - test:
      if: "*[2][self::m:mn and not(contains(., '.'))]"
      then_test:
      - if: "*[2][.='2']"
        then: [T: "négyzetgyöke"]        # phrase(the 'square root' of x)
      - else_if: "*[2][.='3']"
        then: [T: "köbgyöke"]        # phrase(the 'cube root' of x)
      - else: [x: "ToOrdinal(*[2])", T: "gyöke"]      # phrase(the square 'root' of 25)
      else:
      - test:
          if: "*[2][self::m:mi][string-length(.)=1]"
          then:
          - x: "*[2]"
          - pronounce: [text: "-edik", ipa: "ɛdik", sapi5: "edik", eloquence: "edik"]
          else: [x: "*[2]"]
      - T: "gyöke"        # phrase(the square 'root' of)
  - test:
      if: "$Verbosity!='Terse'"
      then: [T: "ennek:"]        # phrase(the square root 'of' x)
  - x: "*[1]"
  - pause: short
  - test:
      if: "not(IsNode(*[1], 'leaf')) and $Impairment = 'Blindness'"
      then: [T: "gyök vége", pause: medium]  # phrase(start the square root of x 'end of root')

# Fraction rules
# Mixed numbers mostly "just work" because the invisible char reads as "and" and other parts read properly on their own
- name: common-fraction
  tag: fraction
  match:
  - "*[1][self::m:mn][not(contains(., '.')) and text()<20]   and"
  - "*[2][self::m:mn][not(contains(., '.')) and 2<= text() and text()<=10]"
  variables: [IsPlural: "*[1]!=1"]
  replace:
  - x: "*[1]"
  - x: "ToOrdinal(*[2], true(), $IsPlural)"   # extra args specify fractional ordinal and whether it is plural

- name: common-fraction-mixed-number
  tag: fraction
  match:
  - "preceding-sibling::*[1][self::m:mo][.='⁤'] and" # preceding element is invisible plus
  - "*[1][self::m:mn][not(contains(., '.'))]   and"
  - "*[2][self::m:mn][not(contains(., '.'))]"
  variables: [IsPlural: "*[1]!=1"]
  replace:
  - x: "*[1]"
  - x: "ToOrdinal(*[2], true(), $IsPlural)"   # extra args specify fractional ordinal and whether it is plural


# Units (e.g., meters per second, m^2/s^2, (3m^2)/s)
- name: per-fraction
  tag: fraction
  match:
  - "BaseNode(*[1])[contains(@data-intent-property, ':unit') or"
  - "               ( self::m:mrow and count(*)=3 and"  # maybe a bit paranoid checking the structure...
  - "                 *[1][self::m:mn] and *[2][.='\u2062'] and BaseNode(*[3])[contains(@data-intent-property, ':unit')] ) ] and"
  - "BaseNode(*[2])[contains(@data-intent-property, ':unit')] "
  replace:
  - x: "*[1]"
  - T: "per"      # phrase('5 meters 'per' second)
  - x: "*[2]"

- name: simple
  # don't include nested fractions. E.g, fraction a plus b over c + 1 end fraction" is ambiguous
  # by simplistic SimpleSpeak's rules "b over c" is a fraction, but if we say nested fractions
  # are never simple, then any 'over' applies only to enclosing "fraction...end fraction" pair.
  tag: fraction
  match:
  - "(IsNode(*[1],'leaf') and IsNode(*[2],'leaf')) and"
  - "not(ancestor::*[name() != 'mrow'][1]/self::m:fraction)" # FIX: can't test for mrow -- what should be used???
  replace:
  - x: "*[1]"
  - T: "per"      # phrase(the fraction 3 'over' 4)
  - x: "*[2]"
  - pause: short

- name: default
  tag: fraction
  match: "."
  replace:
  - test:
      if: "$Impairment = 'Blindness'"
      then: [T: "tört"]      # phrase(the 'fraction' 3 over 4)
  - pause: short
  - x: "*[1]"
  - test:
      if: "not(IsNode(*[1],'leaf'))"
      then: [pause: short]
  - T: "per"      # phrase(the fraction 3 'over' 4)
  - test:
      if: "not(IsNode(*[2],'leaf'))"
      then: [pause: short]
  - x: "*[2]"
  - pause: short
  - test:
      if: "$Impairment = 'Blindness'"
      then: [T: "tört vége"]      # phrase(start 7 over 8 'end of fraction')
  - pause: medium

# rules for functions raised to a power
# these could have been written on 'mrow' but putting them on msup seems more specific
# to see if it is a function, we look right to see if the following sibling is apply-function
- name: inverse-function
  tag: inverse-function
  match: "."
  replace:
  - T: "inverz"      # phrase(the 'inverse' of f)
  - x: "*[1]"

# Handles functions squared or cubed, where the base is not a trig function.
- name: function-squared-or-cubed # audit-ignore
  tag: power
  match:
  - "*[2][self::m:mn][.='2' or .='3'] and"      # the exponent is 2 or 3
  - "following-sibling::*[1][self::m:mo][.='⁡']" #invisible function apply
  replace:
  - x: "*[1]"     # say the trig function name
  - bookmark: "*[2]/@id"
  - test:
      if: "not(IsInDefinition(*[1], 'TrigFunctionNames')) and *[2][.='2']" # the base is not a trig function
      then: [T: "a négyzeten"]      # say "squared"
      else_test:
        if: "not(IsInDefinition(*[1], 'TrigFunctionNames'))" # the base is not a trig function
        then: [T: "a köbön"]      # say "cubed"
        else: [T: ""]

# Handles trig functions with simple arguments (mi or mn), for both 2, 3 and general exponents.
- name: trig-power-argument-before-exponent-general # audit-ignore
  tag: [mi, mn]
  match:
  - "preceding-sibling::*[1][self::m:mo][.='⁡'] and"
  - "preceding-sibling::*[2][self::m:power[IsInDefinition(*[1], 'TrigFunctionNames')]]" # if the previous sibling is function-apply and previous previous sibling is trig power
  replace:
  - test:
    - if: "preceding-sibling::*[2]/*[2][self::m:mn][.='2']" # if the exponent is 2
      then:
      - x: "text()" # say the argument of the trig function
      - T: "a négyzeten"
    - else_if: "preceding-sibling::*[2]/*[2][self::m:mn][.='3']" # if the exponent is 3
      then:
      - x: "text()" # say the argument of the trig function
      - T: "a köbön"
      else:
      - pause: short
      - x: "text()" # say the argument of the function
      - pause: short
      - T: "a(z)"
      - test:
          if: "preceding-sibling::*[2]/*[2][self::m:mn][not(contains(., '.'))]" # if the exponent is an integer
          then: [x: "ToOrdinal(preceding-sibling::*[2]/*[2])"] # say the ordinal form
          else: [x: "preceding-sibling::*[2]/*[2]"] # else, say the exponent
      - T: "hatványon"

# Handles trig functions with grouped arguments (parenthesized or bracketed mrow), for both 2, 3 and general exponents.
- name: trig-power-grouped-argument-before-exponent-general # audit-ignore
  tag: [mo, mrow]
  match:
  - "(self::m:mo[.=')'] and preceding-sibling::*[2][self::m:mo][.='⁡'] and preceding-sibling::*[3][self::m:power[IsInDefinition(*[1], 'TrigFunctionNames')]])"
  - "or"
  - "(self::m:mrow[IsBracketed(., '(', ')')] and preceding-sibling::*[1][self::m:mo][.='⁡'] and preceding-sibling::*[2][self::m:power[IsInDefinition(*[1], 'TrigFunctionNames')]])"
  replace:
  - test:
      if: "self::m:mo" # if the current node is <mo>)</mo>
      then:
      - x: "text()" # say the argument of the function
      - test:
        - if: "preceding-sibling::*[3]/*[2][self::m:mn][.='2']" # if the exponent is 2
          then: [T: "a négyzeten"]
        - else_if: "preceding-sibling::*[3]/*[2][self::m:mn][.='3']" # if the exponent is 3
          then: [T: "a köbön"]
          else:
          - T: "a(z)"
          - test:
              if: "preceding-sibling::*[3]/*[2][self::m:mn][not(contains(., '.'))]" # if the exponent is an integer
              then: [x: "ToOrdinal(preceding-sibling::*[3]/*[2])"] # say the ordinal form
              else: [x: "preceding-sibling::*[3]/*[2]"] # else, say the exponent
          - T: "hatványon"
      else: # if the current node is an <mrow> with parentheses
      - x: "*[1]"
      - x: "*[2]"
      - x: "*[3]"
      - test:
        - if: "preceding-sibling::*[2]/*[2][self::m:mn][.='2']" # if the exponent is 2
          then: [T: "a négyzeten"]
        - else_if: "preceding-sibling::*[2]/*[2][self::m:mn][.='3']" # if the exponent is 3
          then: [T: "a köbön"]
          else:
          - T: "a(z)"
          - test:
              if: "preceding-sibling::*[2]/*[2][self::m:mn][not(contains(., '.'))]" # if the exponent is an integer
              then: [x: "ToOrdinal(preceding-sibling::*[2]/*[2])"] # say the ordinal form
              else: [x: "preceding-sibling::*[2]/*[2]"] # else, say the exponent
          - T: "hatványon"

- name: function-power # audit-ignore
  tag: power
  match:
  - "following-sibling::*[1][self::m:mo][.='⁡'] and" #invisible function apply
  - "not(*[1][IsInDefinition(., 'TrigFunctionNames')])"
  replace:
  - test:
      if: "$Verbosity!='Terse'"
      then: [T: ""]      # phrase('the' third power of 2)
  - bookmark: "*[2]/@id"
  - test:
      if: "*[2][self::m:mn][not(contains(., '.'))]"
      then: [x: "ToOrdinal(*[2])"]
      else: [x: "*[2]"]
  - T: "hatványon"      # phrase(the third 'power of' 6)
  - pause: short
  - x: "*[1]"

# Handles trig function powers (non-2/3) at the base node so generic power rules do not speak the base/exponent too early.
- name: trig-function-power-base-only # audit-ignore
  tag: power
  match:
  - "following-sibling::*[1][self::m:mo][.='⁡'] and"
  - "*[1][IsInDefinition(., 'TrigFunctionNames')] and"
  - "not(*[2][self::m:mn][.='2' or .='3'])"
  replace:
  - x: "*[1]"

- name: AfterPower-nested # audit-ignore
  tag: power
  match: # directly a superscript or an mrow that contains a superscript
  - "$ClearSpeak_Exponents = 'AfterPower' and"
  - "*[2][self::m:power or self::m:power or self::m:mrow[m:power]]"
  replace:
  - x: "*[1]"
  - T: "a következő kitevőre emelve:"      # phrase(5 'raised to the exponent' x plus 1)
  - pause: short
  - x: "*[2]"
  - pause: short
  - T: "kitevő vége"      # phrase(5 raised to the exponent x plus 1 'end exponent')

- name: AfterPower-default # audit-ignore
  tag: power
  match: "$ClearSpeak_Exponents = 'AfterPower'"
  replace:
  - x: "*[1]"
  - T: "a következő hatványra emelve:"      # phrase(x is 'raised to the power' 4)
  - x: "*[2]"
  - pause: short

- name: squared-or-cubed # audit-ignore
  tag: power
  match: "*[2][self::m:mn][.='2' or .='3']"
  replace:
  - x: "*[1]"
  - bookmark: "*[2]/@id"
  - test:
      if: "*[2][.=2]"
      then: [T: "a négyzeten"]      # phrase(5 'squared' equals 25)
      else: [T: "a köbön"]      # phrase(5 'cubed' equals 125)

- name: times # audit-ignore
  tag: mo
  match:
  # say "times" when invisible times is followed by parens or a superscript that has a base with parens or "|"s
  # if we aren't sure if it is times or not, don't say anything
  - ".='⁢' and (not(@data-function-guess) or $ClearSpeak_Functions = 'None') and"
  - "not(ancestor-or-self::*[contains(@data-intent-property, ':literal:')]) and ("
  - "  $ClearSpeak_ImpliedTimes = 'MoreImpliedTimes'"
  - " or "
  - "  following-sibling::*[1]["
  - "    IsBracketed(., '(', ')') or IsBracketed(., '[', ']') or IsBracketed(., '|', '|') or "
  # most of these aren't mentioned in ClearSpeak spec, but are (I think) expected uses of "times"
  - "    self::m:matrix or self::m:determinant or self::m:binomial or" # followed by parens
  - "    self::m:square-root or self::m:msqrt or self::m:root or self::m:mroot or"
  - "    (self::m:msub or self::m:msubsup or"
  - "    ((self::m:msup or self::m:power) and not(IsNode(*[1], 'leaf') and *[2][self::m:mn and (.=2 or '.=3')]))) and " # followed by msup, etc.
  - "     (*[1][self::m:mrow[IsBracketed(., '(', ')') or IsBracketed(., '[', ']') or IsBracketed(., '|', '|')] or "
  - "           self::m:matrix or self::m:determinant] or" # base has parens
  - "      not(IsNode(*[2], 'simple')) or "
  - "      (self::m:msubsup and not(IsNode(*[3], 'simple')))"
  - "     )"
  - "  ]"
  # other possibility is the preceding element has parens (but not the following)
  # this is not mentioned in the ClearSpeak rules or examples but seems like it should say "times". E.g, |x| y
  - " or "
  - "  preceding-sibling::*[1]["
  - "    IsBracketed(., '(', ')') or IsBracketed(., '[', ']') or IsBracketed(., '|', '|')]" # followed by parens
  - " )"
  replace:
  - T: "szorozva"      # phrase(5 'times' 3 equals 15)

- name: simple-integer # audit-ignore
  tag: power
  match: "*[2][self::m:mn][not(contains(., '.'))]"
  replace:
  - x: "*[1]"
  - T: "a(z)"      # phrase(2 raised 'to the' power 7)
  - test:
      if: "*[2][.>=0]"
      then: [x: "ToOrdinal(*[2])"]
      else: [x: "*[2]"]
  - T: "hatványon"

- name: simple-negative-integer # audit-ignore
  tag: power
  match:
  - "*[2][self::m:minus and count(*)=1 and "
  - "     *[1][self::m:mn][not(contains(., '.'))]"
  - "    ]"
  replace:
  - x: "*[1]"
  - T: "a"      # phrase(2 raised 'to the' power 7)
  - x: "*[2]"
  - T: "hatványon"

- name: simple-var # audit-ignore
  tag: power
  match: "*[2][self::m:mi][string-length(.)=1]"
  replace:
  - x: "*[1]"
  - T: "a(z)"      # phrase(3 raised 'to the' power 7)
  - x: "*[2]"
  - pronounce: [text: "-edik", ipa: "ɛdik", sapi5: "edik", eloquence: "edik"]
  - T: "hatványon"

- name: nested-squared-or-cubed # audit-ignore
  tag: power
  match:
  - "$ClearSpeak_Exponents = 'Auto' and"
  - "*[2][self::m:power]["
  - "     *[2][self::m:mn][.='2' or .='3'] and " # exp is 2 or 3
  # base is mn, mi, common fraction ([xxx] case)
  - "     *[1][self::m:mn or self::m:mi or "
  - "          self::m:fraction[*[1][self::m:mn][not(contains(., '.')) and text()<20]   and"
  - "                        *[2][self::m:mn][not(contains(., '.')) and 2<= text() and text()<=10]]"
  - "         ]"
  - "    ]"
  replace:
  - x: "*[1]"
  - T: "emelve a(z)"      # phrase(x 'raised to the' second power)
  - x: "*[2]"
  - T: "hatványra"      # phrase(x raised to the second 'power')

- # - [xxx]^n
  name: nested-negative-squared-or-cubed # audit-ignore
  tag: power
  match:
  - "$ClearSpeak_Exponents = 'Auto' and"
  - " *[2][self::m:minus and count(*)=1 and "
  - "      *[1]/*[1][self::m:power]["
  - "                *[2][self::m:mn][.='2' or .='3'] and " # exp is 2 or 3"
  # base is mn, mi, common fraction ([xxx] case)
  - "                *[1][self::m:mn or self::m:mi or "
  - "                     self::m:fraction[*[1][self::m:mn][not(contains(., '.')) and text()<20]   and"
  - "                                   *[2][self::m:mn][not(contains(., '.')) and 2<= text() and text()<=10]]"
  - "               ]"
  - "          ]"
  - "     ]"
  replace:
  - x: "*[1]"
  - T: "emelve a(z)"      # phrase(x 'raised to the' second power)
  - x: "*[2]"
  - T: "hatványra"      # phrase(x raised to the second 'power')

- # [xxx] var^n
  name: nested-var-squared-or-cubed # audit-ignore
  tag: power
  match:
  - "$ClearSpeak_Exponents = 'Auto' and"
  - "  *[2][self::m:mrow][count(*)=3][ "
  - "       *[3][self::m:power]["
  - "            *[2][self::m:mn][.='2' or .='3'] and " # exp is 2 or 3
  - "            *[1][self::m:mi]"
  - "           ] and "
  - "       *[2][self::m:mo][.='⁢'] and " # invisible times
  # base is mn, or common fraction ([xxx] case)
  - "       *[1][self::m:mn or "
  - "            self::m:fraction[*[1][self::m:mn][not(contains(., '.')) and text()<20]   and"
  - "                          *[2][self::m:mn][not(contains(., '.')) and 2<= text() and text()<=10]]"
  - "           ]"
  - "      ]"
  replace:
  - x: "*[1]"
  - T: "emelve a(z)"      # phrase(x 'raised to the' second power)
  - x: "*[2]"
  - T: "hatványra"      # phrase(x raised to the second 'power')

- # -[xxx] var^n
  name: nested-negative-var-squared-or-cubed # audit-ignore
  tag: power
  match:
  - "$ClearSpeak_Exponents = 'Auto' and"
  - "  *[2][self::m:mrow][count(*)=3][ "
  - "       *[3][self::m:power]["
  - "            *[2][self::m:mn][.='2' or .='3'] and " # exp is 2 or 3
  - "            *[1][self::m:mi]"
  - "           ] and "
  - "       *[2][self::m:mo][.='⁢'] and " # invisible times
  - "       *[1][self::m:minus and count(*)=1 and "
  # base is mn, or common fraction ([xxx] case)
  - "            *[1][self::m:mn or "
  - "                 self::m:fraction[*[1][self::m:mn][not(contains(., '.')) and text()<20]   and"
  - "                                  *[2][self::m:mn][not(contains(., '.')) and 2<= text() and text()<=10]]"
  - "                ]"
  - "           ]"
  - "      ]"
  replace:
  - x: "*[1]"
  - T: "emelve a"      # phrase(x 'raised to the' second power)
  - x: "*[2]"
  - T: "hatványra"      # phrase(x raised to the second 'power')

- name: default-exponent-power # audit-ignore
  tag: power
  match: # directly a superscript or an mrow that contains a superscript
  - "*[2][self::m:power or self::m:power or self::m:mrow[m:power]]"
  replace:
  - x: "*[1]"
  - T: "emelve a következő kitevőre:"      # phrase(x is 'raised to the exponent')
  - pause: short
  - x: "*[2]"
  - pause: short
  - T: "kitevő vége"      # phrase(and now 'end exponent' has been reached)

- name: default
  tag: power
  match: "."
  replace:
  - x: "*[1]"
  - T: "a(z)"      # phrase(x 'raised to the' second power)
  - x: "*[2]"
  - T: "hatványon"      # phrase(x raised to the second 'power')

- name: simple
  tag: power
  match: "IsNode(*[2], 'leaf')"
  replace:
  - x: "*[1]"
  - T: "a(z)"      # phrase(15 raised 'to the' second power equals 225)
  - x: "*[2]"
  - T: "hatványon"


- name: nested
  # it won't end in "power" if the exponent is simple enough
  # FIX: not that important, but this misses the case where the nested exp is a negative integer (change test if this is fixed)
  # ending nested exponents with "...power power" sounds bad
  tag: power
  match:
  - "*[2]["
  - "     (self::m:power and not(IsNode(*[2], 'leaf'))) or" # non-simple nested superscript
  - "     self::m:mrow[*[last()][self::m:power[not(IsNode(*[2], 'leaf'))]]]" # same as above but at the end of an mrow # FIX: need to figure out linear replacement
  - "    ]"
  replace:
  - x: "*[1]"
  - T: "emelve a(z)"      # phrase(15 'raised to the' second power equals 225)
  - x: "*[2]"
  - pause: short
  - test:
      if: "$Impairment = 'Blindness'"
      then:
      - T: "kitevő vége"      # phrase(start 2 raised to the exponent 4 'end of exponent')
      - pause: short
      else:
      - pause: medium

- name: set # audit-ignore
  tag: set
  match: "."
  replace:
  - test:
    - if: "count(*)=0"
      then: [T: "az üres halmaz"]      # phrase('the empty set')
    - else_if: "count(*)=2"
      then:
      - test:
          if: "$Verbosity!='Terse'"
          then: [T: "az"]      # phrase('the' empty set)
      - T: "üres halmaz"      # phrase(the 'empty set')
    - else_if: "count(*[1]/*)=3 and *[1]/*[2][self::m:mo][.=':' or .='|' or .='∣']"
      then:
      - test:
          if: "$Verbosity!='Terse'"
          then: [T: ""]      # phrase('the' set of all integers)
      - x: "*[1]/*[1]"
      - T: "melyekre teljesül, hogy"      # phrase(this is a 'set of' numbers)
      - test:
          if: "$ClearSpeak_Sets != 'woAll'"
          then: [T: "minden"]      # phrase(the set of 'all' integers)
      - x: "*[1]/*[3]"
      else:
      - test:
          if: "$ClearSpeak_Sets != 'SilentBracket'"
          then:
          - test:
              if: "$Verbosity!='Terse'"
              then: [T: "a(z)"]      # phrase('the' set of integers)
      - x: "*[1]"
      - T: "halmaz"      # phrase(this is a 'set' of integers)

#
# Some rules on mrows
#
- # intervals are controlled by a ClearSpeak Preference -- parens/brackets don't have to match, so we avoid IsBracketed
  # alternatively, we could have four (or ten) rules, but there is a lot of duplication if we do that
  # this one rule handles all ten cases listed as part $ClearSpeak_Paren = 'Interval'
  # note that *[2] is an mrow with X, ",", Y, so getting X or Y is a double index
  name: ClearSpeak-intervals # audit-ignore # avoid overriding with default "intervals" name
  variables:
  - is_intervals_start_infinity: "*[1][self::m:minus and count(*)=1 and *[1][.='∞']]"
  - T: "elemet"
  - is_intervals_end_infinity: "*[2][.='∞'or (self::m:plus and count(*)=1 and *[1][.='∞'])]"
  tag: [open-interval, open-closed-interval, closed-interval, closed-open-interval]
  match: "."
  replace:
  - x: "*[1]"
  - T: "től"
  - x: "*[2]"
  - T: "ig terjedő intervallum"
  - pause: short
  - test:
      if: "not($is_intervals_start_infinity)"
      then:
      - test:
          if: "starts-with(name(.), 'open')"
          then: [T: "nem"]      # phrase(the interval from a to b 'not' including b)
      - T: "tartalmazza a"      # phrase(the interval from a to b not 'including' b)
      - x: "*[1]"
      - T: "elemet"
    # logic to deal with [not] arg #1
  - test:
      if: "not($is_intervals_start_infinity or $is_intervals_end_infinity)"
      then_test:
      - if: "name(.)='open-interval'"
        then: [T: "vagy"]      # phrase(the interval including a 'or' b )
      - else_if: "name(.)='closed-interval'"
        then: [T: "és"]      # phrase(the interval including a 'and' b)
        else: [T: "de"]      # phrase(the interval including a 'but' not b)
    # some ugly logic dealing with connectives: or, but, but, and (cleaner to be part of next clause?)
  - test:
      if: "not($is_intervals_end_infinity)"
      then:
      - test:
          # there is some asymmetry to the test because of the and/or/but logic above
          if: "not( name(.)='open-interval' or name(.)='closed-interval' ) or $is_intervals_start_infinity"
          then:
          - test:
              if: "name(.) = 'open-interval' or name(.) = 'closed-open-interval'"
              then: [T: "nem"]      # phrase(the interval 'not' including a)
          - T: "tartalmazza"      # phrase(the interval not 'including' a)
          - T: "a"
      - x: "*[2]"
      - T: "elemet"
    # onto the [not] [including]... part

- name: ClearSpeak_Functions_None
  tag: mo
  match:
  - ".='⁡' and $ClearSpeak_Functions = 'None' and"
  - "not(preceding-sibling::*[1][IsInDefinition(., 'TrigFunctionNames')])" # Functions=None does not apply to "trig" functions
  replace:
    test:
      if: "$ClearSpeak_ImpliedTimes = 'None'"
      then: [T: ""]
      else: [T: "szorozva"]      # phrase(5 'times' 3 equals 15)

- name: no-times
  tag: mo
  match:
  # Note: this rule is also part of the paren rule so that the parens speak
  - ".='⁢' and $ClearSpeak_ImpliedTimes = 'None'"
  replace:
  - T: ""

- name: no-say-parens # audit-ignore
  tag: mrow
  match:
  - "parent::*[not(self::m:msup) and not(self::m:msub) and not(self::m:msubsup) and not(self::m:power) and"
  - "          not(self::m:math) ] and "       # rule out [x] standing alone
  - "( IsBracketed(., '(', ')') or IsBracketed(., '[', ']') ) and "
  - "not( $ClearSpeak_Functions = 'None' and "
  - "     (preceding-sibling::*[1][.='⁡'] or following-sibling::*[1][.='⁡']) ) and "
  - "not( $ClearSpeak_ImpliedTimes = 'None' and "
  - "     (preceding-sibling::*[1][.='⁢'] or following-sibling::*[1][.='⁢']) ) and "
  - "IsNode(*[2], 'simple') and"
  - "not(preceding-sibling::*[1][.='\u2062' and @data-function-guess]) and"
  - "not(ancestor-or-self::*[contains(@data-intent-property, ':literal:')])"
  # missing clause: 'a positive fraction that is spoken as an ordinal
  #   (either by the Ordinal preference or by the default rules)'
  replace:
  - x: "*[2]"

- name: ClearSpeak-default # audit-ignore
  tag: [mtr, mlabeledtr]
  match: "parent::m:matrix or parent::m:determinant"
  variables: [NextLineIsContinuedRow: "following-sibling::*[1][contains(@data-intent-property, ':continued-row:')]"]
  replace:
  - pause: medium
  - x: "count(preceding-sibling::*)+1"
  - T: ". sor"      # phrase(the first 'row' of a matrix)
  - test:
      if: ".[self::m:mlabeledtr]"
      then:
      - T: "címkéje:"      # phrase(the line 'with label' first equation)
      - x: "*[1]/*"
      - pause: short
  - pause: medium
  - test:
      if: ".[self::m:mlabeledtr]"
      then: [x: "*[position()>1]"]
      else: [x: "*"]

- include: "SharedRules/geometry.yaml"
- include: "SharedRules/linear-algebra.yaml"
- include: "SharedRules/general.yaml"
- include: "SharedRules/default.yaml"
