w3c / mathml-core

MathML Core draft
https://w3c.github.io/mathml-core
36 stars 14 forks source link

Interpretation of spaceAfterScript for mmultiscripts's prescripts #217

Open fred-wang opened 8 months ago

fred-wang commented 8 months ago

I stumbled on some interop issue while exporting tests from Gecko.

From https://learn.microsoft.com/en-us/typography/opentype/spec/math:

spaceAfterScript Extra white space to be added after each subscript and superscript. Suggested: 0.5 pt for a 12 pt font. (Note that, in some math layout implementations, a constant value, such as 0.5 pt, may be used for all text sizes. Some implementations may use a constant ratio of text size, such as 1/24 of em.)

MathML Core and Chromium places the space before each prescript at https://w3c.github.io/mathml-core/#base-with-prescripts-and-postscripts:

For each subscript/superscript pair of mmultiscripts prescripts: Increment inline-offset by SpaceAfterScript. ...

But Firefox seems to do it the other way around, i.e. place the space after each prescript.

So the former option makes the rendering more symmetric with respect to the base, but the latter makes it more consistent with the parameter name.

Since we have space between scripts anyway, the significant difference is that the former adds a space between the leftmost scripts (assuming LTR) and the content before ; and the latter adds a space between the base and its closest prescripts.

fred-wang commented 8 months ago

Tentative test: unfortunately, scripts-spaceafterscript3000.woff cannot be access due to CORS policy. It seems chromium badly computes the inline size of mmultitscripts BTW.

<!DOCTYPE html>
<style>
  math {
    font: 50px spaceafterscript3000;
  }
  mspace {
      background: black
  }
  mmultiscripts {
      background: gray;
  }
  @font-face {
    font-family: spaceafterscript3000;
    src: url("http://wpt.live/fonts/math/scripts-spaceafterscript3000.woff");
  }
</style>
<math>
  <mmultiscripts>
    <mspace width="1em" height="1em" depth="1em"/>
    <mspace width="1em" height="1em" depth="1em"/>
    <mspace width="2em" height="1em" depth="1em"/>
    <mspace width="3em" height="1em" depth="1em"/>
    <mspace width="4em" height="1em" depth="1em"/>
    <mprescripts/>
    <mspace width="1em" height="1em" depth="1em"/>
    <mspace width="2em" height="1em" depth="1em"/>
    <mspace width="3em" height="1em" depth="1em"/>
    <mspace width="4em" height="1em" depth="1em"/>
  </mmultiscripts>
</math>
NSoiffer commented 8 months ago

I would tend to lean towards symmetry. Do you have any idea what TeX does for the equivalent {}_{sub}_{sup}{base}_{sub}_{sup}?

I'm not completely sure that is right comparison though. The mhchem package for ${}^{238}\text{U}$ does a lot of tweaking for spacing, so maybe that is a better indicator of what is right. It's a mess though:

<math>
        <mrow>
          <msubsup>
            <mrow>
              <mrow>
                <mpadded width='0'>
                  <mphantom>
                    <mi>A</mi>
                  </mphantom>
                </mpadded>
              </mrow>
            </mrow>
            <mrow>
              <mrow>
                <mpadded height='0' depth='0'>
                  <mphantom></mphantom>
                </mpadded>
              </mrow>
            </mrow>
            <mrow>
              <mrow>
                <mpadded height='0' depth='0'>
                  <mphantom>
                    <mn>238</mn>
                  </mphantom>
                </mpadded>
              </mrow>
            </mrow>
          </msubsup>
          <mspace width='-0.083em' linebreak='nobreak'></mspace>
          <msubsup>
            <mrow>
              <mrow>
                <mpadded width='0'>
                  <mphantom>
                    <mi>A</mi>
                  </mphantom>
                </mpadded>
              </mrow>
            </mrow>
            <mrow>
              <mrow>
                <mpadded width='0'>
                  <mphantom>
                    <mn>2</mn>
                  </mphantom>
                </mpadded>
              </mrow>
              <mrow>
                <mpadded width='0' lspace='-1width'>
                  <mrow>
                    <mpadded height='0'></mpadded>
                  </mrow>
                </mpadded>
              </mrow>
            </mrow>
            <mrow>
              <mrow>
                <mpadded height='0'>
                  <mrow>
                    <mpadded width='0'>
                      <mphantom>
                        <mn>2</mn>
                      </mphantom>
                    </mpadded>
                  </mrow>
                </mpadded>
              </mrow>
              <mrow>
                <mpadded width='0' lspace='-1width'>
                  <mn>238</mn>
                </mpadded>
              </mrow>
            </mrow>
          </msubsup>
          <mrow>
            <mi mathvariant='normal'>U</mi>
          </mrow>
        </mrow>
      </math>
dginev commented 8 months ago

So the former option makes the rendering more symmetric with respect to the base, but the latter makes it more consistent with the parameter name.

I guess one can view the symmetric approach to have a reading of "After" that means "AwayFromBase", or "Outer". "After" is a bit of an unfortunate preposition, since it depends on an implied traversal order...

fred-wang commented 8 months ago

I stumbled on some interop issue while exporting tests from Gecko.

For the record this is the == reftest (note: this is using RTL mmultiscript): http://wpt.live/mathml/presentation-markup/direction/direction-overall-003.html http://wpt.live/mathml/presentation-markup/direction/direction-overall-003-ref.html

The results are not available yet, but they should appear at: https://wpt.fyi/results/mathml/presentation-markup/direction/direction-overall-003.html?label=experimental&label=master&aligned

khaledhosny commented 7 months ago

I tested with MS Word, and spaceAfterScript is added before prescripts (the test font uses a large value to make it obvious):

image
khaledhosny commented 7 months ago

I submitted https://github.com/MicrosoftDocs/typography-issues/issues/1135 for clarifying this in OpenType spec.

fred-wang commented 7 months ago

I tested with MS Word, and spaceAfterScript is added before prescripts (the test font uses a large value to make it obvious):

Thanks Khaled, so this would consistent with MathML Core / Chromium. What is your test? It seems there is only one prescript and presubscript, right? Because I only see one gap.

khaledhosny commented 7 months ago

It seems there is only one prescript and presubscript, right?

Yes. Perhaps this screenshot makes it more obvious:

image
fred-wang commented 7 months ago

OK, I was asking because MathML supports multiple sub/sup pairs of prescripts, so we have a more generic use of spaceAfterScript: https://w3c.github.io/mathml-core/#figure-box-mmultiscripts

khaledhosny commented 7 months ago

I don’t think Microsoft Word support multiple pairs on either side.

fred-wang commented 1 week ago

@khaledhosny So IIUC the conclusion is that the space should be added before pre-scripts (and after post-scripts) so the "symmetric" approach by Chromium, not the "always-after-scripts" approach by Firefox.

khaledhosny commented 1 week ago

Yes. The spec text was also updated to make this more explicit:

Extra white space to be added after each subscript and superscript that occurs after a baseline element, and before each subscript and superscript that occurs before a baseline element.