---
- 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:')"
  replace: []

- name: intent-literal-negative-number
  tag: mn
  match: "starts-with(text(), '-')"
  replace:
  - T: "moins"
  - x: "translate(text(), '-_', '')"

- name: default
  tag: square-root
  match: "."
  replace:
  - test:
      if: "$Verbosity!='Terse'"
      then: [T: "la"]
  - T: "racine carrée"
  - test:
      if: "$Verbosity!='Terse'"
      then: [T: "de"]
      else: [pause: short]
  - x: "*[1]"
  - pause: short
  - test:
      if: "not(IsNode(*[1], 'leaf')) and $Impairment = 'Blindness'"
      then: [T: "fin de racine", pause: medium]

- name: default
  tag: root
  match: "."
  replace:
  - test:
      if: "$Verbosity!='Terse'"
      then: [T: "la"]
  - test:
      if: "*[2][self::m:mn and not(contains(., '.'))]"
      then_test:
      - if: "*[2][.='2']"
        then: [T: "racine carrée"]
      - else_if: "*[2][.='3']"
        then: [T: "racine cubique"]
      - else:
        - x: "*[2]"
        - T: "ième racine"
      else:
      - x: "*[2]"
      - T: "racine"
  - test:
      if: "$Verbosity!='Terse'"
      then: [T: "de"]
  - x: "*[1]"
  - pause: short
  - test:
      if: "not(IsNode(*[1], 'leaf')) and $Impairment = 'Blindness'"
      then: [T: "fin de racine", pause: medium]

- 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)"

- name: common-fraction-mixed-number
  tag: fraction
  match:
  - "preceding-sibling::*[1][self::m:mo][.='⁤'] and"
  - "*[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)"

- name: per-fraction
  tag: fraction
  match:
  - "BaseNode(*[1])[contains(@data-intent-property, ':unit') or"
  - "               ( self::m:mrow and count(*)=3 and"
  - "                 *[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: "par"
  - x: "*[2]"

- name: simple
  tag: fraction
  match:
  - "(IsNode(*[1],'leaf') and IsNode(*[2],'leaf')) and"
  - "not(ancestor::*[name() != 'mrow'][1]/self::m:fraction)"
  replace:
  - x: "*[1]"
  - T: "sur"
  - x: "*[2]"
  - pause: short

- name: default
  tag: fraction
  match: "."
  replace:
  - test:
      if: "$Impairment = 'Blindness'"
      then: [T: "fraction"]
  - pause: short
  - x: "*[1]"
  - test:
      if: "not(IsNode(*[1],'leaf'))"
      then: [pause: short]
  - T: "sur"
  - test:
      if: "not(IsNode(*[2],'leaf'))"
      then: [pause: short]
  - x: "*[2]"
  - pause: short
  - test:
      if: "$Impairment = 'Blindness'"
      then: [T: "fin de fraction"]
  - pause: medium

- name: inverse-function
  tag: inverse-function
  match: "."
  replace:
  - T: "inverse"
  - x: "*[1]"

- name: function-squared-or-cubed
  tag: power
  match:
  - "*[2][self::m:mn][.='2' or .='3'] and"
  - "following-sibling::*[1][self::m:mo][.='⁡']"
  replace:
  - x: "*[1]"
  - bookmark: "*[2]/@id"
  - test:
      if: "*[2][.=2]"
      then: [T: "au carré"]
      else: [T: "au cube"]

- name: function-power
  tag: power
  match:
  - "following-sibling::*[1][self::m:mo][.='⁡']"
  replace:
  - bookmark: "*[2]/@id"
  - x: "*[2]"
  - T: "puissance de"
  - pause: short
  - x: "*[1]"

- name: squared-or-cubed
  tag: power
  match: "*[2][self::m:mn][.='2' or .='3']"
  replace:
  - x: "*[1]"
  - bookmark: "*[2]/@id"
  - test:
      if: "*[2][.=2]"
      then: [T: "au carré"]
      else: [T: "au cube"]

- name: simple-integer
  tag: power
  match: "*[2][self::m:mn][not(contains(., '.'))]"
  replace:
  - x: "*[1]"
  - T: "à la"
  - x: "*[2]"

- name: simple-negative-integer
  tag: power
  match:
  - "*[2][self::m:minus and count(*)=1 and"
  - "     *[1][self::m:mn][not(contains(., '.'))]]"
  replace:
  - x: "*[1]"
  - T: "à la"
  - x: "*[2]"

- name: simple-var
  tag: power
  match: "*[2][self::m:mi][string-length(.)=1]"
  replace:
  - x: "*[1]"
  - T: "à la"
  - x: "*[2]"
  - pronounce: [text: "-ième", ipa: "jɛm", sapi5: "ième", eloquence: "ième"]

- name: simple
  tag: power
  match: "IsNode(*[2], 'leaf')"
  replace:
  - x: "*[1]"
  - T: "à la"
  - x: "*[2]"

- name: nested
  tag: power
  match:
  - "*[2]["
  - "     (self::m:power and not(IsNode(*[2], 'leaf'))) or"
  - "     self::m:mrow[*[last()][self::m:power[not(IsNode(*[2], 'leaf'))]]]"
  - "    ]"
  replace:
  - x: "*[1]"
  - T: "élevé à la"
  - x: "*[2]"
  - pause: short
  - test:
      if: "$Impairment = 'Blindness'"
      then:
      - T: "fin d'exposant"
      - pause: short
      else:
      - pause: medium

- name: default
  tag: power
  match: "."
  replace:
  - x: "*[1]"
  - T: "élevé à la puissance"
  - x: "*[2]"

- name: set
  tag: set
  match: "."
  replace:
  - test:
    - if: "count(*)=0"
      then:
      - T: "ensemble vide"
    - else_if: "count(*[1]/*)=3 and *[1]/*[2][self::m:mo][.=':' or .='|' or .='∣']"
      then:
      - T: "ensemble de tous les"
      - x: "*[1]/*[1]"
      - T: "tel que"
      - x: "*[1]/*[3]"
      else:
      - T: "ensemble"
      - x: "*[1]"

- name: times
  tag: mo
  match:
  - ".='⁢' and"
  - "not(@data-function-guess) and ("
  - "not(ancestor-or-self::*[contains(@data-intent-property, ':literal:')]) and "
  - "  following-sibling::*[1]["
  - "    IsBracketed(., '(', ')') or IsBracketed(., '[', ']') or IsBracketed(., '|', '|') or "
  - "    self::m:matrix or self::m:determinant or self::m:binomial or"
  - "    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 "
  - "     (*[1][self::m:mrow[IsBracketed(., '(', ')') or IsBracketed(., '[', ']') or IsBracketed(., '|', '|')] or "
  - "           self::m:matrix or self::m:determinant] or"
  - "      not(IsNode(*[2], 'simple')) or "
  - "      (self::m:msubsup and not(IsNode(*[3], 'simple')))"
  - "     )"
  - "  ]"
  - " or "
  - "  preceding-sibling::*[1]["
  - "    IsBracketed(., '(', ')') or IsBracketed(., '[', ']') or IsBracketed(., '|', '|')]"
  - " )"
  replace:
  - T: "fois"

- name: no-say-parens
  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 "
  - "( IsBracketed(., '(', ')') or IsBracketed(., '[', ']') ) and "
  - "( IsNode(*[2], 'simple')  ) and"
  - "not(preceding-sibling::*[1][.='\u2062' and @data-function-guess]) and"
  - "not(ancestor-or-self::*[contains(@data-intent-property, ':literal:')])"
  replace:
  - x: "*[2]"

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