We actually use two $$ to start and end.
Ex: $$ c = \pm\sqrt{a^2 + b^2} $$
Or, multiline $$ \frac{1}{\Bigl(\sqrt{\phi \sqrt{5}}-\phi\Bigr) e^{\frac25 \pi}} = 1+\frac{e^{-2\pi}} {1+\frac{e^{-4\pi}} {1+\frac{e^{-6\pi}} {1+\frac{e^{-8\pi}} {1+\cdots} } } } $$
Some details are available [in this post](https://talk.hyvor.com/blog/introducing-katex-embed/) on how it works.
And, katex.renderToString has an option to set throwOnError: false.. So, whenever if the TeX code inside $$ is not valid, it just returns the text.