7 min read

LaTeX codes (for math)

To Start

I got in R, Markdown, LaTeX because of an assignment in Macroeconomics. We have been told we could get a bonus if submitted the assignment in R writing in LaTex.Being a Microsoft Office and Stata user I knew nothing about this software and these languages.But I decided that it was time to learn.

Luckly, there is plenty of information on the net about this topic. However, at the beginning, I found more useful just to replicate the materials provided by the professor in class to get confidence with the new tools. So while learning I ended up writing down the basic codes to start writing economic equations and formulas in LaTeX.

These notes contain codes for writing mathematics in LaTeX with examples. I think you could find them useful for practice and for a quick review. In fact, when you understand the potentiality of the new tools and that you can use for writing your assignments, articles and thesis you will want to know more. In this case I could suggest to have a look at LaTeX Stack Exchange,ShareLaTeX, Yihui Xie, bookdown:Authoring Books andTechnical Documents with R Markdown.

I hope you will find my notes useful for your first assignments.

Greek letters

Here a list of some of the most used Greek letters in Economics:

description latex result
alpha \alpha \(\alpha\)
beta \beta \(\beta\)
gamma \gamma \(\gamma\)
theta \theta \(\theta\)
sigma \sigma \(\sigma\)
rho \rho \(\rho\)
lambda \lambda \(\lambda\)
phi \phi \(\phi\)
psi \psi \(\psi\)
epsilon \epsilon \(\epsilon\)

For the corresponding capital letter, we just write in the same way but with initial capital letter.

Example

description latex result
Gamma \Gamma \(\Gamma\)
Lambda \Lambda \(\Lambda\)
Sigma \Sigma \(\Sigma\)
Psi \Psi \(\Psi\)
Delta \Delta \(\Delta\)
Xi \Xi \(\Xi\)
Upsilon \Upsilon \(\Upsilon\)
Omega \Omega \(\Omega\)
Theta \Theta \(\Theta\)
Pi \Pi \(\Pi\)
Phi \Phi \(\Phi\)

Parenthesis

We can write parenthesis and brackets just giving the input on the keyboard \(()\) or \([]\). This does not work for braces.

Another way is to write parenthesis with the following notation:

LaTeX CODE

$$
\left(
\right) \\
\left[
\right]
$$

RESULT \[ \left( \right) \\ \left[ \right] \]

that is writing \left before opening the parenthesis and \right before closing the parenthesis.

In case of braces, we should use the following notation:

LaTeX CODE

$$
\left\{
\right\}
$$

RESULT \[ \left\{ \right\} \]

Note the difference with brackets that are written \left\ and \right\.

Example:

LaTeX CODE

$$
10 \cdot 
  \left\{
    5 + \left[
      3 + 2 \cdot 
         \left(
            9-1\right)
        \right]  
  \right\}
$$

RESULT \[ 10 \cdot \left\{ 5 + \left[ 3 + 2 \cdot \left( 9-1\right) \right] \right\} \]

The opportunity to write the full notation for parenthesis and brackets will be clear when dealing whit fractions.

Fractions

To write fractions the inputs to give are \frac and then numerator and denominator written between two braces. With an example will be clear.

Example:

LaTeX CODE

$$
\frac{5}{2}
$$

RESULT \[ \frac{5}{2} \]

Example:

LaTeX CODE

$$
\frac{\alpha}{1-\alpha} = \phi
$$

RESULT \[ \frac{\alpha}{1-\alpha} = \phi \]

Paranthesis & Fraction

If we write a fraction in parenthesis with the shortcut

LaTeX CODE

$$
( \frac{5}{2})
$$

RESULT \[ ( \frac{5}{2}) \]

the parenthesis do not fit the fraction.

If we write with full notation

LaTeX CODE

$$
\left(
\frac{5}{2}
\right)
$$

RESULT \[ \left( \frac{5}{2} \right) \]

we will have an appropriate result.

Example:

LaTeX CODE

$$
\frac{Y}{L} =
\left(
\frac{K}{L}, 1
\right)
$$

RESULT \[ \frac{Y}{L} = \left( \frac{K}{L}, 1 \right) \]

Exponential

To write the exponential we use the symbol ^

LaTeX CODE

$$
2^5
$$

RESULT \[ 2^5 \]

In case of operation in the exponential, we need to use braces after ^

Example:

LaTeX CODE

$$
F(K, L) = 
K^\alpha L^\beta
$$

RESULT \[ F(K, L) = K^\alpha L^\beta \]

Example:

LaTeX CODE

$$
F(K, L) =
\left[
\gamma K^\frac{\sigma - 1}{\sigma}
 + (1 - \gamma)L^\frac{\sigma - 1}{\sigma}
\right]^\frac{\sigma}{\sigma - 1}
$$

RESULT \[ F(K, L) = \left[ \gamma K^\frac{\sigma - 1}{\sigma} + (1 - \gamma)L^\frac{\sigma - 1}{\sigma} \right]^\frac{\sigma}{\sigma - 1} \]

Subscript

To write subscript use the symbol _

LaTeX CODE

$$
t_0
$$

RESULT \[ t_0 \]

We use braces in case of operation in subscript

Example

LaTeX CODE

$$
y_ty_{t-j}
$$

RESULT \[ y_ty_{t-j} \]

Derivative

Example:

LaTeX CODE

$$
\frac{dk}{k}
$$

RESULT \[ \frac{dk}{k} \]

To write partial differentiation, write \partial in the fraction notation

Example:

LaTeX CODE

$$
\frac{
\partial F}{
\partial K}
r + \delta
$$

