TeX is a text formatting and markup language developed by D. Knuth in the late 1970s and early 1980s, which has become the de facto standard for document preparation in mathematics and certain areas of the physical sciences because of its unsurpassed utility in typesetting mathematical formulae. LaTeX is an extension of TeX, which for purposes of discussion can be thought of as a third-party macro package for TeX to provide a logical system for document preparation, where the author does not have to give specific formatting instructions in order to achieve a particular look; the look is provided by an external document class description. [1] [2]
|
TeX is named after the Greek letters tau (τ), epsilon (ε), and chi (χ), reflecting the word τέχνη (téchnē), meaning "art," "craft," or "skill" in Greek. It is pronounced "tech" (as in technology), not "teks." LaTeX stands for Lamport TeX, named after its creator, Leslie Lamport. It is pronounced "LAY-tech" or "LAH-tech." |
TeX Live is one of the major TeX systems (e.g., MiKTeX and TeX Live) that provides binaries for most flavors of Unix, including GNU/Linux and macOS, and also Windows. It includes the major TeX-related programs, macro packages, and fonts that are free software, including support for many languages around the world. Many Unix/GNU/Linux operating systems provide TeX Live through their own distributions and package managers. TeX Live is supported by the TeX Users Group and many other user groups around the world. [3 ]
MathJax is an open-source JavaScript display engine for LaTeX, MathML, and AsciiMath notation that works in modern browsers, with built-in support for assistive technology such as screen readers, including automatic speech generation and an expression explorer that can be used to investigate typeset mathematics at a more granular level than the complete expression. [4]
| TeXLive.net is a powerful online site to edit TeX snippets, run LaTeX, and display PDF documents or error logs. |
1. Mathematics
LaTeX allows two writing modes for mathematical expressions: the inline math mode and display math mode: [5]
-
inline math mode is used to write formulas that are part of a paragraph:
The Pythagorean theorem is \(a^2 + b^2 = c^2\).The Pythagorean theorem is \(a^2 + b^2 = c^2\).
-
display math mode is used to write expressions that are not part of a paragraph, and are therefore put on separate lines
The quadratic formula is: \[ x=\frac{-b\pm\sqrt{b^2-4ac}}{2a} \]The quadratic formula is:
\[ x=\frac{-b\pm\sqrt{b^2-4ac}}{2a} \]
1.1. Rules
-
Use curly braces
{}when an exponent contains more than one character.LaTeX Result LaTeX Result x^{a+b}\(x^{a+b}\)
x^a+b\(x^a+b\)
-
Use a backslash (
\) followed by a command name to enter LaTeX symbols and expressions.LaTeX Result LaTeX Result LaTeX Result \frac{a}{b}
\(\frac{a}{b}\)
\sqrt{x}
\(\sqrt{x}\)
x^2
\(x^2\)
\alpha
\(\alpha\)
\infty
\(\infty\)
75\%
\(75\%\)
\text{hello}
\(\text{hello}\)
\textit{hello}
\(\textit{hello}\)
\textbf{hello}
\(\textbf{hello}\)
\underline{x}
\(\underline{x}\)
\overline{x}
\(\overline{x}\)
\vec{x}
\(\vec{x}\)
\quad
\(a \quad b\)
\times
\(a \times b\)
\leq
\(a \leq b\)
\text{for all } x>0
\(\text{for all } x>0\)
\neq
\(a \neq b\)
\pm
\(a \pm b\)
-
Use spacing commands to control the horizontal space between mathematical symbols and expressions.
LaTeX Purpose Example Result LaTeX Purpose Example Result \!Negative thin space
a\!b\(a\!b\)
\Normal space
a\ b\(a\ b\)
\,Thin space
a\,b\(a\,b\)
\:Medium space
a\:b\(a\:b\)
\;Thick space
a\;b\(a\;b\)
\quadWide space
a\quad b\(a\quad b\)
\qquadExtra-wide space
a\qquad b\(a\qquad b\)
\hspace{1em}Custom horizontal space
a\hspace{1em}b\(a\hspace{1em}b\)
\\Line break
\a\\b\(a\\b\)
\newlineNot generally supported as a math-mode line break
-
Use environment that starts with
\begin{...}and ends with\end{...}to format or arrange the content inside it.Environment Purpose LaTeX Result equationA single numbered equation
\begin{equation} E = mc^2 \end{equation}\(E = mc^2\) (numbered)
alignedMultiple aligned equations
\begin{aligned} x + y &= 5 \\ x - y &= 1 \end{aligned}\(\begin{aligned}x+y&=5\\x-y&=1\end{aligned}\)
gatherMultiple centered equations
\begin{gather} x + y = 5 \\ x - y = 1 \end{gather}\(\begin{gather}x+y=5\\x-y=1\end{gather}\)
matrixMatrix elements without surrounding brackets
\begin{matrix} a & b \\ c & d \end{matrix}\(\begin{matrix}a&b\\c&d\end{matrix}\)
pmatrixMatrix elements surrounded by parentheses
\begin{pmatrix} a & b \\ c & d \end{pmatrix}\(\begin{pmatrix}a&b\\c&d\end{pmatrix}\)
bmatrixMatrix elements surrounded by square brackets
\begin{bmatrix} a & b \\ c & d \end{bmatrix}\(\begin{bmatrix}a&b\\c&d\end{bmatrix}\)
casesPiecewise-defined functions
f(x) = \begin{cases} x^2 & x \geq 0 \\ -x & x < 0 \end{cases}\(f(x)=\begin{cases}x^2&x\geq0\\-x&x<0\end{cases}\)
1.2. Superscripts and subscripts
| LaTeX | Result | Meaning |
|---|---|---|
|
\(x^2\) |
\(x\) squared |
|
\(x^{10}\) |
\(x\) to the tenth power |
|
\(a_i\) |
Subscript \(i\) |
|
\(x_i^2\) |
Subscript and superscript |
|
\(x^{n+1}\) |
A multi-character exponent |
|
\(a_{i,j}\) |
A multi-character subscript |
1.3. Fractions and binomials
| LaTeX | Result | LaTeX | Result | LaTeX | Result |
|---|---|---|---|---|---|
|
\(\frac{a}{b}\) |
|
\(\frac{x+1}{x-1}\) |
|
\(\frac{1}{2}\) |
|
\(\binom{n}{k}\) |
|
\(\binom{n}{2}\) |
|
\(\binom{n+1}{k-1}\) |
1.4. Greek letters
| LaTeX | Result | LaTeX | Result | LaTeX | Result |
|---|---|---|---|---|---|
|
\(\alpha, A\) |
|
\(\beta, B\) |
|
\(\gamma, \Gamma\) |
|
\(\delta, \Delta\) |
|
\(\epsilon, \varepsilon, E\) |
|
\(\zeta, Z\) |
|
\(\eta, H\) |
|
\(\theta, \vartheta, \Theta\) |
|
\(\iota, I\) |
|
\(\kappa, K\) |
|
\(\lambda, \Lambda\) |
|
\(\mu, M\) |
|
\(\nu, N\) |
|
\(\xi, \Xi\) |
|
\(o, O\) (omicron) |
|
\(\pi, \varpi, \Pi\) |
|
\(\rho, \varrho, P\) |
|
\(\sigma, \varsigma, \Sigma\) |
|
\(\tau, T\) |
|
\(\upsilon, \Upsilon\) |
|
\(\phi, \varphi, \Phi\) |
|
\(\chi, X\) |
|
\(\psi, \Psi\) |
|
\(\omega, \Omega\) |
1.5. Mathematical operators and symbols
| LaTeX | Result | Meaning | LaTeX | Result | Meaning |
|---|---|---|---|---|---|
|
\(+\) |
Addition |
|
\(-\) |
Subtraction |
|
\(\times\) |
Multiplication |
|
\(\div\) |
Division |
|
\(\pm\) |
Plus or minus |
|
\(\mp\) |
Minus or plus |
|
\(=\) |
Equal to |
|
\(\neq\) |
Not equal to |
|
\(<\) |
Less than |
|
\(>\) |
Greater than |
|
\(\leq\) |
Less than or equal to |
|
\(\geq\) |
Greater than or equal to |
|
\(\approx\) |
Approximately equal to |
|
\(\equiv\) |
Equivalent to; identically equal to |
|
\(\propto\) |
Proportional to |
|
\(\infty\) |
Infinity |
|
\(\sqrt{x}\) |
Square root |
|
\(\sum\) |
Summation |
|
\(\in\) |
Is an element of |
|
\(\notin\) |
Is not an element of |
|
\(\subseteq\) |
Is a subset of |
|
\(\supseteq\) |
Is a superset of |
|
\(\cup\) |
Union of sets |
|
\(\cap\) |
Intersection of sets |
|
\(\emptyset\) |
Empty set |
|
\(\mathbb{R}\) |
Set of real numbers |
|
\(\forall\) |
For all |
|
\(\exists\) |
There exists |
|
\(\land\) |
Logical AND |
|
\(\lor\) |
Logical OR |
|
\(\neg\) |
Logical NOT |
|
\(\Rightarrow\) |
Implies |
|
\(\Leftrightarrow\) |
If and only if |
|
\(\partial\) |
Partial derivative symbol |
|
Use
|
1.6. Summations, products, and integrals
| LaTeX | Result | Remark |
|---|---|---|
|
\(\sum_{i=1}^{n} i\) |
Summation from \(i=1\) to \(i=n\). |
|
\(\sum_{k=0}^{n} k^2\) |
Sum of the squares of the integers from \(0\) to \(n\). |
|
\(\prod_{i=1}^{n} i\) |
Product of the integers from \(1\) to \(n\). |
|
\(\lim_{n\to\infty} \sum_{i=1}^{n} \frac{1}{i}\) |
Limit of a sequence of partial sums. |
|
\(\int x^2\,dx\) |
Indefinite integral; |
|
\(\int_0^1 x^2\,dx\) |
Definite integral from \(0\) to \(1\). |
|
\(\iint_D f(x,y)\,dx\,dy\) |
Double integral over a region \(D\). |
|
\(\iiint_V f(x,y,z)\,dx\,dy\,dz\) |
Triple integral over a volume \(V\). |
|
\(\oint_C F(z)\,dz\) |
Contour integral over a closed curve \(C\). |
|
\(\frac{1}{2\pi i}\oint_C \frac{f(z)}{z-a}\,dz\) |
Example of a contour integral from complex analysis. |
1.7. Brackets and parentheses
| Left delimiter | Right delimiter | LaTeX | Result |
|---|---|---|---|
|
|
|
\(\left( x \right)\) |
|
|
|
\(\left[ x \right]\) |
|
|
|
\(\left\{ x \right\}\) |
|
|
|
\(\left\lvert x \right\rvert\) |
|
|
|
\(\left\lVert \mathbf{x} \right\rVert\) |
|
|
|
\(\left\langle x \right\rangle\) |
|
|
|
\(\left. F(x) \right| _a^b \) |
|
|
|
\(\left| x \right.\) |
|
Every
\[ \left\{\frac{1}{n}:n\in\mathbb{N}\right\} \] To make one side invisible, use a dot (
\[ \left. \text{expression} \right| \] \[ \left| \text{expression} \right. \] |
1.8. Matrices and equations
| LaTeX | Result | LaTeX | Result |
|---|---|---|---|
|
\[ \begin{matrix} a & b \\ c & d \end{matrix} \] |
|
\[ \begin{bmatrix} a & b \\ c & d \end{bmatrix} \] |
|
\[ \begin{pmatrix} a & b \\ c & d \end{pmatrix} \] |
|
\[ \begin{vmatrix} a & b \\ c & d \end{vmatrix} \] |
|
\[ \begin{align*} x+y &= 10 \\ x-y &= 2 \end{align*} \] |
|
\(\begin{split}A &= \frac{\pi r^2}{2} \\ &= \frac{1}{2} \pi r^2\end{split}\) |
1.9. Functions and named operators
| LaTeX | Result | LaTeX | Result | LaTeX | Result |
|---|---|---|---|---|---|
|
\(\sin x\) |
|
\(\cos x\) |
|
\(\tan x\) |
|
\(\cot x\) |
|
\(\sec x\) |
|
\(\csc x\) |
|
\(\arcsin x\) |
|
\(\arccos x\) |
|
\(\arctan x\) |
|
\(\sinh x\) |
|
\(\cosh x\) |
|
\(\tanh x\) |
|
\(\log x\) |
|
\(\ln x\) |
|
\(\log_a x\) |
|
\(\exp x\) |
|
\(\sqrt{x}\) |
|
\(\sqrt[n]{x}\) |
|
\(\lim_{x\to 0}\) |
|
\(\lim_{x\to\infty}\) |
|
\(\infty\) |
|
\(\max(a,b)\) |
|
\(\min(a,b)\) |
|
\(\sup A\) |
|
\(\inf A\) |
|
\(\det A\) |
|
\(\dim V\) |
|
\(\gcd(a,b)\) |
|
\(\arg z\) |
|
\(\ker T\) |
|
\(\Pr(A)\) |
|
\(\sin^2 x\) |
|
\(\cos^2 x\) |
2. STEM in Asciidoctor
Asciidoctor supports mathematical notation through STEM (Science, Technology, Engineering, and Mathematics) processing. It supports both AsciiMath and LaTeX-style mathematical expressions. When generating HTML, Asciidoctor can prepare STEM expressions for rendering by a JavaScript-based mathematics engine such as MathJax. [6]
2.1. Enabling STEM support
A document-level attribute can override the global setting when necessary.
To enable STEM processing, set the stem attribute in the document header or configure the stem attribute globally in the site’s _config.yml file for using the Jekyll Asciidoc plugin:
asciidoctor:
attributes:
stem: latexmath
The value latexmath selects LaTeX syntax as the default for STEM expressions. If no notation is specified, Asciidoctor defaults to AsciiMath.
2.2. Rendering mathematics with MathJax
Asciidoctor processes STEM macros during document conversion, but HTML output generally requires a mathematics renderer to display the expressions as formatted mathematics in the browser. MathJax is a JavaScript library that can render LaTeX mathematics in HTML.
<script>
window.MathJax = { (1)
options: {
ignoreHtmlClass: 'nostem|nolatexmath' (2)
},
tex: {
inlineMath: [['\\(', '\\)']], (3)
displayMath: [['\\[', '\\]']], (4)
tags: 'none' (5)
},
};
</script>
<script defer
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/4.1.3/tex-chtml.min.js" (6)
integrity="sha512-kO24RkUwCpSCXtdV9p2FM/5isVLi06qQPGlE+AsOx8kN9MTc6Mk7qlZBSEh/b7bvCr2vEWlZLAdp20QLkB/qPg=="
crossorigin="anonymous"
referrerpolicy="no-referrer">
</script>
| 1 | Defines the MathJax configuration before the library loads. |
| 2 | Excludes HTML elements whose class matches nostem or nolatexmath from MathJax processing. |
| 3 | Sets \(…\) as the delimiters for inline mathematics. |
| 4 | Sets \[…\] as the delimiters for display mathematics. |
| 5 | Disables automatic equation numbering. |
| 6 | Loads the MathJax TeX-to-Common-HTML component. The tex-chtml.min.js filename indicates TeX input processing, Common HTML output, and a minified JavaScript file. |
2.3. STEM macros versus MathJax delimiters
There are two main ways to include mathematical expressions in an AsciiDoc document: using Asciidoctor’s STEM macros or writing LaTeX expressions directly between delimiters recognized by MathJax.
| Method | Example | Processing |
|---|---|---|
STEM macro |
|
Asciidoctor recognizes the macro and processes the expression according to the configured STEM notation. |
Explicit LaTeX macro |
|
Asciidoctor recognizes the macro and interprets its content as LaTeX notation. |
Raw MathJax delimiters |
|
MathJax processes the delimiters in the generated HTML, provided they are preserved and recognized by its configuration. |
The distinction matters because Asciidoctor processes STEM macros during document conversion, whereas MathJax normally renders mathematical expressions in the browser after the HTML has been generated. The two approaches can coexist, but their processing pipelines should be configured consistently.
For a Jekyll site using Asciidoctor, prefer stem:[...] for inline mathematics and [stem] blocks for display mathematics to make the source more explicit and avoid relying on MathJax to recognize raw delimiters throughout the generated HTML.
|
-
Use the
steminline macro to include a mathematical expression within a paragraph:The equation of a straight line is stem:[y = mx + c].The equation of a straight line is \(y = mx + c\).
To specify LaTeX notation explicitly, use the
latexmathmacro:The quadratic equation is latexmath:[ax^2 + bx + c = 0].The square brackets delimit the macro’s content. Unlike raw MathJax delimiters, the Asciidoctor STEM macro does not require wrapping the expression in
\(...\)or$...$. -
For a standalone equation, use a delimited STEM block:
[stem] ++++ x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} ++++Because the document header specifies
:stem: latexmath, the expression is interpreted as LaTeX and rendered as a display equation:\[x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}\]Alternatively, explicitly specify the notation (e.g., LaTeX) on the block:
[latexmath] ++++ \int_0^1 x^2\,dx = \frac{1}{3} ++++