<t-math>

A KaTeX formula wired into the document. Readers drag parameters inside the formula, and computed results update as they do.

\tangle{P} \cdot \left(1 + \frac{\tangle{r}}{100}\right)^{\tangle{t}} = \val[%,.2f]{P * (1 + r / 100) ** t}

Markers

The content is ordinary KaTeX source, plus two markers:

MarkerShows
\tangle{a}The value of variable a, draggable like a <t-num>.
\tangle[\alpha]{a}The TeX \alpha while idle, and the number while being dragged or edited.
\val{expr}The live result of a JavaScript expression.
\val[fmt]{expr}The same, with a format, such as \val[%.2f]{x / 3}.

A \tangle{} takes its range, step, color and format from the variable's declaration, usually a <t-var> or <t-num> elsewhere in the same scope. Keyboard and click-to-type work exactly as they do for <t-num>.

Symbols until touched

Formulas often read best symbolically. With \tangle[symbol]{name}, the reader sees the symbol, and the number appears only while they drag or edit it:

f(x) = \tangle[a]{a}\,x^2 + \tangle[b]{b}\,x \qquad \text{vertex at } x = \val[%.2f]{-b / (2 * a)}

Inline math

Without display, the formula sits in the line of text:

A pendulum of length 1 swings with period T = 2\pi\sqrt{L/g} = \val[%.2f]{2 * Math.PI * Math.sqrt(L / 9.81)}\,\text{s}.

Matrices

A matrix is ordinary TeX with a marker in each cell. Declare one variable per entry, and the reader can drag any of them:

\begin{pmatrix} \tangle{a} & \tangle{b} \\ \tangle{c} & \tangle{d} \end{pmatrix} \begin{pmatrix} \tangle{x} \\ \tangle{y} \end{pmatrix} = \begin{pmatrix} \val{a * x + b * y} \\ \val{c * x + d * y} \end{pmatrix} \qquad \begin{vmatrix} \tangle{a} & \tangle{b} \\ \tangle{c} & \tangle{d} \end{vmatrix} = \val{a * d - b * c}

The matrix transformations page in the gallery builds on this, and draws what a matrix does to the plane.

Attributes

AttributeDescription
displayRenders the formula as a centered block (KaTeX display mode), instead of inline.
texThe TeX source, as an alternative to the element's text. Useful inside Markdown (see Using it on a blog).

Writing TeX inside HTML

Loading KaTeX

KaTeX is fetched from jsDelivr the first time a <t-math> appears, together with its stylesheet. If the page already has window.katex, that copy is used instead. To self-host it, see KaTeX setup.