Thứ Hai, 10 tháng 12, 2018

Mathematic in LaTeX

How To Write Mathematical Equations, Expressions, and Symbols with LaTeX: A cheatsheet.

What is LaTeX?

LaTeX is a programming language that can be used for writing and typesetting documents. It is especially useful to write mathematical notation such as equations and formulae.

How to use LaTeX to write mathematical notation

There are three ways to enter “math mode” and present a mathematical expression in LaTeX:
  1. inline (in the middle of a text line)
  2. as an equation, on a separate dedicated line
  3. as a full-sized inline expression (displaystyle)

2.1 inline

Inline expressions occur in the middle of a sentence. To produce an inline expression, place the math expression between dollar signs ($ ). For example, typing $E=mc^2$ yields E=mc^2 .

2.2 equation

Equations are mathematical expressions that are given their own line and are centered on the page. These are usually used for important equations that deserve to be showcased on their own line or for large equations that cannot fit inline. To produce an inline expression, place the mathematical expression between the symbols \[ and \] . Typing \[x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}\] yieldsx=\frac{-b\pm\sqrt{b^2-4ac}}{2a}  (1)

2.3 displaystyle

To get full-sized inline mathematical expressions use \displaystyle . Typing I want this $\displaystyle \sum_{n=1}^{\infty} \frac{1}{n}$, not this $\sum_{n=1}^{\infty} \frac{1}{n}$. yields: I want this \displaystyle \sum_{n=1}^{\infty}\frac{1}{n} , not this \sum_{n=1}^{\infty}\frac{1}{n}.

Symbols (in math mode)

3.1 The basics

As discussed above math mode in LaTeX happens inside the dollar signs ($...$ ), inside the square brackets \[...\] and inside equation and displaystyle environments. Here’s a cheatsheet showing what is possible in a math environment:
descriptioncommandoutput
addition++
subtraction--
plus or minus\pm\pm
multiplication (times)\times\times
multiplication (dot)\cdot\cdot
division symbol\div\div
division (slash)//
simple text\text{text}\text{text}
infinity\infty\infty
dots1,2,3,\ldots1,2,3,\ldots
dots1+2+3+\cdots1+2+3+\cdots
fraction\frac{a}{b}\frac{a}{b}
square root\sqrt{x}\sqrt{x}
n th root\sqrt[n]{x}\sqrt[n]{x}
exponentiationa^ba^{b}
subscripta_ba_{b}
absolute value|x||x|
natural log\ln(x)\ln(x)
logarithms\log_{a}b\log_{a}b
exponential functione^x=\exp(x)e^{x}=\exp(x)
deg\deg(f)\deg(f)
degree\degree\degree
arcmin^\prime^\prime
arcsec^{\prime\prime}^{\prime\prime}
circle plus\oplus\oplus
circle times\otimes\otimes
equal==
not equal\ne\ne
less than<<
less than or equal to\le\le
greater than or equal to\ge\ge
approximately equal to\approx\approx

3.2 Functions

descriptioncommandoutput
maps to\to\to
composition\circ\circ

3.3 Greek and Hebrew letters

commandoutputcommandoutput
\alpha\alpha \tau\tau
\beta\beta \theta\theta
\chi\chi \upsilon\upsilon
\delta\delta \xi\xi
\epsilon\epsilon \zeta\zeta
\varepsilon\varepsilon \Delta\Delta
\eta\eta \Gamma\Gamma
\gamma\gamma \Lambda\Lambda
\iota\iota \Omega\Omega
\kappa\kappa \Phi\Phi
\lambda\lambda \Pi\Pi
\mu\mu \Psi\Psi
\nu\nu \Sigma\Sigma
\omega\omega \Theta\Theta
\phi\phi \Upsilon\Upsilon
\varphi\varphi \Xi\Xi
\pi\pi \aleph\aleph
\psi\psi \beth\beth
\rho\rho \daleth\daleth
\sigma\sigma \gimel\gimel

3.4 Vectors

descriptioncommandoutput
vector\vec{v}\vec{v}
vector\mathbf{v}\mathbf{v}
norm||\vec{v}||||\vec{v}||

3.5 Set theory

