Skip to content

Don't assume "fill in the blank" for spacing around mtext #468

@NSoiffer

Description

@NSoiffer

I found the following in a TeX translation from a textbook. The author was trying to add a lot of space around the word "or", but the Nemeth turned this into "fill in the blank". That happens for UEB and maybe other braille codes.

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
  <mstyle displaystyle="true" scriptlevel="0">
    <mfrac>
      <mn>1</mn>
      <mn>2</mn>
    </mfrac>
  </mstyle>
  <mo stretchy="false">(</mo>
  <mi>p</mi>
  <mo>+</mo>
  <mi>q</mi>
  <mo stretchy="false">)</mo>
  <mtext>&#xA0;</mtext>
  <mtext>&#xA0;</mtext>
  <mtext>&#xA0;</mtext>
  <mtext>&#xA0;</mtext>
  <mtext>or</mtext>
  <mtext>&#xA0;</mtext>
  <mtext>&#xA0;</mtext>
  <mtext>&#xA0;</mtext>
  <mtext>&#xA0;</mtext>
  <mstyle displaystyle="true" scriptlevel="0">
    <mfrac>
      <mrow>
        <mi>p</mi>
        <mo>+</mo>
        <mi>q</mi>
      </mrow>
      <mn>2</mn>
    </mfrac>
  </mstyle>
</math>

MathCAT canonicalizes that by collapsing the spaces:

 <math display='block'>
  <mrow data-changed='added'>
    <mfrac displaystyle='true' scriptlevel='0'>
      <mn>1</mn>
      <mn>2</mn>
    </mfrac>
    <mo data-changed='added'>&#x2062;</mo>
    <mrow data-changed='added'>
      <mo stretchy='false'>(</mo>
      <mrow data-changed='added'>
        <mi>p</mi>
        <mo>+</mo>
        <mi>q</mi>
      </mrow>
      <mo stretchy='false'>)</mo>
    </mrow>
    <mo data-changed='added'>&#x2062;</mo>
    <mtext data-previous-space-width='2.800'>or</mtext>
    <mo data-changed='added'>&#x2062;</mo>
    <mfrac displaystyle='true' scriptlevel='0' data-previous-space-width='2.800'>
      <mrow>
        <mi>p</mi>
        <mo>+</mo>
        <mi>q</mi>
      </mrow>
      <mn>2</mn>
    </mfrac>
  </mrow>
 </math>

Ignoring the preceding space is easy because data-previous-space-width is added to an mtext. Catching the following spaces is a little trickier.

A similar problem happens with leading a trailing spaces that the textbook also uses:

<math>
  <mtext> </mtext><mtext> </mtext><mi>x</mi><mtext> </mtext><mtext> </mtext>
</math>

This canonicalizes to:

<math>
  <mi data-previous-space-width='1.400' data-following-space-width='1.400'>x</mi>
</math>

Here are some larger examples with spaces at the start or at the end

<math><mtext> </mtext><mtext> </mtext><mn>2</mn><mo>+</mo><mi>x</mi></math>

which goes to

 <math>
  <mrow data-changed='added'>
    <mrow data-changed='added'>
      <mn data-previous-space-width='1.400'>2</mn>
      <mo>+</mo>
      <mi>x</mi>
    </mrow>
    <mo>?</mo>
  </mrow>
 </math>

At the end:

<math><msup><mi>x</mi><mn>2</mn></msup><mo>+</mo><mn>9</mn><mtext> </mtext><mtext> </mtext><mtext> </mtext><mtext> </mtext><mtext> </mtext></math>

which goes to

 <math display='block'>
  <mrow data-changed='added'>
    <msup>
      <mi>x</mi>
      <mn>2</mn>
    </msup>
    <mo>+</mo>
    <mn data-following-space-width='3.500'>9</mn>
  </mrow>
 </math>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions