14 Mathematical formulae - practicalseries/GitHub-Wiki-Design-and-Implementation GitHub Wiki
GitHub flavoured Markdown supports the use of mathematical formulae (this was introduced in 2022). These are entered using the TeX and LaTeX💠1 (more LaTeX than TeX).
LaTeX is a programming syntax used to encode a particular formula; it is a plain-text format. This is then interpreted by the JavaScript application MathJax which renders the formula in the correct, visually pleasing, form.
The following is the LaTeX syntax for the common quadratic equation:
Markdown and GitHub output |
---|
|
$x=\frac{-b\pm\sqrt{b^2—4ac}}{2a}$
|
|
|
Table 14.1 — GitHub Wiki rendering of a mathematical formulae |
This rendering is carried out by the MathJax application. It’s pretty good and does an excellent job of rendering equations.
I’ve used MathJax before, in fact I have a website about it here. The thing I liked about MathJax was that it could use AsciiMath💠2.
AsciiMath is quite intuitive to use, this for example, is the quadratic formulae in AsciiMath form (the one we all know from O levels):
x=(-b +- sqrt(b^2 — 4ac))/(2a)
MathJax would render it as:
AsciiMath is a bit hard to explain, but at an intuitive level you can see exactly how it works. If you wanted to type that equation as a single line on a computer terminal, I bet you would come up with something similar to the above.
When I found out the GitHub was using MathJax I had high hopes that it could use AsciiMath, but it can’t. It only uses the LaTeX syntax and this is harder to understand, see the next section.
GitHub supports inline equations. Inline equations appear in the middle of a line or paragraph of text.
Inline equations are surrounded by an open dollar sign and left brace ${
and closed with a right brace and a dollar sign }$
:
Markdown and GitHub output |
---|
|
GitHub supports the use of inline formulae; they can be inserted directly into a paragraph of text
and the equation will be given the correct amount of spacing above and below. This is an inline
formula ${x=\frac{-b\pm\sqrt{b^2—4ac}}{2a}}$, it sits in the middle of a line. The text
surrounding the equation is normal body text, the equation itself uses a mathematical
font that forms part of MathJax.
|
|
GitHub supports the use of inline formulae; they can be inserted directly into a paragraph of text
and the equation will be given the correct amount of spacing above and below. This is an inline
formula |
Table 14.1 — Inline equation |
Generally, the use of inline equations should be restricted to single line type equations (
The normal delimiter for an inline equation is ${...}$
. An alternative is to start the equation with a dollar, backtick ($`
) and end it with a backtick dollar (`$
).
A formula block is an equation that appears outside any text and may span multiple lines:
Markdown and GitHub output |
---|
|
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
```math
x=\frac{-b\pm\sqrt{b^2—4ad}}{2a}
```
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
|
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. |
Table 14.2 — Block equation |
Alternatively, the equation can be surrounded by a double dollar sign ($$
) or the dollar, braces arrangement (${...}$
):
Markdown and GitHub output |
---|
|
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
$$x=\frac{-b\pm\sqrt{b^2—4ad}}{2a}$$
${x=\frac{-b\pm\sqrt{b^2—4ad}}{2a}}$
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
|
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. |
Table 14.3 — Block equation alternative |
Both do exactly the same thing.
Important
Block equations must have a blank line above and below.
The following section gives some insights into the LaTeX equation syntax, this section has several examples of the types of equations that are possible:
|
|
---|
```math
f(x)=(x+a)(x+b)
```
|
```math
\cos(2\theta\phi) = \cos^2 \theta\phi - \sin^2 \theta\phi
```
|
```math
(a+b)\left[1-\frac{b}{a+b}\right]=a
```
|
```math
\int_a^bu\frac{d^2v}{dx^2}\,dx
=\left.u\frac{dv}{dx}\right|_a^b
-\int_a^b\frac{du}{dx}\frac{dv}{dx}\,dx
```
|
```math
\tilde f(\omega)=\frac{1}{2\pi}
\int_{-\infty}^\infty f(x)e^{-i\omega x}\,dx
```
|
```math
x = a_0 + \frac{1}{a_1 + \frac{1}{a_2 + \frac{1}{a_3 + a_4}}}
```
|
```math
x = a_0 + \frac{1}{\displaystyle a_1
+ \frac{1}{\displaystyle a_2
+ \fr
```
|
```math
\begin{bmatrix}
1 & x & 0 \\
0 & 1 & -1
\end{bmatrix}\begin{bmatrix}
1 \\
y \\
1
\end{bmatrix}
=\begin{bmatrix}
1+xy \\
y-1
\end{bmatrix}
```
|
```math
\begin{pmatrix}
2 & 3 & 4\\
5 & 6 & 7\\
8 & 9 & 10 \end{pmatrix} v = 0
```
|
```math
\begin{matrix}
-2 & 1 & 0 & 0 & \cdots & 0 \\
1 & -2 & 1 & 0 & \cdots & 0 \\
0 & 1 & -2 & 1 & \cdots & 0 \\
0 & 0 & 1 & -2 & \ddots & \vdots \\
\vdots & \vdots & \vdots & \ddots & \ddots & 1 \\
0 & 0 & 0 & \cdots & 1 & -2
\end{matrix}
```
|
```math
|x|=\begin{cases}
x, & \text{if }x\geq 0 \\
-x, & \text{if }x< 0
\end{cases}
```
|
```math
(1+x)^n = \sum_{i=0}^n {n \choose i} x^i
```
|
```math
e^x = 1 + x + \frac{x^2}{2} + \cdots = \sum_{n\geq 0} \frac{x^n}{n!}
```
|
```math
\frac{n!}{k!(n-k)!} = \binom{n}{k}
```
|
```math
e^x = 1 + x + \frac{x^2}{2} + \cdots = \sum_{n\geq 0} \frac{x^n}{n!}
```
|
Table 14.4 — Example equations
|
LaTeX isn’t quite as intuitive as AsciiMath, but the more you use it, the more you begin to understand it.
LaTeX uses some mathematical operators: +
, -
, =
, and brackets and parenthesis []
, ()
directly, just by typing them on a keyboard. Other things are entered as commands: \sqrt
these always start with a backslash character.
Some commands have arguments, these are encompassed in braces {}
. For example the fraction is in the form:
```math
\frac{a}{a+b}
```
|
Everything in the first pair of braces is numerator (top of the fraction) and everything in the second pair of braces is the denominator (bottom of the fraction).
Brackets and parenthesis do not by default expand vertically to encompass whatever is inside them:
```math
x=(1-\frac{a}{b})
```
|
Here, the parentheses remain small and the fraction extends above and below it.
To make brackets and parenthesis resize, precede the left bracket/parenthesis with \left
and the right bracket/parenthesis with \right
:
```math
x=\left(1-\frac{a}{b}\right)
```
|
To use braces (instead of brackets or parentheses), precede the brace with a backslash:
```math
x=\{1-\frac{a}{b}\}
```
|
\left and \right: work in the same way as before:
```math
x=\left\{1-\frac{a}{b}\right\}
```
|
Various characters (Greek characters, symbols &c.) have their own commands:
```math
\tau\epsilon\chi
```
|
Superscript characters are preceded with ^
and subscript with _
. Thes can also be used for limits on operators:
```math
a^b
```
|
```math
a_b
```
|
With limits, it is like this:
```math
\sum_{n=1}^{\infty}
```
|
```math
\int_{0}^{\infty}
```
|
The braces are not always required, but where multiple limit (or super/subscript) terms are used, it is best to put the braces around everything that should be a limit or super/subscript.
The following tables summarise all the LaTeX commands:
Sym | Command | Sym | Command | Sym | Command | Sym | Command |
---|---|---|---|---|---|---|---|
|
\alpha |
|
\gamma |
|
\omega |
|
\sigma |
|
\beta |
|
\iota |
|
\phi |
|
\tau |
|
\chi |
|
\kappa |
|
\varphi |
|
\theta |
|
\delta |
|
\lambda |
|
\pi |
|
\upsilon |
|
\epsilon |
|
\mu |
|
\psi |
|
\xi |
|
\eta |
|
\nu |
|
\rho |
|
\zeta |
Sym | Command | Sym | Command | Sym | Command | Sym | Command |
---|---|---|---|---|---|---|---|
|
\Delta |
|
\Psi |
|
\varepsilon |
|
\aleph |
|
\Gamma |
|
\Sigma |
|
\varkappa |
|
\beth |
|
\Lambda |
|
\Theta |
|
\Phi |
|
\daleth |
|
\Omega |
|
\Upsilon |
|
\Pi |
|
\gimel |
|
\Xi |
|
\vartheta |
|
\varepsilon |
Sym | Command | Sym | Command | Sym | Command |
---|---|---|---|---|---|
|
\frac{abc}{xyz} |
|
\overline{abc} |
|
\overrightarrow{abc} |
|
f’ |
|
\underline{abc} |
|
\overleftarrow{abc} |
|
\sqrt{abc} |
|
\widehat{abc} |
|
\overbrace{abc} |
|
\sqrt[n]{abc} |
|
\widetilde{abc} |
|
\underbrace{abc} |
Sym | Command | Sym | Command | Sym | Command | Sym | Command |
---|---|---|---|---|---|---|---|
|
| |
|
\{ |
|
\Uparrow |
|
/ |
|
\vert |
|
\} |
|
\uparrow |
|
\backslash |
|
\Vert |
|
\langle |
|
\Downarrow |
||
|
( |
|
\rangle |
|
\downarrow |
||
|
) |
|
\lfloor |
|
\llcorner |
||
|
[ |
|
\rfloor |
|
\lrcorner |
||
|
] |
|
\lceil |
|
\ulcorner |
||
|
\rceil |
|
\urcorner |
Precede the first delimiter with \left and last delimiter with \right to match the height of their content (note \left and \right must be paired). E.g.:
Sym | Command | Sym | Command |
---|---|---|---|
|
\left(1-\frac{a}{b}\right) |
|
\left[1-\frac{a}{b}\right] |
Sym | Command | Sym | Command |
---|---|---|---|
|
\sum |
|
\biguplus |
|
\prod |
|
\bigcap |
|
\coprod |
|
\bigcup |
|
\int |
|
\bigoplus |
|
\oint |
|
\bigotimes |
|
\iint |
|
\bigodot |
|
\iiint |
|
\bigvee |
|
\lim |
|
\bigwedge |
Sym | Command | Sym | Command |
---|---|---|---|
|
\sum_{def}^{abc}x_y^z |
|
\biguplus_{n=1}^{10}A_n |
|
\prod_{def}^{abc} x_y^z |
|
\bigcap_{n=1}^{10}A_n |
|
\coprod_{n=1}^{\infty} x_y^z |
|
\bigcup_{n=1}^{10}A_n |
|
\int_{0}^{\infty} x^2 dx |
|
\bigoplus_{b\epsilon B}R_b |
|
\oint_{c_1} \frac{-y}{x^2 +y^2}dr |
|
\bigotimes_{b\epsilon B}R_b |
|
\iint_{w}^{k} dV |
|
\bigodot_{b\epsilon B}R_b |
|
\iiint_{w}^{k} dV |
|
\bigvee_{n=1}^{10}A_n |
|
\lim_{x\to \infty} x^2 |
|
\bigwedge_{n=1}^{10}A_n |
Sym | Command | Sym | Command | Sym | Command | Sym | Command |
---|---|---|---|---|---|---|---|
|
\arccos |
|
\arcsin |
|
\arctan |
|
\arg |
|
\cos |
|
\cosh |
|
\cot |
|
\coth |
|
\csc |
|
\deg |
|
\det |
|
\dim |
|
\exp |
|
\gcd |
|
\hom |
|
\inf |
|
\ker |
|
\lg |
|
\lim |
|
liminf |
|
\limsup |
|
\ln |
|
\log |
|
\max |
|
\min |
|
\Pr |
|
\sec |
|
\sin |
|
\sinh |
|
\sup |
|
\tan |
|
\tanh |
Standard functions should appear as Roman regular characters, not italics.
Sym | Command | Sym | Command | Sym | Command | Sym | Command |
---|---|---|---|---|---|---|---|
|
\ast |
|
\pm |
|
\cap |
|
\lhd |
|
\aaa |
|
\mp |
|
\cup |
|
\rhd |
|
\cdot |
|
\amalg |
|
\uplus |
|
\triangleleft |
|
\circ |
|
\odot |
|
\sqcap |
|
\triangleright |
|
\bullet |
|
\ominus |
|
\sqcup |
|
\unlhd |
|
\bigcirc |
|
\oplus |
|
\wedge |
|
\unrhd |
|
\diamond |
|
\oslash |
|
\vee |
|
\bigtriangledown |
|
\times |
|
\otimes |
|
\dagger |
|
\bigtriangleup |
|
\div |
|
\wr |
|
\ddagger |
|
\setminus |
|
\centerdot |
|
\Box |
|
\barwedge |
|
\veebar |
|
\circledast |
|
\boxplus |
|
\curlywedge |
|
\curlyvee |
|
\circledcirc |
|
\boxminus |
|
\Cap |
|
\Cup |
|
\circleddash |
|
\boxtimes |
|
\bot |
|
\top |
|
\dotplus |
|
\boxdot |
|
\intercal |
|
\rightthreetimes |
|
\divideontimes |
|
\square |
|
\doublebarwedge |
|
\leftthreetimes |
Sym | Command | Sym | Command | Sym | Command | Sym | Command |
---|---|---|---|---|---|---|---|
|
\equiv |
|
\leq |
|
\geq |
|
\perp |
|
\cong |
|
\prec |
|
\succ |
|
\mid |
|
\neq |
|
\preceq |
|
\succeq |
|
\parallel |
|
\sim |
|
\ll |
|
\gg |
|
\bowtie |
|
\simeq |
|
\subset |
|
\supset |
|
\Join |
|
\approx |
|
\subseteq |
|
\supseteq |
|
\ltimes |
|
\asymp |
|
\sqsubset |
|
\sqsupset |
|
\rtimes |
|
\doteq |
|
\sqsubseteq |
|
\sqsupseteq |
|
\smile |
|
\propto |
|
\dashv |
|
\vdash |
|
\frown |
|
\models |
|
\in |
|
\ni |
|
\notin |
Sym | Command | Sym | Command | Sym | Command | Sym | Command |
---|---|---|---|---|---|---|---|
|
\approxeq |
|
\leqq |
|
\geqq |
|
\lessgtr |
|
\thicksim |
|
\leqslant |
|
\geqslantcc |
|
\lesseqgtr |
|
\backsim |
|
\lessapprox |
|
\gtrapprox |
|
\lesseqqgtr |
|
\backsimeq |
|
\lll |
|
\ggg |
|
\gtreqqless |
|
\triangleq |
|
\lessdot |
|
\gtrdot |
|
\gtreqless |
|
\circeq |
|
\lesssim |
|
\gtrsim |
|
\gtrless |
|
\bumpeq |
|
\eqslantless |
|
\eqslantgtr |
|
\backepsilon |
|
\Bumpeq |
|
\precsim |
|
\succsim |
|
\between |
|
\doteqdot |
|
\precapprox |
|
\succapprox |
|
\pitchfork |
|
\thickapprox |
|
\Subset |
|
\Supset |
|
\shortmid |
|
\fallingdotseq |
|
\subseteqq |
|
\csupseteqqcc |
|
\smallfrown |
|
\risingdotseq |
|
\sqsubset |
|
\sqsupset |
|
\smallsmile |
|
\varpropto |
|
\preccurlyeq |
|
\succcurlyeq |
|
\Vdash |
|
\therefore |
|
\curlyeqprec |
|
\curlyeqsucc |
|
\vDash |
|
\because |
|
\blacktriangleleft |
|
\blacktriangleright |
|
\Vvdash |
|
\eqcirc |
|
\trianglelefteq |
|
\trianglerighteq |
|
\shortparallel |
|
\neq |
|
\vartriangleleft |
|
\vartriangleright |
|
\nshortparallel |
Sym | Command | Sym | Command | Sym | Command | Sym | Command |
---|---|---|---|---|---|---|---|
|
\ncong |
|
\nleq |
|
\ngeq |
|
\nsubseteq |
|
\nmid |
|
\nleqq |
|
\ngeqq |
|
\nsupseteq |
|
\nparallel |
|
\nleqslant |
|
\ngeqslant |
|
\nsubseteqq |
|
\nshortmid |
|
\nless |
|
\ngtr |
|
\nsupseteqq |
|
\nshortparallel |
|
\nprec |
|
\nsucc |
|
\subsetneq |
|
\nsim |
|
\npreceq |
|
\nsucceq |
|
\supsetneq |
|
\nVDash |
|
\precnapprox |
|
\succnapprox |
|
\subsetneqq |
|
\nvDash |
|
\precnsim |
|
\succnsim |
|
\supsetneqq |
|
\nvdash |
|
\lnapprox |
|
\gnapprox |
|
\varsubsetneq |
|
\ntriangleleft |
|
\lneq |
|
\gneq |
|
\varsupsetneq |
|
\ntrianglelefteq |
|
\lneqq |
|
\gneqq |
|
\varsubsetneqq |
|
\ntriangleright |
|
\lnsim |
|
\gnsim |
|
\varsupsetneqq |
|
\ntrianglerighteq |
|
\blvertneqqbb |
|
\gvertneqq |
Sym | Command | Sym | Command | Sym | Command |
---|---|---|---|---|---|
|
\leftarrow |
|
\longleftarrow |
|
\uparrow |
|
\Leftarrow |
|
\Longleftarrow |
|
\Uparrow |
|
\rightarrow |
|
\longrightarrow |
|
\downarrow |
|
\Rightarrow |
|
\Longrightarrow |
|
\Downarrow |
|
\leftrightarrow |
|
\longleftrightarrow |
|
\updownarrow |
Sym | Command | Sym | Command | Sym | Command |
---|---|---|---|---|---|
|
\mapsto |
|
\longmapsto |
|
\nearrow |
|
\hookleftarrow |
|
\hookrightarrow |
|
\searrow |
|
\leftharpoonup |
|
\rightharpoonup |
|
\swarrow |
|
\leftharpoondown |
|
\rightharpoondown |
|
\nwarrow |
|
\rightleftharpoons |
Sym | Command | Sym | Command | Sym | Command |
---|---|---|---|---|---|
|
\dashrightarrow |
|
\dashleftarrow |
|
\leftleftarrows |
|
\leftrightarrows |
|
\Lleftarrow |
|
\twoheadleftarrow |
|
\leftarrowtail |
|
\looparrowleft |
|
\leftrightharpoons |
|
\curvearrowleft |
|
\circlearrowleft |
|
\Lsh |
|
\upuparrows |
|
\upharpoonleft |
|
\downharpoonleft |
|
\multimap |
|
\leftrightsquigarrow |
|
\rightrightarrows |
|
\rightleftarrows |
|
\rightrightarrows |
|
\rightleftarrows |
|
\twoheadrightarrow |
|
\rightarrowtail |
|
\looparrowright |
|
\rightleftharpoons |
|
\curvearrowright |
|
\circlearrowright |
|
\Rsh |
|
\downdownarrows |
|
\upharpoonright |
|
\downharpoonright |
|
\rightsquigarrow |
Sym | Command | Sym | Command | Sym | Command |
---|---|---|---|---|---|
|
\nleftarrow |
|
\nrightarrow |
|
\nLeftarrow |
|
\nRightarrow |
|
\nleftrightarrow |
|
\nLeftrightarrow |
Sym | Command | Sym | Command | Sym | Command | Sym | Command |
---|---|---|---|---|---|---|---|
|
\infty |
|
\forall |
|
\Diamond |
|
\complement |
|
\nabla |
|
\exists |
|
\Finv |
|
\dtriangledowndd |
|
\partial |
|
\nexists |
|
\triangle |
||
|
\eth |
|
\emptyset |
|
\hbar |
|
\vartriangle |
|
\clubsuit |
|
\varnothing |
|
\hslash |
|
\blacklozenge |
|
\diamondsuit |
|
\imath |
|
\lozenge |
|
\blacksquare |
|
\heartsuit |
|
\jmath |
|
\mho |
|
\blacktriangle |
|
\spadesuit |
|
\ell |
|
\prime |
||
|
\cdots |
|
\sharp |
|
\square |
|
\backprime |
|
\vdots |
|
\flat |
|
\surd |
|
\circledS |
|
\ldots |
|
\natural |
|
\wp |
|
\measuredangle |
|
\Im |
|
\Re |
|
\diagdown |
|
\diagup |
Sym | Command | Sym | Command | Sym | Command | Sym | Command |
---|---|---|---|---|---|---|---|
|
\acute{a} |
|
\bar{a} |
|
\breve{a} |
|
\check{a} |
|
\ddot{a} |
|
\dot{a} |
|
\grave{a} |
|
\hat{a} |
|
\atilde{a}aa |
|
\vec{a} |
Matrices can be generated using the \begin{xmatrix}
command where x
defines the type of delimiter used.
Following the command, columns are separated by the &
character and a new row follows a double backslash character \\
.
The following are some examples (in each case the x
character preceding matrix changes):
|
|
|
---|
No delimiter |
```math
\begin{matrix}
1 & 2 & 3\\
a & b & c
\end{matrix}
```
|
---|
Parentheses |
```math
\begin{pmatrix}
1 & 2 & 3\\
a & b & c
\end{pmatrix}
```
|
---|
Brackets |
```math
\begin{bmatrix}
1 & 2 & 3\\
a & b & c
\end{bmatrix}
```
|
---|
Braces |
```math
\begin{Bmatrix}
1 & 2 & 3\\
a & b & c
\end{Bmatrix}
```
|
---|
Pipes |
```math
\begin{vmatrix}
1 & 2 & 3\\
a & b & c
\end{vmatrix}
```
|
---|
Double pipes |
```math
\begin{Vmatrix}
1 & 2 & 3\\
a & b & c
\end{Vmatrix}
```
|
---|
Left and right ceiling delimiters (these use a plain matrix inside the specified delimiter) |
```math
\left\lceil
\begin{matrix}
1 & 2 & 3\\
a & b & c
\end{matrix}
\right\rceil
```
|
---|
Different delimiters either side |
```math
\left\langle
\begin{matrix}
1 & 2 & 3\\
a & b & c
\end{matrix}
\right\rangle
```
|
---|
Matrices automatically align the columns where the content is wider:
Different column widths |
```math
\begin{pmatrix}
111 & 2 & 3\\
a & b & ccc
\end{pmatrix}
```
|
---|
Table 14.5 — Matrices
|
Cases are a variation of matrices; they are often referred to as a piecewise function and consist of a left brace containing the results that occur under specific conditions. Cases are generated using the \begin{cases}
command.
Following the command, columns are separated by the &
character and a new row follows a double backslash character \\
.
|
|
|
---|
Typical case |
```math
x=\begin{cases}
x, & \text{if }x\geq 0 \\
0, & \text{if }x< 0
\end{cases}
```
|
---|
Table 14.6 — Cases
|
The \text{}
command is used to render the text between the braces literally (see Text formatting — the text command section for details).
The \begin{align}
command will align multiple equations at the &
sign, the &
can be inserted anywhere in the equation (usually before the equals sign).
The equations for each line are separated by the double backslash character \\
.
|
|
|
---|
Equation alignment |
```math
\begin{align}
x - 5y &= 8 \\
3x + 9y &= -12
\end{align}
```
|
---|
Table 14.7 — Aligning multiple equations
|
LaTeX is a typsetting language and supports various text formatting operations, these are discussed below:
LaTeX supports different font sizes, some are general sizes (large
, tiny
&c.) and some are mathematical formula sizes (these all end with the word style
). GitHub is a bit inconsistent in how these render (some are just duplicates of others).
To change the font size, use the command below, everything following the command will be at the size specified. The point sizes are those generated by GitHub in the main body text area:
|
|
|
---|---|---|
\scriptscriptstyle |
9.60 | |
\tiny |
11.31 | |
\scriptsize |
11.31 | |
\scriptstyle |
11.68 | |
\small |
13.60 | |
\normalsize |
16.00 | |
\textstyle |
16.00 | |
\displaystyle |
16.00 | |
\large |
19.20 | |
\Large |
23.04 | |
\huge |
23.04 | |
\Huge |
23.04 | |
Table 14.8 — LaTeX text formatting, point size |
The \color{}
command can be used to change the colour of any text that follows.
It is fairly flexible in its approach, it can use pre-named colours, RGB hex colours, RGB decimal colours, RGBA with transparency, HSL colours and HSLA with transparency.
Once invoked, everything that follows the closing brace will be in the specified colour:
Sym | Command |
---|---|
|
\color{red}EXAMPLE |
|
\color{blue}EXAMPLE |
|
\color{#446FBD}EXAMPLE |
|
\color{rgb(255,0,0)}EXAMPLE |
|
\color{rgba(0,255,0, 0.5)}EXAMPLE |
|
\color{hsl(100%,0,0)}EXAMPLE |
|
\color{hsla(120, 100%, 50%, 0.5)}EXAMPLE |
Table 14.9 — LaTeX text formatting, colours |
The predefined colours are:
Colour | Name | RGB | Hex |
---|---|---|---|
black |
0,0,0 |
#000000 |
|
blue |
0,0,255 |
#0000FF |
|
brown |
191,248,64 |
#BF8040 |
|
cyan |
0,185,224 |
#00B9F2 |
|
darkgrey |
64,64,64 |
#404040 |
|
gray |
156,156,156 |
#9C9C9C |
|
green |
0,255,0 |
#00FF00 |
|
lightgrey |
191,191,191 |
#BFBFBF |
|
lime |
191,255,0 |
#BFFF00 |
|
magenta |
251,49,153 |
#FB3199 |
|
olive |
159,140,24 |
#9F8C18 |
|
orange |
255,128,0 |
#FF8000 |
|
pink |
255,191,191 |
#FFBFBF |
|
purple |
191,0,64 |
#BF0040 |
|
red |
255,0,0 |
#FF0000 |
|
teal |
0,128,128 |
#008080 |
|
violet |
128,0,128 |
#800080 |
|
yellow |
255,235,61 |
#FFEB3D |
|
white |
255,255,255 |
#FFFFFF |
|
Table 14.10 — LaTeX predefined colours |
Text can be entered directly into an equation by just typing it in:
Sym | Command |
---|---|
|
EXAMPLE |
The problem with this is that text entered this way is always in italics and, depending on the context and position, some spaces can go missing.
To ensure that text is displayed correctly, use the \text{}
command:
Sym | Command |
---|---|
|
\text{EXAMPLE} |
The \text{}
command can be a bit hit and miss with spaces, to make sure that a space is definitely shown, precede it with a backslash (\
). I.e. backslash space.
Sym | Command |
---|---|
|
\text{EXAMPLE\ TEXT} |
Important
The \
backslash space also works in an equation outside of the \text{}
command, as does the \space
option (which does not work inside the\text{}
command).
LaTeX supports different fonts (of course it does, it’s a typesetting language). It has all the following options available to it (and this is just for maths formulae).
It should work like this:
|
|
|
---|---|---|
\mathsf{ABCDEF} |
San-serif font | ![]() |
\mathbf{ABCDEF} |
Bold font | ![]() |
\mathcal{ABCDEF} |
Script font | ![]() |
\mathbb{ABCDEF} |
Double struck font | ![]() |
\mathefrak{ABCDEF} |
Frakturs font | ![]() |
This is good I thought, now I can play tunes with GitHub, but it wasn’t to be.
GitHub ignores all commands that apply specific fonts. All LaTeX entries are always rendered in the standard GitHub Math font (a serif font).
So there go my hopes for using a different font.
Er… I might need to rethink that title.
GitHub doesn’t allow the font colour to be changed. It will change it itself for things like links, but as users, we can’t just change the font to green for example.
The following uses inline LaTeX formulas to add text in any colour to a GitHub page, it is a poor substitute, it is clumsy to enter and uses the standard LaTeX serif font, but it does work:
The following is an extract from an earlier section of this document:
The Markdown behind this is:
Markdown |
---|
|
$$\large \color{#7030A0}\text{https:/}\text{/github.com}\color{#446FBD}\text{/}\color{#ED7D31}\text{[UserName]}\color{#446FBD}\text{/}\color{#00B050}\text{[RepositoryName]}\color{#446FBD}\text{/}\color{#c00000}\text{wiki}$$
|
Table 14.11 — Coloured text example |
It starts and ends with a double dollar sign ($$
), this makes it a block equation (centres it on the page). It then uses a series of \color{}
and \text{}
commands to construct the visible text string and assign the different colours.
The only oddball thing here is the splitting of the https://github.com
web address, it has become \text{https:}\text{//github.com}
. I.e. it has been split into two parts, https:
and //github.com
.
The reason for this is that GitHub doesn’t like links in LaTeX formula (it won’t render the formula if there is a link in it), hence splitting it into two components that are not interpreted by GitHub as a link, but look like one when joined together.
Inline colour is perfectly possible too:
This line has inline
The Markdown being
Markdown |
---|
|
This line has inline ${\color{#C00000}\text{coloured}}$ ${\color{#00B050}\text{text}}$ information.
|
Table 14.12 — Inline colours |
The principle is exactly the same, just encapsulate it between ${…}$
to signify an inline formula (see section 14.2)
Footnotes:
Note
💠1 TeX and LaTeX; TeX (pronounced tech) came first. It’s named after the Greek word τέχνη which means something between art and skill, the first three letters being tau, epsilon, and chi or TEX in the Roman alphabet (the chi character looks like an x, but is pronounced “k”, hence tech not tex).
TeX is a very low-level typesetting programming language (developed by Donald Knuth in 1978), it was intended as a mechanism for producing professional documents, in particular it is used for the publication of mathematical, engineering and physics documentation. It is a comprehensive set of extensions (sometimes engines) and macros that provide extensive type-setting functions, including the representation of mathematical formulae.
LaTeX (pronounced Lay-tech) is a version of TeX created by Leslie Lamport in 1984 (the La being the first two letters of his surname). It works at a (slightly) higher programming language level than TeX and provides various macros that move away from the elementary programming commands of Tex to a markup language format.
Generally, LaTeX is more widely used and it is this format that GitHub uses to display mathe-matical formulae↩