简体   繁体   English

如何在 Katex 中创建换行符?

[英]How can I create a line break in Katex?

I am trying to test rendering of katex on my browser.我正在尝试在我的浏览器上测试 katex 的渲染。 It renders correctly, but when I try using \newline to signal a line break, it throws me an error:它正确呈现,但是当我尝试使用\newline来表示换行符时,它会抛出一个错误:

ParseError: KaTeX parse error: Expected 'EOF', got '\newline' at position 45: …)-\tfrac{1}{2}x\̲n̲e̲w̲l̲i̲n̲e̲ \Righta… ParseError:KaTeX 解析错误:预期 'EOF',在位置 45 得到 '\newline':...)-\tfrac{1}{2}x\̲n̲e̲w̲l̲i̲n̲e̲ \Righta...

<body>
   <div class="maths">
       \Rightarrow\quad F(x)-\tfrac{1}{2}x
       \Rightarrow\quad  F(x)-F(a)\leq\tfrac{1}{2}(x-a)[2ex]
</div> 
<script>
// Get all <div class ="maths"> elements in the document
    var x = document.getElementsByClassName('maths');  
    for (var i = 0; i < x.length; i++) {
        try {
            if (x[i].tagName == "DIV") {
                t = katex.render(x[i].textContent, x[i], { displayMode: true });
            } else {
                t = katex.render(x[i].textContent, x[i]);
            }
        }
        catch (err) {
            x[i].style.color = 'red';
            x[i].textContent = err;
        }
}
</script>

How can I call for a newline in Katex since "\newline" doesn't work?由于 "\newline" 不起作用,我如何在 Katex 中调用换行符?

Use three backslashs instead of two.使用三个反斜杠而不是两个。

I'm using markdown to publish blog with KaTeX.我正在使用 Markdown 发布带有 KaTeX 的博客。 It works for me.这个对我有用。

$$
\begin{aligned}
&(n-1)(n-1)\\\
&=n^2-2n+1
\end{aligned}
$$

It renders:它呈现:

KaTeX 输出

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

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