javascript - Generating HTML with KaTeX and nodejs -


i run problems trying render nontrivial formula in html , css. creates sort of jumbled mess of unicode characters on screen.

i downloaded katex directory ./katex/ , created test.js:

var katex = require('./katex/katex.min.js'); var html = katex.rendertostring("x^y"); console.log(html); 

i ran command 'nodejs test.js' , pasted output minimal html file test.html (with line breaks inserted readability):

<html> <head> <link rel="stylesheet" type="text/css" href="./katex/katex.min.css"> </head> <body>  <span class="katex"><span class="katex-mathml"><math><semantics> <mrow><msup><mi>x</mi><mi>y</mi></msup></mrow> <annotation encoding="application/x-tex">x^y</annotation></semantics> </math></span><span class="katex-html" aria-hidden="true"> <span class="strut" style="height:0.664392em;"></span> <span class="strut bottom" style="height:0.664392em;vertical-align:0em;"> </span><span class="base textstyle uncramped"><span class="mord"> <span class="mord mathit">x</span><span class="vlist"> <span style="top:-0.363em;margin-right:0.05em;"> <span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">​ </span></span><span class="reset-textstyle scriptstyle uncramped"> <span class="mord mathit" style="margin-right:0.03588em;">y</span> </span></span><span class="baseline-fix"> <span class="fontsize-ensurer reset-size5 size5"> <span style="font-size:0em;">​</span></span>​</span></span></span> </span></span></span>  </body> </html> 

you can't see here, there unicode zero-width space characters (200b).

i opened in browser , got mess of unicode-like characters.

displaying test.html

the same thing happens other formulas \sqrt{} , \frac{}. doing wrong? thanks.

this encoding issue. add meta tag in html file solve issue.

<head>  <meta charset="utf-8"/>  <link rel="stylesheet" type="text/css" href="./katex/katex.min.css">  </head>


Comments