Maths
Math is an equation on its own line. Its text is LaTeX, kept exactly as written, so braces and backslashes need no escaping. A long equation can go in a ```latex block over several lines, and a long Paragraph can end its lines with \ (see Long strings and blocks of text). Equations are numbered, and id: lets the text refer to the number with [#id]:
<KScript.Document title="Maths" to="'maths.pdf'">
<Math id="eq-gauss">\int_{-\infty}^{\infty} e^{-x^2} \, dx = \sqrt{\pi}</Math>
<Math numbered="false">\sum_{k=1}^{n} k = \frac{n(n+1)}{2}</Math>
<Math>A = \begin{pmatrix} a & b \\ c & d \end{pmatrix}, \quad \det A = ad - bc</Math>
</KScript.Document>import KScript.Document
Document(title: 'Maths', to: 'maths.pdf') {
Math(id: 'eq-gauss') "\int_{-\infty}^{\infty} e^{-x^2} \, dx = \sqrt{\pi}"
Math(numbered: false) "\sum_{k=1}^{n} k = \frac{n(n+1)}{2}"
Math "A = \begin{pmatrix} a & b \\\\ c & d \end{pmatrix}, \quad \det A = ad - bc"
}In a "..." string \\ is how you write one backslash, so a LaTeX row break \\ is written \\\\. A new line inside an environment also ends a row:
<KScript.Document title="Cases" to="'cases.pdf'">
<Math>|x| = \begin{cases}
x & \text{if } x \ge 0
-x & \text{otherwise}
\end{cases}</Math>
</KScript.Document>import KScript.Document
Document(title: 'Cases', to: 'cases.pdf') {
Math "|x| = \begin{cases}
x & \text{if } x \ge 0
-x & \text{otherwise}
\end{cases}"
}What the maths understands:
- Letters, numbers and operators with TeX's spacing;
^and_for superscripts and subscripts;'for primes. \frac,\dfrac,\tfrac,\binom,\sqrt,\sqrt[n].- Greek letters (
\alphato\Omega), relations (\le,\approx,\in,\subseteq,\to...), operators (\pm,\times,\cdot,\cup...), arrows, and symbols such as\infty,\partial,\nabla,\forall,\exists. - Large operators with limits:
\sum,\prod,\int,\iint,\oint,\bigcup...; functions such as\sin,\log,\lim,\max, and\operatorname{name}. \left( ... \right)and the other delimiters, which grow to fit.matrix,pmatrix,bmatrix,vmatrix,cases,alignedandarrayenvironments.\text{...},\mathbf,\mathit,\mathrm,\mathbb,\mathcal,\mathsf,\mathtt; accents such as\hat,\bar,\vec,\dot,\tilde,\overline,\underline; and spaces\,,\;,\quad,\qquad.
Unknown commands are errors that name the command, so a typo is caught when the script runs rather than in the finished PDF. Each format gets the maths in its own form: drawn in the PDF, amsmath in LaTeX, Word equations in .docx, and MathML in HTML.