0

I've been struggling to understand how to render Katex without having to use $$ before and after the math expression. Katex on github says I should use this:

<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? Thank you!

AllocSystems
  • 1,049
  • 2
  • 11
  • 16

1 Answers1

1

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.

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 \.

<!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>
Vincent
  • 2,689
  • 3
  • 24
  • 40
  • 1
    Katex docs acknowledged the double backslash inconvenience [here](https://katex.org/docs/api.html#in-browser-rendering) and recommended to use [String.raw](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw) if someone wishes to avoid using it. – Nayeemul Islam Swad Dec 31 '18 at 19:30