-
Notifications
You must be signed in to change notification settings - Fork 22.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add text-transform: math-auto #35540
Conversation
Preview URLs External URLs (1)URL:
(comment last updated: 2024-09-11 19:40:33) |
https://drafts.csswg.org/css-text/#intro But according to the full text of the specification there is no mention of this option so I want to know what is going on Or do I need to remove this option |
This comment was marked as resolved.
This comment was marked as resolved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is in CSS text level 4: https://drafts.csswg.org/css-text-4/#text-transform-property We need to update the spec link in BCD too. According to the compat data, math-auto
is already supported, so we indeed should document this, which means adding this to the values list below, and one example of how it may be used. Do you want to do that?
When I said "examples" I meant an example on this page, but interactive examples are of course welcome :) Could you update the values list right below this code too? And an example section. |
I'm not confident that I can guarantee that the addition to the example will be appropriate |
Maybe check https://w3c.github.io/mathml-core/#new-text-transform-values? The idea is to map normal ASCII letters to math italic characters. |
i can't |
I originally conceived of the following example: <div>
(sin <span>x</span>)<sup>2</sup> + (cos <span>x</span>)<sup>2</sup> = 1
</div> div {
text-transform: math-auto;
} But in fact, using proper MathML markup, we get the same result out of the box: <math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
<semantics>
<mrow>
<mo stretchy="false">(</mo>
<mo lspace="0em" rspace="0em">sin</mo>
<mspace width="0.16666666666666666em"></mspace>
<mi>x</mi>
<msup>
<mo stretchy="false">)</mo>
<mn>2</mn>
</msup>
<mo>+</mo>
<mo stretchy="false">(</mo>
<mo lspace="0em" rspace="0em">cos</mo>
<mspace width="0.16666666666666666em"></mspace>
<mi>x</mi>
<msup>
<mo stretchy="false">)</mo>
<mn>2</mn>
</msup>
<mo>=</mo>
<mn>1</mn>
</mrow>
<annotation encoding="TeX">(\sin\,x)^2+(\cos\,x)^2=1</annotation>
</semantics>
</math> @fred-wang What is the intended use case of |
@Josh-Cena This italicization is something defined in MathML 3, when we wrote MathML Core it was suggested to expose the internal magic, so this is essentially what this CSS text-transform value is doing. I imagine, this could be used for italicization in math markup using HTML markup only, or to easily cancel italicization on single-char mi, but not sure these are strong use cases. |
Yes, I imagined that this was implemented only so that MathML rendering can reuse CSS machinery, but it seems there's no real use case that can't be solved using MathML natively? |
@Josh-Cena right, I'm not really aware of other use cases. |
I've added some description and an example based on my understanding. @fred-wang Could you review? Thanks! |
@@ -65,6 +65,9 @@ text-transform: unset; | |||
- : Is a keyword that forces the writing of a character — mainly ideograms and Latin scripts — inside a square, allowing them to be aligned in the usual East Asian scripts (like Chinese or Japanese). | |||
- `full-size-kana` | |||
- : Generally used for {{htmlelement("ruby")}} annotation text, the keyword converts all small Kana characters to the equivalent full-size Kana, to compensate for legibility issues at the small font sizes typically used in ruby. | |||
- `math-auto` | |||
- : Used to automatically render text in math italic where appropriate. It transforms ASCII and Greek letters to [italic mathematical symbols](https://www.unicode.org/charts/PDF/U1D400.pdf) but only if it's applied on a text node containing a single character. For example, "x" will become "𝑥" (U+1D465), but "exp" will stay as "exp". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just FYI, as I think it does not matter much for MDN but the exact set of characters that are transformed is https://w3c.github.io/mathml-core/#italic-mappings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did read that table and it looked like it's just Latin/Greek (+some variants like partial derivatives, variant greek, and dotless i/j), so I figured I could just handwave here.
text-transform: math-auto; | ||
} | ||
``` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine, but I would use a .math-identifier
identifier so we can more accurately tag math identifiers:
<span class="math-identifier">sin</span>
etc
In your example, browsers would actually try to perform the transform on any text node, not just math identifiers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My goal is to show that math-auto
is "smart" and only does the transform where necessary—otherwise why would we apply math-identifier
to sin
at all, when it would have no other semantic significance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Going to merge this :) Thanks @fred-wang for the review
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Description
Motivation
It's mentioned below but it's not here so I think it's missing
Additional details
Related issues and pull requests