Skip to content

KaTeX produces invalid MathML with \vcenter #4078

@slotThe

Description

@slotThe

Describe the bug:
The input a \mathrel{\vcenter{:}}= b produces the following markup:

<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>a</mi><mo><mpadded class ="vcenter"><mo lspace="0em" rspace="0em">:</mo></mpadded></mo><mo>=</mo><mi>b</mi></mrow><annotation encoding="application/x-tex">a \mathrel{\vcenter{:}}= b</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.4653em;"></span><span class="mord mathnormal">a</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.4653em;"><span style="top:-3.0347em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mrel">:</span></span></span></span></span></span></span></span><span class="base"><span class="strut" style="height:0.3669em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.6944em;"></span><span class="mord mathnormal">b</span></span></span></span>

Note the <mo><mpadded class ="vcenter">…</mo></mpadded> at the start. As https://validator.w3.org/nu/ informs me,

Error: Element mpadded not allowed as child of element mo in this context.

However, it doesn't give a link to the MathML specs where this is stated.

To Reproduce:

I used the following script to generate the markup:

import { createInterface } from "node:readline"

import { createRequire } from "module";
const katex = createRequire(import.meta.url)('katex');

for await (const line of createInterface({ input: process.stdin })) {
  try {
    console.log(katex.renderToString(line, {
      displayMode: false,
      strict: "error",
      throwOnError: true,
    }));
  } catch (error) {
    throw new Error(`Input: ${line}\n\nError: ${error}`);
  }
}

and then checked the output via https://validator.w3.org/nu/#textarea

Environment (please complete the following information):

  • KaTeX Version: 0.16.21
  • Device: Desktop
  • OS: NixOS
  • Browser: n/a
  • Version: n/a

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions