FxEditor
User guideQuickstartExamplesAPIDesignLaTeX for beginnersFxTeX
OverviewAPIExamplesRight-click menuSupported commandsAccessibilityFxTeX Packages
Using packagesmhchemchemfigphysicspictureFxTeX Server
OverviewAPIAccess and keysSelf-hostingSpeedPlugins
OverviewLicensing
How licensing worksLaTeX for beginners
LaTeX is widely used by mathematicians, scientists and engineers to write equations. Although the notation may look unfamiliar at first, it is based on a few simple ideas. This page introduces commands, superscripts, subscripts and groups, explains how to type special characters, and covers fractions, sums, integrals, matrices and tables. It ends with a complete LaTeX document showing how to include equations from fxEditor in a paper or thesis.
You do not need to learn LaTeX to use fxEditor — the toolbar writes it for you — but knowing how it works makes you much faster. Type into the box under the equation below and watch it change, and click any example on this page to open it here and try it yourself.
The basics: letters, numbers and commands
In LaTeX maths, what you type is mostly what you get. Letters become variables, set in
italic; numbers and the symbols on your keyboard (+ - = < > ( ) [ ] / | ! ' :)
stand for themselves. Everything else is a command: a backslash followed by a
name, such as \alpha, \infty or \times.
Spaces you type are ignored in maths — LaTeX spaces an equation itself, by what each piece
is (a + gets more room than a letter). A space does matter in one place: it ends a
command's name, so \alpha x is α times x, while \alphax is
a command called alphax, which does not exist.
a+b = cLetters are variables, in italic. Spaces make no difference.
2\pi r \times \alpha \leq \inftyCommands start with a backslash: Greek letters, operators and symbols.
\sin x + \log y \neq sinxFunctions such as \sin and \log are commands too. Without the backslash, sinx is read as four variables multiplied together.
a\,b \; c \quad d \qquad eIf you do want space: \, thin, \; thick, \quad and \qquad wide.
In a LaTeX document, maths in a line of text goes between $ ... $ (or
\( ... \)), and an equation on a line of its own between \[ ... \]. In
fxEditor you type only what goes inside.
Superscripts and subscripts: ^ and _
The caret ^ raises what follows it into a superscript (a power), and the
underscore _ lowers it into a subscript (an index). The rule that catches out every
beginner: each applies to the one next thing only — a single character, a
single command, or a group in braces.
x^2 \quad x_iOne character: no braces needed.
x^10Wrong: only the 1 is raised, and the 0 sits on the line.
x^{10} \quad a_{n+1}Right: braces make 10 and n+1 one thing.
x_i^2 = x^2_iBoth at once, in either order: they stack.
e^{-x^2/2}A superscript can hold anything, even another superscript.
x^{a^b} \quad {x^a}^bBraces say which is which: x to the ab, or xa to the b.
T_{\text{max}} \quad a_{i,j} \quad \alpha_\betaA command counts as one thing, so \alpha_\beta needs no braces. \text makes a word upright.
{}^{14}_{6}\mathrm{C}Scripts before a symbol: attach them to an empty group, {}.
Writing x^^2 or x__i is an error: a symbol can have only one of
each. To add a prime as well, f'(x) and f''(x) just work.
Groups: { and }
Braces are LaTeX's way of saying “treat all of this as one thing”. They are never
printed. You have already seen them hold a superscript together; they also hold together the
arguments of a command. \frac takes two — a numerator and a
denominator — each in its own pair of braces; \sqrt takes one.
\frac{a+b}{2}\frac{top}{bottom}: two groups, two arguments.
\frac12 \quad \frac a bAs with ^, an argument of one character needs no braces — but braces are clearer.
\sqrt{x^2+y^2}Groups inside groups: the square root of a sum of squares.
(a+b) \quad \{a+b\}To print braces, escape them: \{ and \}. Round brackets need nothing.
Every { needs its }. When an equation goes wrong, a missing or extra
brace is the first thing to look for.
Special characters, and how to escape them
Ten characters mean something to LaTeX, so typing one does not print it. To print most of them, put a backslash in front — that is called escaping it.
| Character | What it does | To print it |
|---|---|---|
\ | starts a command | \backslash in maths, \textbackslash in text |
{ } | make a group | \{ and \} |
^ | superscript | \hat{x} for a hat on x, \wedge for ∧, \^{} in text |
_ | subscript | \_ |
& | separates the columns of a matrix or table | \& |
% | starts a comment — the rest of the line is ignored | \% |
$ | starts and ends maths in a document | \$ |
# | a parameter, in a command you define | \# |
~ | a space the line will not break at | \sim in maths, \textasciitilde in text |
\{ \} \_ \& \% \$ \#Seven of them, escaped.
\text{Profit: } 15\% \text{ of } \$200Forget the backslash before % and the rest of the line vanishes as a comment.
\{\, x \mid x > 0 \,\}A set: escaped braces, and \mid for the bar.
Note that \\ is not an escaped backslash: it is the command that starts a new
line, or a new row of a matrix or table.
Fractions, roots and brackets
Brackets typed as ( ) or [ ] stay one size. Put
\left and \right in front of them and they grow to fit what is between
them. The two must always be used as a pair; \left. or \right. is an
invisible bracket, for when you want only one side.
\frac{1}{1+\frac{1}{x}}A fraction in a fraction.
\sqrt{2} \quad \sqrt[3]{x} \quad \sqrt[n]{1+x}The optional argument, in square brackets, is the root's index.
(\frac{a}{b}) \quad \left( \frac{a}{b} \right)Plain brackets, then brackets that fit.
\left[ \sum_{k=1}^{n} x_k \right]^2Square brackets that grow, then squared.
\left. \frac{df}{dx} \right|_{x=0}“Evaluated at”: an invisible left bracket and a bar on the right.
\binom{n}{k} = \frac{n!}{k!\,(n-k)!}A binomial coefficient.
Sums, products, integrals and limits
The big operators — \sum, \prod, \int and the rest
— take their limits with the same _ and ^ as anything else. Where
the limits go depends on the operator and on the space: on an equation of its own, a sum's limits
sit above and below it; in a line of text, beside it, so as not to push the lines apart. An
integral's limits always go beside it unless you ask, with \limits.
\sum_{k=1}^{n} k^2 = \frac{n(n+1)(2n+1)}{6}A sum, with its limits above and below.
\textstyle \sum_{k=1}^{n} k^2The same sum as it is set in a line of text.
\prod_{i=1}^{n} x_iA product.
\int_0^\infty e^{-x}\,dx = 1An integral. \, puts the small space LaTeX does not add before dx.
\int\limits_a^b f(x)\,dx\limits puts an integral's limits above and below.
\iint_D f\,dA \quad \iiint_V \rho\,dV \quad \oint_C \mathbf{F}\cdot d\mathbf{r}Double, triple and contour integrals.
\lim_{x \to 0} \frac{\sin x}{x} = 1\lim: the condition goes below, in a subscript.
\sum_{\substack{0 < i < m \\ 0 < j < n}} P(i,j)A limit of more than one line: \substack, with \\ between the lines.
Text and fonts in an equation
Words typed straight into maths come out as italic variables, run together. Put them in
\text{...} instead: it is set as ordinary text, and spaces inside it count. For a
function LaTeX has no command for, use \operatorname, which spaces it as it does
\sin.
x = 1 if y > 0Wrong: “if” is read as i times f.
x = 1 \text{ if } y > 0Right: the spaces inside \text are kept.
\operatorname{sgn}(x) \quad \operatorname{Var}(X)Functions of your own.
\mathbf{v} \quad \mathbb{R} \quad \mathcal{L} \quad \mathrm{d}xBold, blackboard bold, calligraphic and upright.
Matrices
A matrix is written row by row. & separates the entries in a row, and
\\ ends the row. The name of the environment chooses the brackets around it; the
entries are always centred.
\begin{matrix} a & b \\ c & d \end{matrix}matrix: no brackets.
\begin{pmatrix} a & b \\ c & d \end{pmatrix}pmatrix: parentheses.
\begin{bmatrix} a & b \\ c & d \end{bmatrix}bmatrix: square brackets.
\begin{vmatrix} a & b \\ c & d \end{vmatrix} = ad - bcvmatrix: bars, for a determinant. Vmatrix gives double bars and Bmatrix braces.
I_n = \begin{pmatrix} 1 & 0 & \cdots & 0 \\ 0 & 1 & \cdots & 0 \\ \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & \cdots & 1 \end{pmatrix}Dots: \cdots across, \vdots down, \ddots diagonally.
\mathbf{x} = \begin{pmatrix} x_1 \\ x_2 \\ x_3 \end{pmatrix}A column vector: one entry per row.
Arrays and tables: for maths, and for text
When you need more than a matrix gives you — columns aligned left or right, lines between
them — use array or tabular. The two are written the same way, and
look alike. The difference is what goes in the cells:
array is for maths. Every cell is maths:
x^2 is x squared, letters are italic variables. Use it inside an equation.
tabular is for text. Every cell is text, as in
a sentence: words keep their spaces and are upright, and x^2 is not a power. To put
maths in a cell, wrap it in $...$. In a document, a table of words or data is a
tabular.
\begin{array}{cc} x^2 & area of square \end{array}array: the words become italic letters, with their spaces lost.
\begin{tabular}{cc} x^2 & area of square \end{tabular}tabular: the words are right, but x^2 is printed as typed.
\begin{tabular}{cc} $x^2$ & area of square \end{tabular}Right: a text table, with $...$ round the maths.
Both begin with a column specification in braces, one letter for each column, saying how it is aligned:
| In the specification | Gives |
|---|---|
l, c, r | a column aligned left, centred, or right |
p{3cm} | a column of text 3 cm wide, which wraps onto more lines (in a document) |
| | a vertical line between the columns either side of it |
|| | a double vertical line |
\begin{array}{lcr} 1 & 1 & 1 \\ 100 & 100 & 100 \\ 10 & 10 & 10 \end{array}{lcr}: the first column left-aligned, the second centred, the third right.
\begin{array}{rl} 3x + 2 & = 11 \\ 3x & = 9 \\ x & = 3 \end{array}{rl}: equations lined up on their equals signs.
\left( \begin{array}{cc|c} 1 & 2 & 3 \\ 4 & 5 & 6 \end{array} \right)An augmented matrix: an array with a line, in brackets.
Aligning equations, and cases
For working that runs over several lines, aligned is simpler than an
array: put & just before the sign to line up on, and
\\ at the end of each line. cases is the brace for a function defined
piece by piece; each line has a value, then &, then its condition.
\begin{aligned} (a+b)^2 &= (a+b)(a+b) \\ &= a^2 + 2ab + b^2 \end{aligned}aligned: the lines line up at each &=.
|x| = \begin{cases} x & \text{if } x \geq 0 \\ -x & \text{if } x < 0 \end{cases}cases, with \text for the words.
Borders and lines
Vertical lines go in the column specification, as |. Horizontal lines go between
the rows, as \hline: one at the start draws a line along the top, one after a
\\ draws a line under that row. \hline\hline draws a double line. The same
works in array and tabular.
\begin{array}{|c|c|} \hline a & b \\ \hline c & d \\ \hline \end{array}A border round every cell: | between and around the columns, \hline above, between and below the rows.
\begin{array}{|cc|} \hline a & b \\ c & d \\ \hline \end{array}A box round the outside only.
\begin{array}{c|cc} \times & 1 & 2 \\ \hline 1 & 1 & 2 \\ 2 & 2 & 4 \end{array}A heading row and column, divided from the rest.
\begin{array}{c||c} a & b \\ \hline\hline c & d \end{array}Double lines: || and \hline\hline.
\begin{tabular}{|l|r|} \hline Item & Cost \\ \hline Tea & 2.50 \\ Cake & 3.00 \\ \hline Total & 5.50 \\ \hline \end{tabular}A text table: words left-aligned, numbers right-aligned so their decimal points line up.
Changing the thickness of the lines
Every line in an array or table is \arrayrulewidth thick — 0.4 pt unless
you change it. Set it with \setlength before the table, and every line in it, across
and down, is drawn that thick:
\setlength{\arrayrulewidth}{1.5pt} \begin{array}{|c|c|} \hline a & b \\ \hline c & d \\ \hline \end{array}Lines 1.5 pt thick.
\setlength{\arrayrulewidth}{3pt} \begin{tabular}{|c|} \hline Thick \\ \hline \end{tabular}Lines 3 pt thick.
More in a LaTeX document
A LaTeX document has more for tables than fxEditor draws, and these are worth knowing when you get there:
\cline{2-3} draws a line under columns 2 to 3 only, and
\multicolumn{2}{c}{...} makes one cell span two columns. Both are part of LaTeX.
\renewcommand{\arraystretch}{1.5} puts more space between the rows,
and \setlength{\tabcolsep}{12pt} (\arraycolsep in an
array) more between the columns. fxEditor accepts these, so an equation that has
them still works, but sets its rows and columns at their usual spacing.
The booktabs package gives the
clean lines that books and journals use — \toprule, \midrule and
\bottomrule, a little thicker at top and bottom, and no vertical lines. For a table of
text or data in a paper, it is usually the best choice.
Using your equations in a LaTeX document
Everything fxEditor makes is LaTeX, so it can go straight into a document. Here is a complete
one, using most of what is on this page. Copy the LaTeX from fxEditor's box and paste it between
\[ and \] for an equation on its own line, or between $ and
$ in the middle of a sentence.
\documentclass{article}
\usepackage{amsmath} % matrices, cases, aligned, \text, \operatorname, \binom, \iint
\usepackage{amssymb} % extra symbols, and \mathbb for R, N, Z ...
\usepackage{xcolor} % colours: \textcolor{red}{x}
\usepackage{fxpicture} % pictures from fxEditor's picture editor (loads pict2e)
\begin{document}
\section*{A short example}
The roots of $ax^2 + bx + c = 0$ are
\[
x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}.
\]
The sum of the first $n$ squares is
\[
\sum_{k=1}^{n} k^2 = \frac{n(n+1)(2n+1)}{6},
\]
and the area under a bell curve is
\[
\int_{-\infty}^{\infty} e^{-x^2}\,dx = \sqrt{\pi}.
\]
A rotation through an angle $\theta$, and the absolute value:
\[
R = \begin{pmatrix} \cos\theta & -\sin\theta \\
\sin\theta & \cos\theta \end{pmatrix},
\qquad
|x| = \begin{cases} x & \text{if } x \geq 0 \\
-x & \text{if } x < 0 \end{cases}
\]
\begin{center}
\setlength{\arrayrulewidth}{0.8pt}
\begin{tabular}{|l|r|}
\hline
Item & Cost (\$) \\
\hline
Tea & 2.50 \\
Cake & 3.00 \\
\hline
\end{tabular}
\end{center}
A right-angled triangle, drawn with fxEditor's picture editor:
\[
\begin{picture}(58,54)(-11,-12)
\polygon(0,0)(45,0)(0,40)
\polyline(4,0)(4,4)(0,4)
\put(-9,17){$a$}
\put(20,-10){$b$}
{\linestyle{dashed}\Line(0,0)(22.5,20)}
\end{picture}
\]
\end{document}
The packages
| Package | Needed for |
|---|---|
amsmath | Almost every document with maths in it. The matrix environments, cases, aligned, \text, \operatorname, \binom, \substack, \boxed, \iint and more. |
amssymb | Extra symbols, and \mathbb (ℝ, ℕ, ℤ). |
xcolor | Coloured maths. In a document use \textcolor{red}{x}, or {\color{red} x} with the colour in a group of its own. |
fxpicture | Pictures from fxEditor's picture editor. It loads pict2e and adds dashed and dotted lines. It is not in TeX distributions yet: download fxpicture.zip and put fxpicture.sty beside your .tex file. A picture with only solid lines needs just pict2e. |
mhchem, chemfig, physics | Only if you use those packages in fxEditor — \ce{...}, \chemfig{...}, \dv, \ket and the like. |
Compiling it: pdfLaTeX or XeLaTeX
A .tex file is a set of instructions; a TeX engine reads them and
writes the PDF. You need a TeX distribution installed — TeX
Live on Linux and Windows, MacTeX on a Mac, or
MiKTeX on Windows — or an online editor such as
Overleaf, which needs nothing installed. Save the document
above as example.tex, with fxpicture.sty beside it, and run:
pdflatex example.tex
This writes example.pdf. pdfLaTeX is the usual choice, and the
right one for this document: it is fast, and every journal accepts it. Use
XeLaTeX (or LuaLaTeX) instead when the document needs fonts installed on your
computer — with the fontspec or unicode-math packages — or is
written in a language pdfLaTeX struggles with, such as Arabic, Chinese or Hindi:
xelatex example.tex
Both read the same document, and fxpicture works in both. If a document has cross-references
(\label and \ref) or a table of contents, run the command twice, so the
second run can fill in what the first found. latexmk -pdf example.tex (or
latexmk -xelatex) runs it as many times as needed for you. In Overleaf, choose the
engine under Menu → Compiler.
Further reading
The Not So Short Introduction to LaTeX — the classic free introduction to LaTeX as a whole, with a chapter on maths.
Short Math Guide for LaTeX — the American Mathematical Society's summary of writing maths with amsmath.
amsmath on CTAN — its user's guide, for every environment and command it adds.
LaTeX/Mathematics and LaTeX/Tables on Wikibooks — thorough, with many examples.
Overleaf's LaTeX guides — short, practical articles on maths, matrices, tables and more.
array and booktabs on CTAN — for more control over tables in a document.
More
User guide — the editor's toolbar, keyboard and menus.
Supported commands — every command fxEditor understands.
picture — drawing diagrams, and fxpicture.sty.
CodeCogs®