mathcat 0.1.26

MathCAT: Math Capable Assistive Technology ('Speech and braille from MathML')
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
---
#default rules shared among several speech rules
- name: default
  tag: math
  match: "."
  replace:
  - with:
      variables:
      - ClearSpeak_Fractions: "IfThenElse($Verbosity='Verbose' and $ClearSpeak_Fractions='Auto', 'EndFrac', $ClearSpeak_Fractions)"
      - ClearSpeak_AbsoluteValue: "IfThenElse($Verbosity='Verbose' and $ClearSpeak_AbsoluteValue='Auto', 'AbsEnd', $ClearSpeak_AbsoluteValue)"
      - ClearSpeak_Roots: "IfThenElse($Verbosity='Verbose' and $ClearSpeak_Roots='Auto', 'RootEnd', $ClearSpeak_Roots)"
      replace:
      - test:
          if: "$MathRate = 100"
          then: [{x: "*"}]
          else:
          - rate:
              value: "$MathRate"
              replace: [{x: "*"}]

- name: empty-mrow
  tag: mrow
  match: "not(*)"
  replace:
  - t: " " # say nothing -- placeholder

- name: default
  tag: mrow
  match: "."
  replace:
  - insert:
      nodes: "*"
      replace: [{pause: auto}]

- name: default
  tag: [mi, mn, mo, mtext]
  match: "."
  replace:
  - bookmark: "@id"
  - x: "text()"

- name: default
  tag: ms
  match: "."
  replace:
  - t: "the string"
  - pause: short
  - x: "text()"

- name: default
  tag: mstyle
  match: "."
  replace: [{x: "*"}]

- name: simple-sub
  tag: particular-value-of
  # invisible comma -- want "x sub 1 1" without "end sub"
  match: "IsNode(*[2], 'simple') or *[2][self::m:mrow][*[2][text()='⁣']]"
  replace:
  - x: "*[1]"
  - test:
      if: "$Verbosity!='Terse' or not(*[2][self::m:mn])" # just say "x 1" for terse vs "x sub 1"
      then: [{t: "sub"}]
  - x: "*[2]"

- name: default
  tag: particular-value-of
  match: "."
  replace:
  - x: "*[1]"
  - t: "sub"
  - x: "*[2]"
  - t: "end sub"
  - pause: short

- name: default
  tag: msubsup
  match: "."
  replace:
  - x: "*[1]"
  - t: sub
  - x: "*[2]"
  - t: "raised to the"
  - x: "*[3]"
  - t: power
- name: default
  tag: munder
  match: "."
  replace:
  - test:
      if: "not(IsNode(*[1], 'simple'))"
      then: [{t: "modified"}]
  - x: "*[1]"
  - t: "with"
  - x: "*[2]"
  - t: below

- name: default
  tag: mover
  match: "."
  replace:
  - test:
      if: "not(IsNode(*[1], 'simple'))"
      then: [{t: "modified"}]
  - x: "*[1]"
  - t: "with"
  - x: "*[2]"
  - t: "above"

- name: default
  tag: munderover
  match: "."
  replace:
  - test:
      if: "not(IsNode(*[1], 'simple'))"
      then: [{t: "modified"}]
  - x: "*[1]"
  - t: "with"
  - x: "*[2]"
  - t: "below and"
  - x: "*[3]"
  - t: "above"

- name: default
  #   Here we support up to 2 prescripts and up to 4 postscripts -- that should cover all reasonable cases
  #   If there are more, we just dump them out without regard to sup/super :-(
  # FIX: this could use more special cases 
  # There is (currently) no way in MathCAT to deal with n-ary arguments other than "all" ('*') or an individual entry ('*[1]').
  tag: mmultiscripts
  match: "."
  variables:
  # computing the number of postscripts is messy because of <mprescripts> being optionally present -- we use "mod" to get the count right
  - Prescripts: "m:mprescripts/following-sibling::*"
  - NumChildren: "count(*)" # need to stash this since the count is wrong inside '*[...]' below
  - Postscripts: "*[position()>1 and position() < (last() + ($NumChildren mod 2) -count($Prescripts))]"
  replace:
  - x: "*[1]"
  - test:
      if: "$Prescripts" # more common case
      then:
      - with:
          variables:
          - PreSubscript: "IfThenElse($Verbosity='Verbose', 'pre-subscript', 'pre-sub')"
          - PreSuperscript: "IfThenElse($Verbosity='Verbose', 'pre-superscript', 'pre-super')"
          replace:
          - test: # only bother announcing if there is more than one prescript
              if: "count($Prescripts) > 2"
              then:
              - t: "with"
              - x: "count($Prescripts) div 2"
              - t: "prescripts"
              - pause: short
          - test:
              if: "not($Prescripts[1][self::m:none])"
              then:
              - x: "$PreSubscript"
              - x: "$Prescripts[1]"
          - test:
              if: "not($Prescripts[1][self::m:none] or $Prescripts[2][self::m:none])"
              then: [{t: "and"}]
          - test:
              if: "not($Prescripts[2][self::m:none])"
              then:
              - x: "$PreSuperscript"
              - x: "$Prescripts[2]"
          - pause: short
          - test:
              if: "count($Prescripts) > 2" # more common case
              then:
              - test:
                  if: "not($Prescripts[3][self::m:none])"
                  then:
                  - x: "$PreSubscript"
                  - x: "$Prescripts[3]"
              - test:
                  if: "not($Prescripts[3][self::m:none] or $Prescripts[4][self::m:none])"
                  then: [{t: "and"}]
              - test:
                  if: "not($Prescripts[4][self::m:none])"
                  then:
                  - x: "$PreSuperscript"
                  - x: "$Prescripts[4]"
              - test:
                  if: "count($Prescripts) > 4" # give up and just dump them out so at least the content is there
                  then:
                  - t: "and alternating prescripts"
                  - x: "$Prescripts[position() > 4]"
                  - t: "end prescripts"
  - test:
      if: "$Postscripts"
      then:
      - with:
          variables:
          - PostSubscript: "IfThenElse($Verbosity='Verbose', 'subscript', 'sub')"
          - PostSuperscript: "IfThenElse($Verbosity='Verbose', 'superscript', 'super')"
          replace:
          - test: # only bother announcing if there is more than one postscript
              if: "count($Postscripts) > 2"
              then:
              - test:
                  if: "$Prescripts"
                  then: [{t: "and"}]
              - t: "with"
              - x: "count($Postscripts) div 2"
              - t: "postscripts"
              - pause: short
          - test:
              if: "not($Postscripts[1][self::m:none])"
              then:
              - x: "$PostSubscript"
              - x: "$Postscripts[1]"
          - test:
              if: "not($Postscripts[1][self::m:none] or $Postscripts[2][self::m:none])"
              then: [{t: "and"}]
          - test:
              if: "not($Postscripts[2][self::m:none])"
              then:
              - x: "$PostSuperscript"
              - x: "$Postscripts[2]"
          - test:
              if: "count($Postscripts) > 2"
              then:
              - test:
                  if: "not($Postscripts[3][self::m:none])"
                  then:
                  - x: "$PostSubscript"
                  - x: "$Postscripts[3]"
              - test:
                  if: "not($Postscripts[3][self::m:none] or $Postscripts[4][self::m:none])"
                  then: [{t: "and"}]
              - test:
                  if: "not($Postscripts[4][self::m:none])"
                  then:
                  - x: "$PostSuperscript"
                  - x: "$Postscripts[4]"
              - test:
                  if: "count($Postscripts) > 4"
                  then:
                  - test:
                      if: "not($Postscripts[5][self::m:none])"
                      then:
                      - x: "$PostSubscript"
                      - x: "$Postscripts[5]"
                  - test:
                      if: "not($Postscripts[5][self::m:none] or $Postscripts[6][self::m:none])"
                      then: [{t: "and"}]
                  - test:
                      if: "not($Postscripts[6][self::m:none])"
                      then:
                      - x: "$PostSuperscript"
                      - x: "$Postscripts[6]"
                  - test:
                      if: "count($Postscripts) > 6"
                      then:
                      - test:
                          if: "not($Postscripts[7][self::m:none])"
                          then:
                          - x: "$PostSubscript"
                          - x: "$Postscripts[7]"
                      - test:
                          if: "not($Postscripts[7][self::m:none] or $Postscripts[8][self::m:none])"
                          then: [{t: "and"}]
                      - test:
                          if: "not($Postscripts[8][self::m:none])"
                          then:
                          - x: "$PostSuperscript"
                          - x: "$Postscripts[8]"
                      - test:
                          if: "count($Postscripts) > 8" # give up and just dump them out so at least the content is there
                          then:
                          - t: "and alternating scripts"
                          - x: "$Postscripts[position() > 8]"
                          - t: "end scripts"