descriptioncommandoutput
set brackets\{1,2,3\}\{1,2,3\}
element of\in\in
subset of\subset\subset
subset of\subseteq\subseteq
contains\supset\supset
contains\supseteq\supseteq
union\cup\cup
intersection\cap\cap
big union\bigcup_{n=1}^{10}A_n\displaystyle \bigcup_{n=1}^{10}A_{n}
big intersection\bigcap_{n=1}^{10}A_n\displaystyle \bigcap_{n=1}^{10}A_{n}
empty set\emptyset\emptyset
power set\mathcal{P}\mathcal{P}
minimum\min\min
maximum\max\max
supremum\sup\sup
infimum\inf\inf
limit superior\limsup\limsup
limit inferior\liminf\liminf
closure\overline{A}\overline{A}

3.6 Logic

descriptioncommandoutput
not\sim\sim
and\land\land
or\lor\lor
if...then\to\to
if and only if\leftrightarrow\leftrightarrow
logical equivalence\equiv\equiv
therefore\therefore\therefore
there exists\exists\exists
for all\forall\forall
implies\Rightarrow\Rightarrow
equivalent\Leftrightarrow\Leftrightarrow

3.7 Calculus

descriptioncommandoutput
derivative\frac{df}{dx}\displaystyle \frac{df}{dx}
derivative\f'f'
partial derivative\frac{\partial f} {\partial x}\displaystyle \frac{\partial f}{\partial x}
limits\lim_{x\to \infty}\displaystyle \lim_{x\to \infty}
summation\sum_{n=1}^{\infty}a_n\displaystyle \sum_{n=1}^{\infty}a_n
product\prod_{n=1}^{\infty}a_n\displaystyle \prod_{n=1}^{\infty}a_n
integral\int\displaystyle\int
double integral\iint\displaystyle\iint
triple integral\iiint\displaystyle\iiint

3.8 Number theory

descriptioncommandoutput
divides||
does not divide\not |\not |
greatest common divisor\gcd\gcd
ceiling\lceil x \rceil\lceil x\rceil
floor\lfloor x \rfloor\lfloor x \rfloor

3.9 Geometry and trigonometry

descriptioncommandoutput
angle\angle ABC\angle ABC
degree90^{\circ}90^{\circ}
triangle\triangle ABC\triangle ABC
segment\overline{AB}\overline{AB}
sine\sin\sin
cosine\cos\cos
tangent\tan\tan
cotangent\cot\cot
secant\sec\sec
cosecant\csc\csc
inverse sine\arcsin\arcsin
inverse cosine\arccos\arccos
inverse tangent\arctan\arctan

Symbols (in text mode)

The followign symbols do not have to be surrounded by dollar signs.
descriptioncommandoutput
dollar sign\$$
percent\%%
ampersand\&&
pound\##
backslash\textbackslash\
left quote marks``
right quote marks & '' & ”
single left quote`
single right quote & ' & ’
hyphenX-rayX-ray
en-dashpp. 5--15pp. 5–15
em-dashYes---or no?Yes—or no?

Writing LaTeX notation in Authorea

Authorea supports LaTeX writing, but you don’t have to know LaTeX to use Authorea! In order to insert LaTeX in an Authorea document:
  1. Click on the Insert button in the toolbar and then select LaTeX from the dropdown.
Here are some tips for writing LaTeX in Authorea:
  1. Click anywhere outside of the LaTeX block to render it.
  2. Hover on Preview to see a Preview of the rendered content.
  3. Do not paste an entire LaTeX article! Instead import documents from your homepage.
  4. Only type LaTeX content in a LaTeX block, i.e. everything you would write after \begin{document} .
  5. Do not type preamble (e.g. documentclass), frontmatter, macros or figures.
  6. To add macros (newcommands) and packages, click Settings \rightarrow  Edit Macros
  7. Use the Insert Figure button to insert images (and data).
  8. Use math mode for equations, e.g. \mathcal L_{EM}=-\frac14F^{\mu\nu}F_{\mu\nu} .
  9. Try the citation tool (click cite) to find and add citations, or use \cite{} .
  10. To insert more LaTeX blocks click Insert \rightarrow  LaTeX.
  11. You can use sectioning commands like \section{},\subsection{},\subsubsection{} to add headings.1

Further reading

Interested in finding out more about LaTeX? Check out these examples of how LaTeX can be used to write mathematical equations, and follow these instructions to create powerful documents in LaTeX on Authorea, beyond mathematics.