Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Enable PDF book style build via LaTeX #193

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
10d0d9d
changes necessary for pdf build
AakashGfude Oct 18, 2021
3099b49
mathjax config
AakashGfude Oct 18, 2021
b09df2b
Github Actions: Enable building of pdf and download notebooks in CI
mmcky Oct 18, 2021
1cf42fe
add imagemagick for sphinx.ext.imgconverter
mmcky Oct 19, 2021
e3a1290
add failure artifact upload
mmcky Oct 19, 2021
3af0edc
TEMP: install myst-nb@master
mmcky Oct 25, 2021
c944329
enforce sphinx-tojupyter==0.2.0
mmcky Oct 25, 2021
a286759
upgrade to jupyter-book=0.12 and sphinx>=4
mmcky Oct 25, 2021
cde5d36
Merge branch 'main' into pdf-changes
mmcky Oct 25, 2021
51875b9
change name of pdf
mmcky Oct 25, 2021
dcbe5e7
Merge branch 'main' into pdf-changes
AakashGfude Dec 6, 2021
c9e7606
adding text-macros and mathjaxv2
AakashGfude Dec 6, 2021
f18da1a
text-macros not loading
AakashGfude Dec 7, 2021
90925f0
changing to mathjax 2.7.9
AakashGfude Dec 7, 2021
3c52d1f
adding cache and mathjax key
AakashGfude Dec 7, 2021
854da9c
pinning version to 0.2.1
AakashGfude Dec 7, 2021
a11426a
pinning versions to fix to sphinx3
AakashGfude Dec 8, 2021
5b4f69a
build other files as well
AakashGfude Dec 8, 2021
ea7eb99
pinning to sphinx v3
AakashGfude Dec 15, 2021
95c34ca
removing cache to see fresh build
AakashGfude Dec 15, 2021
3700fe2
testing with plotly file only
AakashGfude Dec 15, 2021
2a1a92c
without error
AakashGfude Dec 16, 2021
1023fca
checking with old ci
AakashGfude Dec 16, 2021
2e7b312
error off
AakashGfude Dec 16, 2021
e59096e
putting myst-nb latest install in ci
AakashGfude Dec 16, 2021
06219e7
adding latex dependencies
AakashGfude Dec 16, 2021
fa94e47
added latex build
AakashGfude Dec 16, 2021
138d170
downloading, uploading artifacts
AakashGfude Dec 16, 2021
0c702dd
build folder from cache
AakashGfude Dec 16, 2021
1f4f0c8
upload artifacts
AakashGfude Dec 16, 2021
e35a921
reports path
AakashGfude Dec 16, 2021
aa37ac0
adding cache build folder
AakashGfude Dec 16, 2021
8571bb8
reverting changes to toc and config
AakashGfude Dec 16, 2021
ea50268
uploading build as artifact
AakashGfude Dec 16, 2021
4c1c2cd
-W
AakashGfude Dec 16, 2021
78167d5
trying out the whole build
AakashGfude Dec 16, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,37 @@ jobs:
python-version: 3.8
environment-file: environment.yml
activate-environment: lecture-datascience
- name: Install myst-nb
run: |
pip install git+https://github.com/executablebooks/MyST-NB@master
- name: Install sphinx
run: |
pip install sphinx==3.5.0
- name: Install latex dependencies
run: |
sudo apt-get -qq update
sudo apt-get install -y \
texlive-latex-recommended \
texlive-latex-extra \
texlive-fonts-recommended \
texlive-fonts-extra \
texlive-xetex \
latexmk \
xindy \
imagemagick
- name: Display Conda Environment Versions
shell: bash -l {0}
run: conda list
- name: Display Pip Versions
shell: bash -l {0}
run: pip list
# Build Assets (Download Notebooks and PDF via LaTeX)
- name: Build PDF from LaTeX
shell: bash -l {0}
run: |
jb build lectures --builder pdflatex --path-output ./ -n --keep-going
mkdir -p _build/html/_pdf
cp -u _build/latex/*.pdf _build/html/_pdf
- name: Download "build" folder (cache)
uses: dawidd6/action-download-artifact@v2
with:
Expand Down Expand Up @@ -49,6 +74,11 @@ jobs:
run: |
mkdir -p _build/html/assets/data
cp -a lectures/_data/. _build/html/assets/data/
- name: Save Build as Artifact
uses: actions/upload-artifact@v1
with:
name: _build
path: _build
- name: Preview Deploy to Netlify
uses: nwtgck/actions-netlify@v1.1
with:
Expand All @@ -58,4 +88,4 @@ jobs:
deploy-message: "Preview Deploy from GitHub Actions"
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
7 changes: 4 additions & 3 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ dependencies:
- anaconda=2021.05
- pip
- pip:
- jupyter-book>=0.12.1,<0.13
- sphinx==3.5.0
- jupyter-book>=0.12.1,<0.13.0
- sphinxext-rediraffe
- sphinx-multitoc-numbering
- sphinx-exercise
- sphinx-exercise==0.2.1
- joblib
- interpolation
- sphinx-tojupyter
- sphinx-tojupyter==0.1.2
- fiona
- geopandas
- pyLDAvis >= 3.3.0
Expand Down
10 changes: 7 additions & 3 deletions lectures/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ execute:
html:
baseurl: https://datascience.quantecon.org/

latex:
latex_documents:
targetname: datascience-book.tex

sphinx:
extra_extensions: [sphinx_multitoc_numbering, sphinx_exercise, sphinx_tojupyter]
config:
Expand All @@ -32,9 +36,9 @@ sphinx:
binderhub_url: https://mybinder.org
google_analytics_id: UA-54984338-5
persistent_sidebar: true
mathjax2_config:
mathjax_config:
TeX:
extensions: ["autobold.js"]
extensions: ["autobold.js", "text-macros.js"]
Macros:
"argmax" : "arg\\,max"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AakashGfude I presume these aren't required for datascience

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they are already added in quantecon-book-theme for mathjax v3. https://github.com/QuantEcon/quantecon-book-theme/blob/master/quantecon_book_theme/layout.html#L10 .

Since, there is no variable in sphinx to add configuration for mathjax3 in config file. I think it should be introduced in sphinxv4 though.

Copy link
Contributor

@mmcky mmcky Oct 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the new variable in sphinx version 4+ is mathjax3_config

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AakashGfude I have opened a issue to track that inclusion

QuantEcon/quantecon-book-theme#167

"argmin" : "arg\\,min"
Expand All @@ -45,7 +49,7 @@ sphinx:
SVG:
scale: 0.92,
useGlobalCache: true
mathjax_path: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML
mathjax_path: https://cdn.jsdelivr.net/npm/mathjax@2.7.9/MathJax.js?config=TeX-MML-AM_CHTML
tojupyter_static_file_path: ["_static"]
tojupyter_target_html: true
tojupyter_urlpath: "https://datascience.quantecon.org/"
Expand Down
9 changes: 4 additions & 5 deletions lectures/applications/heterogeneity.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ When treatment is randomly assigned, we can estimate average treatment
effects because

$$
\begin{align*}
\begin{aligned}
E[y_i(1) - y_i(0) ] = & E[y_i(1)] - E[y_i(0)] \\
& \text{random assignment } \\
= & E[y_i(1) | d_i = 1] - E[y_i(0) | d_i = 0] \\
= & E[y_i | d_i = 1] - E[y_i | d_i = 0 ]
\end{align*}
\end{aligned}
$$

### Average Treatment Effects
Expand Down Expand Up @@ -164,12 +164,12 @@ logic that lets us estimate unconditional average treatment effects
also suggests that we can estimate conditional average treatment effects.

$$
\begin{align*}
\begin{aligned}
E[y_i(1) - y_i(0) |X_i=x] = & E[y_i(1)|X_i = x] - E[y_i(0)|X_i=x] \\
& \text{random assignment } \\
= & E[y_i(1) | d_i = 1, X_i=x] - E[y_i(0) | d_i = 0, X_i=x] \\
= & E[y_i | d_i = 1, X_i = x] - E[y_i | d_i = 0, X_i=x ]
\end{align*}
\end{aligned}
$$

Conditional average treatment effects tell us whether there are
Expand Down Expand Up @@ -209,7 +209,6 @@ $S(x)$ approximates $s_0(x)$ is to look at the best linear
projection of $s_0(x)$ on $S(x)$.

$$
\DeclareMathOperator*{\argmin}{arg\,min}
\beta_0, \beta_1 = \argmin_{b_0,b_1} E[(s_0(x) -
b_0 - b_1 (S(x)-E[S(x)]))^2]
$$
Expand Down
12 changes: 6 additions & 6 deletions lectures/applications/regression.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ only the livable square footage of the home.
The linear regression model for this situation is

$$
\log(\text{price}) = \beta_0 + \beta_1 \text{sqft_living} + \epsilon
\log(\text{price}) = \beta_0 + \beta_1 \text{sqft\_living} + \epsilon
$$

$\beta_0$ and $\beta_1$ are called parameters (also coefficients or
Expand All @@ -132,14 +132,14 @@ that best fit the data.

$\epsilon$ is the error term. It would be unusual for the observed
$\log(\text{price})$ to be an exact linear function of
$\text{sqft_living}$. The error term captures the deviation of
$\log(\text{price})$ from a linear function of $\text{sqft_living}$.
$\text{sqft\_living}$. The error term captures the deviation of
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AakashGfude just for clarity for when I update the style guide we need to escape the _ right?

This change QuantEcon/quantecon-book-theme@ec8d8c8 will then enable the correct Tex to be processed by mathjax.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, if we want to write a literal underscore, then we will have to escape it like that. http://docs.mathjax.org/en/latest/input/tex/extensions/textmacros.html#quoted-special-characters . I was about to comment about mentioning textmacros in the style guide as well http://docs.mathjax.org/en/latest/input/tex/extensions/textmacros.html

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that would be great -- can you remind me or open an issue on: QuantEcon.manual

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mmcky what is QuantEcon.manual ?

$\log(\text{price})$ from a linear function of $\text{sqft\_living}$.

The linear regression algorithm will choose the parameters that minimize the
*mean squared error* (MSE) function, which for our example is written.

$$
\frac{1}{N} \sum_{i=1}^N \left(\log(\text{price}_i) - (\beta_0 + \beta_1 \text{sqft_living}_i) \right)^2
\frac{1}{N} \sum_{i=1}^N \left(\log(\text{price}_i) - (\beta_0 + \beta_1 \text{sqft\_living}_i) \right)^2
$$

The output of this algorithm is the straight line (hence linear) that passes as
Expand Down Expand Up @@ -218,7 +218,7 @@ Suppose that in addition to `sqft_living`, we also wanted to use the `bathrooms`
In this case, the linear regression model is

$$
\log(\text{price}) = \beta_0 + \beta_1 \text{sqft_living} +
\log(\text{price}) = \beta_0 + \beta_1 \text{sqft\_living} +
\beta_2 \text{bathrooms} + \epsilon
$$

Expand All @@ -227,7 +227,7 @@ We could keep adding one variable at a time, along with a new $\beta_{j}$ coeffi
Let's write this equation in vector/matrix form as

$$
\underbrace{\begin{bmatrix} \log(\text{price}_1) \\ \log(\text{price}_2) \\ \vdots \\ \log(\text{price}_N)\end{bmatrix}}_Y = \underbrace{\begin{bmatrix} 1 & \text{sqft_living}_1 & \text{bathrooms}_1 \\ 1 & \text{sqft_living}_2 & \text{bathrooms}_2 \\ \vdots & \vdots & \vdots \\ 1 & \text{sqft_living}_N & \text{bathrooms}_N \end{bmatrix}}_{X} \underbrace{\begin{bmatrix} \beta_0 \\ \beta_1 \\ \beta_2 \end{bmatrix}}_{\beta} + \epsilon
\underbrace{\begin{bmatrix} \log(\text{price}_1) \\ \log(\text{price}_2) \\ \vdots \\ \log(\text{price}_N)\end{bmatrix}}_Y = \underbrace{\begin{bmatrix} 1 & \text{sqft\_living}_1 & \text{bathrooms}_1 \\ 1 & \text{sqft\_living}_2 & \text{bathrooms}_2 \\ \vdots & \vdots & \vdots \\ 1 & \text{sqft\_living}_N & \text{bathrooms}_N \end{bmatrix}}_{X} \underbrace{\begin{bmatrix} \beta_0 \\ \beta_1 \\ \beta_2 \end{bmatrix}}_{\beta} + \epsilon
$$

Notice that we can add as many columns to $X$ as we'd like and the linear
Expand Down
4 changes: 2 additions & 2 deletions lectures/problem_sets/problem_set_3.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,10 @@ face value $M$, yield to maturity $i$, and periods to maturity
$N$ is

$$
\begin{align*}
\begin{aligned}
P &= \left(\sum_{n=1}^N \frac{C}{(i+1)^n}\right) + \frac{M}{(1+i)^N} \\
&= C \left(\frac{1 - (1+i)^{-N}}{i} \right) + M(1+i)^{-N}
\end{align*}
\end{aligned}
$$

In the code cell below, we have defined variables for `i`, `M` and `C`.
Expand Down
4 changes: 2 additions & 2 deletions lectures/python_fundamentals/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -633,10 +633,10 @@ that can be interchanged.
That is, the following are identical.

$$
\begin{eqnarray}
\begin{aligned}
f(K, L) &= z\, K^{\alpha} L^{1-\alpha}\\
f(K_2, L_2) &= z\, K_2^{\alpha} L_2^{1-\alpha}
\end{eqnarray}
\end{aligned}
$$

The same concept applies to Python functions, where the arguments are just
Expand Down
4 changes: 2 additions & 2 deletions lectures/scientific/applied_linalg.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,11 @@ $\begin{bmatrix} 1 & 2 \\ 3 & 1 \end{bmatrix}$ then we can multiply both sides b
to get

$$
\begin{align*}
\begin{aligned}
\begin{bmatrix} 1 & 2 \\ 3 & 1 \end{bmatrix}^{-1}\begin{bmatrix} 1 & 2 \\ 3 & 1 \end{bmatrix} \begin{bmatrix} x_1 \\ x_2 \end{bmatrix} &= \begin{bmatrix} 1 & 2 \\ 3 & 1 \end{bmatrix}^{-1}\begin{bmatrix} 3 \\ 4 \end{bmatrix} \\
I \begin{bmatrix} x_1 \\ x_2 \end{bmatrix} &= \begin{bmatrix} 1 & 2 \\ 3 & 1 \end{bmatrix}^{-1} \begin{bmatrix} 3 \\ 4 \end{bmatrix} \\
\begin{bmatrix} x_1 \\ x_2 \end{bmatrix} &= \begin{bmatrix} 1 & 2 \\ 3 & 1 \end{bmatrix}^{-1} \begin{bmatrix} 3 \\ 4 \end{bmatrix}
\end{align*}
\end{aligned}
$$

Computing the inverse requires that a matrix be square and satisfy some other conditions
Expand Down
4 changes: 2 additions & 2 deletions lectures/scientific/numpy_arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -521,10 +521,10 @@ face value $M$, yield to maturity $i$, and periods to maturity
$N$ is

$$
\begin{align*}
\begin{aligned}
P &= \left(\sum_{n=1}^N \frac{C}{(i+1)^n}\right) + \frac{M}{(1+i)^N} \\
&= C \left(\frac{1 - (1+i)^{-N}}{i} \right) + M(1+i)^{-N}
\end{align*}
\end{aligned}
$$

In the code cell below, we have defined variables for `i`, `M` and `C`.
Expand Down