-3

I have a 3rd party api that returns me mathematical equations in katex form. Is there a way to convert katex into utf-8 in c#. Thanks.

desiguy
  • 652
  • 2
  • 9
  • 25
  • 2
    No? Katex is a derivative of Tex. It is like you asked "can I convert an html document to utf8?" The textual part can be easily extracted, but the formatting can't. – xanatos Jan 29 '21 at 22:31

1 Answers1

1

No. You can't. And there is a very good reason why.

Let's start about what with the fact that KaTeX is (I'm quoting the tag): KaTeX is a fast, easy-to-use JavaScript library for TeX math rendering on the web.

So it is a renderer (written in javascript, but it is irrelevant) that transforms some TeX commands (and some real text) into formatted text. Some (many) of those TeX commands are commands that print a character (\xi prints ξ for example). Others control the formatting (similarly to the formatting tags of html we could say). Now. The first ones could be extracted and converted. We look for \xi and we print ξ. The second ones we can't. In the same way that we can't put in a C# string the "bold" formatting. Formatting is part of the presentation.

For example:

\widetilde{\f\relax{x} = \int_{-\infty}^\infty \f\hat\xi\,e^{2 \pi i \xi x}\,d\xi}

is formatted by KaTeX to

If we convert all the TeX commands that simply print a character we will obtain:

f(x)=∫−∞∞f^(ξ) e2πiξx dξ

I don't think it would be very useful. We have lost the formatting and we have lost the undulated line that was above the equation (the equation was taken from the homepage of the KaTeX project, but I've added the \widetilde{} undulated line to show this point). The line isn't an unicode character. It is drawn with SVG.

xanatos
  • 109,618
  • 12
  • 197
  • 280