Add test suite, README and .gitignore rules; untrack LibreOffice locks

Why: the repository was reported as a 328 MB LaTeX collection, which is a red
flag for a text project. The weight map shows the bulk is real content --
literature PDFs (169 MB), slide decks (92 MB) and figures (62 MB) -- and the
only build leftovers ever committed were two empty LibreOffice lock files.
So: audit the tree, prove the documents compile, and leave an automated check
behind so later edits cannot quietly break them.

- Untrack thesis/.~lock.thesis.pptx# and thesis/.~lock.thesis-arch.pptx#
  (2 files, 132 bytes; the files stay on disk). The checkout loses 233 bytes
  of 666 MB: there was no junk to remove.
- .gitignore: the full LaTeX build-product set (adds .lof/.lot/.nav/.snm/.vrb/
  .run.xml/.dvi/... to the existing rules) plus OS, editor and office leftovers.
- tests/: `make test` compiles the five main documents with latexmk and checks
  page counts, fatal errors, unresolved references and citations, missing input
  files, every \includegraphics on disk and every \cite key against the .bib;
  eight negative and control checks; non-zero exit when a check fails.
- README.md: what the three folders are, the weight map and largest files, the
  duplicated trees and the stray LNCS sample left in place, the real build
  commands, the test output, and why no licence is applied.

Compilation verified on TeX Live 2025 on the Pi 5. Missing packages installed:
biber, texlive-lang-portuguese and texlive-publishers -- without splncs04.bst
from the last one both IBPria papers keep 63 undefined citations and latexmk
exits 12.

