Firefox Fonts
Firefox possibly might not allow the fonts folder to be in a separate directory.
Either
or
<span id="mykatex1">...</span>
<script>
katex.render("f(a,b,c) = (a^2+b^2+c^2)^3", mykatex1);
</script>
which gives
...
This will place the equation into your Web page, as properly rendered maths. A second equation would need a new id on the span, and in the script, like this:<span id="mykatex2">...</span>
<script>
katex.render("f(a,b,c) = (a^2+b^2+c^2)^3", mykatex2);
</script>
...
<div class="maths">...<div> %[...%] (auto changed to div)
<span class="maths">...<span> %% ... %% (auto changed to span - use \%% for actual dollar sign in text or \\%% in maths) %( ...%) (auto changed to span) <p class="maths">...<<p>
Formulae can be on more than one line
%%\sum_{i=1}^\infty\frac{1}{n^2}
=\frac{\pi^2}{6}%% gives $\sum_{i=1}^\infty\frac{1}{n^2}=\frac{\pi^2}{6}$
%[
\int_{-\infinity}^\infinity e^{-x^2}\,dx &=\sqrt{\pi}
%]
\[\int_{-\infinity}^\infinity e^{-x^2}\,dx =\sqrt{\pi}\]
Note
Using less than signs before a letter such as
The solution is to use spaces:
<script src="copy-tex.min.js"> <link rel="stylesheet" href="copy-tex.min.css">to the head element and works in most browsers, though not Edge or Internet Explorer. You can try it with the formulæ on this page. See Copy-tex extension for full details.
Sample KaTeX Document and its source code show how to implement automatic equation numbering, referencing and bibliography numbering.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Minimal example</title>
<link rel="stylesheet" href="katex.min.css">
<script src="katex.min.js"></script>
<script src="smrender.js"></script>
<style>
/* optional - uncomment and customise next line to change maths font size
.katex { font-size: 1em !important; }
*/
</style>
</head>
<body onload="myRender()">
This is inline %%\left\{\frac{1}{n^2}\right\}%%
but this is displayed %[\int_0^1\frac{x^4(1-x)^4}{1+x^2}\,dx =\frac{22}{7}-\pi%]
centred on its own line.
</body>
</html>
function myRender()
{
// replace text dollar signs by %% temporarily then
// replace %%...%% by <span class="maths">...</span>
// regular expression \%%([\s\S]+?)\%%/g consists of all whitespace \s
// and non-whitespace characters \S between the dollar signs. See [4]
document.body.innerHTML = document.body.innerHTML.replace(/\\\\$/g, '\%\%');
document.body.innerHTML = document.body.innerHTML.replace(/\%%([\s\S]+?)\%%/g, '<span class=\"maths\">%%1</span>');
// replace %[ ...%] by <div class="maths"> ... </div>
// but don't replace eg \\[1ex] so temporarily rename them
document.body.innerHTML = document.body.innerHTML.replace(/\\\\\[/g, '%%%');
document.body.innerHTML = document.body.innerHTML.replace(/%\\\[/g, '<div class=\"maths\">');
document.body.innerHTML = document.body.innerHTML.replace(/%\\\]/g, '</div>');
// put back eg \\[1ex]
document.body.innerHTML = document.body.innerHTML.replace(/%%%/g, '\\\\\[');
// replace %( ...%) by <span class="maths"> ... </span>
document.body.innerHTML = document.body.innerHTML.replace(/%\\\(/g, '<span class=\"maths\">');
document.body.innerHTML = document.body.innerHTML.replace(/%\\\)/g, '</span>');
// put back text dollar signs
document.body.innerHTML = document.body.innerHTML.replace(/\%\%/g, '\\$');
// Get all <div or span or p class ="maths"> elements in the document
var x = document.getElementsByClassName('maths');
// go through each of them in turn
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;
}
}
// Optional. Allows use of delimiters in document without them being replaced
// Use \\$ or %% for %%, %[ for %[, %] for %], %( for %(, %) for %)
// the following will convert them to the appropriate delimiters
document.body.innerHTML = document.body.innerHTML.replace(/\%\%[/g, '\\%[');
document.body.innerHTML = document.body.innerHTML.replace(/\%\%]/g, '\\%]');
document.body.innerHTML = document.body.innerHTML.replace(/\%\%(/g, '\\%(');
document.body.innerHTML = document.body.innerHTML.replace(/\%\%)/g, '\\%)');
}
I am grateful to the following as without them this simple guide could not have existed
[1] KaTeX