arnog / mathlive

A web component for easy math input
https://cortexjs.io/mathlive
MIT License
1.58k stars 277 forks source link

Superscripts are rendered as subscripts when using convertLatexToMarkup #2524

Closed Repo-SK closed 1 month ago

Repo-SK commented 1 month ago

Description

Superscripts are being rendered as subscripts in the generated HTML when using convertLatexToMarkup. The math-field component renders it as expected, it's just the static rendering with convertLatexToMarkup that's not behaving as expected.

I tried different fonts, including the bundled katex font but the behavior is the same. It looks like a bug in the css code as I can see some spans are correctly positioned but the final superscript element isn't respecting the parent(s). I'll look into it in more detail tomorrow morning.

Steps to Reproduce

<h1
  dangerouslySetInnerHTML={{
    __html: convertLatexToMarkup("x^{2}"),
  }}
/>

Actual Behavior

"2" is rendered as a subscript of "x". CleanShot 2024-09-21 at 22 23 58@2x

Expected Behavior

It should be rendered as x^2 with the "2" anchored to the top-right of "x".

Environment

0.101.0

Operating System macOS

Browser Chrome, Firefox, Safari

arnog commented 1 month ago

From the screenshot, it would appear you do not have the required CSS stylesheet loaded to display formulas correctly.

To correctly display this markup, import the stylesheet with import "mathlive/static.css". The stylesheet can be found in dist/mathlive-static.css.

Repo-SK commented 1 month ago

Yep that was it, thanks.