🌐 US-Proxy
class="logged-out env-production page-responsive" style="word-wrap: break-word;" >
Skip to content

Supporting calc(100% + 0.333em) in the width attribute of <mpadded> #306

Open

Description

@tmke8

<mpadded> is only really useful for horizontal spacing when it's possible to add something to the width. For example, if one sets lspace on <mpadded> but does not change the width, then the lspace eats into the width of the content.

MathML 3 had the width="+0.333em" notation for this (with + as the prefix) but this was apparently replaced by a new notation in MathML 4, see this example:

<mrow>
  <mi>x</mi>
  <mpadded lspace="0.3em" width="calc(100% +0.6em)">
    <mi>y</mi>
  </mpadded>
  <mi>z</mi>
</mrow>

The problem for MathML Core here is that the 100% here refers to the width of the child, and not to the width of the parent, as is the case in CSS.

But there is actually a solution in CSS, with the newly proposed calc-size function. The following actually works correctly in Chrome (which is the only browser currently implementing calc-size):

<math display="block">
  <mi>x</mi>
  <mpadded lspace="0.16667em" style="width: calc-size(min-content, size + 0.33333em)">
    <mi>sin</mi>
  </mpadded>
  <mi>θ</mi>
</math>

So, I think the spec should be either changed so that:

  1. width on <mpadded> accepts any CSS value (currently only allows length-percentage), so that the new calc-size() can be used there
  2. support for calc(100% + 0.333em) is explicitly hard-coded in the spec and is internally translated to calc-size()
  3. (as David says below) width accepts calc-size() in addition to length-percentage

Activity

  1. davidcarlisle commented on Jan 6, 2026

    @davidcarlisle
    Collaborator

    Thanks for this, It means that the example in the MathM4 draft is wrong (and I just confirmed it is as you say) so we should change that to use calc-size (probably with a warning that it's not generally implemented) I'm a bit confused as it's been in the draft for quite a while I'm sure we tested that at the time, but perhaps we were confused by the implementation status.

    so the question would be whether we should allow length-percentage or calc-size everywhere that we currently allow length-percentage or just on mpadded (doing it for all length attributes seems more consistent)

    support for calc(100% + 0.333em) is explicitly hard-coded in the spec and is internally translated to calc-size()

    I'm not sure we need to do that, it seems just to be a spec error (in mathML4 draft) not something that needs to be supported.

  2. dginev commented on Jan 27, 2026

    @dginev
    Member

    During the MathML Core meeting yesterday this issue was discussed and I encountered the percentage widths being ignored in Chromium. I have now reread the related discussion in #183 that motivates that behavior.

    Here is a codepen example of what I witnessed:
    https://codepen.io/dginev/pen/yyJPmBQ

    Writing that in here, since I assume an mpadded width of calc() based on a percentage value will not be well-founded until #183 is resolved in some way.

  3. tmke8 commented on Jan 27, 2026

    @tmke8
    Author

    Writing that in here, since I assume an mpadded width of calc() based on a percentage value will not be well-founded until #183 is resolved in some way.

    Basing it on calc will indeed not work, as I show above in the first example. But, as I wrote after that, it does work when it's based on calc-size(). Your example works then:

    <math>
      <mpadded style="width: calc-size(min-content, 3 * size); height: calc-size(min-content, 3 * size)">
        <mi>x</mi>
      </mpadded>
    </math>
  4. davidcarlisle commented on Jan 27, 2026

    @davidcarlisle
    Collaborator

    @tmke8 yes calc-size works but there was feeling it was too early to suggest that as a general replacement at the current time as its implementation status is uncertain. We can always come back to that,

  5. davidcarlisle commented on Jan 27, 2026

    @davidcarlisle
    Collaborator

    @dginev I missed this during the meeting, but percentages not working for width is actually specified behaviour in core.

    https://www.w3.org/TR/mathml-core/#inner-box-and-requested-parameters

    ... If the width attribute is present, valid and not a percentage then that attribute is used as a presentational hint setting the element's width property to the corresponding value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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