Skip to content
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

Merged
merged 5 commits into from
Sep 11, 2024
Merged

Add text-transform: math-auto #35540

merged 5 commits into from
Sep 11, 2024

Conversation

zhangenming
Copy link
Contributor

Description

Motivation

It's mentioned below but it's not here so I think it's missing

Additional details

Related issues and pull requests

@zhangenming zhangenming requested a review from a team as a code owner August 21, 2024 02:57
@zhangenming zhangenming requested review from estelle and removed request for a team August 21, 2024 02:57
@github-actions github-actions bot added Content:CSS Cascading Style Sheets docs size/xs [PR only] 0-5 LoC changed labels Aug 21, 2024
Copy link
Contributor

github-actions bot commented Aug 21, 2024

Preview URLs

External URLs (1)

URL: /en-US/docs/Web/CSS/text-transform
Title: text-transform

(comment last updated: 2024-09-11 19:40:33)

@zhangenming
Copy link
Contributor Author

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
thanks

Or do I need to remove this option

@zhangenming

This comment was marked as resolved.

Copy link
Member

@Josh-Cena Josh-Cena left a 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?

@Josh-Cena
Copy link
Member

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.

@zhangenming
Copy link
Contributor Author

I'm not confident that I can guarantee that the addition to the example will be appropriate

@Josh-Cena
Copy link
Member

Maybe check https://w3c.github.io/mathml-core/#new-text-transform-values? The idea is to map normal ASCII letters to math italic characters.

@zhangenming
Copy link
Contributor Author

i can't
Not sure what to do
need more help

@Josh-Cena
Copy link
Member

I originally conceived of the following example:

<div>
  (sin&hairsp;<span>x</span>)<sup>2</sup> + (cos&hairsp;<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 text-transform: math-auto, outside of being able to specify mi?

@Josh-Cena Josh-Cena changed the title Fill the missing options, from Formal syntax below Add text-transform: math-auto Aug 22, 2024
@estelle estelle removed their request for review August 23, 2024 22:46
@fred-wang
Copy link
Contributor

@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.

@Josh-Cena
Copy link
Member

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?

@fred-wang
Copy link
Contributor

@Josh-Cena right, I'm not really aware of other use cases.

@Josh-Cena
Copy link
Member

I've added some description and an example based on my understanding. @fred-wang Could you review? Thanks!

@github-actions github-actions bot added size/m [PR only] 51-500 LoC changed and removed size/xs [PR only] 0-5 LoC changed labels Sep 2, 2024
@@ -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".
Copy link
Contributor

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

Copy link
Member

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;
}
```

Copy link
Contributor

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.

Copy link
Member

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?

Copy link
Member

@Josh-Cena Josh-Cena left a 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>
@Josh-Cena Josh-Cena merged commit dad91b2 into mdn:main Sep 11, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:CSS Cascading Style Sheets docs size/m [PR only] 51-500 LoC changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants