From 18fab00cc832d5fedd4d0a1e69e8ab2032390bbb Mon Sep 17 00:00:00 2001 From: Danil <81031453+Kostenkov-2021@users.noreply.github.com> Date: Tue, 29 Sep 2026 18:28:06 +0300 Subject: [PATCH] Fix intent detection for limits and norms This commit improves intent recognition for several TeX-derived patterns: it ignores the invisible function-application character when matching limit expressions, treats TeX's gathered environments as lines, and recognizes subscripted norms from TeX4ht and canonicalized MathML shapes. These fixes keep speech and navigation output consistent for common display math cases. --- Rules/Intent/general.yaml | 18 ++++++++++++- Rules/Intent/linear-algebra.yaml | 43 ++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/Rules/Intent/general.yaml b/Rules/Intent/general.yaml index 15bd1dc7a..5b4997bdc 100644 --- a/Rules/Intent/general.yaml +++ b/Rules/Intent/general.yaml @@ -333,7 +333,7 @@ - name: limit tag: [msub, munder] - variables: [NoSpacesBase: "translate(*[1], ' \u00A0\u2004\u2005\u2006\u2007\u2008\u2009\u200A','')"] # Sometimes these have (weird) spaces in them + variables: [NoSpacesBase: "translate(*[1], ' \u00A0\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u2061','')"] # Sometimes these have spaces or an invisible function-application character in them match: "*[1][$NoSpacesBase='lim' or $NoSpacesBase='limsup' or $NoSpacesBase='liminf']" replace: - intent: @@ -795,6 +795,22 @@ variables: [TableProperty: "'determinant'"] replace: [x: "*[2]"] +- + # TeX's gathered environment is one derivation split across display lines, + # not a system whose rows are independent equations. + name: mtable-gathered-property + tag: mtable + match: "contains(concat(' ', normalize-space(@class), ' '), ' gathered ')" + replace: + - with: + variables: + - TableProperty: "'lines'" + replace: + - intent: + name: "lines" + children: + - x: "*" + - name: mtable-equations-property tag: mtable diff --git a/Rules/Intent/linear-algebra.yaml b/Rules/Intent/linear-algebra.yaml index f8c8fd7bf..4b7afe816 100644 --- a/Rules/Intent/linear-algebra.yaml +++ b/Rules/Intent/linear-algebra.yaml @@ -39,6 +39,49 @@ - x: "*[1]/*[2]" # grab the contents of the bracketed expr - x: "*[2]" +- + # TeX4ht commonly attaches the norm's subscript to the closing bar only: + # ∥...∥p. + name: norm-with-subscripted-closing-bar + tag: mrow + match: + - "count(*) >= 3 and *[1][.='∥'] and *[last()][self::m:msub and *[1][.='∥']]" + replace: + - intent: + name: "subscripted-norm" + attrs: "data-intent-property='concat(data-intent-property, \":function:\")'" + children: + - x: "*[position() > 1 and position() < last()]" + - x: "*[last()]/*[2]" + +- + # The same TeX4ht shape can use two ordinary vertical bars for each double bar. + name: norm-with-doubled-bars-and-subscripted-closing-bar + tag: mrow + match: + - "count(*) >= 5 and *[1][.='|'] and *[2][.='|'] and *[last()-1][.='|'] and *[last()][self::m:msub and *[1][.='|']]" + replace: + - intent: + name: "subscripted-norm" + attrs: "data-intent-property='concat(data-intent-property, \":function:\")'" + children: + - x: "*[position() > 2 and position() < last()-1]" + - x: "*[last()]/*[2]" + +- + # Canonicalization groups ||x||_p as an indexed row containing a nested |x|. + name: norm-with-canonicalized-doubled-bars + tag: msub + match: + - "*[1][self::m:mrow and count(*)=3 and *[1][.='|'] and *[2][self::m:mrow and IsBracketed(., '|', '|')] and *[3][.='|']]" + replace: + - intent: + name: "subscripted-norm" + attrs: "data-intent-property='concat(data-intent-property, \":function:\")'" + children: + - x: "*[1]/*[2]/*[2]" + - x: "*[2]" + - name: vector-magnitude tag: mrow