简体   繁体   English

如何在不使用$$的情况下自动渲染katex?

[英]How can I auto render katex without having to use $$?

I've been struggling to understand how to render Katex without having to use $$ before and after the math expression. 我一直在努力理解如何在不使用数学表达式之前和之后使用$$的情况下渲染Katex。 Katex on github says I should use this: github上的Katex说我应该使用这个:

<script>
    renderMathInElement(document.body);
  </script>

But I still need to use $$ for each line of code. 但是我仍然需要为每行代码使用$$。 How can I render the whole page as katex? 如何将整个页面呈现为katex? Thank you! 谢谢!

Here's a simple example. 这是一个简单的例子。 If you paste this code in an HTML file and then open that file in a browser, it should render, and with no occurrences of $$ anywhere to be found, so hopefully you can then tweak it to whatever you need. 如果将此代码粘贴到HTML文件中,然后在浏览器中打开该文件,则它将呈现,并且在任何地方都找不到$$出现,因此希望您可以根据需要进行调整。

Not sure why, but I needed to use \\\\ wherever I found \\ on the Katex function support page , so if \\\\ doesn't work for you, try switching it to \\ . 不知道为什么,但是无论我在Katex 功能支持页面上找到\\地方,都需要使用\\\\ ,所以如果\\\\不适用于您,请尝试将其切换为\\

<!doctype html>

<html>
<head>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.7.1/katex.min.css">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.7.1/katex.min.js"></script>
</head>

<body>
  <span id="formula">f(x)</span>
  <script>
    katex.render("\\int_0^1{f(x)}", formula);
  </script> 
</body>
</html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM