How to write math with LaTeX?
To write mathematical formulae neatly, use LaTeX which is a document composition language that allows much more than mathematical formulas.
To find out more about LaTeX, please consult the official documentation.
For mathematical formulae in SPIP, there are three cases:
- Inline’ formulas
- Centred’ formulas
To write a mathematical formula in SPIP, you have to put it between HTML tags <math>
and </math>
.
<math>
<!-- your formula -->
</math>
Formulas
Inline’ formulas
The mass of Jupiter is equal to \(1.898 \times {10}^{27} \space \text{kg}\) and the mass of the Earth is equal to \(5.974 \times {10}^{24} \space \text{kg}\). From this, we can deduce that \(1 \space \text{M}_{\text{Earth}} = 317.8 \space \text{M}_{\text{Jup}}\).
Formulas in inline mode will be displayed in the text without separation, which is very useful when you need to write a small formula in the body of a text.
To do this, you start and end your formula with $
and then write the formula inside the <math>$
and $</math>
tags. This gives, for the example above:
<math>$1.898 \times {10}^{27} \space \text{kg}$</math>
The mass of Jupiter is equal to
and the mass of the Earth is equal to<math>$5.974 \times {10}^{24} \space \text{kg}$</math>. From this, we can deduce that
<math>$1 \space \text{M}_{\text{Earth}} = 317.8 \space \text{M}_{\text{Jup}}$</math>.
Centred’ formulas
In the catalogue, one column gives an equilibrium temperature, in kelvins, calculated from other known parameters. The formula used is:
\[T_{\text{equ}}=T_{*}(\frac{R_{*}}{2a})^{0.5}(1-A)^{0.25}\]
In this formula, \(T_*\) is the temperature of the star in kelvins, \(R_*\) is the radius of the star, \(a\) is the semi-major axis of the planet’s orbit and \(A\) is the planet’s albedo.
The only difference for centred formulas is the LaTeX ‘tags’ used. To space the formula on a new line, simply use $$
before and after the formula. This gives, for the formula above:
In the catalogue, one column gives an *equilibrium temperature, in kelvins*, calculated from other known parameters. The formula used is:
<math>$$T_{\text{equ}}=T_{*}(\frac{R_{*}}{2a})^{0.5}(1-A)^{0.25}$$</math>
<math>$T_*$</math> is the temperature of the star in kelvins, <math>$R_*$</math> is
In this formula, <math>$a$</math> is the semi-major axis of the planet’s orbit and <math>$A$> </math> is the planet’s albedo. the radius of the star,
You can also write a formula on several lines. To do this, use the LaTeX idiom \\
, which allows you to skip a line. The result is:
<math>$$
\begin{aligned}
\text{One light year (km)}
\\&= 365 \space \text{(days)} \times 24 \space \text{(hours)} \times 3,600 \space \text{(seconds)}
\\&\quad \space \times 300,000 \space \text{(km per second)}
\\&=1 \space \text{l.y.}
\\&= 9.46 \times 10^{15} \text{m}
\\&= 60,000 \space \text{AU}
\\
\end{aligned}</math> $$
\[ \begin{aligned} \text{One light year (km)} \\ &= 365 \space \text{(days)} \times 24 \space \text{(hours)} \times 3,600 \space \text{(seconds)} \\ &\quad \space \times 300,000 \space \text{(km per second)} \\ &=1 \space \text{l.y.} \\ &= 9.46 \times 10^{15} \text{m} \\ &= 60,000 \space \text{AU} \\ \end{aligned} \]
LaTeX syntax
We’re not going to list all the LaTeX syntax in this section, we’ll just give a few widely-used examples. For more information on syntax, you can read these documentations:
To practise and test your formulas, an online editor is available.
Symboles
For arithmetic operations, we can use different symbols. The most commonly used are listed below. Please refer to the documentation for more information.
Symbol | LaTeX symbol | Example | Result of example |
---|---|---|---|
+ | + |
$1 + 2$ |
\(1 + 2\) |
- | - |
$1 - 2$ |
\(1 - 2\) |
X | \times |
$1 \times 2$ |
\(1 \times 2\) |
· | \cdot |
$1 \cdot 2$ |
\(1 \cdot 2\) |
/ | / |
$1 / 2$ |
\(1 / 2\) |
÷ | \div |
$1 \div 2$ |
\(1 \div 2\) |
\(\frac{x}{y}\) | \frac |
$\frac{1}{2}$ |
\(\frac{1}{2}\) |
≠ | \neq |
$1 \neq 2$ |
\(1 \neq 2\) |
\(\simeq\) | \simeq |
$1 \div 3 \simeq 0.333$ |
\(1 \div 3 \simeq 0.333\) |
\(\sqrt{x}\) | \sqrt |
$\sqrt{81} = 9$ |
\(\sqrt{81} = 9\) |
We can also make astrophysical symbols such as the Earth, Jupiter, degrees, etc.
Symbol | LaTeX symbol | Example | Result of example |
---|---|---|---|
° | ^{\circ} |
${273}^{\circ}$ |
\({273}^{\circ}\) |
🜨 | \oplus |
$185 \space M_{\oplus}$ |
\(185 \space \text{M}_{\oplus}\) |
☉ | \odot |
$18 \space M_{\odot}$ |
\(18 \space \text{M}_{\odot}\) |
∞ | \infty |
$\infty$ |
\(\infty\) |
Mathematical functions
Many mathematical functions are avalaible in LaTeX. We give just some example, see documentation for more.
Function | LaTeX symbol | Example | Result of example |
---|---|---|---|
sin(x) | \sin |
$\sin(x)$ |
\(\sin(x)\) |
cos(x) | \cos |
$\cos(x)$ |
\(\cos(x)\) |
tan(x) | \tan |
$\tan(x)$ |
\(\tan(x)\) |
ln(x) | \ln |
$\ln(x)$ |
\(\ln(x)\) |
log(x) | \log |
$\log(x)$ |
\(\log(x)\) |
exp(x) | \exp |
$\exp(x)$ |
\(\exp(x)\) |
Exponent and index
To add an exponent or subscript, simply use ^
and _
with brackets if necessary.
Function | LaTeX symbol | Example | Result of example |
---|---|---|---|
exponent | {}^{} |
${1}^{18}$ |
\({1}^{18}\) |
index | {}_{} |
${1}_{jup}$ |
\({1}_{jup}\) |
Examples
Example | Result |
---|---|
$1^2$ |
\(1^2\) |
$1^{12}$ |
\(1^{12}\) |
${12}^1$ |
\({12}^1\) |
${1.8}^{34}$ |
\({1.8}^{34}\) |
$1_x$ |
\(1_x\) |
$1_{jup}$ |
\(1_{jup}\) |
${12}_x$ |
\({12}_x\) |
${1.8}_{jup}$ |
\({1.8}_{jup}\) |
Greek letters
You can also write the Greek letters with their names. If you want the letter to be capitalised, just capitalise the first letter of the name.
All letters are not capitalized. Letters identical to Latin letters are not defined (alpha capital is identical to A, khi capital is identical to X).
Greek letter | LaTeX symbol lowercase | LaTeX symbol uppercase | Examples | Result of examples |
---|---|---|---|---|
gamma | \gamma |
\Gamma |
$\gamma$ and $\Gamma$ |
\(\gamma\) and \(\Gamma\) |
delta | \delta |
\Delta |
$\delta$ and $\Delta$ |
\(\delta\) and \(\Delta\) |
theta | \theta |
\Theta |
$\theta$ and $\Theta$ |
\(\theta\) and \(\Theta\) |
lambda | \lambda |
\Lambda |
$\lambda$ and $\Lambda$ |
\(\lambda\) and \(\Lambda\) |
pi | \pi |
\Pi |
$\pi$ and $\Pi$ |
\(\pi\) and \(\Pi\) |
phi | \phi |
\Phi |
$\phi$ and $\Phi$ |
\(\phi\) and \(\Phi\) |
Text, spaces and parenthesis
It is useful to be able to write text in certain formulas (for units, for example), so LaTeX also has a syntax for this.
Text and space
Symbol | LaTeX symbol | Example | Result of example |
---|---|---|---|
space | \space |
$1 \space 2$ |
\(1 \space 2\) |
text | \text{example} |
$\text{kilogram}$ |
\(\text{kilogram}\) |
Parenthesis
For parenthesis, you can use ()
but LaTeX provides brackets that adapt to what they contain.
Symbol | LaTeX symbol | Example | Result of example |
---|---|---|---|
() | \left( and \right) |
$\left( 3 \sqrt{{23}^{81}} \right)$ |
\(\left( 3 \sqrt{{23}^{81}} \right)\) |
For the example if you use simple parenthesis ()
you got this result: \(( 3 \sqrt{{23}^{81}})\)