From ce68014eec7e2408130a7ae1793eec5f9070fd10 Mon Sep 17 00:00:00 2001 From: mark Date: Tue, 10 Oct 2023 17:34:45 -0700 Subject: [PATCH 01/10] Bugfixes --- Advanced/Cryptography/parts/1 mod.tex | 2 +- Advanced/Intro to Proofs/main.tex | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Advanced/Cryptography/parts/1 mod.tex b/Advanced/Cryptography/parts/1 mod.tex index 5fa7786..5213b3d 100755 --- a/Advanced/Cryptography/parts/1 mod.tex +++ b/Advanced/Cryptography/parts/1 mod.tex @@ -8,7 +8,7 @@ Create a multiplication table for $\mathbb{Z}_4$: \begin{center} \begin{tabular}{c | c c c c} - \times & 0 & 1 & 2 & 3 \\ + $\times$ & 0 & 1 & 2 & 3 \\ \hline 0 & ? & ? & ? & ? \\ 1 & ? & ? & ? & ? \\ diff --git a/Advanced/Intro to Proofs/main.tex b/Advanced/Intro to Proofs/main.tex index 126d59b..8b3cf1e 100755 --- a/Advanced/Intro to Proofs/main.tex +++ b/Advanced/Intro to Proofs/main.tex @@ -220,10 +220,10 @@ Show that for any two functions $g: Y \to W$ and $h: Y \to W$, if $g \circ f = h \circ f \implies g = h$. - \item[\star] Let $f: X \to Y$ be a function where for any set $Z$ and functions $g: Z \to X$ and $h: Z \to X$, + \item[$\star$] Let $f: X \to Y$ be a function where for any set $Z$ and functions $g: Z \to X$ and $h: Z \to X$, $f \circ g = f \circ h \implies g = h$. Show that $f$ is injective. - \item[\star] Let $f: X \to Y$ be a function where for any set $W$ and functions $g: Y \to W$ and $h: Y \to W$, + \item[$\star$] Let $f: X \to Y$ be a function where for any set $W$ and functions $g: Y \to W$ and $h: Y \to W$, $g \circ f = h \circ f \implies g = h$. Show f is surjective. \end{itemize} From 910cf342624e3f18cacae3581f376193683de57a Mon Sep 17 00:00:00 2001 From: mark Date: Tue, 10 Oct 2023 17:34:55 -0700 Subject: [PATCH 02/10] Updated gitignore --- .gitignore | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index ab0d7b6..83a8a6d 100644 --- a/.gitignore +++ b/.gitignore @@ -6,10 +6,7 @@ __pycache__ # Output files main.pdf **/build - -# CI files -/_build -/_output +_output # TeX build files *.synctex.gz* From e716e48fa2e5d9992974cdebd089ec94da4a9453 Mon Sep 17 00:00:00 2001 From: mark Date: Tue, 10 Oct 2023 20:46:36 -0700 Subject: [PATCH 03/10] Added build.sh --- resources/scripts/build.sh | 45 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 resources/scripts/build.sh diff --git a/resources/scripts/build.sh b/resources/scripts/build.sh new file mode 100755 index 0000000..fa8aae7 --- /dev/null +++ b/resources/scripts/build.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +START=$(pwd) +OUTPUT="${START}/_output" + +function build() { + local DIR="$(dirname "${1}")" + local MAIN="$(basename "${1}")" + local NAME="$(basename "${DIR}")" + + echo "|> Building ${NAME}..." + cd "${DIR}" + + tectonic \ + --outfmt pdf \ + --chatter minimal \ + main.tex + + stat=$? + + if [[ $stat == 0 ]]; then + mv main.pdf "${OUTPUT}/${NAME}.pdf" + echo "" + else + rm -f main.pdf + echo "|> Build failed" + echo "" + fi +} + + +for d in ../../Advanced/*/ ; do + DIR=$(realpath "${d}") + OUTPUT="${START}/_output/Advanced" + mkdir -p "${OUTPUT}" + + build "${DIR}/main.tex" +done + +for d in ../../Intermediate/*/ ; do + DIR=$(realpath "${d}") + OUTPUT="${START}/_output/Intermediate" + mkdir -p "${OUTPUT}" + + build "${DIR}/main.tex" +done \ No newline at end of file From e96c02531cdc73001a50fab89a4c314c5527c742 Mon Sep 17 00:00:00 2001 From: mark Date: Tue, 10 Oct 2023 21:02:04 -0700 Subject: [PATCH 04/10] Updated build script --- .gitignore | 1 - resources/scripts/.gitignore | 2 + resources/scripts/Jenkinsfile | 28 ------ resources/scripts/build.py | 155 ------------------------------- resources/scripts/build.sh | 11 ++- resources/scripts/build.toml | 12 --- resources/scripts/helpers/tex.py | 60 ------------ 7 files changed, 9 insertions(+), 260 deletions(-) create mode 100644 resources/scripts/.gitignore delete mode 100644 resources/scripts/Jenkinsfile delete mode 100644 resources/scripts/build.py delete mode 100644 resources/scripts/build.toml delete mode 100644 resources/scripts/helpers/tex.py diff --git a/.gitignore b/.gitignore index 83a8a6d..178f4e0 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,6 @@ __pycache__ # Output files main.pdf **/build -_output # TeX build files *.synctex.gz* diff --git a/resources/scripts/.gitignore b/resources/scripts/.gitignore new file mode 100644 index 0000000..2f0a250 --- /dev/null +++ b/resources/scripts/.gitignore @@ -0,0 +1,2 @@ +output +output.zip \ No newline at end of file diff --git a/resources/scripts/Jenkinsfile b/resources/scripts/Jenkinsfile deleted file mode 100644 index 26b2f20..0000000 --- a/resources/scripts/Jenkinsfile +++ /dev/null @@ -1,28 +0,0 @@ -pipeline { - agent none - environment { - NC_CRED = credentials("nc-jenkins-cred") - NO_TEST = true - } - stages { - stage("Build") { - agent { - docker { - image "git.betalupi.com/mark/latex:latest" - } - } - steps { - // Keep these in one "sh" directive. - // Todo: create setup files so we don't - // have to pip install manually here. - // Maybe integrate python packages into the docker container? - sh ''' - python -m venv venv - source venv/bin/activate - pip install tomli webdavclient3 - python resources/scripts/build.py - ''' - } - } - } -} diff --git a/resources/scripts/build.py b/resources/scripts/build.py deleted file mode 100644 index 19a4e73..0000000 --- a/resources/scripts/build.py +++ /dev/null @@ -1,155 +0,0 @@ -# Build script for CI. -# This file is run from the root of the repository - -import os -import tomli -from pathlib import Path -import shutil - -from webdav3.client import Client - -import helpers.tex as tex - -conf_path = "resources/scripts/build.toml" - -# Prepare envvars -e = os.environ.copy() -e["TEXINPUTS"] = f"::/usr/share/texmf-dist/tex//" -print(Path.cwd()) - -# If true, rebuild everything -# without checking for changes. -# Currently unused. -if "FORCE_ALL" in e: - force_all = e["FORCE_ALL"] == "true" -else: - force_all = False - -if "NO_TEST" in e: - test = e["NO_TEST"] == "false" -else: - test = True - - -# Used only for debug -class FakeClient: - def __init__(self): - pass - - def mkdir(self, path): - print(f"[Dry run] Making dir {path}") - - def upload_sync(self, local_path, remote_path): - print(f"[Dry run] Synced {local_path} to {remote_path}") - - def clean(self, path): - print(f"[Dry run] Cleaning {path}") - - - -# Load configuration -with open(conf_path, mode="rb") as fp: - config = tomli.load(fp) - -# Prepare directories -builddir = Path().absolute() / config["core"]["build_dir"] -output = Path().absolute() / config["core"]["output_dir"] -output.mkdir(parents = True, exist_ok = True) -builddir.mkdir(parents = True, exist_ok = True) - - - -if not test: - # Connect to webdav - client = Client({ - "webdav_login": e["NC_CRED_USR"], - "webdav_password": e["NC_CRED_PSW"], - "webdav_hostname": e["DAV_HOSTNAME"], # https://host:port - "webdav_root": e["DAV_ROOT"] # the rest of the url - # client.list() will break if we do not seperate the hostname - # and the root path. - }) -else: - client = FakeClient() - - -def upload_dir(local_path: Path): - for p in local_path.rglob("*"): - r = p.relative_to(output) - if p.is_dir(): - client.mkdir(str(r)) - - elif p.is_file(): - client.upload_sync( # type: ignore - remote_path = str(r), - local_path = p - ) - - -# Print envvars for debug -#print(e) - - -for i, item in enumerate(config["dir-of-dirs"]): - p = Path(item["path"]) - - for s in p.iterdir(): - # s: path to directory, - # # relative to repo root - if not s.is_dir(): - continue - - print(f"Building {s}/main.tex") - - # Make pdf - pdf_nosolutions = tex.build( - s, - mainfile = "main.tex", - jobname = f"{i}-nosols", - build_dir = builddir, - solutions = False, - - env = e, - test = test - ) - - pdf_solutions = tex.build( - s, - mainfile = "main.tex", - jobname = f"{i}-sols", - build_dir = builddir, - solutions = True, - - env = e, - test = test - ) - - target_dir = output / s.parent - target_dir.mkdir(parents = True, exist_ok = True) - - shutil.copy( - pdf_nosolutions, - target_dir / (s.stem + ".pdf") - ) - - shutil.copy( - pdf_solutions, - target_dir / (s.stem + ".sols.pdf") - ) - - -# TODO: this breaks when the output directory is empty. -# Fix it eventually. -if not test: - # Delete old files - for i in client.list(): - if i.endswith("/"): - i = i[:-1] - client.clean(i) - -upload_dir(output) - -# Remove output files so they don't persist -# shutil.rmtree(output) -# Shouldn't be necessary if you tell -# jenkins to "clean before checkout." \ No newline at end of file diff --git a/resources/scripts/build.sh b/resources/scripts/build.sh index fa8aae7..6c18fff 100755 --- a/resources/scripts/build.sh +++ b/resources/scripts/build.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash START=$(pwd) -OUTPUT="${START}/_output" +OUT_SUBDIR="output" function build() { local DIR="$(dirname "${1}")" @@ -30,7 +30,7 @@ function build() { for d in ../../Advanced/*/ ; do DIR=$(realpath "${d}") - OUTPUT="${START}/_output/Advanced" + OUTPUT="${START}/${OUT_SUBDIR}/Advanced" mkdir -p "${OUTPUT}" build "${DIR}/main.tex" @@ -38,8 +38,11 @@ done for d in ../../Intermediate/*/ ; do DIR=$(realpath "${d}") - OUTPUT="${START}/_output/Intermediate" + OUTPUT="${START}/${OUT_SUBDIR}/Intermediate" mkdir -p "${OUTPUT}" build "${DIR}/main.tex" -done \ No newline at end of file +done + + +zip -FSrj output.zip "${OUT_SUBDIR}/*" \ No newline at end of file diff --git a/resources/scripts/build.toml b/resources/scripts/build.toml deleted file mode 100644 index ef5c3fb..0000000 --- a/resources/scripts/build.toml +++ /dev/null @@ -1,12 +0,0 @@ -# All paths are relative to the root of this repository. - -[core] -build_dir = "_build" -output_dir = "_output" - - -[[dir-of-dirs]] -path = "Advanced" - -[[dir-of-dirs]] -path = "Intermediate" \ No newline at end of file diff --git a/resources/scripts/helpers/tex.py b/resources/scripts/helpers/tex.py deleted file mode 100644 index 8350e6b..0000000 --- a/resources/scripts/helpers/tex.py +++ /dev/null @@ -1,60 +0,0 @@ -from pathlib import Path -import subprocess - -def build( - path: Path, - *, - solutions: bool = True, - mainfile: str = "main.tex", - jobname: str = "main", - build_dir: Path = Path("build"), - - test = False, - env: dict = {}, - ) -> Path: - """ - Build a directory using XeTeX. - - Args: - path (Path): directory to build - solutions (bool, optional): Create a handout with solutions? Defaults to True. - mainfile (str, optional): Path to main TeX file, relative to path. Defaults to "main.tex". - jobname (str, optional): TeX job name. Defaults to "main". - build_dir (Path, optional): Where to place build files. Defaults to Path("build"). - - test (bool, optional): If true, dry run. Defaults to False. - env (dict): Dictionary of environment variables. - - Returns: - Path: Absolute path to output pdf. - """ - - # Make temporary file for TeX build arg hack - if solutions: - with (build_dir/"tmp.tex").open("w") as f: - f.write("\\def\\argYesSolutions{1}\\input{" + mainfile + "}") - else: - with (build_dir/"tmp.tex").open("w") as f: - f.write("\\def\\argNoSolutions{1}\\input{" + mainfile + "}") - - cmd = subprocess.run([ - "latexmk", - "-interaction=nonstopmode", - "-file-line-error", - f"-outdir={build_dir}", - "-xelatex", - f"-jobname={jobname}", - build_dir/"tmp.tex" - ], - cwd = path, - env = env, - stdout = None if test else subprocess.DEVNULL, - stderr = None if test else subprocess.DEVNULL - ) - - assert cmd.returncode == 0 - - # Remove tmp file - (build_dir / "tmp.tex").unlink() - - return build_dir / f"{jobname}.pdf" From 5b0f22c917fb2b9df22b8f74084a33d83d027922 Mon Sep 17 00:00:00 2001 From: mark Date: Tue, 10 Oct 2023 21:39:54 -0700 Subject: [PATCH 05/10] Fixed path --- resources/scripts/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/scripts/build.sh b/resources/scripts/build.sh index 6c18fff..f853653 100755 --- a/resources/scripts/build.sh +++ b/resources/scripts/build.sh @@ -45,4 +45,4 @@ for d in ../../Intermediate/*/ ; do done -zip -FSrj output.zip "${OUT_SUBDIR}/*" \ No newline at end of file +zip -FSrj output.zip "${OUT_SUBDIR}"/* \ No newline at end of file From 0fb5c3a11820e6d96612d3e406ce21d33dc9a0ca Mon Sep 17 00:00:00 2001 From: mark Date: Tue, 10 Oct 2023 22:00:32 -0700 Subject: [PATCH 06/10] Minor cleanup --- .gitignore | 2 ++ build.sh | 55 ++++++++++++++++++++++++++++++++++++ resources/scripts/.gitignore | 2 -- resources/scripts/build.sh | 48 ------------------------------- 4 files changed, 57 insertions(+), 50 deletions(-) create mode 100755 build.sh delete mode 100644 resources/scripts/.gitignore delete mode 100755 resources/scripts/build.sh diff --git a/.gitignore b/.gitignore index 178f4e0..87ec4fc 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,8 @@ __pycache__ *-ignore # Output files +/output +/output.zip main.pdf **/build diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..dda3867 --- /dev/null +++ b/build.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env bash +run_dir=$(pwd) +target="output" + +rm -drf "${target}" +rm -f "output.zip" + +function build() { + local doc_dir="$(dirname "${1}")" + local main_file="$(basename "${1}")" + local job_name="$(basename "${doc_dir}")" + + echo "|> Building ${job_name}..." + cd "${doc_dir}" + + tectonic \ + --outfmt pdf \ + --chatter minimal \ + main.tex + + stat=$? + + if [[ $stat == 0 ]]; then + mv main.pdf "${OUTPUT}/${job_name}.pdf" + echo "" + else + rm -f main.pdf + echo "|> Build failed" + echo "" + fi + + cd "${run_dir}" +} + + +for d in ./Advanced/*/ ; do + doc_dir=$(realpath "${d}") + OUTPUT="${run_dir}/${target}/Advanced" + mkdir -p "${OUTPUT}" + + build "${doc_dir}/main.tex" +done + +for d in ./Intermediate/*/ ; do + doc_dir=$(realpath "${d}") + OUTPUT="${run_dir}/${target}/Intermediate" + mkdir -p "${OUTPUT}" + + build "${doc_dir}/main.tex" +done + +ls +pwd + +zip -FSrj output.zip "${target}" \ No newline at end of file diff --git a/resources/scripts/.gitignore b/resources/scripts/.gitignore deleted file mode 100644 index 2f0a250..0000000 --- a/resources/scripts/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -output -output.zip \ No newline at end of file diff --git a/resources/scripts/build.sh b/resources/scripts/build.sh deleted file mode 100755 index f853653..0000000 --- a/resources/scripts/build.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env bash -START=$(pwd) -OUT_SUBDIR="output" - -function build() { - local DIR="$(dirname "${1}")" - local MAIN="$(basename "${1}")" - local NAME="$(basename "${DIR}")" - - echo "|> Building ${NAME}..." - cd "${DIR}" - - tectonic \ - --outfmt pdf \ - --chatter minimal \ - main.tex - - stat=$? - - if [[ $stat == 0 ]]; then - mv main.pdf "${OUTPUT}/${NAME}.pdf" - echo "" - else - rm -f main.pdf - echo "|> Build failed" - echo "" - fi -} - - -for d in ../../Advanced/*/ ; do - DIR=$(realpath "${d}") - OUTPUT="${START}/${OUT_SUBDIR}/Advanced" - mkdir -p "${OUTPUT}" - - build "${DIR}/main.tex" -done - -for d in ../../Intermediate/*/ ; do - DIR=$(realpath "${d}") - OUTPUT="${START}/${OUT_SUBDIR}/Intermediate" - mkdir -p "${OUTPUT}" - - build "${DIR}/main.tex" -done - - -zip -FSrj output.zip "${OUT_SUBDIR}"/* \ No newline at end of file From 2af36f942f6cc1097d2e0ba6de7a03708f3e39dd Mon Sep 17 00:00:00 2001 From: mark Date: Tue, 10 Oct 2023 22:11:31 -0700 Subject: [PATCH 07/10] Fixed zip command --- build.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/build.sh b/build.sh index dda3867..892271f 100755 --- a/build.sh +++ b/build.sh @@ -49,7 +49,5 @@ for d in ./Intermediate/*/ ; do build "${doc_dir}/main.tex" done -ls -pwd - -zip -FSrj output.zip "${target}" \ No newline at end of file +cd "${target}" +zip -FSr ../output.zip . \ No newline at end of file From 307dc407a4ec8ab8365fa3d3076d753e8a9c0636 Mon Sep 17 00:00:00 2001 From: mark Date: Tue, 10 Oct 2023 22:20:22 -0700 Subject: [PATCH 08/10] Updated build links --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4196340..67819c9 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # ORMC Handouts This repository contains all the handouts I've written for the [ORMC](https://circles.math.ucla.edu/circles/). \ -You can find the latest PDFs [here](https://nc.betalupi.com/s/ormc-handouts). +You can find the latest PDFs [here](https://static.betalupi.com/ormc). **For my students:** Handouts will appear here a few days before class. Please don't look at them (or their solutions) beforehand, that spoils all the fun! @@ -21,7 +21,7 @@ Grade levels are estimates. ## 🛠️ Building these Handouts -Automatic builds are [here](https://nc.betalupi.com/s/ormc-handouts), if you just want the PDFs. +Automatic builds are [here](https://static.betalupi.com/ormc), if you just want the PDFs. If you want to edit these files, you'll need to download a custom document class. \ To compile one handout, do the following: From 7468dce444237da2afd3b842cdce90f5034d2a83 Mon Sep 17 00:00:00 2001 From: mark Date: Tue, 10 Oct 2023 22:21:42 -0700 Subject: [PATCH 09/10] Build solutions too --- build.sh | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/build.sh b/build.sh index 892271f..e8cb328 100755 --- a/build.sh +++ b/build.sh @@ -13,19 +13,40 @@ function build() { echo "|> Building ${job_name}..." cd "${doc_dir}" - tectonic \ - --outfmt pdf \ - --chatter minimal \ - main.tex + + # Build handout + echo "\\def\\argNoSolutions{1}\\input{main.tex}" | \ + tectonic \ + --outfmt pdf \ + --chatter minimal \ + - stat=$? if [[ $stat == 0 ]]; then - mv main.pdf "${OUTPUT}/${job_name}.pdf" + mv texput.pdf "${OUTPUT}/${job_name}.pdf" + else + rm -f texput.pdf + echo "|> Handout build failed" + echo "" + fi + + + # Build solutions + echo "\\def\\argYesSolutions{1}\\input{main.tex}" | \ + tectonic \ + --outfmt pdf \ + --chatter minimal \ + - + + stat=$? + + if [[ $stat == 0 ]]; then + mv texput.pdf "${OUTPUT}/${job_name}.sols.pdf" echo "" else - rm -f main.pdf - echo "|> Build failed" + rm -f texput.pdf + echo "|> Solution build failed" echo "" fi @@ -33,6 +54,8 @@ function build() { } + + for d in ./Advanced/*/ ; do doc_dir=$(realpath "${d}") OUTPUT="${run_dir}/${target}/Advanced" @@ -41,6 +64,7 @@ for d in ./Advanced/*/ ; do build "${doc_dir}/main.tex" done + for d in ./Intermediate/*/ ; do doc_dir=$(realpath "${d}") OUTPUT="${run_dir}/${target}/Intermediate" @@ -49,5 +73,8 @@ for d in ./Intermediate/*/ ; do build "${doc_dir}/main.tex" done + + + cd "${target}" zip -FSr ../output.zip . \ No newline at end of file From 30a0c7a7824ac03b62daed7f3ae601b6818c4b11 Mon Sep 17 00:00:00 2001 From: mark Date: Wed, 11 Oct 2023 09:44:32 -0700 Subject: [PATCH 10/10] Updated build script --- build.sh | 108 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 78 insertions(+), 30 deletions(-) diff --git a/build.sh b/build.sh index e8cb328..c3b813e 100755 --- a/build.sh +++ b/build.sh @@ -1,21 +1,44 @@ #!/usr/bin/env bash +# +# This script builds every document in this repo, +# (handout and solutions, if they exist), and creates +# a zip of all resulting files. + + + +# Where we're running this script run_dir=$(pwd) -target="output" -rm -drf "${target}" -rm -f "output.zip" +# Output files +target_dir="${run_dir}/output" +target_zip="${run_dir}/output.zip" + + + +# Clean up previous build +rm -drf "${target_dir}" +rm -f "${target_zip}" + + +# Build one document. +# Args: +# target_dir: move output pdf to this directory +# job_name: name of this document. Output is saved as job_name.pdf +# doc_dir: cd here before building. +# main_file: build this tex file. Usually main.tex function build() { - local doc_dir="$(dirname "${1}")" - local main_file="$(basename "${1}")" - local job_name="$(basename "${doc_dir}")" + local target_dir="${1}" + local job_name="${2}" + local doc_dir="${3}" + local main_file="${4}" echo "|> Building ${job_name}..." cd "${doc_dir}" # Build handout - echo "\\def\\argNoSolutions{1}\\input{main.tex}" | \ + echo "\\def\\argNoSolutions{1}\\input{${main_file}}" | \ tectonic \ --outfmt pdf \ --chatter minimal \ @@ -24,8 +47,10 @@ function build() { stat=$? if [[ $stat == 0 ]]; then - mv texput.pdf "${OUTPUT}/${job_name}.pdf" + mkdir -p "${target_dir}" + mv texput.pdf "${target_dir}/${job_name}.pdf" else + rmdir --ignore-fail-on-non-empty "${target_dir}" rm -f texput.pdf echo "|> Handout build failed" echo "" @@ -33,7 +58,7 @@ function build() { # Build solutions - echo "\\def\\argYesSolutions{1}\\input{main.tex}" | \ + echo "\\def\\argYesSolutions{1}\\input{${main_file}}" | \ tectonic \ --outfmt pdf \ --chatter minimal \ @@ -42,39 +67,62 @@ function build() { stat=$? if [[ $stat == 0 ]]; then - mv texput.pdf "${OUTPUT}/${job_name}.sols.pdf" - echo "" + mkdir -p "${target_dir}" + mv texput.pdf "${target_dir}/${job_name}.sols.pdf" else + rmdir --ignore-fail-on-non-empty "${target_dir}" rm -f texput.pdf echo "|> Solution build failed" - echo "" fi + # Clean up if files contents are identical + if cmp --silent -- "${target_dir}/${job_name}.sols.pdf" "${target_dir}/${job_name}.pdf"; then + echo "|> Versions identical, removing ${job_name}.sols.pdf" + rm "${target_dir}/${job_name}.sols.pdf" + fi + + echo "" + cd "${run_dir}" } -for d in ./Advanced/*/ ; do - doc_dir=$(realpath "${d}") - OUTPUT="${run_dir}/${target}/Advanced" - mkdir -p "${OUTPUT}" - build "${doc_dir}/main.tex" + +for d in "${run_dir}/Misc/Warm-Ups"/*.tex ; do + file="$(basename "${d}")" + build \ + "${target_dir}/Warm-Ups" \ + "${file%.*}" \ + "${run_dir}/Misc/Warm-Ups" \ + "${file}" +done + +for d in "${run_dir}/Advanced"/*/ ; do + doc_dir=$(realpath "${d}") + job_name="$(basename "${doc_dir}")" + + build \ + "${target_dir}/Advanced" \ + "${job_name}" \ + "${doc_dir}" \ + "main.tex" +done + +for d in "${run_dir}/Intermediate"/*/ ; do + doc_dir=$(realpath "${d}") + job_name="$(basename "${doc_dir}")" + + build \ + "${target_dir}/Intermediate" \ + "${job_name}" \ + "${doc_dir}" \ + "main.tex" done -for d in ./Intermediate/*/ ; do - doc_dir=$(realpath "${d}") - OUTPUT="${run_dir}/${target}/Intermediate" - mkdir -p "${OUTPUT}" - - build "${doc_dir}/main.tex" -done - - - - -cd "${target}" -zip -FSr ../output.zip . \ No newline at end of file +# cd so paths in zip are relative +cd "${target_dir}" +zip -FSr "${target_zip}" . \ No newline at end of file