Skip to content

Deprecate/Remove mathvariant attributes #77

Closed

Description

@fred-wang

I'm opening this for the record as that was discussed in previous meetings.

Basically, some people think this attribute is not very useful as one can just use the equivalent transformed unicode characters. It was designed a long time ago to work around issues with non-BMP characters.

Others mentioned that modern LaTeX engines just perform the character transform and only allow to use commands like \mathfrak for text (i.e. \mathfrak{a} but not \mathfrak{\frac{a}{b}}). (note: my version of XeLaTeX still seem to support \mathfrak{\frac{a}{b}}) so we could somewhat restrict mathvariant to token elements.

I suspect mathvariant is still quite popular in tools / existing content. Trying \mathfrak{\frac{a}{b}}) on LaTeXML, Mathoid/Wikipedia and TeXZilla, the first uses transformed characters, the second mathvariant on mi elements, the third mathvariant on mstyle element.

The consensus was to try to make it part of CSS's text-transform:
https://lists.w3.org/Archives/Public/public-mathml4/2019Mar/0007.html
See also #31 #1

Activity

  1. added
    MathML Core
    MathML 4
    opentype / tex
    compatibility
    on Mar 20, 2019
  2. fred-wang commented on Mar 26, 2019

    @fred-wang
    Author

    First results from #55 suggest that mathvariant is still widely used, so I'm don't think we can remove it and browsers should still support it.

  3. physikerwelt commented on Mar 31, 2019

    @physikerwelt
    Member

    First results from #55 suggest that mathvariant is still widely used, so I'm don't think we can remove it and browsers should still support it.

    Most usage statistics are collections generated from converting TeX to MathML. I think, modifying the converters to output mathml4 instead of mathml3 has to be done anyhow... Thus I think, we should better ask ourselves how much effort would the change in the converter be, rather than how much is a particular element used.

  4. fred-wang commented on Mar 31, 2019

    @fred-wang
    Author

    I agree it is worthwhile to know how much effort it is to update the converter. However
    (1) It's still useful to know if an element/attribute is actually used at all in real page, even when converters have capability to generate it.
    (2) There are other uses than LaTeX to MathML converters (we need more stats for them!).
    (3) Changing the converters will not necessarily automatically update existing content.

    In the case of mathvariant, we have a converter like itex2MML (and its JS clone TeXZilla) which has been there for 20 years. It is a LALR parser generated by bison/flex tools, which makes it extremely fast (compared to other LaTeX to MathML converters) but since it generates the output stream bottom-up you cannot apply the mathvariant transform at the time you output the character. Maybe that can be fixed with some complete refactoring to generate a JSON structure instead of a string (fred-wang/TeXZilla#10) probably at the price of a performance loss. In any case, that does not solve the case of existing content.

    For the browser implementation:
    (1) mathvariant is very similar to CSS text-transform, so it shouldn't be a problem to implement it that way if the CSS WG accepts it.
    (2) The automatic italic feature is necessary anyway, so we would still need to implement some character transformation, even if we remove mathvariant from core.

  5. dani31415 commented on Apr 1, 2019

    @dani31415

    A side effect of text-transform is that when copy and paste as plain text, the content should be the original one and not the transformed according to the CSS specification (w3c/csswg-drafts#627 (comment)). If this is okay, it seems reasonable to use, from my point of view, the text-transform.

  6. bkardell commented on Apr 5, 2019

    @bkardell
    Collaborator

    @dani31415 wellllllllll.... there is a lot here that is written down and a lot that works differently from what is written down and a lot that is being debated for various reasons, so I don't think that this is necessarily a given. See also for example w3c/csswg-drafts#3775, for one of the many open issues here.

  7. fred-wang commented on Apr 14, 2019

    @fred-wang
    Author

    Additional note: we still need mathvariant="normal" to cancel the automatic math italic behavior on single-char mi, so we won't be able to completely get rid of the mathvariant attribute anyway.

  8. fred-wang commented on Apr 26, 2019

    @fred-wang
    Author

    Current proposal:

    1. New text-transform values for math, handled/discussed at the CSS WG.
    2. This implies we should follow whatever the CSS/a11y/implementers decide regarding text copy / accessible tree of text-transforms ([css-text] text-transform's design, intent and reality resolution csswg-drafts#3775):
    • Update the MathML spec accordingly regarding copy of the character. I believe, there is not any clear choice between copying the original or copying the transformed character. When copying the MathML tree, the mathvariant attribute is preserved anyway.
    • Add a note for a11y, saying that it is expected enough information will be exposed to assistive technologies so that they can present the transformed text (hence we don't depend on what the CSS WG decides regarding the exposed character).
    1. Keep mathvariant and automatic italic in MathML Core but specify a native implementation using text-transform:
    • mi { text-transform: math-auto; }
    • Map mathvariant value X to text-transform: math-X;
  9. fred-wang commented on May 16, 2019

    @fred-wang
    Author

    Resolution:

    Specification:

    • N/A

    Implementation:

    • N/A

    Polyfill:

    • N/A

    Tests:

    • N/A
  10. davidcarlisle commented on May 24, 2025

    @davidcarlisle
    Collaborator

    I am re-opening this as the relevant text-transform property was not supported so this requires a polyfill.

  11. 44 remaining items

  12. physikerwelt commented on Jun 26, 2025

    @physikerwelt
    Member

    For comparison, the compressed JSON when transmitted using gzip is 1287 bytes, while https://github.com/MurrayIII/mathml-polyfills/blob/868d65466c1e21966c45e91f52930096a3128443/mathvariant/mathvariant.js#L31C1-L216C3 compresses to 4404 bytes. The uncompressed.js is 9558 characters long and compresses to 4884 bytes.

    uncompressed.json.gz

    original.js.gz

    Note that

    https://github.com/MurrayIII/mathml-polyfills/blob/868d65466c1e21966c45e91f52930096a3128443/mathvariant/mathvariant.js#L282-L299

    compares if all the characters in the original file are contained in the one I generated from the XML. The other way is not checked. I get the impression that the list I generated contains more characters. I think since we don't foresee billions of downloads of the polyfill, I would suggest proceeding with the uncompressed JSON I generated from XML, as it contains all characters, is native to JS, and is only 4kb large. The code to read from this JSON is simple, while loading from the compressed list is more complex. And thus the CO2 developers produce when trying to understand how to uncompress the list might be higher than the CO2 saved by the data transfer.

  13. physikerwelt commented on Jun 26, 2025

    @physikerwelt
    Member

    Please try to use JSON when embedding data directly inside javascript. It simplifies everything, as it is native to the host language.

    When the compressed form is being used, and one decides to generate the uncompressed version in memory, it does not make a difference if it's a string or a JSON object. So I think the proposal of @MurrayIII '0𝟎10' (without the b that I would put into the key) would be best.

    xquery version "3.1";
    let $doc := doc("unicode.xml")
    
    let $out := for $variant in distinct-values($doc//character[surrogate]/surrogate/@mathvariant)
      order by $variant
      return
        <pair name="{$variant}" type="array">{
          
          let $items := for $c
            in $doc//character[surrogate/@mathvariant=$variant]
            order by $c/surrogate/@ref 
            let $unicode := $c/surrogate/@ref
            let $unicode_dec := xs:integer( $doc//character[@id=$unicode]/@dec)
            let $res := xs:integer(($doc//character[@id=$c/bmp/@ref]/@dec,$c/@dec)[1])
            return <item in="{$unicode_dec}" out="{$res}" len="1"/>
            
          let $compressed :=  fold-left($items,(),function($seq,$new){
            let $last :=  $seq[last()]
            let $len := $last/@len
            let $unchanged := $new/@in = $last/@in+$len and
              $new/@out = $last/@out+$len
            return if ($unchanged) then (
              subsequence($seq, 1, count($seq) - 1), <item in="{$last/@in}" out="{$last/@out}" len="{$len+1}"/>
              ) else ( 
              $seq, $new )
              })
            
          return for $i in $compressed return
            <item type="string">
              {codepoints-to-string($i/@in)}
              {codepoints-to-string($i/@out)}
              {if ($i/@len = 1) then ("" ) else ( xs:integer($i/@len))}
            </item>
          }
          </pair>
    
    return json:serialize(
      <json type="object">{$out}</json>,
      {'format': 'attributes', 'indent':'no'})

    Which outputs

    {
      "bold": [
        "0𝟎10",
        "A𝐀26",
        "a𝐚26",
        "Α𝚨17",
        "Σ𝚺7",
        "α𝛂25",
        "ϑ𝛝",
        "ϕ𝛟",
        "ϖ𝛡",
        "Ϝ𝟊2",
        "ϰ𝛞",
        "ϱ𝛠",
        "ϴ𝚹",
        "ϵ𝛜",
        "∂𝛛",
        "∇𝛁"
      ],
      "bold-fraktur": [
        "A𝕬26",
        "a𝖆26"
      ],
      "bold-italic": [
        "A𝑨26",
        "a𝒂26",
        "Α𝜜17",
        "Σ𝜮7",
        "α𝜶25",
        "ϑ𝝑",
        "ϕ𝝓",
        "ϖ𝝕",
        "ϰ𝝒",
        "ϱ𝝔",
        "ϴ𝜭",
        "ϵ𝝐",
        "∂𝝏",
        "∇𝜵"
      ],
      "bold-sans-serif": [
        "0𝟬10",
        "A𝗔26",
        "a𝗮26",
        "Α𝝖17",
        "Σ𝝨7",
        "α𝝰25",
        "ϑ𝞋",
        "ϕ𝞍",
        "ϖ𝞏",
        "ϰ𝞌",
        "ϱ𝞎",
        "ϴ𝝧",
        "ϵ𝞊",
        "∂𝞉",
        "∇𝝯"
      ],
      "bold-script": [
        "A𝓐26",
        "a𝓪26"
      ],
      "double-struck": [
        "0𝟘10",
        "A𝔸2",
        "Cℂ",
        "D𝔻4",
        "Hℍ",
        "I𝕀5",
        "Nℕ",
        "O𝕆",
        "Pℙ2",
        "Rℝ",
        "S𝕊7",
        "Zℤ",
        "a𝕒26",
        "ب𞺡",
        "ت𞺵2",
        "ج𞺢",
        "ح𞺧",
        "خ𞺷",
        "د𞺣",
        "ذ𞺸",
        "ر𞺳",
        "ز𞺦",
        "س𞺮",
        "ش𞺴",
        "ص𞺱",
        "ض𞺹",
        "ط𞺨",
        "ظ𞺺",
        "ع𞺯",
        "غ𞺻",
        "ف𞺰",
        "ق𞺲",
        "ل𞺫3",
        "و𞺥",
        "ي𞺩"
      ],
      "fraktur": [
        "A𝔄2",
        "Cℭ",
        "D𝔇4",
        "Hℌ",
        "Iℑ",
        "J𝔍8",
        "Rℜ",
        "S𝔖7",
        "Zℨ",
        "a𝔞26"
      ],
      "initial": [
        "ب𞸡",
        "ت𞸵2",
        "ج𞸢",
        "ح𞸧",
        "خ𞸷",
        "س𞸮",
        "ش𞸴",
        "ص𞸱",
        "ض𞸹",
        "ع𞸯",
        "غ𞸻",
        "ف𞸰",
        "ق𞸲",
        "ك𞸪4",
        "ه𞸤",
        "ي𞸩"
      ],
      "isolated": [
        "ا𞸀2",
        "ت𞸕2",
        "ج𞸂",
        "ح𞸇",
        "خ𞸗",
        "د𞸃",
        "ذ𞸘",
        "ر𞸓",
        "ز𞸆",
        "س𞸎",
        "ش𞸔",
        "ص𞸑",
        "ض𞸙",
        "ط𞸈",
        "ظ𞸚",
        "ع𞸏",
        "غ𞸛",
        "ف𞸐",
        "ق𞸒",
        "ك𞸊4",
        "و𞸅",
        "ي𞸉",
        "ٮ𞸜",
        "ٯ𞸟",
        "ڡ𞸞",
        "ں𞸝"
      ],
      "italic": [
        "A𝐴26",
        "a𝑎7",
        "hℎ",
        "i𝑖18",
        "ı𝚤",
        "ȷ𝚥",
        "Α𝛢17",
        "Σ𝛴7",
        "α𝛼25",
        "ϑ𝜗",
        "ϕ𝜙",
        "ϖ𝜛",
        "ϰ𝜘",
        "ϱ𝜚",
        "ϴ𝛳",
        "ϵ𝜖",
        "∂𝜕",
        "∇𝛻"
      ],
      "looped": [
        "ا𞺀2",
        "ت𞺕2",
        "ج𞺂",
        "ح𞺇",
        "خ𞺗",
        "د𞺃",
        "ذ𞺘",
        "ر𞺓",
        "ز𞺆",
        "س𞺎",
        "ش𞺔",
        "ص𞺑",
        "ض𞺙",
        "ط𞺈",
        "ظ𞺚",
        "ع𞺏",
        "غ𞺛",
        "ف𞺐",
        "ق𞺒",
        "ل𞺋3",
        "ه𞺄2",
        "ي𞺉"
      ],
      "monospace": [
        "0𝟶10",
        "A𝙰26",
        "a𝚊26"
      ],
      "sans-serif": [
        "0𝟢10",
        "A𝖠26",
        "a𝖺26"
      ],
      "sans-serif-bold-italic": [
        "A𝘼26",
        "a𝙖26",
        "Α𝞐17",
        "Σ𝞢7",
        "α𝞪25",
        "ϑ𝟅",
        "ϕ𝟇",
        "ϖ𝟉",
        "ϰ𝟆",
        "ϱ𝟈",
        "ϴ𝞡",
        "ϵ𝟄",
        "∂𝟃",
        "∇𝞩"
      ],
      "sans-serif-italic": [
        "A𝘈26",
        "a𝘢26"
      ],
      "script": [
        "A𝒜",
        "Bℬ",
        "C𝒞2",
        "Eℰ2",
        "G𝒢",
        "Hℋ",
        "Iℐ",
        "J𝒥2",
        "Lℒ",
        "Mℳ",
        "N𝒩4",
        "Rℛ",
        "S𝒮8",
        "a𝒶4",
        "eℯ",
        "f𝒻",
        "gℊ",
        "h𝒽7",
        "oℴ",
        "p𝓅11"
      ],
      "stretched": [
        "ب𞹡",
        "ت𞹵2",
        "ج𞹢",
        "ح𞹧",
        "خ𞹷",
        "س𞹮",
        "ش𞹴",
        "ص𞹱",
        "ض𞹹",
        "ط𞹨",
        "ظ𞹺",
        "ع𞹯",
        "غ𞹻",
        "ف𞹰",
        "ق𞹲",
        "ك𞹪",
        "م𞹬2",
        "ه𞹤",
        "ي𞹩",
        "ٮ𞹼",
        "ڡ𞹾"
      ],
      "tailed": [
        "ج𞹂",
        "ح𞹇",
        "خ𞹗",
        "س𞹎",
        "ش𞹔",
        "ص𞹑",
        "ض𞹙",
        "ع𞹏",
        "غ𞹛",
        "ق𞹒",
        "ل𞹋",
        "ن𞹍",
        "ي𞹉",
        "ٯ𞹟",
        "ں𞹝"
      ]
    }

    Note that the output must be processed according to the designated text direction. So the first char in "ت𞹵2", is ت
    , and the last one 2. If JS is aware of that, it's not more difficult to process. This format has 1652 chars and 1184bytes in the compressed format.

  14. davidcarlisle commented on Jun 26, 2025

    @davidcarlisle
    Collaborator

    I would suggest proceeding with the uncompressed JSON I generated from XML, as it contains all characters, is native to JS, and is only 4kb large. The code to read from this JSON is simple, while loading from the compressed list is more complex.

    +1 to this, I don't think the bytes saved by compressing the run lengths are really worth the extra complication in the run time code.

    On the whole I'd prefer to use the tables generated from the XML as it's easier to regenerate them in a documented way if needed (if for example we finally get sans serif Greek) and they avoid the indirection through the "tex-like" names which as Murray says are useful in other contexts but not really here in the core polyfills.

  15. MurrayIII commented on Jun 26, 2025

    @MurrayIII

    For comparison purposes I added ~50 lines of JavaScript to https://github.com/MurrayIII/mathml-polyfills/blob/main/mathvariant/mathvariant.js that converts the ASCII alphanumerics to math alphanumerics. It's surpisingly easy to do in spite of the Letterlike holes! Greek and Arabic should be easy too. Then we can compare table vs code implementations.

  16. MurrayIII commented on Jun 27, 2025

    @MurrayIII

    https://github.com/MurrayIII/mathml-polyfills/blob/main/mathvariant/mathvariant.js now includes a code approach (see GetMathAlphanumeric()) for getting the math alphanumeric characters from the corresponding unstyled BMP characters. The implementation is 97 lines of JavaScript if comments and blank lines are removed. One advantage of the algorithm is that it reveals the structure of the Unicode math alphanumerics.

  17. MurrayIII commented on Jun 30, 2025

    @MurrayIII

    The latest polyfill includes code support for the mathvariants 'roundhand' and 'chancery'. We need to add these mathvariants to the MathML spec. The resulting Unicode character codes are not yet supported in math fonts but one has to start somewhere.

    The polyfill currently includes tests comparing results of table-driven approaches to the code approach. Since it's smaller and faster, I recommend using the code approach in the final polyfill. But since more alphabets are likely to be added to Unicode, we need to have a test comparing the symbols from a table generated from the Unicode Standard to the symbols returned by the code. Provided new alphabets have the same orders as the current ones, code changes will be minimal.

  18. physikerwelt commented on Jul 1, 2025

    @physikerwelt
    Member

    @MurrayIII I did also start with the code based approach. I think in the end the compressed tables are as fast and small but easier to maintain. In the end each entry in the table needs one line of code. One could optimise the table a bit in allowing exceptions, which would merge some blocks.

  19. physikerwelt commented on Jul 13, 2025

    @physikerwelt
    Member

    @MurrayIII, what is the status here? I see https://github.com/w3c/mathml-polyfills/pull/28/files#diff-b3ff9e29572602ffd1d0ba8781267f316667ffaaeb3aabfe5806869135e5dc3b, while I personally think it's too complex and too difficult to maintain, I don't want to block it.
    I have merged the table-based version for Wikimedia, so I don't plan any further work here. If you find someone who wants to review your PR, we can merge it and close this issue.

  20. removed
    need polyfill
    on May 2, 2026
  21. NSoiffer commented on May 2, 2026

    @NSoiffer
    Contributor

    Removed 'need polyfill' because @MurrayIII created one.

    @MurrayIII: I added a test file. Until the PR is merged, you can look at it at https://nsoiffer.github.io/mathml-polyfills/mathvariant/index.html. I couldn't find a font where chancery/roundhand distinction was apparent (last two rows in the table).

  22. physikerwelt commented on May 4, 2026

    @physikerwelt
    Member

    I think this is good enough. If there is anything else to do, we can reopen it, but I don't see anything at the moment.

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

Metadata

Metadata

Assignees

Labels

MathML 4MathML Corecompatibilityopentype / tex

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions