|
174 | 174 | replace: |
175 | 175 | - t: "<⠆" # signal start of fraction (needed for state machine to replace spaces) |
176 | 176 | - test: |
177 | | - # FIX: it seems like this should be more general, but examples break when it is more general |
178 | | - if: "not(IsNode(*[1], 'leaf')) and preceding-sibling::*[1][self::m:mo and (.='-' or .='+')]" |
179 | | - then: [t: "+"] # "+" says to keep the indicator -- need to make sure the "numerator" appears to be in the fraction |
| 177 | + # Keep fraction start (p26 rule 4b): numerator begins with minus, or a unary minus precedes the fraction. |
| 178 | + # Do NOT keep merely because a binary +/- precedes the fraction (p28_3 omits start after binary minus). |
| 179 | + if: "(*[1][self::m:mo and .='-'] or *[1][self::m:mrow][*[1][self::m:mo and .='-']]) or |
| 180 | + (preceding-sibling::*[1][self::m:mo and .='-'] and not(preceding-sibling::*[2]))" |
| 181 | + then: [t: "+"] # "+" says to keep the indicator |
180 | 182 | - x: "*[1]" |
181 | 183 | - t: "W/" |
182 | 184 | - test: |
|
476 | 478 | - x: "*[1]" |
477 | 479 | - T: "⠆⠆" |
478 | 480 |
|
| 481 | +- |
| 482 | + # empty-base msup of primes (from MathML like <msup><mrow/><mo>″</mo></msup>); |
| 483 | + # skip the empty base so we don't emit W/⠈ before the primes |
| 484 | + name: prime-exception |
| 485 | + tag: msup |
| 486 | + match: "*[2][translate(., \"′″‴⁗\",'')=''] and translate(*[1], '\u00A0','')=''" |
| 487 | + replace: |
| 488 | + - x: "*[2]" |
| 489 | + |
479 | 490 | - |
480 | 491 | name: diacriticals |
481 | 492 | tag: [mover, msup] |
|
515 | 526 | - x: "*[2]" |
516 | 527 |
|
517 | 528 | - |
518 | | - name: prime-exception # 4.3.1 |
| 529 | + # 4.3.1 / p35: primes with subscript — either primes first, or reverse order |
| 530 | + # (primes after the subscript) which requires keeping the simple close ⠱. |
| 531 | + # NBSP may remain in *[3]'s string-value from canonicalize of an empty-base nested msup. |
| 532 | + name: prime-exception |
519 | 533 | tag: msubsup |
520 | | - match: "*[3][translate(., \"′″‴⁗\",'')='']" |
| 534 | + match: "translate(*[3], \"′″‴⁗\u00A0\",'')=''" |
521 | 535 | replace: |
522 | 536 | - x: "*[1]" |
523 | 537 | - test: |
524 | | - if: "*[2][self::m:mn and translate(., '0123456789', '') = '']" |
525 | | - then: |
526 | | - - t: "<⠡" |
527 | | - - x: "BrailleChars(translate(*[2], '0123456789', '\ue000\ue001\ue002\ue003\ue004\ue005\ue006\ue007\ue008\ue009'), 'Polish')" |
528 | | - - t: ">⠱+" |
529 | | - - x: "*[3]" |
530 | | - else: |
531 | | - - x: "*[3]" |
532 | | - - t: "<⠡" |
533 | | - - x: "*[2]" |
534 | | - - t: ">⠱" |
| 538 | + - if: "*[2][self::m:mn and translate(., '0123456789', '') = '']" |
| 539 | + then: |
| 540 | + - t: "<⠡" |
| 541 | + - x: "BrailleChars(translate(*[2], '0123456789', '\ue000\ue001\ue002\ue003\ue004\ue005\ue006\ue007\ue008\ue009'), 'Polish')" |
| 542 | + - t: ">⠱+" |
| 543 | + - x: "*[3]" |
| 544 | + # reverse order for compound subscripts (e.g. x_{n+1}″) |
| 545 | + - else_if: "*[2][self::m:mrow or not(IsNode(., 'leaf'))]" |
| 546 | + then: |
| 547 | + - t: "<⠡" |
| 548 | + - x: "*[2]" |
| 549 | + - t: ">⠱+" |
| 550 | + - x: "*[3]" |
| 551 | + else: |
| 552 | + # primes first (e.g. a″_n) |
| 553 | + - x: "*[3]" |
| 554 | + - t: "<⠡" |
| 555 | + - x: "*[2]" |
| 556 | + - t: ">⠱" |
535 | 557 |
|
536 | 558 | - |
537 | 559 | name: log-with-base |
|
615 | 637 |
|
616 | 638 | - |
617 | 639 | # scripts |
618 | | - # for some reason, the spec reverses the order of sub and sup for cap letters that are not chemistry |
| 640 | + # for some reason, the spec reverses the order of sub and sup for cap letters C (combinatorics) and V (???) that are not chemistry |
619 | 641 | name: cap-letter-scripts |
620 | 642 | tag: msubsup |
621 | | - match: "not(@data-chem-element) and BaseNode(*[1])[translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', '') = '']" |
| 643 | + match: "not(@data-chem-element) and BaseNode(*[1])[.='C' or .='V']" |
622 | 644 | # the examples all use superscripts, not exponents for cap letters these (for example p39 and p55) |
623 | 645 | # also, for some reason, the cap letters use superscripts first |
624 | 646 | replace: |
|
652 | 674 | # the examples all use superscripts, not exponents for cap letters these (for example p39 and p55) |
653 | 675 | # also, for some reason, the cap letters use superscripts first |
654 | 676 | variables: |
655 | | - - IsCapLetter: "BaseNode(*[1])[translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', '') = '']" |
656 | | - - BaseNeedsSuperscript: "self::m:msubsup and (BaseNode(*[1])[self::m:mo or .='lim' or $IsCapLetter] or parent::m:mrow[parent::m:msup])" |
| 677 | + # ⠌ (superscript) vs ⠬ (exponent): |
| 678 | + # - mo/'lim' bases always use superscript |
| 679 | + # - msubsup nested under an outer msup uses ⠌ for its superscript half (p34_1, p34_4) |
| 680 | + # - plain nested msup (e.g. a^{2^{2k-1}-1}) must stay ⠬ (p33_3) -- do NOT apply the |
| 681 | + # parent::m:mrow[parent::m:msup] clause to self::m:msup |
| 682 | + - BaseNeedsSuperscript: "(self::m:msup and BaseNode(*[1])[self::m:mo or .='lim']) or |
| 683 | + (self::m:msubsup and (BaseNode(*[1])[self::m:mo or .='lim'] or parent::m:mrow[parent::m:msup]))" |
657 | 684 | replace: |
658 | 685 | - x: "*[1]" |
659 | 686 | - test: |
|
0 commit comments