<t-math>
A KaTeX formula wired into the document. Readers drag parameters inside the formula, and computed results update as they do.
Markers
The content is ordinary KaTeX source, plus two markers:
| Marker | Shows |
|---|---|
\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:
Inline math
Without display, the formula sits in the line of text:
A pendulum of length
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:
- Columns are separated by
&(the&written for HTML), and rows by\\. pmatrixuses round brackets,bmatrixsquare ones andvmatrixbars, for a determinant.- A variable can appear in more than one cell. Put the same name in both off-diagonal cells
and the matrix stays symmetric while the reader drags:
\begin{pmatrix} 1 & \tangle{r} \\ \tangle{r} & 1 \end{pmatrix}. - To work with the whole matrix in expressions or a chart script, collect the
entries with a
<t-let>:<t-let name="A" expr="[[a, b], [c, d]]"></t-let>makesA[0][1]the same asb.
The matrix transformations page in the gallery builds on this, and draws what a matrix does to the plane.
Attributes
| Attribute | Description |
|---|---|
display | Renders the formula as a centered block (KaTeX display mode), instead of inline. |
tex | The TeX source, as an alternative to the element's text. Useful inside Markdown (see Using it on a blog). |
Writing TeX inside HTML
- In the element text, write
<as<and&as&, including inside\val{}expressions. Inside thetexattribute, both can be written as-is. - A marker inserts just the number. With negative values, write
-(\tangle{b})rather than-\tangle{b}, which would render as--2. - Text results, such as from
\val{x > 0 ? 'yes' : 'no'}, are set with\text{…}. So are formatted numbers with letters in them, such as\val[%d km]{d}. - If the TeX doesn't parse, the KaTeX error is shown in place of the formula. Hover over it for the source.
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.