Write mathematics
Write formulae in a sentence and on their own lines, align a chain of equations, number an equation and link to it, and lay out a derivation.
Formulae in LibreTimes Markdown are LaTeX, set by KaTeX. If you write LaTeX, almost everything you know works; this guide shows the parts that are specific to writing it inside Markdown, and the few places KaTeX differs from a LaTeX installation.
Put a formula in a sentence
- Wrap the formula in single dollar signs, with no space just inside them:
A function is continuous if is open for every open .
A function $f\colon X \to Y$ is continuous if $f^{-1}(U)$ is open for every open $U \subseteq Y$.The formula sits in the line and takes the line's size, so keep it short:
fractions in a line read better as \tfrac{1}{2} or 1/2 than as a full
\frac.
\( … \) works too, so text pasted from a .tex file needs no rewriting. A
dollar sign meant as money is written \$.
Put a formula on its own line
- Write
$$on a line of its own, the formula on the next lines, and$$on a line of its own after it:
The Gaussian integral is
The Gaussian integral is
$$
\int_{-\infty}^{\infty} e^{-x^2}\,dx = \sqrt{\pi}.
$$The two $$ lines must stand alone. Written $$\sqrt{\pi}$$ inside a line,
or even alone on one line, the formula stays in the line: it is not centred,
and an environment that needs a display, such as align*, is shown in red.
The editor always writes the form on separate lines. \[ and \] on lines
of their own are the same as $$.
A display formula wider than the screen scrolls sideways inside its own box, so a long formula never widens the page on a phone.
Align a chain of equations
- Inside a display, open
alignedand put&before the sign each line aligns on, and\\at the end of every line but the last:
$$
\begin{aligned}
(a+b)^2 &= (a+b)(a+b) \\
&= a^2 + ab + ba + b^2 \\
&= a^2 + 2ab + b^2
\end{aligned}
$$align, align*, gather, cases and the matrix environments work as
well; the full list is on KaTeX's
supported environments.
Number an equation and link to it
KaTeX does not number equations by itself, so a number is one you write, and a link to it is an ordinary link to an anchor.
- Put
\tag{…}at the end of the formula with the number you want printed. - Put an attribute line with an anchor, such as
{#eq-energy}, directly above the$$line, with no blank line between them. - Link to it from the text with
[(1)](#eq-energy), putting the number in the link text yourself:
By (1), a body at rest still has energy.
{#eq-energy}
$$
E = mc^2 \tag{1}
$$
By [(1)](#eq-energy), a body at rest still has energy.\label, \ref and \eqref are not available in a formula. An anchor
name starts with a letter and is used once per document; a name that
contains a . or a : is written {id="eq:2.1"}. See
Cite works and cross-reference
for links to theorems and figures, which work the same way.
Lay out a derivation
A proof written as numbered lines, each with its justification, is one display
formula: an array with a column for each part of a line.
- Open
\begin{array}{lll}inside a display, onelper column. - Write one line of the derivation per row, with
&between the columns and\\at the end of every row but the last. - Set names of rules and abbreviations in
\text{…}, so they are upright:
$$
\begin{array}{lll}
[\text{Hyp}] & \vdash p \supset q & (1)\\
[\text{Hyp}] & \vdash q \supset r & (2)\\
[(1), (2), \text{Syll}] & \vdash p \supset r & (3)
\end{array}
$$Use c or r instead of l for a column that should be centred or flush
right. There is no separate block for derivations, and none is needed: this
layout renders as written and converts to LaTeX unchanged.
Check what you wrote
- Open Preview in the editor, or look at the published page.
- Find anything shown in red. That is a formula, or a command inside one, that KaTeX could not read; the rest of the page renders normally.
- Fix it with the causes below, which cover almost every red formula.
- A command KaTeX does not know. There are no packages, so a command from
one, such as
\normor\absfromphysics, is red. Write it out:\lVert x \rVert,\lvert x \rvert. KaTeX's supported functions page is the list. - A display environment written inline. Put the
$$on lines of their own. - A macro from another formula. A
\newcommandor\deflasts only to the end of the formula that defines it, so define nothing you need twice; write the command out where it is used. - A link.
\hrefand\urlare refused. Put the link in the sentence.
The expected result is a page where every formula is typeset and none is red: formulae in sentences at the size of the text, displays centred on lines of their own, an aligned chain lined up on its signs, and tagged equations with their numbers at the right.
Draw a commutative square
A rectangular diagram with straight arrows is a formula: KaTeX reads the
CD environment of amscd.
- Inside a display, open
\begin{CD}. - Write the objects with the arrows between them:
@>f>>is an arrow to the right labelled above,@>>k>one labelled below,@VgVVan arrow down labelled on the left,@VVhVone labelled on the right. End each row with\\.
$$
\begin{CD}
A @>f>> B \\
@VgVV @VVhV \\
C @>>k> D
\end{CD}
$$Diagonal or curved arrows, plots and drawings are not maths mode. Draw them in a TikZ block, which a real LaTeX compiles when the work is saved.