Maths between dollar signs
Write in a sentence, put a formula between $ on its own lines, or use LaTeX's own delimiters and environments, and it is set as maths — in the preview, in the file you download, in a shared link and in what the API returns. A price written as $5 to $10 is still a price.
$…$ in a line and $… $ on lines of their own are read as TeX and typeset with
KaTeX.
And LaTeX's own delimiters
\( … \) for a formula in a sentence, \[ … \] for one on a line of its own, and the
environments themselves — \begin{equation}, \begin{align}, gather, multline,
alignat and their starred forms — handed to KaTeX whole, so aligned equations line up on the
equals sign the way they were written to.
These are what a paper, a thesis or anything written near LaTeX actually uses, and they almost never begin a paragraph: people write the sentence introducing the formula and the delimiter on the next line, with no blank line between. Markdown reads that as one paragraph, so they are found wherever they turn up in a line rather than only at the start of a block.
What is not read is the rest of LaTeX. \section, \textbf, \begin{itemize} and the
preamble are a document format, not maths, and this converts Markdown. Paste a whole .tex file
and the formulas in it will set; the commands around them stay as text.
Everywhere, not only on screen
This one renders the same in every place a document is built, because KaTeX runs in a server as happily as in a browser. The preview, the downloaded .html, a shared link and the API's own HTML all carry the same formula, worked out once, with no second pass anywhere.
What travels inside the file
MathML — the maths vocabulary browsers lay out themselves — rather than KaTeX's own HTML. The difference matters exactly once, and it is the moment somebody saves the file: KaTeX's HTML is a stack of positioned boxes that means nothing without a stylesheet and the better part of a megabyte of fonts, and a document that carries those has stopped being a document. MathML needs neither. A formula in a saved file opens correctly on a machine with no network, which is what every other part of that file already promised.
It is also text. The formula can be selected and copied, a screen reader reads it as maths rather than as a picture, and the TeX you typed is kept alongside it inside the document.
A price is not a formula
Two dollar signs in one line are how most tools decide something is maths, and it is why "it costs $5 to $10" comes out of some of them as one long italic formula. Here the text between the dollars has to look like maths — operators and short symbols once its commands are accounted for, rather than words — or the dollars stay dollars. Three letters in a row that no command or brace explains means a sentence.
Half-written TeX keeps its source too, rather than being replaced by an error.