Skip to content

Commit

Permalink
Ensure $ math can be \ escaped and replace {math} roles/directive…
Browse files Browse the repository at this point in the history
…s with `$` notation in docs (#17)
  • Loading branch information
chrisjsewell committed Feb 13, 2020
1 parent b29369f commit f1c348f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 36 deletions.
8 changes: 7 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@ if you find any more.
To install the myst parser (and thus to be able to build these docs),
run the following:

```bash
pip install -e git+https://github.com/ExecutableBookProject/myst_parser.git#egg=myst_parser[sphinx]
```

Or for package development:

```bash
git clone https://github.com/chrisjsewell/mistletoe
cd mistletoe
git checkout myst
pip install .[sphinx,testing]
pip install -e .[sphinx,testing]
```

This should install the myst fork of mistletoe, along with the Sphinx parser
Expand Down
56 changes: 22 additions & 34 deletions docs/wealth_dynamics_md.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ ax.legend()
plt.show()
```

This curve can be understood as follows: if point {math}`x,y` lies on the
curve, it means that, collectively, the bottom {math}`100x)\%` of the
population holds {math}`(100y)\%` of the wealth.
This curve can be understood as follows: if point $x,y$ lies on the
curve, it means that, collectively, the bottom $(100x)\%$ of the
population holds $(100y)\%$ of the wealth.

```{code-block} python
a_vals = (1, 2, 5) # Pareto tail index
Expand Down Expand Up @@ -114,15 +114,13 @@ complete inequality (all wealth held by the richest household).
The [QuantEcon.py](https://github.com/QuantEcon/QuantEcon.py) library
contains a function to calculate the Gini coefficient.

We can test it on the Weibull distribution with parameter {math}`a`, where the
We can test it on the Weibull distribution with parameter $a$, where the
Gini coefficient is known to be

```{math}
G = 1 - 2^{-1/a}
```
$$G = 1 - 2^{-1/a}$$

Let's see if the Gini coefficient computed from a simulated sample
matches this at each fixed value of {math}`a`.
matches this at each fixed value of $a$.

```{code-block} python
a_vals = range(1, 20)
Expand Down Expand Up @@ -152,43 +150,33 @@ dynamics.

The model we will study is

```{math}
w_{t+1} = (1 + r_{t+1}) s(w_t) + y_{t+1}
```
$$w_{t+1} = (1 + r_{t+1}) s(w_t) + y_{t+1}$$

where

- {math}`w_t` is wealth at time $t$ for a given household,
- {math}`r_t` is the rate of return of financial assets,
- {math}`y_t` is current non-financial (e.g., labor) income and
- {math}`s(w_t)` is current wealth net of consumption
- $w_t$ is wealth at time $t$ for a given household,
- $r_t$ is the rate of return of financial assets,
- $y_t$ is current non-financial (e.g., labor) income and
- $s(w_t)$ is current wealth net of consumption

Letting {math}`\{z_t\}` be a correlated state process of the form
Letting $\{z_t\}$ be a correlated state process of the form

```{math}
z_{t+1} = a z_t + b + \sigma_z \epsilon_{t+1}
```
$$z_{t+1} = a z_t + b + \sigma_z \epsilon_{t+1}$$

we'll assume that

```{math}
R_t := 1 + r_t = c_r \exp(z_t) + \exp(\mu_r + \sigma_r \xi_t)
```
$$R_t := 1 + r_t = c_r \exp(z_t) + \exp(\mu_r + \sigma_r \xi_t)$$

and

```{math}
y_t = c_y \exp(z_t) + \exp(\mu_y + \sigma_y \zeta_t)
```
$$y_t = c_y \exp(z_t) + \exp(\mu_y + \sigma_y \zeta_t)$$

Here {math}`\{ ($\epsilon_t$, \xi_t, \zeta_t) \}` is IID and standard normal in
{math}`\mathbb R^3`.
Here $\{ (\epsilon_t, \xi_t, \zeta_t) \}$ is IID and standard normal in
$\mathbb R^3$.

```{math}
s(w) = s_0 w \cdot \mathbb 1\{w \geq \hat w\}
```
$$s(w) = s_0 w \cdot \mathbb 1\{w \geq \hat w\}$$

where {math}`s_0` is a positive constant.
where $s_0$ is a positive constant.

## Implementation

Expand Down Expand Up @@ -394,8 +382,7 @@ def generate_lorenz_and_gini(wdy, num_households=100_000, T=500):
Now we investigate how the Lorenz curves associated with the wealth
distribution change as return to savings varies.

The code below plots Lorenz curves for three different values of
{math}`\mu_r`.
The code below plots Lorenz curves for three different values of $\mu_r$.

If you are running this yourself, note that it will take one or two
minutes to execute.
Expand Down Expand Up @@ -424,6 +411,7 @@ plt.show()
The Lorenz curve shifts downwards as returns on financial income rise,
indicating a rise in inequality.

(htop_again)=

```{image} htop_again.png
---
Expand All @@ -445,7 +433,7 @@ Once again, we see that inequality increases as returns on financial
income rise.

Let's finish this section by investigating what happens when we change
the volatility term {math}`\sigma_r` in financial returns.
the volatility term $\sigma_r$ in financial returns.

```{code-block} python
fig, ax = plt.subplots()
Expand Down
7 changes: 6 additions & 1 deletion myst_parser/span_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
LineBreak,
RawText,
)
from mistletoe.latex_token import Math

"""
Tokens to be included in the parsing process, in the order specified.
Expand Down Expand Up @@ -52,6 +51,12 @@ def __init__(self, match):
)


class Math(span_token.SpanToken):
pattern = re.compile(r"(?<!\\|`)(?:\\\\)*(\${1,2})([^\$]+?)\1")
parse_inner = False
parse_group = 0


class Target(span_token.SpanToken):
"""Target tokens. ("!(target name)")"""

Expand Down

0 comments on commit f1c348f

Please sign in to comment.