Skip to content

Commit

Permalink
🧹 Splitup notebooks into appendix part with autogenerated index.tex
Browse files Browse the repository at this point in the history
and manual include
  • Loading branch information
s-weigand committed Mar 8, 2023
1 parent 1033f0d commit c76f8ce
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 54 deletions.
28 changes: 0 additions & 28 deletions notebooks/analysis1.ipynb → notebooks/appendix/appendix1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@
"cell_type": "markdown",
"id": "f9bf23c9",
"metadata": {
"papermill": {
"duration": 0.003531,
"end_time": "2022-10-08T17:53:35.288857",
"exception": false,
"start_time": "2022-10-08T17:53:35.285326",
"status": "completed"
},
"tags": []
},
"source": [
Expand All @@ -22,13 +15,6 @@
"execution_count": null,
"id": "cf7fa0db",
"metadata": {
"papermill": {
"duration": 0.016909,
"end_time": "2022-10-08T17:53:35.308675",
"exception": false,
"start_time": "2022-10-08T17:53:35.291766",
"status": "completed"
},
"tags": []
},
"outputs": [],
Expand All @@ -41,13 +27,6 @@
"cell_type": "markdown",
"id": "dfb4f5d5",
"metadata": {
"papermill": {
"duration": 0.003047,
"end_time": "2022-10-08T17:53:35.314662",
"exception": false,
"start_time": "2022-10-08T17:53:35.311615",
"status": "completed"
},
"tags": []
},
"source": [
Expand All @@ -59,13 +38,6 @@
"cell_type": "markdown",
"id": "b8783e22",
"metadata": {
"papermill": {
"duration": 0.003258,
"end_time": "2022-10-08T17:53:35.320660",
"exception": false,
"start_time": "2022-10-08T17:53:35.317402",
"status": "completed"
},
"tags": []
},
"source": [
Expand Down
21 changes: 0 additions & 21 deletions notebooks/analysis2.ipynb → notebooks/appendix/appendix2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@
"cell_type": "markdown",
"id": "3956d5a2",
"metadata": {
"papermill": {
"duration": 0.003024,
"end_time": "2022-10-08T17:53:36.677206",
"exception": false,
"start_time": "2022-10-08T17:53:36.674182",
"status": "completed"
},
"tags": []
},
"source": [
Expand All @@ -22,13 +15,6 @@
"execution_count": null,
"id": "fdf379f6",
"metadata": {
"papermill": {
"duration": 0.011521,
"end_time": "2022-10-08T17:53:36.692041",
"exception": false,
"start_time": "2022-10-08T17:53:36.680520",
"status": "completed"
},
"tags": []
},
"outputs": [],
Expand All @@ -43,13 +29,6 @@
"execution_count": null,
"id": "7883ce10",
"metadata": {
"papermill": {
"duration": 0.012985,
"end_time": "2022-10-08T17:53:36.707853",
"exception": false,
"start_time": "2022-10-08T17:53:36.694868",
"status": "completed"
},
"tags": []
},
"outputs": [],
Expand Down
57 changes: 57 additions & 0 deletions notebooks/sections/application.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"id": "90790ecd",
"metadata": {
"tags": []
},
"source": [
"# Application"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "1791469b",
"metadata": {
"tags": []
},
"source": [
"## Basic usage example"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "7a2573a0",
"metadata": {
"tags": []
},
"source": [
"1+1"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "master-thesis",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
11 changes: 7 additions & 4 deletions scripts/run_notebook_and_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
NOTEBOOK_DIR = REPO_ROOT / "notebooks"
OUTPUT_DIR = REPO_ROOT / "src/notebooks"

CONVERTER = LatexExporter(template_file=(REPO_ROOT / "scripts/latex_template.tex").as_posix())
CONVERTER = LatexExporter(
template_file=(REPO_ROOT / "scripts/latex_template.tex").as_posix()
)

NOTEBOOK_BODY_PATTERN = re.compile(
r".+\\begin{document}(:?\s+\\maketitle)\s*(?P<notebook_body>.+)\s*\\end{document}",
Expand Down Expand Up @@ -65,17 +67,18 @@ def convert_notebook(notebook_path: Path) -> None:
body = extract_notebook_tex_body(body)
body = raise_heading_level(body)
rel_path = notebook_path.relative_to(NOTEBOOK_DIR)
(OUTPUT_DIR / rel_path).parent.mkdir(parents=True, exist_ok=True)
(OUTPUT_DIR / rel_path).with_suffix(".tex").write_text(body)


def create_notebook_tex_index():
def create_notebook_tex_appendix_index():
"""Create index file including the notebooks."""
notebook_includes = [
f"\\include{{{notebook_tex_path.relative_to(OUTPUT_DIR.parent)}}}"
for notebook_tex_path in OUTPUT_DIR.rglob("*.tex")
if notebook_tex_path.name != "index.tex"
]
(OUTPUT_DIR / "index.tex").write_text("\n".join(notebook_includes))
(OUTPUT_DIR / "appendix/index.tex").write_text("\n".join(notebook_includes))


def compile_thesis():
Expand All @@ -93,7 +96,7 @@ def main():
for notebook_path in NOTEBOOK_DIR.rglob("*.ipynb"):
run_notebooks(notebook_path)
convert_notebook(notebook_path)
create_notebook_tex_index()
create_notebook_tex_appendix_index()
compile_thesis()


Expand Down
2 changes: 2 additions & 0 deletions src/chapters/4_results.tex
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
\chapter{Results}

\input{notebooks/sections/application.tex}
2 changes: 1 addition & 1 deletion src/master_thesis.tex
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
\addtocontents{toc}{\protect\setcounter{tocdepth}{0}}
% \input{chap/6append}
%
\input{notebooks/index.tex}
\input{notebooks/appendix/index.tex}
\end{appendices}

\end{document}

0 comments on commit c76f8ce

Please sign in to comment.