Skip to content

Commit 6c5f4be

Browse files
AakashGfudemmcky
andauthored
🐛 FIX: changes in source file for pdf build (#136)
* changes for pdf build * requirements file update * Update jupyter-book to 0.13.1 * harmonise with lecture-python.myst * restrict jupyter-server * FIX: align environment for pdf * FIX: add latexify to adjust output to png Co-authored-by: mmcky <[email protected]>
1 parent 74e248f commit 6c5f4be

File tree

8 files changed

+41
-37
lines changed

8 files changed

+41
-37
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ jobs:
4242
name: build-cache
4343
path: _build
4444
# Build Assets (Download Notebooks and PDF via LaTeX)
45-
# - name: Build PDF from LaTeX
46-
# shell: bash -l {0}
47-
# run: |
48-
# jb build lectures --builder pdflatex --path-output ./ -n --keep-going
49-
# mkdir -p _build/html/_pdf
50-
# cp -u _build/latex/*.pdf _build/html/_pdf
45+
- name: Build PDF from LaTeX
46+
shell: bash -l {0}
47+
run: |
48+
jb build lectures --builder pdflatex --path-output ./ -n --keep-going
49+
mkdir -p _build/html/_pdf
50+
cp -u _build/latex/*.pdf _build/html/_pdf
5151
- name: Build Download Notebooks (sphinx-tojupyter)
5252
shell: bash -l {0}
5353
run: |

lectures/Manifest.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# This file is machine-generated - editing it directly is not advised
22

3-
julia_version = "1.8.3"
3+
julia_version = "1.8.5"
44
manifest_format = "2.0"
5-
project_hash = "f509bdfe41f89452dd3da3343ba86802b3f9cdba"
5+
project_hash = "426ee44181a1827c854acad97427614830a3ef74"
66

77
[[deps.AMD]]
88
deps = ["Libdl", "LinearAlgebra", "SparseArrays", "Test"]
@@ -330,7 +330,7 @@ version = "3.46.0"
330330
[[deps.CompilerSupportLibraries_jll]]
331331
deps = ["Artifacts", "Libdl"]
332332
uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae"
333-
version = "0.5.2+0"
333+
version = "1.0.1+0"
334334

335335
[[deps.CompositeTypes]]
336336
git-tree-sha1 = "02d2316b7ffceff992f3096ae48c7829a8aa0638"
@@ -1005,9 +1005,9 @@ version = "0.4.5"
10051005

10061006
[[deps.Latexify]]
10071007
deps = ["Formatting", "InteractiveUtils", "LaTeXStrings", "MacroTools", "Markdown", "OrderedCollections", "Printf", "Requires"]
1008-
git-tree-sha1 = "ab9aa169d2160129beb241cb2750ca499b4e90e9"
1008+
git-tree-sha1 = "2422f47b34d4b127720a18f86fa7b1aa2e141f29"
10091009
uuid = "23fbe1c1-3f47-55db-b15f-69d7ec21a316"
1010-
version = "0.15.17"
1010+
version = "0.15.18"
10111011

10121012
[[deps.LayoutPointers]]
10131013
deps = ["ArrayInterface", "ArrayInterfaceOffsetArrays", "ArrayInterfaceStaticArrays", "LinearAlgebra", "ManualMemory", "SIMDTypes", "Static"]

lectures/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ IterativeSolvers = "42fd0dbc-a981-5370-80f2-aaf504508153"
2626
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
2727
KernelDensity = "5ab0869b-81aa-558d-bb23-cbf5423bbe9b"
2828
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
29+
Latexify = "23fbe1c1-3f47-55db-b15f-69d7ec21a316"
2930
LeastSquaresOptim = "0fc2ff8b-aaa3-5acd-a817-1944a5e08891"
3031
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
3132
LinearMaps = "7a12625a-238d-50fd-b39a-03d52299707e"

lectures/dynamic_programming_squared/opt_tax_recur.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,6 @@ and $\tau_0$ is the time $t=0$ tax rate.
697697
In equation {eq}`opt_tax_eqn_10`, it is understood that
698698

699699
```{math}
700-
:nowrap:
701700
702701
\begin{aligned}
703702
\tau_0 = 1 - \frac{u_{l,0}}{u_{c,0}} \\

lectures/tools_and_techniques/geom_series.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Below we'll use the following packages:
4747

4848
```{code-cell} julia
4949
using LinearAlgebra, Statistics
50-
using Distributions, LaTeXStrings, Plots, Random, Symbolics
50+
using Distributions, LaTeXStrings, Plots, Random, Symbolics, Latexify
5151
```
5252

5353
## Key Formulas
@@ -550,9 +550,11 @@ For a reason soon to be revealed, we assume that $G < R$.
550550
The **present value** of the lease is
551551

552552
$$
553-
\begin{aligned} p_0 & = x_0 + x_1/R + x_2/(R^2) + \ddots \\
554-
& = x_0 (1 + G R^{-1} + G^2 R^{-2} + \cdots ) \\
555-
& = x_0 \frac{1}{1 - G R^{-1}} \end{aligned}
553+
\begin{aligned}
554+
p_0 & = x_0 + x_1/R + x_2/(R^2) + \ddots \\
555+
& = x_0 (1 + G R^{-1} + G^2 R^{-2} + \cdots ) \\
556+
& = x_0 \frac{1}{1 - G R^{-1}}
557+
\end{aligned}
556558
$$
557559

558560
where the last line uses the formula for an infinite geometric series.
@@ -605,7 +607,11 @@ $$
605607
The present value of this lease is:
606608

607609
$$
608-
\begin{aligned} \begin{split}p_0&=x_0 + x_1/R + \dots +x_T/R^T \\ &= x_0(1+GR^{-1}+\dots +G^{T}R^{-T}) \\ &= \frac{x_0(1-G^{T+1}R^{-(T+1)})}{1-GR^{-1}} \end{split}\end{aligned}
610+
\begin{aligned}
611+
\begin{split}
612+
p_0&=x_0 + x_1/R + \dots +x_T/R^T \\ &= x_0(1+GR^{-1}+\dots +G^{T}R^{-T}) \\ &= \frac{x_0(1-G^{T+1}R^{-(T+1)})}{1-GR^{-1}}
613+
\end{split}
614+
\end{aligned}
609615
$$
610616

611617
Applying the Taylor series to $R^{-(T+1)}$ about $r=0$ we get:
@@ -629,7 +635,9 @@ $$
629635
Expanding:
630636

631637
$$
632-
\begin{aligned} p_0 &=\frac{x_0(1-1+(T+1)^2 rg -r(T+1)+g(T+1))}{1-1+r-g+rg} \\&=\frac{x_0(T+1)((T+1)rg+r-g)}{r-g+rg} \\ &\approx \frac{x_0(T+1)(r-g)}{r-g}+\frac{x_0rg(T+1)}{r-g}\\ &= x_0(T+1) + \frac{x_0rg(T+1)}{r-g} \end{aligned}
638+
\begin{aligned}
639+
p_0 &=\frac{x_0(1-1+(T+1)^2 rg -r(T+1)+g(T+1))}{1-1+r-g+rg} \\&=\frac{x_0(T+1)((T+1)rg+r-g)}{r-g+rg} \\ &\approx \frac{x_0(T+1)(r-g)}{r-g}+\frac{x_0rg(T+1)}{r-g}\\ &= x_0(T+1) + \frac{x_0rg(T+1)}{r-g}
640+
\end{aligned}
633641
$$
634642

635643
We could have also approximated by removing the second term
@@ -756,23 +764,23 @@ G = (1 + g)
756764
R = (1 + r)
757765
p0 = x0 / (1 - G * R ^ (-1))
758766
print("Our formula is")
759-
p0
767+
latexify(p0) |> s -> render(s, MIME("image/png"))
760768
```
761769

762770
```{code-cell} julia
763771
# Partial derivative with respect to g
764772
dg = Differential(g)
765773
dp_dg = expand_derivatives(dg(p0))
766774
print("dp0 / dg is")
767-
dp_dg
775+
latexify(dp_dg) |> s -> render(s, MIME("image/png"))
768776
```
769777

770778
```{code-cell} julia
771779
# Partial derivative with respect to r
772780
dr = Differential(r)
773781
dp_dr = expand_derivatives(dr(p0))
774782
print("dp0 / dr is")
775-
dp_dr
783+
latexify(dp_dr) |> s -> render(s, MIME("image/png"))
776784
```
777785

778786
We can see that for $\frac{\partial p_0}{\partial r}<0$ as long as

lectures/tools_and_techniques/iterative_methods_sparsity.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ To solve for the coefficients, we notice that this is a simple system of equatio
218218

219219
$$
220220
\begin{array}
221-
\,y_0 = c_0 + c_1 x_0 + \ldots c_N x_0^N\\
221+
cy_0 = c_0 + c_1 x_0 + \ldots c_N x_0^N\\
222222
\,\ldots\\
223223
\,y_N = c_0 + c_1 x_N + \ldots c_N x_N^N
224224
\end{array}
@@ -502,10 +502,10 @@ $$
502502
Rearrange the $(D + R)x = b$ as
503503

504504
$$
505-
\begin{align}
505+
\begin{aligned}
506506
D x &= b - R x\\
507507
x &= D^{-1} (b - R x)
508-
\end{align}
508+
\end{aligned}
509509
$$
510510

511511
where, since $D$ is diagonal, its inverse is trivial to calculate with $O(N)$ complexity.
@@ -618,12 +618,12 @@ operations.
618618
To see an example of a right-preconditioner, consider a matrix $P$ which has a convenient and numerically stable inverse. Then
619619

620620
$$
621-
\begin{align}
621+
\begin{aligned}
622622
A x &= b\\
623623
A P^{-1} P x &= b\\
624624
A P^{-1} y &= b\\
625625
P x &= y
626-
\end{align}
626+
\end{aligned}
627627
$$
628628

629629
That is, solve $(A P^{-1})y = b$ for $y$, and then solve $P x = y$ for $x$.
@@ -1000,12 +1000,12 @@ before we enumerate them linearly, take a $v\in R^{\mathbf{N}}$ interpreted as a
10001000
For example, if we were implementing the product at the row of $Q$ corresponding to the $(n_1, \ldots, n_M)$ state, then
10011001

10021002
$$
1003-
\begin{align}
1003+
\begin{aligned}
10041004
Q_{(n_1, \ldots n_M)} \cdot v &=
10051005
\theta \sum_{m=1}^M (n_m < N) v(n_1, \ldots, n_m + 1, \ldots, n_M)\\
10061006
&+ \zeta \sum_{m=1}^M (1 < n_m) v(n_1, \ldots, n_m - 1, \ldots, n_M)\\
10071007
&-\left(\theta\, \text{Count}(n_m < N) + \zeta\, \text{Count}( n_m > 1)\right)v(n_1, \ldots, n_M)
1008-
\end{align}
1008+
\end{aligned}
10091009
$$
10101010

10111011
Here:
@@ -1182,12 +1182,12 @@ The logic for the adjoint is that for a given $n = (n_1,\ldots, n_m, \ldots n_M)
11821182
Implementing this logic, first in math and then in code,
11831183

11841184
$$
1185-
\begin{align}
1185+
\begin{aligned}
11861186
Q^T_{(n_1, \ldots, n_M)} \cdot \psi &=
11871187
\theta \sum_{m=1}^M (n_m > 1) \psi(n_1, \ldots, n_m - 1, \ldots, n_M)\\
11881188
&+ \zeta \sum_{m=1}^M (n_m < N) \psi(n_1, \ldots, n_m + 1, \ldots, n_M)\\
11891189
&-\left(\theta\, \text{Count}(n_m < N) + \zeta\, \text{Count}( n_m > 1)\right)\psi(n_1, \ldots, n_M)
1190-
\end{align}
1190+
\end{aligned}
11911191
$$
11921192

11931193
```{code-cell} julia

lectures/tools_and_techniques/linear_algebra.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,6 @@ $$
12861286
To evaluate the function
12871287

12881288
```{math}
1289-
:nowrap:
12901289
12911290
\begin{aligned}
12921291
v(x) &= -(Ax+ B u)'P(Ax+Bu) - u'Q u \\
@@ -1301,7 +1300,6 @@ For simplicity, denote by $S := (Q + B'PB)^{-1} B'PA$, then $u = -Sx$.
13011300
Regarding the second term $- 2u'B'PAx$,
13021301

13031302
```{math}
1304-
:nowrap:
13051303
13061304
\begin{aligned}
13071305
- 2u'B'PAx &= -2 x'S'B'PAx \\
@@ -1315,7 +1313,6 @@ are symmetric.
13151313
Regarding the third term $- u'(Q + B'PB) u$,
13161314

13171315
```{math}
1318-
:nowrap:
13191316
13201317
\begin{aligned}
13211318
- u'(Q + B'PB) u &= - x'S' (Q + B'PB)Sx \\
@@ -1329,7 +1326,6 @@ $x'A'PB(Q + B'PB)^{-1}B'PAx$.
13291326
This implies that
13301327

13311328
```{math}
1332-
:nowrap:
13331329
13341330
\begin{aligned}
13351331
v(x) &= - x'A'PAx - 2u'B'PAx - u'(Q + B'PB) u\\

requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
jupyter-book==0.12.3
2-
sphinxext.rediraffe==0.2.7
3-
sphinx-tojupyter==0.2.1
42
quantecon-book-theme==0.3.1
5-
markupsafe==2.1.1
3+
sphinx-tojupyter==0.2.1
4+
sphinxext.rediraffe==0.2.7
5+
jupyter-server<2

0 commit comments

Comments
 (0)