Add HTML inside LaTeX expressions

Viewed 108

I have some Mathematical expressions to which I would like to add some classes within its subelements. For example,

\sqrt[3]{x}

would be similar to

\sqrt[<span class="xyz">3</span>]{x}

However, this would make the LaTeX invalid. Is there any way to embed HTML inside LaTeX expressions like this?

I am using KaTeX https://katex.org/docs/supported.html if that matters.

Thanks.

2 Answers

To style certain block you can use this command:

\style{background-color:yellow}{\frac{x+1}{y+2}}

Rendering the cubic root of x in KaTeX works both in display mode and inline mode:

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.css" 
 integrity="sha384-zB1R0rpPzHqg7Kpt0Aljp8JPLqbXI3bhnPWROx27a9N0Ll6ZP/+DiW/UqRcLbRjq" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.js" 
 integrity="sha384-y23I5Q6l+B6vatafAwxRu/0oK/79VlbSz7Q9aiSZUvyWYIYsd+qj+o24G5ZU2zJz" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/contrib/auto-render.min.js" 
integrity="sha384-kWPLUVMOks5AQFrykwIup5lo0m3iMkkHrD0uJ4H5cjeGihAutqP0yW0J6dpFiVkI" crossorigin="anonymous" 
onload="renderMathInElement(document.body);"></script>

<!-- -->

\[
\sqrt[3]{x}
\]

<p>Text \(\sqrt[3]{x}\) text.</p>

<p>Text &sup3;&Sqrt;x text.</p>

Otherwise, to make it inline, you can use html entities as in the last line of my code above.

Please comment If I misunderstood your doubt or if you need further setting or explaination!

Related