No text, figure or bibliography content was changed.
This commit is contained in:
dsh
2026-10-08 18:34:04 +01:00
parent 3ace2beb5f
commit f77151ddd1
13 changed files with 768 additions and 9 deletions
+39 -7
View File
@@ -1,17 +1,49 @@
*.log # LaTeX / latexmk build products -- never commit these
*.aux *.aux
*.bbl *.log
*.blg
*.brf
*.fls
*.fdb_latexmk
*.out *.out
*.toc *.toc
*.lof
*.lot
*.fls
*.fdb_latexmk
*.synctex.gz *.synctex.gz
*.synctex(busy)
*.bbl
*.blg
*.bcf *.bcf
*.run.xml
*.nav
*.snm
*.vrb
*.idx
*.ilg
*.ind
*.dvi
*.xdv
*.brf
*.acn
*.acr
*.alg
*.glg
*.glo
*.gls
*.ist
*.loa
*.lol
*.xdy
build/
# Editor, OS and office leftovers
.vscode/ .vscode/
.DS_Store
Thumbs.db
*~
*.swp
.~lock.*#
*.pptx#
# Compile the real documents by name: main, and not its artefacts
main.* main.*
!main.tex !main.tex
!main.pdf !main.pdf
+40
View File
@@ -0,0 +1,40 @@
# Makefile for the master-thesis LaTeX collection. See README.md.
#
# make test compile and check every main document (slow, ~4 min)
# make test-static source checks only, no compilation (fast)
# make build compile every main document into build/ (not committed)
# make clean remove build/
SHELL := /bin/bash
DOCS := thesis papers/ibpria2025 papers/ibpria-extended2025 papers/demographic-bias papers/on-paper-data-aug
BUILD := build
.PHONY: all test test-static build clean help
all: help
help:
@echo "make test compile and check every main document"
@echo "make test-static source checks only (figures, citations)"
@echo "make build compile into $(BUILD)/ (not committed)"
@echo "make clean remove $(BUILD)/"
test:
@tests/run.sh full
test-static:
@tests/run.sh static
build:
@mkdir -p $(BUILD)
@for d in $(DOCS); do \
echo "== $$d"; \
mkdir -p "$(BUILD)/$$d"; \
( cd "$$d" && latexmk -pdf -interaction=nonstopmode -file-line-error -outdir="$(CURDIR)/$(BUILD)/$$d" main.tex ) \
| tail -3; \
done
@echo "PDFs in $(BUILD)/<document>/main.pdf"
clean:
@rm -rf $(BUILD)
@echo "removed $(BUILD)/"
+164
View File
@@ -0,0 +1,164 @@
# master-thesis
> LaTeX sources for an M.Sc. dissertation on automatic image-quality assessment, the four papers built on the same work, and the reference material, poster and slides that go with them.
## What it is
Three top-level folders, 180 tracked files and 343 MB of tracked content (Gitea reports 320 MB; the working tree plus `.git` occupies 666 MB on disk). This is a LaTeX collection, not a program: nothing runs, everything compiles.
- **`thesis/`** (55 files, 60 MB) — the dissertation: *"Metrics of automatic Image Quality Assessment based on Human Perception — A comparative study and a proposal of a new metric"*, an M.Sc. in Electrical and Computer Engineering (University of Coimbra), **114 pages** when compiled. `thesis/main.tex` (270 lines) holds the preamble and the chapter order; the text lives in `thesis/chapters/` (7 files) and `thesis/appendix/` (4 files), the front matter in `thesis/misc/` (title page, abstract, resumo, acronyms, `references.bib` with 150 entries), and the 28 figures in `thesis/images/`. The committed `thesis/main.pdf` is the submitted PDF, `thesis/main_v0.pdf` is an earlier snapshot of the same 114 pages, and `thesis/thesis.pptx` (21.57 MB) is the defence presentation.
- **`papers/`** (96 files, 178 MB) — four self-contained LaTeX projects, each with its own document class, `.bib`, figures and compiled PDF. All four are by André Neto, three of them with Nuno Gonçalves (University of Coimbra) as co-author:
- `papers/demographic-bias/` — *"Optimizing Image Quality Assessment metrics for subjective perception controlling demographic bias"*, IEEE (`IEEEtran.cls`, `ieeetr`), **6 pages**;
- `papers/ibpria2025/` — *"Pseudo-MOS Learning: A Full-to-No-Reference FIQA Framework"*, Springer LNCS (`llncs.cls`, `splncs04`), **15 pages**;
- `papers/ibpria-extended2025/` — the extended version of the same paper, LNCS, **15 pages**;
- `papers/on-paper-data-aug/` — *"An On-Paper Data Augmentation Algorithm for Dataset Generation"*, LNCS, **7 pages**.
- **`documents/`** (25 files, 106 MB) — material around the thesis, not documents to compile: 24 literature PDFs on image-quality metrics and subjective assessment (TID2013, ITU-R BT.500, SSIM/PSNR surveys…), the CoDEEC poster and presentation (`documents/coDEEC/poster.pptx`, 42.73 MB, the largest single file in the repository) and `documents/notes.txt`. No `.tex` file exists here, so nothing here is built.
The 343 MB is content, not litter. By kind (at clone time, 180 files): PDFs 169.48 MB (59 files), slide decks `.pptx` 92.27 MB (5), images `.jpg`/`.png`/`.eps` 62.31 MB (53), one `.zip` 12.87 MB, LaTeX sources `.tex`/`.bib`/`.cls` 0.80 MB (50), three `-eps-converted-to.pdf` caches 5.52 MB, everything else 0.15 MB. The ten largest files are:
| MB | file |
|---|---|
| 42.73 | `documents/coDEEC/poster.pptx` |
| 39.70 | `papers/on-paper-data-aug/main.pdf` |
| 21.57 | `thesis/thesis.pptx` |
| 13.59 | `papers/ibpria-extended2025/ibpria.pptx` |
| 13.59 | `papers/ibpria2025/ibpria.pptx` |
| 13.27 | `thesis/main.pdf` |
| 13.03 | `thesis/main_v0.pdf` |
| 12.87 | `papers/ibpria2025.zip` |
| 12.48 | `papers/on-paper-data-aug/images/006.jpg` |
| 8.57 | `papers/demographic-bias/main.pdf` |
Nothing in the history is compilation junk: the only two build leftovers ever committed were the empty LibreOffice lock files `thesis/.~lock.thesis.pptx#` and `thesis/.~lock.thesis-arch.pptx#`, and they were removed from the index on 2026-10-08 (`.gitignore` now covers that pattern). The binaries above are deliverables — the submitted PDFs, the defence and conference slides, the high-resolution figures and the literature — so they stay.
Four things are duplicated or vestigial. They are left in place, because deciding what is content and what is waste is not a decision for a cleanup commit:
- `papers/ibpria-extended2025/` is **byte-for-byte identical** to `papers/ibpria2025/`: `diff -rq` reports no difference at all and both trees are 35,011,632 bytes. The two committed PDFs differ only in their PDF identifiers. The "extended" paper is therefore a copy of the regular one, and one copy is redundant.
- `papers/ibpria2025.zip` (12.87 MB) is an archive of the `papers/ibpria2025/` folder that is already in the tree.
- `papers/on-paper-data-aug/aux.tex` (173 lines) is the unmodified Springer LNCS `samplepaper.tex`: it is not reachable from `main.tex`, and its `\includegraphics{fig1.eps}` points at a file that was never committed — the only missing figure in the repository. The 70 `\includegraphics` of the five main documents all resolve (thesis 29, each IBPria paper 13, demographic-bias 6, on-paper-data-aug 9).
- `thesis/main_v0.pdf` (13,659,246 bytes) is an earlier snapshot of `thesis/main.pdf` (13,911,763 bytes); both are 114 pages.
Two content defects are recorded here and were **not** corrected, because the text and the bibliography are the author's:
- `thesis/misc/references.bib` uses the month macros `September` and `April` unbraced (lines 346 and 354), so `biber` warns `undefined macro`; lines 1035 and 1047 carry stray characters ("13 characters of junk seen at toplevel", "1 character of junk"). All 146 cited keys do resolve, and the three remaining `.bib` warnings per paper are of the same kind.
- Four entries of `thesis/misc/references.bib` are never cited (`liu2012gssim`, `neto2025pseudo`, `svr`, `tutuncu2018steganography`); `papers/ibpria2025/references.bib` has 31 uncited entries of 94 and `papers/demographic-bias/references.bib` 36 of 71. Unused entries are reported by the tests, never treated as a failure.
## Requirements
- A TeX Live installation with `pdflatex`, `latexmk`, `bibtex` and `biber`, and these Debian packages: `texlive-latex-base`, `texlive-latex-recommended`, `texlive-latex-extra`, `texlive-fonts-recommended`, `texlive-science`, `texlive-pictures`, `texlive-bibtex-extra`, `texlive-publishers`, `texlive-lang-portuguese`, `lmodern`, `latexmk`, `biber`.
- `biber` (2.20) is required by `thesis/main.tex`, which loads `biblatex` with `backend=biber`.
- `texlive-lang-portuguese` provides the `portuguese` language and hyphenation patterns the thesis asks `babel` for.
- `texlive-publishers` provides `splncs04.bst`, the Springer LNCS bibliography style used by the three LNCS papers. Without it `bibtex` stops with `I couldn't open style file splncs04.bst`, no `.bbl` is produced and every citation stays undefined.
- `make` for the test and build targets.
- `python3` for `tests/check.py`, and `pdfinfo` (`poppler-utils`) to count PDF pages.
Tested on Debian 13 (arm64, Raspberry Pi 5) with TeX Live 2025.
## Install / Build
```sh
sudo apt-get install -y texlive-latex-base texlive-latex-recommended texlive-latex-extra \
texlive-fonts-recommended texlive-science texlive-pictures texlive-bibtex-extra \
texlive-publishers texlive-lang-portuguese lmodern latexmk biber make python3 poppler-utils
```
Each document is built with `latexmk`, which runs `pdflatex`/`biber`/`bibtex` as many times as the cross-references need. Run it from the document's directory and keep the output out of the repository, so the committed PDFs are never overwritten by a test run:
```sh
cd thesis && latexmk -pdf -outdir=/tmp/build/thesis main.tex # 114 pages, ~50 s
cd papers/ibpria2025 && latexmk -pdf -outdir=/tmp/build/ibpria2025 main.tex # 15 pages
```
`make build` compiles all five documents the same way into `build/` (git-ignored) and prints where the PDFs are.
## Usage
```sh
make build # all five documents into build/<document>/main.pdf
make clean # remove build/
```
To build one document by hand, `cd` into its folder and call `latexmk` with an `-outdir=...` outside the repository, e.g.
```sh
cd papers/demographic-bias && latexmk -pdf -outdir=/tmp/db main.tex
```
`documents/` contains no `.tex` file: it is reference material and slide decks, and there is nothing to compile there. `papers/on-paper-data-aug/aux.tex` is a stray LNCS sample that no build uses; `latexmk -pdf aux.tex` on it fails, correctly, because the `fig1.eps` it asks for does not exist.
## Tests
`make test` (equivalently `tests/run.sh full`) compiles all five main documents into a temporary directory with `latexmk` and checks the result; `make test-static` (`tests/run.sh static`) runs only the source checks, in a few seconds. The suite exits non-zero if anything fails.
`tests/check.py static` follows the `\input`/`\include` tree of each main file and asserts, from the sources alone, that every `\includegraphics` resolves to a file on disk and that every `\cite` key has an entry in the project's `.bib` (unused entries are reported, not fatal). `tests/check.py build` adds the compiled checks: the PDF exists, has exactly the expected number of pages (`tests/documents.conf`), and the final pass has no fatal error, no unresolved reference, no unresolved citation and no missing input file. Overfull and underfull boxes are reported as information.
The suite also carries negative checks, which must fail for the suite to be green: a figure pointing at a file that does not exist (both as a fixture and injected into the real `papers/demographic-bias` before building), a citation with no `.bib` entry, a real thesis copy with a used `.bib` entry deleted, a real thesis copy with `images/` removed, and a build whose expected page count is wrong. Two control checks (a clean fixture that must pass static and build) prove the negative checks are not failing for the wrong reason.
The whole suite on the committed tree (`make test`; the per-document headings and the compile logs are trimmed here):
```text
| document | pages (want -> got) | static | build | unresolved | result |
|---|---|---|---|---|---|
| `thesis/main.tex` | 114 -> 114 | ok | ok | refs 0/cites 0 unresolved | PASS |
| `papers/ibpria2025/main.tex` | 15 -> 15 | ok | ok | refs 0/cites 0 unresolved | PASS |
| `papers/ibpria-extended2025/main.tex` | 15 -> 15 | ok | ok | refs 0/cites 0 unresolved | PASS |
| `papers/demographic-bias/main.tex` | 6 -> 6 | ok | ok | refs 0/cites 0 unresolved | PASS |
| `papers/on-paper-data-aug/main.tex` | 7 -> 7 | ok | ok | refs 0/cites 0 unresolved | PASS |
| check | expectation | actual | ok |
|---|---|---|---|
| fixture: figure points at a file that does not exist | static must fail | failed (exit 1) | yes |
| fixture: citation with no .bib entry | static must fail | failed (exit 1) | yes |
| fixture: clean document (control) | static must pass | passed (exit 0) | yes |
| fixture: clean document compiles (control) | build must pass | passed (exit 0) | yes |
| fixture: wrong expected page count | build must fail | failed (exit 1) | yes |
| thesis copy: used .bib entry 'abed2025fiqabiometric' deleted | static must fail | exit 1 | yes |
| thesis copy with images/ deleted | static must fail | exit 1 | yes |
| real paper + \includegraphics to a missing file | build must fail | exit 1 | yes |
checks: 13 | failed: 0
RESULT: PASS
```
The five documents then build to **114, 15, 15, 6 and 7 pages** — the same page counts as the committed PDFs — with 0 fatal errors, 0 unresolved references, 0 unresolved citations and 0 missing files each; 6 overfull and 4 underfull boxes in the thesis, 1 overfull in `on-paper-data-aug` and 1 underfull box in `demographic-bias` are the only typesetting warnings. The 70 `\includegraphics` and 307 `\cite` keys of those documents all resolve. A full run takes a few minutes on the Pi 5, the thesis alone about 50 seconds.
## Structure
```
thesis/main.tex 270 lines; preamble, chapter order, bibliography (biblatex, biber)
thesis/main.pdf 114 pages; the submitted dissertation
thesis/main_v0.pdf 114 pages; earlier snapshot of the same thesis
thesis/thesis.pptx 21.57 MB; defence presentation
thesis/chapters/ 7 files; introduction to conclusion
thesis/appendix/ 4 files; screening, full reference list, regression models, environment
thesis/misc/ title page, abstract, resumo, acronyms, UC logos, references.bib (150 entries)
thesis/images/ 28 figures
thesis/README.md the upstream template's README, kept as it came (see License)
papers/demographic-bias/ IEEE paper, IEEEtran.cls + references.bib (71 entries), 6 pages
papers/ibpria2025/ LNCS paper, llncs.cls + references.bib (94 entries), 15 pages
papers/ibpria-extended2025/ byte-identical copy of papers/ibpria2025/, 15 pages
papers/on-paper-data-aug/ LNCS paper, 7 pages; aux.tex is a stray LNCS sample
papers/ibpria2025.zip 12.87 MB; archive of papers/ibpria2025/
documents/methods/, metrics/, surveys/ 24 literature PDFs
documents/coDEEC/ poster.pptx (42.73 MB) and apresentacao.pptx
documents/notes.txt working notes
tests/run.sh, tests/check.py the test suite
tests/documents.conf the five main documents and their expected page counts
Makefile test, test-static, build, clean
.gitignore LaTeX build products, editor and office leftovers
```
## License
Por definir — trabalho académico com orientação e co-autoria.
No `LICENSE` file exists in this repository and none was added on 2026-10-08. The dissertation's title page names a supervisor (Nuno Miguel Mendonça da Silva Gonçalves) and a co-supervisor (João de Sena Baptista Pimentel Marcos), and three of the four papers are co-authored with Nuno Gonçalves. Choosing a licence for someone else's academic work is not a decision one of the authors can take alone, so until all of them agree, all rights are reserved and no licence is granted.
That decision does not extend to the third-party material, which keeps its own origin and terms and is not covered by any licence of this repository.
### Provenance of the template and the document classes
- `thesis/` is built on **`latex-dissertation-template`**, a public M.Sc. dissertation template by Mário Cristóvão (<https://github.com/mjpc13/latex-dissertation-template>). `thesis/main.tex` says so in its header ("A work by Mário Cristóvão, based on an example by Gonçalo Martins and José Faria") and `thesis/README.md` is that project's README, kept verbatim. The template follows the University of Coimbra / FCTUC visual identity, uses the standard `book` class, and carries no licence notice of any kind in this repository; it is kept here because the thesis does not compile without it.
- `papers/ibpria2025/llncs.cls`, `papers/ibpria-extended2025/llncs.cls` and `papers/on-paper-data-aug/llncs.cls` are **Springer's LNCS document class** (`LLNCS DOCUMENT CLASS -- version 2.24 (29-Jan-2024)`), vendored per paper. They are pinned, not taken from the TeX distribution: they differ from the TeX Live copy at `/usr/share/texlive/texmf-dist/tex/latex/llncs/llncs.cls`. The two `ibpria*` copies are identical to each other; the `on-paper-data-aug` copy is a different revision.
- `papers/demographic-bias/IEEEtran.cls` is the **IEEE** class for IEEE Transactions papers (`IEEEtran.cls 2015/08/26 version V1.8b`, <http://www.michaelshell.org/tex/ieeetran/>, <https://www.ieee.org/>).
- The three `*-eps-converted-to.pdf` files in `papers/demographic-bias/images/` were produced by `epstopdf` from the `.eps` files next to them; they regenerate at build time and could be dropped from the index if the author prefers.
Executable
+329
View File
@@ -0,0 +1,329 @@
#!/usr/bin/env python3
"""Checks for the master-thesis LaTeX collection (see README.md, "Tests").
Sub-commands
------------
static <project-dir> <main.tex>
Follows the \\input/\\include tree of <main.tex> and checks, from the
sources alone:
* every \\includegraphics argument resolves to a file on disk;
* every \\cite key has an entry in the project's .bib file.
Unused .bib entries are reported but never fail the run.
build <project-dir> <main.tex> <expected-pages> [outdir]
Runs `latexmk -pdf` (output to <outdir>, or a fresh temporary directory)
and checks the PDF exists, has exactly <expected-pages> pages, and that
the final pass reports no fatal error, no unresolved reference, no
unresolved citation and no missing input file. Overfull/underfull boxes
are reported as information.
usedkeys <project-dir> <main.tex> one cited key per line
drop-entry <bib-file> <key> removes one entry from a .bib file
inject-graphic <main.tex> <path> inserts \\includegraphics{<path>} before \\end{document}
Exit status is 0 only when every check of the sub-command passed.
"""
import glob
import os
import re
import shutil
import subprocess
import sys
import tempfile
CITE_RE = re.compile(
r"\\(?:cite|citep|citet|citealp|citeauthor|citeyear|Cite|parencite|textcite"
r"|autocite|footcite|smartcite|nocite)\*?(?:\[[^\]]*\])*\s*\{([^}]*)\}"
)
GRAPHICS_RE = re.compile(r"\\includegraphics\s*(?:\[[^\]]*\])?\s*\{([^}]*)\}")
INPUT_RE = re.compile(r"\\(?:input|include)\s*\{([^}]*)\}")
ADDBIB_RE = re.compile(r"\\addbibresource(?:\[[^\]]*\])?\s*\{([^}]*)\}")
BIBLIO_RE = re.compile(r"\\bibliography\s*\{([^}]*)\}")
ENTRY_RE = re.compile(r"@\w+\s*\{\s*([^,\s]+)\s*,")
GRAPHIC_EXTS = ("", ".pdf", ".png", ".jpg", ".jpeg", ".eps", ".ps", ".PNG", ".JPG")
def fail(msg):
print(" FAIL: " + msg)
def note(msg):
print(" note: " + msg)
def strip_comments(text):
out = []
for line in text.splitlines():
res, i = "", 0
while i < len(line):
if line[i] == "%" and (i == 0 or line[i - 1] != "\\"):
break
res += line[i]
i += 1
out.append(res)
return "\n".join(out)
def read(path):
with open(path, encoding="utf-8", errors="replace") as fh:
return strip_comments(fh.read())
def input_tree(project, main):
"""All .tex reachable from <main> through \\input/\\include (LaTeX order)."""
seen, order = set(), []
def walk(rel):
path = os.path.join(project, rel)
if not os.path.isfile(path) or os.path.abspath(path) in seen:
return
seen.add(os.path.abspath(path))
order.append(rel)
text = read(path)
for raw in INPUT_RE.findall(text):
target = raw.strip()
if not target or "\\" in target: # macro or \input{|cmd}
continue
if not os.path.splitext(target)[1]:
target += ".tex"
walk(target)
walk(main)
return order
def bib_entries(project, rel_files):
"""{key: (bib file, index)} for every entry of the project's .bib files."""
entries, files = {}, []
for rel in rel_files:
text = read(os.path.join(project, rel))
for bib in ADDBIB_RE.findall(text) + BIBLIO_RE.findall(text):
for name in bib.split(","):
name = name.strip()
if not name:
continue
name = name if name.endswith(".bib") else name + ".bib"
if name not in files:
files.append(name)
for name in files:
path = os.path.join(project, name)
if not os.path.isfile(path):
fail("declared bibliography %s does not exist" % name)
continue
raw = open(path, encoding="utf-8", errors="replace").read()
for m in ENTRY_RE.finditer(raw):
entries.setdefault(m.group(1).strip(), (name, raw))
return entries, files
def check_static(project, main, quiet_ok=False):
project = os.path.abspath(project)
rels = input_tree(project, main)
failures = 0
if not rels:
fail("main file %s not found under %s" % (main, project))
return 1
print(" input tree: %d .tex files (%s)" % (len(rels), ", ".join(rels[:6]) +
(", ..." if len(rels) > 6 else "")))
# ---- figures -------------------------------------------------------
total = missing = 0
missing_list = []
for rel in rels:
for raw in GRAPHICS_RE.findall(read(os.path.join(project, rel))):
name = raw.strip()
if not name or "\\" in name:
continue
total += 1
base = os.path.join(project, name)
candidates = [base + e for e in GRAPHIC_EXTS]
if not any(os.path.isfile(c) for c in candidates):
missing += 1
missing_list.append("%s -> %s" % (rel, name))
if missing:
failures += 1
fail("%d of %d \\includegraphics do not exist on disk" % (missing, total))
for item in missing_list[:10]:
print(" " + item)
if len(missing_list) > 10:
print(" ... and %d more" % (len(missing_list) - 10))
elif not quiet_ok:
print(" figures: %d/%d \\includegraphics resolve" % (total - missing, total))
# ---- citations -----------------------------------------------------
used = set()
for rel in rels:
for field in CITE_RE.findall(read(os.path.join(project, rel))):
for key in field.split(","):
key = key.strip()
if key and key != "*":
used.add(key)
entries, bibfiles = bib_entries(project, rels)
absent, unused = [], []
if not bibfiles:
if used:
failures += 1
fail("%d citation keys but no .bib is declared by the main tree" % len(used))
else:
note("no bibliography declared and no citations used")
else:
absent = sorted(k for k in used if k not in entries)
if absent:
failures += 1
fail("%d \\cite keys have no entry in %s: %s"
% (len(absent), ", ".join(bibfiles), ", ".join(absent[:8])))
else:
print(" citations: %d/%d \\cite keys found in %s"
% (len(used), len(used), ", ".join(bibfiles)))
unused = sorted(k for k in entries if k not in used)
if unused:
note("%d .bib entries are never cited (reported, not a failure): %s%s"
% (len(unused), ", ".join(unused[:8]), " ..." if len(unused) > 8 else ""))
# ---- stray .tex files (not part of the main tree) -------------------
on_disk = {os.path.relpath(p, project) for p in
glob.glob(os.path.join(project, "**", "*.tex"), recursive=True)}
stray = sorted(on_disk - set(rels))
if stray:
note("not reachable from %s (ignored by these checks): %s"
% (main, ", ".join(stray)))
print(" summary: figures=%d figures_missing=%d cites=%d cites_missing=%d "
"bib_entries=%d bib_unused=%d"
% (total, missing, len(used), len(absent), len(entries), len(unused)))
return failures
def check_build(project, main, expected_pages, outdir=None):
project = os.path.abspath(project)
failures = 0
temp = None
if outdir is None:
temp = tempfile.mkdtemp(prefix="master-thesis-build-")
outdir = temp
os.makedirs(outdir, exist_ok=True)
stem = os.path.splitext(os.path.basename(main))[0]
log_path, pdf_path = os.path.join(outdir, stem + ".log"), os.path.join(outdir, stem + ".pdf")
cmd = ["latexmk", "-pdf", "-interaction=nonstopmode", "-file-line-error",
"-outdir=" + outdir, main]
print(" $ (cd %s && %s)" % (os.path.relpath(project), " ".join(cmd)))
proc = subprocess.run(cmd, cwd=project, capture_output=True, text=True,
encoding="utf-8", errors="replace")
out = proc.stdout + proc.stderr
if proc.returncode != 0:
failures += 1
fail("latexmk exited %d" % proc.returncode)
for line in out.splitlines():
if line.startswith("Latexmk:") and ("rror" in line or "ailed" in line):
print(" " + line.strip())
if not os.path.isfile(pdf_path):
failures += 1
fail("no PDF produced at %s" % pdf_path)
print(" summary: pages=0/%d unresolved_refs=0 unresolved_cites=0 "
"missing_files=0 fatal_errors=0 latexmk_rc=%d"
% (expected_pages, proc.returncode))
if temp:
shutil.rmtree(temp, ignore_errors=True)
return failures
if not os.path.isfile(log_path):
failures += 1
fail("no .log produced at %s" % log_path)
return failures
log = open(log_path, encoding="utf-8", errors="replace").read()
errors = re.findall(r"(?m)^! (.*)$", log)
if errors:
failures += 1
fail("%d fatal error(s) in the final pass: %s" % (len(errors), errors[0].strip()))
missing = sorted({m for m in re.findall(r"File `([^']*)' not found", log)})
if missing:
failures += 1
fail("missing input file(s): %s" % ", ".join(missing[:6]))
undef_refs = sorted({m for m in re.findall(r"Reference `([^']*)' on page", log)})
if undef_refs:
failures += 1
fail("%d unresolved reference(s): %s" % (len(undef_refs), ", ".join(undef_refs[:8])))
undef_cites = sorted({m for m in re.findall(r"Citation `([^']*)' on page", log)})
if undef_cites:
failures += 1
fail("%d unresolved citation(s): %s" % (len(undef_cites), ", ".join(undef_cites[:8])))
info = subprocess.run(["pdfinfo", pdf_path], capture_output=True, text=True,
encoding="utf-8", errors="replace").stdout
m = re.search(r"(?m)^Pages:\s+(\d+)", info)
pages = int(m.group(1)) if m else 0
if pages != expected_pages:
failures += 1
fail("PDF has %d pages, expected %d" % (pages, expected_pages))
else:
print(" pages: %d (expected %d), %d bytes"
% (pages, expected_pages, os.path.getsize(pdf_path)))
if not errors and not missing and not undef_refs and not undef_cites:
print(" log: 0 fatal errors, 0 unresolved references, 0 unresolved citations")
overfull = len(re.findall(r"Overfull \\hbox", log))
underfull = len(re.findall(r"Underfull \\hbox", log))
note("%d overfull and %d underfull boxes (typesetting, not failures)"
% (overfull, underfull))
print(" summary: pages=%d/%d unresolved_refs=%d unresolved_cites=%d "
"missing_files=%d fatal_errors=%d latexmk_rc=%d"
% (pages, expected_pages, len(undef_refs), len(undef_cites),
len(missing), len(errors), proc.returncode))
return failures
def main(argv):
if len(argv) < 2:
print(__doc__)
return 2
cmd = argv[1]
if cmd == "static":
return 1 if check_static(argv[2], argv[3] if len(argv) > 3 else "main.tex") else 0
if cmd == "build":
outdir = argv[5] if len(argv) > 5 else None
bad = check_build(argv[2], argv[3], int(argv[4]), outdir)
return 1 if bad else 0
if cmd == "usedkeys":
project, main = os.path.abspath(argv[2]), argv[3] if len(argv) > 3 else "main.tex"
used = set()
for rel in input_tree(project, main):
for field in CITE_RE.findall(read(os.path.join(project, rel))):
for key in field.split(","):
key = key.strip()
if key and key != "*":
used.add(key)
print("\n".join(sorted(used)))
return 0
if cmd == "drop-entry":
bib, key = argv[2], argv[3]
raw = open(bib, encoding="utf-8", errors="replace").read()
pattern = re.compile(r"@\w+\s*\{\s*" + re.escape(key) + r"\s*,[\s\S]*?(?=\n@|\Z)")
new, n = pattern.subn("", raw, count=1)
if not n:
print(" FAIL: no entry %r in %s" % (key, bib))
return 1
open(bib, "w", encoding="utf-8").write(new)
print(" dropped entry %r from %s" % (key, bib))
return 0
if cmd == "inject-graphic":
path, target = argv[2], argv[3]
raw = open(path, encoding="utf-8", errors="replace").read()
idx = raw.rfind("\\end{document}")
if idx < 0:
print(" FAIL: %s has no \\end{document}" % path)
return 1
raw = raw[:idx] + "\\includegraphics{%s}\n" % target + raw[idx:]
open(path, "w", encoding="utf-8").write(raw)
print(" injected \\includegraphics{%s} into %s" % (target, path))
return 0
print(__doc__)
return 2
if __name__ == "__main__":
sys.exit(main(sys.argv))
+7
View File
@@ -0,0 +1,7 @@
# Main documents of this repository: <directory>|<main .tex>|<pages of a fresh build>
# Page counts are what `latexmk -pdf` produces today (see README.md, "Tests").
thesis|main.tex|114
papers/ibpria2025|main.tex|15
papers/ibpria-extended2025|main.tex|15
papers/demographic-bias|main.tex|6
papers/on-paper-data-aug|main.tex|7
+7
View File
@@ -0,0 +1,7 @@
% Negative fixture: \cite{ghost-entry} has no entry in refs.bib.
\documentclass{article}
\begin{document}
See \cite{ghost-entry} for a reference that does not exist.
\bibliographystyle{plain}
\bibliography{refs}
\end{document}
+9
View File
@@ -0,0 +1,9 @@
@article{knuth1984,
author = {Knuth, Donald E.},
title = {Literate Programming},
journal = {The Computer Journal},
volume = {27},
number = {2},
pages = {97--111},
year = {1984}
}
+7
View File
@@ -0,0 +1,7 @@
% Negative fixture: the figure below is not on disk, so `check.py static`
% (and a latexmk build of this file) must fail.
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\includegraphics{images/this-file-does-not-exist.png}
\end{document}
+8
View File
@@ -0,0 +1,8 @@
% Control fixture: one citation that exists in refs.bib, no figures.
% Both `check.py static` and `check.py build` must pass on this file.
\documentclass{article}
\begin{document}
See \cite{knuth1984}.
\bibliographystyle{plain}
\bibliography{refs}
\end{document}
+9
View File
@@ -0,0 +1,9 @@
@article{knuth1984,
author = {Knuth, Donald E.},
title = {Literate Programming},
journal = {The Computer Journal},
volume = {27},
number = {2},
pages = {97--111},
year = {1984}
}
Executable
+149
View File
@@ -0,0 +1,149 @@
#!/usr/bin/env bash
# Test suite for the master-thesis LaTeX collection. See README.md, "Tests".
#
# tests/run.sh compile every main document and check it (slow)
# tests/run.sh static sources only, no compilation (fast)
#
# Exits non-zero if any check fails.
set -u
ROOT=$(cd "$(dirname "$0")/.." && pwd)
CHECK="$ROOT/tests/check.py"
CONF="$ROOT/tests/documents.conf"
MODE="${1:-full}"
case "$MODE" in full|static) ;; *) echo "usage: $0 [full|static]" >&2; exit 2 ;; esac
WORK=$(mktemp -d "${TMPDIR:-/tmp}/master-thesis-tests.XXXXXX")
cleanup() {
case "$WORK" in /tmp/*|"${TMPDIR:-/tmp}"/*) rm -rf "$WORK" ;; esac
}
trap cleanup EXIT
CHECKS=0
FAILED=0
declare -a ROWS=()
declare -a DOCROWS=()
add_row() { # name | expectation | actual | ok
ROWS+=("| $1 | $2 | $3 | $4 |")
CHECKS=$((CHECKS + 1))
[ "$4" = "yes" ] || FAILED=$((FAILED + 1))
}
add_doc() { # document | pages want/got | static | build | unresolved | result
DOCROWS+=("| $1 | $2 | $3 | $4 | $5 | $6 |")
CHECKS=$((CHECKS + 1))
[ "$6" = "PASS" ] || FAILED=$((FAILED + 1))
}
summary() { sed -n 's/^ summary: //p' <<<"$1" | tail -1; }
echo "== master-thesis test suite =="
echo "root: $ROOT"
echo "mode: $MODE ($([ "$MODE" = full ] && echo 'compile + sources' || echo 'sources only'))"
echo "tex: $(pdflatex --version 2>/dev/null | head -1)"
echo "tool: $(latexmk -v 2>/dev/null | head -1)"
echo
echo "-- main documents --"
while IFS='|' read -r dir main pages; do
case "$dir" in ''|'#'*) continue ;; esac
doc="$dir/$main"
echo "### $doc"
out=$("$CHECK" static "$ROOT/$dir" "$main" 2>&1); rc=$?
ssum=$(summary "$out")
echo "$out" | sed 's/^/ /'
[ "$rc" = 0 ] && static="ok" || static="FAIL"
build="n/a"; usum="n/a"; got="$pages"
if [ "$MODE" = full ]; then
out=$("$CHECK" build "$ROOT/$dir" "$main" "$pages" "$WORK/build/$dir" 2>&1); rc=$?
echo "$out" | sed 's/^/ /'
bsum=$(summary "$out")
[ "$rc" = 0 ] && build="ok" || build="FAIL"
got=$(sed -n 's/.*pages=\([0-9]*\)\/.*/\1/p' <<<"$bsum" | tail -1)
[ -n "$got" ] || got="?"
refs=$(sed -n 's/.*unresolved_refs=\([0-9]*\).*/\1/p' <<<"$bsum" | tail -1)
cits=$(sed -n 's/.*unresolved_cites=\([0-9]*\).*/\1/p' <<<"$bsum" | tail -1)
usum="refs ${refs:-?}/cites ${cits:-?} unresolved"
fi
if [ "$static" = ok ] && { [ "$MODE" = static ] || [ "$build" = ok ]; }; then res="PASS"; else res="FAIL"; fi
add_doc "\`$doc\`" "${pages} -> ${got}" "$static" "$build" "$usum" "$res"
done < "$CONF"
echo
echo "-- negative and control checks --"
run_negative() { # name | expectation | command...
local name="$1" expect="$2"; shift 2
local out rc
out=$("$@" 2>&1); rc=$?
local actual ok
if [ "$rc" != 0 ]; then actual="failed (exit $rc)"; else actual="passed (exit 0)"; fi
if [[ "$expect" == *"must fail"* ]]; then
ok=$([ "$rc" != 0 ] && echo yes || echo no)
else
ok=$([ "$rc" = 0 ] && echo yes || echo no)
fi
add_row "$name" "$expect" "$actual" "$ok"
if [ "$ok" = no ]; then echo " --- output of the failing check ---"; echo "$out" | sed 's/^/ /'; fi
}
run_negative "fixture: figure points at a file that does not exist" "static must fail" \
"$CHECK" static "$ROOT/tests/fixtures/missing-figure" main.tex
run_negative "fixture: citation with no .bib entry" "static must fail" \
"$CHECK" static "$ROOT/tests/fixtures/missing-cite" main.tex
run_negative "fixture: clean document (control)" "static must pass" \
"$CHECK" static "$ROOT/tests/fixtures/ok" main.tex
run_negative "fixture: clean document compiles (control)" "build must pass" \
"$CHECK" build "$ROOT/tests/fixtures/ok" main.tex 1 "$WORK/build/fixture-ok"
run_negative "fixture: wrong expected page count" "build must fail" \
"$CHECK" build "$ROOT/tests/fixtures/ok" main.tex 99 "$WORK/build/fixture-pages"
# A used .bib entry removed from a copy of the real thesis sources.
cp -r "$ROOT/thesis" "$WORK/thesis-bib" 2>/dev/null
key=$(python3 "$CHECK" usedkeys "$ROOT/thesis" main.tex | head -1)
if [ -n "$key" ]; then
python3 "$CHECK" drop-entry "$WORK/thesis-bib/misc/references.bib" "$key" >/dev/null 2>&1
fi
out=$(python3 "$CHECK" static "$WORK/thesis-bib" main.tex 2>&1); rc=$?
ok=no
[ -n "$key" ] && [ "$rc" != 0 ] && ok=yes
add_row "thesis copy: used .bib entry '$key' deleted" "static must fail" "exit $rc" "$ok"
[ "$ok" = yes ] || { echo " --- output ---"; echo "$out" | sed 's/^/ /'; }
# The real thesis sources with no images on disk.
cp -r "$ROOT/thesis" "$WORK/thesis-fig" 2>/dev/null
rm -rf "$WORK/thesis-fig/images"
out=$(python3 "$CHECK" static "$WORK/thesis-fig" main.tex 2>&1); rc=$?
ok=no; [ "$rc" != 0 ] && ok=yes
add_row "thesis copy with images/ deleted" "static must fail" "exit $rc" "$ok"
[ "$ok" = yes ] || { echo " --- output ---"; echo "$out" | sed 's/^/ /'; }
if [ "$MODE" = full ]; then
# A real paper with one extra graphic that does not exist: the build must fail.
cp -r "$ROOT/papers/demographic-bias" "$WORK/db-bad" 2>/dev/null
python3 "$CHECK" inject-graphic "$WORK/db-bad/main.tex" images/DOES-NOT-EXIST.png >/dev/null 2>&1
out=$(python3 "$CHECK" build "$WORK/db-bad" main.tex 6 "$WORK/build/db-bad" 2>&1); rc=$?
add_row "real paper + \includegraphics to a missing file" "build must fail" "exit $rc" \
"$([ "$rc" != 0 ] && echo yes || echo no)"
else
echo " (compile-level negative checks skipped in static mode)"
fi
echo
echo "-- documents --"
echo "| document | pages (want -> got) | static | build | unresolved | result |"
echo "|---|---|---|---|---|---|"
printf '%s\n' "${DOCROWS[@]}"
echo
echo "-- checks --"
echo "| check | expectation | actual | ok |"
echo "|---|---|---|---|"
printf '%s\n' "${ROWS[@]}"
echo
echo "checks: $CHECKS | failed: $FAILED"
if [ "$FAILED" = 0 ]; then echo "RESULT: PASS"; else echo "RESULT: FAIL"; fi
[ "$FAILED" = 0 ] || exit 1
exit 0
-1
View File
@@ -1 +0,0 @@
,twevo,sigma,24.09.2025 20:01,/home/twevo/.local/share/onlyoffice;
-1
View File
@@ -1 +0,0 @@
,twevo,sigma,25.09.2025 20:18,/home/twevo/.local/share/onlyoffice;