From ab31eff6bb96c20bc1aaffd9898acfa00ca28b1d Mon Sep 17 00:00:00 2001
From: Luke Naylor <l.naylor@sms.ed.ac.uk>
Date: Wed, 8 May 2024 16:43:03 +0100
Subject: [PATCH] Add extra appendix for the 'pseudowalls' python library

---
 .devcontainer/Dockerfile |  2 ++
 .gitlab-ci.yml           |  1 +
 .gitmodules              |  3 +++
 Makefile                 | 13 +++++++++++++
 pseudowalls              |  1 +
 tex/appendix.tex         | 11 +++++++++++
 tex/chromalisting.lua    | 13 +++++++++++++
 tex/chromalisting.sty    |  1 +
 8 files changed, 45 insertions(+)
 create mode 160000 pseudowalls

diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile
index d9bbae8..eb03f23 100644
--- a/.devcontainer/Dockerfile
+++ b/.devcontainer/Dockerfile
@@ -2,6 +2,8 @@ FROM registry.gitlab.com/lukenaylor/latex/sage-tex-chroma-image:latest
 
 # Add the tree-sitter parser for Rust
 RUN git clone --depth=1 --branch v0.20.4 https://github.com/tree-sitter/tree-sitter-rust.git /root/src/tree-sitter-rust
+# Add the tree-sitter parser for Python
+RUN git clone --depth=1 --branch v0.21.0 https://github.com/tree-sitter/tree-sitter-python /root/src/tree-sitter-python
 # Install the pseudowalls sage package
 RUN /usr/bin/bash -c ". ~/.bashrc; sage -pip install pseudowalls --extra-index-url https://gitlab.com/api/v4/projects/43962374/packages/pypi/simple"
 RUN /usr/bin/bash -c ". ~/.bashrc; sage -pip install pandas"
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 32e0ef6..40d6676 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -9,6 +9,7 @@ build:
     - echo $SHELL
     - source /root/.bashrc
     - git clone --depth=1 --branch v0.20.4 https://github.com/tree-sitter/tree-sitter-rust.git /root/src/tree-sitter-rust
+    - git clone --depth=1 --branch v0.21.0 https://github.com/tree-sitter/tree-sitter-python /root/src/tree-sitter-python
     - sage -pip install pseudowalls --extra-index-url https://gitlab.com/api/v4/projects/43962374/packages/pypi/simple
     - sage -pip install pandas
   script:
diff --git a/.gitmodules b/.gitmodules
index 13ace21..1a31441 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -19,3 +19,6 @@
 [submodule "subprojects/intro-to-bridgeland-stability-parametrisations"]
 	path = subprojects/intro-to-bridgeland-stability-parametrisations
 	url = git@git.ecdf.ed.ac.uk:personal-latex-documents/research/intro-to-bridgeland-stability-parametrisations.git
+[submodule "pseudowalls"]
+	path = pseudowalls
+	url = https://gitlab.com/pseudowalls/pseudowalls.git
diff --git a/Makefile b/Makefile
index 161ded2..54cb132 100644
--- a/Makefile
+++ b/Makefile
@@ -71,6 +71,19 @@ $(foreach _base, $(RUSTBASENAMES), $(eval $(call RUST_TO_TEX_RULE, $(_base))))
 
 rust_tex: $(addsuffix .tex, $(RUSTBASENAMES))
 
+# TEX FILES FROM PYTHON
+#
+define PY_TO_TEX_RULE
+$(1).tex: $(1).py
+	chromacode -r -i $(1).py -o $(1).tex
+endef
+
+PYBASENAMES=$(basename $(shell find pseudowalls/src/pseudowalls/ -regex '.*\.py$$'))
+
+$(foreach _base, $(PYBASENAMES), $(eval $(call PY_TO_TEX_RULE, $(_base))))
+
+py_tex: $(addsuffix .tex, $(PYBASENAMES))
+
 .PHONY: clean
 clean:
 	latexmk -C
diff --git a/pseudowalls b/pseudowalls
new file mode 160000
index 0000000..17e4163
--- /dev/null
+++ b/pseudowalls
@@ -0,0 +1 @@
+Subproject commit 17e4163da4699e346d1e75353a68b1d1959fc43d
diff --git a/tex/appendix.tex b/tex/appendix.tex
index 9496743..4f24282 100644
--- a/tex/appendix.tex
+++ b/tex/appendix.tex
@@ -30,6 +30,17 @@
 \rustlisting{../tilt.rs/src/}{tilt_stability/left_pseudo_semistabilizers/fixed_q_beta/fixed_r.tex}
 \rustlisting{../tilt.rs/src/}{tilt_stability/left_pseudo_semistabilizers/fixed_q_beta/fixed_r/bound_on_d.tex}
 
+\chapter{Pseudowalls Computer Algebra Library}
+
+\pylisting{../pseudowalls/src/}{pseudowalls/integral_chern.tex}
+\pylisting{../pseudowalls/src/}{pseudowalls/chern_character.tex}
+\pylisting{../pseudowalls/src/}{pseudowalls/__init__.tex}
+\pylisting{../pseudowalls/src/}{pseudowalls/integral_chern.tex}
+\pylisting{../pseudowalls/src/}{pseudowalls/stability.tex}
+\pylisting{../pseudowalls/src/}{pseudowalls/utils/__init__.tex}
+\pylisting{../pseudowalls/src/}{pseudowalls/utils/stability_util.tex}
+\pylisting{../pseudowalls/src/}{pseudowalls/utils/symb_util.tex}
+
 \chapter{Jupyter Notebooks}
 
 \bgroup
diff --git a/tex/chromalisting.lua b/tex/chromalisting.lua
index 6e7e738..084cba6 100644
--- a/tex/chromalisting.lua
+++ b/tex/chromalisting.lua
@@ -12,3 +12,16 @@ function rust_listing (dir, subpath)
     .. "]{" .. dir .. subpath .. "}"
     )
 end
+function py_listing (dir, subpath)
+    local module_name = subpath
+        :gsub(".tex$","")
+        :gsub("/","\\discretionary{}{.}{.}")
+
+    local caption = "\\raggedleft \\texttt{" ..  module_name .. "}"
+
+    return (
+        "\\lstinputlisting["
+        .. "caption={" .. caption .. "}"
+    .. "]{" .. dir .. subpath .. "}"
+    )
+end
diff --git a/tex/chromalisting.sty b/tex/chromalisting.sty
index 0298861..200ae6e 100644
--- a/tex/chromalisting.sty
+++ b/tex/chromalisting.sty
@@ -5,3 +5,4 @@ private package for chromacode listings with automatically created captions
 
 \directlua{require("chromalisting.lua")}
 \newcommand\rustlisting[2]{ \directlua{tex.sprint(rust_listing("#1", "#2"))} }
+\newcommand\pylisting[2]{ \directlua{tex.sprint(py_listing("#1", "#2"))} }
-- 
GitLab