From ce7947411c5831a7320ed54c8abcb9eb006f65f0 Mon Sep 17 00:00:00 2001
From: INES Benali <ebenali@tradeterminal.io>
Date: Fri, 8 Mar 2024 21:28:43 -0800
Subject: [PATCH 01/10] unbreak with newer texlive

---
 .gitmodules           | 3 +++
 src/Makefile          | 3 ++-
 src/external/listings | 1 +
 src/macros.tex        | 4 +++-
 src/ts.tex            | 2 +-
 5 files changed, 10 insertions(+), 3 deletions(-)
 create mode 100644 .gitmodules
 create mode 160000 src/external/listings

diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..b39cb49
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "src/external/listings"]
+	path = src/external/listings
+	url = git://git.gnu.org.ua/listings.git
diff --git a/src/Makefile b/src/Makefile
index 5de6844..08334ce 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -13,7 +13,8 @@
 
 FIGURES = $(patsubst %.dot,%.pdf,$(wildcard *.dot))
 
-TSPDF = pdflatex ts | grep -v "^Overfull"
+TSPDF:
+	TEXINPUTS=./external/listings//: pdflatex ts.tex | grep -v "^Overfull"
 
 default: rebuild
 
diff --git a/src/external/listings b/src/external/listings
new file mode 160000
index 0000000..2d9771b
--- /dev/null
+++ b/src/external/listings
@@ -0,0 +1 @@
+Subproject commit 2d9771b13d4ce189cb8d9cb0651bc688a86391ba
diff --git a/src/macros.tex b/src/macros.tex
index eafb519..cea1a46 100644
--- a/src/macros.tex
+++ b/src/macros.tex
@@ -78,7 +78,9 @@
 % Set the xref label for a clause to be "Clause n", not just "n".
 \makeatletter
 \newcommand{\customlabel}[2]{%
-\@bsphack \begingroup \protected@edef \@currentlabel {\protect \M@TitleReference{#2}{\M@currentTitle}}\MNR@label{#1}\endgroup \@esphack%
+  \@bsphack
+  \protected@write\@auxout{}{\string\newlabel{#1}{{#2}{\thepage}}}%
+  \@esphack
 }
 \makeatother
 \newcommand{\clauselabel}[1]{\customlabel{#1}{Clause \thechapter}}
diff --git a/src/ts.tex b/src/ts.tex
index faff217..1192fa6 100644
--- a/src/ts.tex
+++ b/src/ts.tex
@@ -10,7 +10,7 @@
 \usepackage[iso,american]
            {isodate}      % use iso format for dates
 \usepackage[final]
-           {listings}     % code listings
+           {./external/listings/listings}     % code listings
 \usepackage{longtable}    % auto-breaking tables
 \usepackage{ltcaption}    % fix captions for long tables
 \usepackage{relsize}      % provide relative font size changes

From a6f739d4c7315b4a4fd07e703d64af25b51a86fb Mon Sep 17 00:00:00 2001
From: INES Benali <ebenali@tradeterminal.io>
Date: Fri, 8 Mar 2024 22:03:22 -0800
Subject: [PATCH 02/10] makefile: automate external/listings rebuild steps and
 inclusion

---
 src/Makefile | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/Makefile b/src/Makefile
index 08334ce..a04d926 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -13,8 +13,7 @@
 
 FIGURES = $(patsubst %.dot,%.pdf,$(wildcard *.dot))
 
-TSPDF:
-	TEXINPUTS=./external/listings//: pdflatex ts.tex | grep -v "^Overfull"
+TSPDF = TEXINPUTS=./external/listings//: pdflatex ts.tex | grep -v "^Overfull"
 
 default: rebuild
 
@@ -25,6 +24,8 @@ refresh:
 	$(TSPDF)
 
 rebuild:
+	test -d ../.git && git submodule update --init --recursive
+	make -C ./external/listings
 	$(TSPDF)
 	$(TSPDF)
 	$(TSPDF)

From f46c9dc2cc98e017849ddf24ad4ddc44f1e9a8ef Mon Sep 17 00:00:00 2001
From: INES Benali <ebenali@tradeterminal.io>
Date: Fri, 8 Mar 2024 22:04:19 -0800
Subject: [PATCH 03/10] add gh Action to build and release PDF on main branch
 tags pushes

---
 .github/workflows/build.yaml | 38 ++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 .github/workflows/build.yaml

diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml
new file mode 100644
index 0000000..2dea820
--- /dev/null
+++ b/.github/workflows/build.yaml
@@ -0,0 +1,38 @@
+---
+name: Build tagged version
+
+on:
+  push:
+    tags:
+      - '*'
+
+jobs:
+  build:
+    runs-on: ubuntu-latest
+    steps:
+      - name: Install dependencies
+        run: |
+          sudo apt update
+          sudo apt install --no-install-recommends -y texlive-latex-extra make
+
+      - name: Checkout
+        uses: actions/checkout@v4
+        with:
+          submodules: true
+
+      - name: Build
+        id: build_step
+        run: |
+          cd src
+          make
+          TAG_NAME=${GITHUB_REF#refs/tags/}
+          echo "pdfFilename=$TAG_NAME" >> "$GITHUB_OUTPUT"
+          mv ts.pdf "${TAG_NAME}.pdf"
+
+      - name: Release
+        if: github.base_ref == 'main' && steps.build_step.outcome == 'success'
+        uses: ncipollo/release-action@v1
+        with:
+          artifacts: '${{ steps.build_step.outputs.pdfFilename }}'
+          generateReleaseNotes: true
+          artifactContentType: 'application/pdf'

From 80b425e67c0b3d6fcee34b8c80751839840f522a Mon Sep 17 00:00:00 2001
From: INES Benali <ebenali@tradeterminal.io>
Date: Fri, 8 Mar 2024 22:09:02 -0800
Subject: [PATCH 04/10] ghAction: yml: let apt install what it sees fit

---
 .github/workflows/build.yaml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml
index 2dea820..eee4bbb 100644
--- a/.github/workflows/build.yaml
+++ b/.github/workflows/build.yaml
@@ -13,7 +13,7 @@ jobs:
       - name: Install dependencies
         run: |
           sudo apt update
-          sudo apt install --no-install-recommends -y texlive-latex-extra make
+          sudo apt install -y texlive-latex-extra make
 
       - name: Checkout
         uses: actions/checkout@v4

From b9244517ec8a98f2cc67744df1201d9861e22e8f Mon Sep 17 00:00:00 2001
From: INES Benali <ebenali@tradeterminal.io>
Date: Fri, 8 Mar 2024 22:21:00 -0800
Subject: [PATCH 05/10] ghAction: build.yaml: use alternative check for 'main'
 branch

---
 .github/workflows/build.yaml | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml
index eee4bbb..15a8890 100644
--- a/.github/workflows/build.yaml
+++ b/.github/workflows/build.yaml
@@ -20,6 +20,16 @@ jobs:
         with:
           submodules: true
 
+      - name: Verify Tag is on Main Branch
+        id: verify_tag
+        run: |
+          TAG_COMMIT=$(git rev-list -n 1 ${GITHUB_REF})
+          if git merge-base --is-ancestor $TAG_COMMIT origin/main; then
+            echo "on_main=true" >>"$GITHUB_OUTPUT"
+          else
+            echo "on_main=false" >>"$GITHUB_OUTPUT"
+          fi
+
       - name: Build
         id: build_step
         run: |
@@ -30,7 +40,9 @@ jobs:
           mv ts.pdf "${TAG_NAME}.pdf"
 
       - name: Release
-        if: github.base_ref == 'main' && steps.build_step.outcome == 'success'
+        if: >
+          steps.verify_tag.outputs.on_main == 'true' &&
+          steps.build_step.outcome == 'success'
         uses: ncipollo/release-action@v1
         with:
           artifacts: '${{ steps.build_step.outputs.pdfFilename }}'

From 49fe96cc4b9872f48654dfa1622302001421232a Mon Sep 17 00:00:00 2001
From: INES Benali <ebenali@tradeterminal.io>
Date: Fri, 8 Mar 2024 22:36:31 -0800
Subject: [PATCH 06/10] ghAction: checkout: fetch-depth 0 to make sure branch
 ref is available

---
 .github/workflows/build.yaml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml
index 15a8890..a76eb8d 100644
--- a/.github/workflows/build.yaml
+++ b/.github/workflows/build.yaml
@@ -19,6 +19,7 @@ jobs:
         uses: actions/checkout@v4
         with:
           submodules: true
+          fetch-depth: 0
 
       - name: Verify Tag is on Main Branch
         id: verify_tag

From 5d1db005a0226eb6e4543e81e2a6d397f8b9d3a2 Mon Sep 17 00:00:00 2001
From: INES Benali <ebenali@tradeterminal.io>
Date: Fri, 8 Mar 2024 22:40:03 -0800
Subject: [PATCH 07/10] ghAction: remember to append '.pdf' for filename step
 output

---
 .github/workflows/build.yaml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml
index a76eb8d..e7e069e 100644
--- a/.github/workflows/build.yaml
+++ b/.github/workflows/build.yaml
@@ -37,7 +37,7 @@ jobs:
           cd src
           make
           TAG_NAME=${GITHUB_REF#refs/tags/}
-          echo "pdfFilename=$TAG_NAME" >> "$GITHUB_OUTPUT"
+          echo "pdfFilename=$TAG_NAME.pdf" >> "$GITHUB_OUTPUT"
           mv ts.pdf "${TAG_NAME}.pdf"
 
       - name: Release

From aae53ff42ec70fc4a8237249c32f9261a5926ff4 Mon Sep 17 00:00:00 2001
From: INES Benali <ebenali@tradeterminal.io>
Date: Fri, 8 Mar 2024 23:11:35 -0800
Subject: [PATCH 08/10] ghAction: rename pdf verbosely

---
 .github/workflows/build.yaml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml
index e7e069e..ed52a76 100644
--- a/.github/workflows/build.yaml
+++ b/.github/workflows/build.yaml
@@ -38,7 +38,7 @@ jobs:
           make
           TAG_NAME=${GITHUB_REF#refs/tags/}
           echo "pdfFilename=$TAG_NAME.pdf" >> "$GITHUB_OUTPUT"
-          mv ts.pdf "${TAG_NAME}.pdf"
+          mv -v ts.pdf "$TAG_NAME.pdf" && stat "$TAG_NAME.pdf" && realpath "$TAG_NAME.pdf"
 
       - name: Release
         if: >

From 2e92aafaa58c44d95fd0372c5586e3e2ef693c1e Mon Sep 17 00:00:00 2001
From: INES Benali <ebenali@tradeterminal.io>
Date: Fri, 8 Mar 2024 23:17:36 -0800
Subject: [PATCH 09/10] ghAction yaml: specify artifact path absolutely

---
 .github/workflows/build.yaml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml
index ed52a76..840cb24 100644
--- a/.github/workflows/build.yaml
+++ b/.github/workflows/build.yaml
@@ -37,7 +37,7 @@ jobs:
           cd src
           make
           TAG_NAME=${GITHUB_REF#refs/tags/}
-          echo "pdfFilename=$TAG_NAME.pdf" >> "$GITHUB_OUTPUT"
+          echo "pdfFilename=$GITHUB_WORKSPACE/$TAG_NAME.pdf" >> "$GITHUB_OUTPUT"
           mv -v ts.pdf "$TAG_NAME.pdf" && stat "$TAG_NAME.pdf" && realpath "$TAG_NAME.pdf"
 
       - name: Release

From 28e947396ecc35ef06c6618f98f53975aafb61df Mon Sep 17 00:00:00 2001
From: INES Benali <ebenali@tradeterminal.io>
Date: Fri, 8 Mar 2024 23:24:49 -0800
Subject: [PATCH 10/10] ghAction: add src/ component to pdfFilename path

---
 .github/workflows/build.yaml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml
index 840cb24..2db155f 100644
--- a/.github/workflows/build.yaml
+++ b/.github/workflows/build.yaml
@@ -37,7 +37,7 @@ jobs:
           cd src
           make
           TAG_NAME=${GITHUB_REF#refs/tags/}
-          echo "pdfFilename=$GITHUB_WORKSPACE/$TAG_NAME.pdf" >> "$GITHUB_OUTPUT"
+          echo "pdfFilename=$GITHUB_WORKSPACE/src/$TAG_NAME.pdf" >> "$GITHUB_OUTPUT"
           mv -v ts.pdf "$TAG_NAME.pdf" && stat "$TAG_NAME.pdf" && realpath "$TAG_NAME.pdf"
 
       - name: Release