I'm building an electron app so I don't want to use the CDN. Is there any way around this?
Secondly, how do I render a math block with multiple lines of code? the documentation only gives an example of rendering one like of code.
I tried rendering this,
\begin{vmatrix}
a & b \\
c & d
\end{vmatrix}
but the following does't work.
katex.render("\begin{vmatrix} a & b \\ c & d\end{vmatrix}", theorem, {
throwOnError: false,
displayMode: true
});
Yes, there's no need to use the CDN. Just include the js, css, and fonts directory in your project, e.g. via NPM. I do it this way in my Meteor project.
Your example just isn't escaping the backslashes correctly.
katex.render("\\begin{vmatrix} a & b \\\\ c & d\\end{vmatrix}", theorem, {
throwOnError: false,
displayMode: true
});
If you want to use multiple actual lines, you can use \n; see documentation for JavaScript strings.
I did install using npm. I also copied the katex.js, katex.css and the fonts folder from the latest build release to my root project directory. I used the following example code I found but it doesn't render.
<div class="all">
<div>The formula $a^2+b^2=c^2$ will be rendered inline, but $$a^2+b^2=c^2$$ will be rendered as a block element.</div>
<br>
<div>The formula \(a^2+b^2=c^2\) will be rendered inline, but \[a^2+b^2=c^2\] will be rendered as a block element.</div>
</div>
<script type="text/javascript" src="assets/katex.js"></script>
<script>
const katex = require('katex');
renderMathInElement(
// document.querySelector(".all"),
{
delimiters: [
{left: "$$", right: "$$", display: true},
{left: "\\[", right: "\\]", display: true},
{left: "$", right: "$", display: false},
{left: "\\(", right: "\\)", display: false}
]
}
);
</script>
Can you please post a link to the javascript strings in the documentation I can't find it.
@OnlineVagrant I don't see anything wrong with that in principle. We'd need a complete example (online or e.g. uploaded in Github or Gist) to debug further. You probably also want to check your Developer Console to look for error messages that might be happening.
Here is documentation of how JavaScript strings work: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String
(Apologies if you already know this; it's all I meant.)
I've got this issue as well. The browser console says TypeError: o.a is undefined when using auto-render.**min**.js but when using auto-render.js I get external_katex_default.a is undefined. Probably the same thing? The details of the error with the unminified version is as follows:
renderMathInText http://localhost:1313/katex/auto-render.js: 251
renderElem http://localhost:1313/katex/auto-render.js: 273
renderElem http://localhost:1313/katex/auto-render.js: 285
renderElem http://localhost:1313/katex/auto-render.js: 287
renderElem http://localhost:1313/katex/auto-render.js: 285
renderElem http://localhost:1313/katex/auto-render.js: 287
renderElem http://localhost:1313/katex/auto-render.js: 285
renderElem http://localhost:1313/katex/auto-render.js: 287
renderElem http://localhost:1313/katex/auto-render.js: 285
renderElem http://localhost:1313/katex/auto-render.js: 287
I don't know enough javascript to understand what the issues are, but they're presumably on those lines.
Edit: As noted already these errors don't occur when using the CDN version.
@edemaine I though you meant that there was a function in the katex module that deals with strings :)
I get the following error.
Uncaught ReferenceError: renderMathInElement is not defined
I'm assuming this is because I didn't include the auto render extention CDN. As I don't want to use the CDN.
I reduced the code to the simplest form possible.Please take a look if needed.
KatexExample.zip
@OnlineVagrant You're missing the <script> tag to include the local katex.js.
@edemaine I'm not sure I understand. Didn't I link to the katex.js file using
Most helpful comment
If you're using a build system like webpack or parcel you should be able to do
in one of your source files. With webpack you'll need to set up
css-loaderfor this to work properly. While I've done this for just KaTeX, I haven't tried this for auto-render yet.