简体   繁体   中英

How can I create a line break in Katex?

I am trying to test rendering of katex on my browser. It renders correctly, but when I try using \newline to signal a line break, it throws me an error:

ParseError: KaTeX parse error: Expected 'EOF', got '\newline' at position 45: …)-\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?

Use three backslashs instead of two.

I'm using markdown to publish blog with KaTeX. It works for me.

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

It renders:

KaTeX 输出

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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