RESULT \[ \frac{ \partial F}{ \partial K} r + \delta \]

Lagrangian

The symbol of Lagrangian is written as follows:

LaTeX CODE

$$
\mathcal L
$$

RESULT \[ \mathcal L \]

Summation

The code to write summation is the following: symbol of \sum_ followed by braces with lower bound of summation and ^ before the brace with the upper bound of summation.

Example:

LaTeX CODE

$$
\sum_{t_0}^{\infty}
$$

RESULT \[ \sum_{t_0}^{\infty} \]

An example summing up what we saw until now:

LaTeX CODE

$$
\mathcal L =
\sum_{t=0}^{\infty}
\left(
\frac {1}{1 + \rho}
\right)^{t} u(c_t)
\frac{L_t}{H}
 + \lambda
\left[
S_0 + \sum_{t=0}^{\infty}
R_t^{-1}w_t
\left(
\frac{L_t}{H}
\right)
- \sum_{t=0}^{\infty} R_t^{-1}c_t
\left(
\frac{L_t}{H}
\right)
\right]
$$

RESULT \[ \mathcal L = \sum_{t=0}^{\infty} \left( \frac {1}{1 + \rho} \right)^{t} u(c_t) \frac{L_t}{H} + \lambda \left[ S_0 + \sum_{t=0}^{\infty} R_t^{-1}w_t \left( \frac{L_t}{H} \right) - \sum_{t=0}^{\infty} R_t^{-1}c_t \left( \frac{L_t}{H} \right) \right] \]

Limit

The code for limit is written as follows:

LaTeX CODE

$$
\lim_{t\to\infty}
$$

RESULT \[ \lim_{t\to\infty} \]

Example:

LaTeX CODE

$$
\lim_
{t\to\infty}
R_t^{-1}S_t = 0
$$

RESULT \[ \lim_ {t\to\infty} R_t^{-1}S_t = 0 \]

Example

LaTeX CODE

$$
e^{
lim_{\gamma\to0}
\frac{1}{\gamma}ln
\left[
\alpha K^\gamma + (1 - \alpha)L^\gamma
\right]}
$$

RESULT \[ e^{ lim_{\gamma\to0} \frac{1}{\gamma}ln \left[ \alpha K^\gamma + (1 - \alpha)L^\gamma \right]} \]

Integrals

LaTeX CODE

$$
\int_0^\infty
$$

RESULT \[ \int_0^\infty \]

Example

$$
\int_0^\infty
  \left[
    r(t)e^{-R(t)}S(t) 
    + e^{-R(t)} w(t) 
    \frac{L(t)}{H}
    -e^{-R(t)}c(t) 
    \frac{L(t)}{H} 
  \right]
  dt
$$

\[ \int_0^\infty\left[r(t)e^{-R(t)}S(t) + e^{-R(t)} w(t) \frac{L(t)}{H}-e^{-R(t)}c(t) \frac{L(t)}{H} \right]dt \]

Matrix

The following example shows how to write a matrix.

Note that \bmatrix stands for bracket matrix while \pmatrix stands for parenthesized matrix. Other kinds of matrix are available.

Moreover, \vdots stands for vertical dots while \ddots for diagonal dots. \cdots stands for central dots, used also as multiplication sign.

$$
A =
\begin{bmatrix}
  a_{11} & a_{12} & a_{13} & \dots & a_{1n} \\
  a_{21} & a_{22} & a_{23} & \dots & a_{2n} \\
  \vdots & \vdots & \vdots & \vdots & \vdots\\
  a_{m1} & a_{m2} & a_{m3} & \dots & a_{mn} \\
\end{bmatrix}
\ne
B =
\begin{pmatrix}
 b_{11} & b_{12} & b_{13} & \cdots & b_{1n} \\
 b_{21} & \ddots & b_{23} & \cdots & b_{2n} \\
 ...&...&... & \ddots &... \\
 b_{m1} & b_{m2} & b_{m3} & \dots & b_{mn} \\
\end{pmatrix}
$$

\[ A = \begin{bmatrix} a_{11} & a_{12} & a_{13} & \dots & a_{1n} \\ a_{21} & a_{22} & a_{23} & \dots & a_{2n} \\ \vdots & \vdots & \vdots & \vdots & \vdots\\ a_{m1} & a_{m2} & a_{m3} & \dots & a_{mn} \\ \end{bmatrix} \ne B = \begin{pmatrix} b_{11} & b_{12} & b_{13} & \cdots & b_{1n} \\ b_{21} & \ddots & b_{23} & \cdots & b_{2n} \\ ...&...&... & \ddots &... \\ b_{m1} & b_{m2} & b_{m3} & \dots & b_{mn} \\ \end{pmatrix} \]

Equalities and Inequalities

desription latex result
Equality or assignment = \(=\)
Inequality \neq \(\neq\)
Less than < \(<\)
Less than or equal to \leq \(\leq\)
Greater than > \(>\)
Greater than or equal to \geq \(\geq\)
Approximately equal to \simeq \(\simeq\)

Subset and Functions

desription latex result
A is included in B A \subset B \(A \subset B\)
A includes B A \supset B \(A \supset B\)
A intersection B A \cap B \(A \cap B\)
A union B A \cup B \(A \cup B\)
x is in A x \in A \(x \in A\)
A contains x A \ni x \(A \ni x\)
x is not in A x \notin A \(x \notin A\)
for some x \exists x \(\exists x\)
for any x \forall x \(\forall x\)
tends to / maps into \to \(\to\)
gets \gets \(\gets\)
A implies B A \implies B \(A \implies B\)