- name: default
  tag: mtable
  variables: [{IsColumnSilent: false()}]
  match: "."
  replace:
  - t: "table with"
  - x: count(*)
  - test:
      if: count(*)=1
      then: {t: "row"}
      else: {t: "rows"}
  - t: and
  - x: "count(*[1]/*)"
  - test:
      if: "count(*[1]/*)=1"
      then: {t: "column"}
      else: {t: "columns"}
  - pause: long
  - x: "*"

- name: default
  # callers/context should do that.
  # this may get called from navigation -- in that case, there is no context to speak the row #, so don't do it
  tag: mtr
  match: "."
  replace:
  - x: "*"

- name: default
  tag: mtd
  match: "."
  replace:
  - t: "column"
  - x: "count(preceding-sibling::*)+1"
  - pause: medium
  - x: "*" # speak the entry
  - pause: long

- name: default
  # The ordering below is the order in which words come out when there is more than one value
  # Note: @notation can contain more than one value
  tag: menclose
  match: "."
  replace:
  - test:
      if: ".[contains(concat(' ', normalize-space(@notation), ' '), ' box ')]"
      then: [{t: box}, {pause: short}]
  - test:
      if: ".[contains(@notation,'roundedbox')]"
      then: [{t: round box}, {pause: short}]
  - test:
      if: ".[contains(@notation,'circle')]"
      then: [{t: circle}, {pause: short}]
  - test:
      if: ".[ contains(concat(' ', normalize-space(@notation), ' '), ' left ') or contains(concat(' ', normalize-space(@notation), ' '), ' right ') or contains(@notation,'top') or contains(@notation,'bottom') ]"
      then:
      - t: line on
      - test:
          if: ".[contains(concat(' ', normalize-space(@notation), ' '), ' left ')]"
          then: [{t: left}, {pause: short}]
      - test:
          if: ".[contains(concat(' ', normalize-space(@notation), ' '), ' right ')]"
          then: [{t: right}, {pause: short}]
      - test:
          if: ".[contains(@notation,'top')]"
          then: [{t: top}, {pause: short}]
      - test:
          if: ".[contains(@notation,'bottom')]"
          then: [{t: bottom}, {pause: short}]
  - test:
      if: ".[ contains(@notation,'updiagonalstrike') or contains(@notation,'downdiagonalstrike') or contains(@notation,'verticalstrike') or contains(@notation,'horizontalstrike') ]"
      then:
      - test:
          if: ".[contains(@notation,'updiagonalstrike') and contains(@notation,'downdiagonalstrike')]"
          then: [{spell: "'x'"}, {pause: short}] # seems better to say 'x cross out' than 'up diagonal, down diagonal cross out'
          else:
          - test:
              if: ".[contains(@notation,'updiagonalstrike')]"
              then: [{t: up diagonal}, {pause: short}]
          - test:
              if: ".[contains(@notation,'downdiagonalstrike')]"
              then: [{t: down diagonal}, {pause: short}]
      - test:
          if: ".[contains(@notation,'verticalstrike')]"
          then: [{t: vertical}, {pause: short}]
      - test:
          if: ".[contains(@notation,'horizontalstrike')]"
          then: [{t: horizontal}, {pause: short}]
      - t: cross out
      - pause: short
  - test:
      if: ".[contains(@notation,'uparrow')]"
      then: [{t: up arrow}, {pause: short}]
  - test:
      if: ".[contains(concat(' ', normalize-space(@notation), ' '), ' downarrow ')]"
      then: [{t: down arrow}, {pause: short}]
  - test:
      if: ".[contains(@notation,'leftarrow')]"
      then: [{t: left arrow}, {pause: short}]
  - test:
      if: ".[contains(concat(' ', normalize-space(@notation), ' '), ' rightarrow ')]"
      then: [{t: right arrow}, {pause: short}]
  - test:
      if: ".[contains(@notation,'northeastarrow')]"
      then: [{t: northeast arrow}, {pause: short}]
  - test:
      if: ".[contains(concat(' ', normalize-space(@notation), ' '), ' southeastarrow ')]"
      then: [{t: southeast arrow}, {pause: short}]
  - test:
      if: ".[contains(concat(' ', normalize-space(@notation), ' '), ' southwestarrow ')]"
      then: [{t: southwest arrow}, {pause: short}]
  - test:
      if: ".[contains(@notation,'northwestarrow')]"
      then: [{t: northwest arrow}, {pause: short}]
  - test:
      if: ".[contains(@notation,'updownarrow')]"
      then: [{t: double ended vertical arrow}, {pause: short}]
  - test:
      if: ".[contains(@notation,'leftrightarrow')]"
      then: [{t: double ended horizontal arrow}, {pause: short}]
  - test:
      if: ".[contains(@notation,'northeastsouthwestarrow')]"
      then: [{t: double ended up diagonal arrow}, {pause: short}]
  - test:
      if: ".[contains(@notation,'northwestsoutheastarrow')]"
      then: [{t: double ended down diagonal arrow}, {pause: short}]
  - test:
      if: ".[contains(@notation,'actuarial')]"
      then: [{t: actuarial symbol}, {pause: short}]
  - test:
      if: ".[contains(@notation,'madrub')]"
      then: [{t: arabic factorial symbol}, {pause: short}]
  - test:
      if: ".[contains(@notation,'phasorangle')]"
      then: [{t: phasor angle}, {pause: short}]
  - test:
      if: ".[contains(@notation,'longdiv') or not(@notation) or normalize-space(@notation) ='']" # default
      then: [{t: long division symbol}, {pause: short}]
  - test:
      if: ".[contains(@notation,'radical')]"
      then: [{t: square root}, {pause: short}]
  - t: enclosing
  - x: "*"
  - test:
      if: "$Impairment = 'Blindness' and ( $SpeechStyle != 'SimpleSpeak' or not(IsNode(*[1], 'leaf')) )"
      then: [{t: end enclosure}]
  - pause: short

- name: semantics
  tag: "semantics"
  match: "*[@encoding='MathML-Presentation']"
  replace:
  - x: "*[@encoding='MathML-Presentation']/*[1]"

- name: semantics-default
  tag: "semantics"
  match: .
  replace:
  - x: "*[1]"

- name: default-text
  # unknown leaf -- just speak the text -- could be a literal intent
  tag: "literal"
  match: "."
  replace:
  - x: "translate(text(), '-_.', ' ')"
- name: default-children
  # uncaught intent -- speak as foo of arg1 comma arg2 ....
  tag: "*"
  match: count(*)>0
  replace:
  - x: "translate(name(.), '-', ' ')"
  - t: "of"
  - pause: short
  - insert:
      nodes: "*"
      replace: [{t: "comma"}, {pause: auto}]

- name: default-text
  # unknown leaf -- just speak the text -- could be a literal intent
  tag: "*"
  match: "."
  replace:
  - x: "translate(name(), '-', ' ')"