stacks thesis?
This commit is contained in:
parent
a364f3cd81
commit
9bd7155777
11 changed files with 255 additions and 2 deletions
2
.envrc
2
.envrc
|
@ -1,2 +1,2 @@
|
|||
layout python3
|
||||
use flake
|
||||
# use flake
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
{
|
||||
outputs = { self, nixpkgs, flake-utils }: flake-utils.lib.eachDefaultSystem (system:
|
||||
let pkgs = import nixpkgs { inherit system; };
|
||||
let
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
flakePkgs = rec {
|
||||
gerby = pkgs.callPackage ./nix/gerby.nix {};
|
||||
};
|
||||
in {
|
||||
packages = flake-utils.lib.flattenTree flakePkgs;
|
||||
devShell = pkgs.mkShell {};
|
||||
});
|
||||
}
|
||||
|
|
1
thesis/.gitignore
vendored
Normal file
1
thesis/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
_build
|
49
thesis/Justfile
Normal file
49
thesis/Justfile
Normal file
|
@ -0,0 +1,49 @@
|
|||
set export
|
||||
builddir := `pwd` / "_build"
|
||||
|
||||
all: gerby_db
|
||||
|
||||
serve: gerby_db
|
||||
#!/usr/bin/env bash
|
||||
cd $builddir/gerby-website/gerby
|
||||
cp tools/*.sqlite .
|
||||
flask --app . run --host 0.0.0.0
|
||||
|
||||
pdf: book_tex
|
||||
tectonic $builddir/book.tex
|
||||
|
||||
gerby_src:
|
||||
#!/usr/bin/env bash
|
||||
mkdir -p $builddir
|
||||
if [ ! -d "$builddir/gerby-website" ]; then
|
||||
git clone https://github.com/gerby-project/gerby-website $builddir/gerby-website
|
||||
fi
|
||||
|
||||
gerby_db: plastex_files gerby_src
|
||||
#!/usr/bin/env bash
|
||||
cd $builddir/gerby-website/gerby/tools
|
||||
rm -rf stacks stacks.paux stacks.tags
|
||||
cp -r $builddir/web/book stacks
|
||||
cp $builddir/web/book.paux stacks.paux
|
||||
cp $builddir/web/tags stacks.tags
|
||||
python3 update.py
|
||||
|
||||
plastex_files: book_tex tags bib
|
||||
#!/usr/bin/env bash
|
||||
mkdir -p $builddir/web
|
||||
cd $builddir/web
|
||||
rm -r book
|
||||
cp tags $builddir/web/tags
|
||||
cp $builddir/my.bib $builddir/web/my.bib
|
||||
plastex --renderer=Gerby $builddir/book.tex
|
||||
|
||||
tags:
|
||||
mkdir -p $builddir
|
||||
python3 scripts/update_tags.py tags
|
||||
|
||||
bib:
|
||||
touch $builddir/my.bib
|
||||
|
||||
book_tex:
|
||||
mkdir -p $builddir
|
||||
python3 scripts/build_book.py > $builddir/book.tex
|
4
thesis/index
Normal file
4
thesis/index
Normal file
|
@ -0,0 +1,4 @@
|
|||
# Ordered index of modules
|
||||
|
||||
src/intro.tex
|
||||
src/mltt.tex
|
3
thesis/preamble.tex
Normal file
3
thesis/preamble.tex
Normal file
|
@ -0,0 +1,3 @@
|
|||
\documentclass{amsart}
|
||||
|
||||
\usepackage{hyperref}
|
65
thesis/scripts/build_book.py
Normal file
65
thesis/scripts/build_book.py
Normal file
|
@ -0,0 +1,65 @@
|
|||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
def debug(*args, **kwargs): print(*args, file=sys.stderr, **kwargs)
|
||||
def is_label(t: str): return t.find("\\label{") >= 0
|
||||
|
||||
with open("preamble.tex") as f:
|
||||
for line in f.readlines():
|
||||
line = line.strip()
|
||||
if line.find("\\documentclass") == 0:
|
||||
line = line.replace("amsart", "amsbook")
|
||||
line = line.replace("stacks-project", "stacks-project-book")
|
||||
print(line)
|
||||
|
||||
print("""
|
||||
\\begin{document}
|
||||
|
||||
\\begin{titlepage}
|
||||
\\pagestyle{empty}
|
||||
\\setcounter{page}{1}
|
||||
\\vskip1in
|
||||
\\noindent
|
||||
\\end{titlepage}
|
||||
""")
|
||||
|
||||
ignored_lines = [
|
||||
"\\input{preamble}",
|
||||
"\\begin{document}",
|
||||
"\\bibliography",
|
||||
"\\end{document}",
|
||||
"\\tableofcontents",
|
||||
"\\input{chapters}",
|
||||
"\\maketitle",
|
||||
]
|
||||
|
||||
with open("index") as f:
|
||||
files = []
|
||||
for line in f.readlines():
|
||||
line = line.strip()
|
||||
if line.startswith("#"): continue
|
||||
if line == "": continue
|
||||
files.append(line)
|
||||
|
||||
for fname in files:
|
||||
file = Path(fname)
|
||||
with open(file) as f:
|
||||
print(f"\\part{{{file.stem}}}")
|
||||
print(f"\\label{{{file.stem}}}")
|
||||
|
||||
for line in f.readlines():
|
||||
line = line.strip()
|
||||
if any(line.find(i) == 0 for i in ignored_lines):
|
||||
continue
|
||||
if is_label(line):
|
||||
line = line.replace("\\label{", f"\\label{{{file.stem}-")
|
||||
if line.find("\\title{") == 0:
|
||||
line = line.replace("\\title{", "\\chapter{")
|
||||
print(line)
|
||||
|
||||
print("""
|
||||
\\bibliography{my}
|
||||
\\bibliographystyle{amsalpha}
|
||||
\\end{document}
|
||||
""")
|
82
thesis/scripts/update_tags.py
Normal file
82
thesis/scripts/update_tags.py
Normal file
|
@ -0,0 +1,82 @@
|
|||
import sys
|
||||
import click
|
||||
import pathlib
|
||||
import json
|
||||
import math
|
||||
import re
|
||||
|
||||
letters = "0123456789ABCDEFGHJKLMNPQRSTUVWXYZ"
|
||||
label_pat = re.compile(r"\\label\{([^\}]*)\}")
|
||||
|
||||
def tag2num(tag: str):
|
||||
arr = [letters.find(c) for c in tag]
|
||||
return sum(n * pow(len(letters), i) for i, n in enumerate(arr[::-1]))
|
||||
|
||||
def num2tag(n: int):
|
||||
largest = math.ceil(math.log(n, len(letters)))
|
||||
coeffs = []
|
||||
start = False
|
||||
for i in range(largest, -1, -1):
|
||||
p = pow(len(letters), i)
|
||||
coeff, r = n // p, n % p
|
||||
n = r
|
||||
if coeff != 0:
|
||||
start = True
|
||||
coeffs.append(coeff)
|
||||
elif start: coeffs.append(coeff)
|
||||
return "".join(letters[c] for c in coeffs).zfill(4)
|
||||
|
||||
def next_tag(nums: list[int], highest: int) -> tuple[int, int]:
|
||||
prev = 0
|
||||
for c in nums:
|
||||
if c - prev > 1: return (prev + 1, highest)
|
||||
prev = c
|
||||
highest = min(prev, highest)
|
||||
highest += 1
|
||||
return (highest, highest)
|
||||
|
||||
@click.command()
|
||||
@click.argument("filename", type=click.Path(path_type=pathlib.Path))
|
||||
def main(filename):
|
||||
# Load existing tags
|
||||
tag_numbers = []
|
||||
tag_names = set()
|
||||
try:
|
||||
with open(filename) as f:
|
||||
for line in f.readlines():
|
||||
if line.startswith("#"): continue
|
||||
tag_s, name = line.strip().split(",")
|
||||
tag_n = tag2num(tag_s)
|
||||
tag_numbers.append(tag_n)
|
||||
tag_names.add(name)
|
||||
except: pass
|
||||
|
||||
tag_numbers.sort()
|
||||
highest_tag = tag_numbers[-1] if len(tag_numbers) > 0 else 0
|
||||
|
||||
new_tags = []
|
||||
src_dir = pathlib.Path("src")
|
||||
for file in src_dir.iterdir():
|
||||
name = file.stem
|
||||
with open(file) as f:
|
||||
for line in f.readlines():
|
||||
m = label_pat.match(line)
|
||||
if m is None: continue
|
||||
label = m.group(1)
|
||||
full = f"{name}-{label}"
|
||||
if full not in tag_names:
|
||||
n, highest_tag = next_tag(tag_numbers, highest_tag)
|
||||
tag_numbers.append(n)
|
||||
if highest_tag != n: tag_numbers.sort()
|
||||
new_tags.append((n, full))
|
||||
|
||||
# Write back to file
|
||||
with open(filename, "a") as f:
|
||||
for tag_n, name in new_tags:
|
||||
tag_s = num2tag(tag_n)
|
||||
f.write(f"{tag_s},{name}\n")
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
19
thesis/src/intro.tex
Normal file
19
thesis/src/intro.tex
Normal file
|
@ -0,0 +1,19 @@
|
|||
\input{preamble}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\title{Introduction}
|
||||
|
||||
\maketitle
|
||||
|
||||
\phantomsection
|
||||
\label{section-phantom}
|
||||
|
||||
\tableofcontents
|
||||
|
||||
Hello
|
||||
|
||||
|
||||
|
||||
\end{document}
|
||||
|
21
thesis/src/mltt.tex
Normal file
21
thesis/src/mltt.tex
Normal file
|
@ -0,0 +1,21 @@
|
|||
\input{preamble}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\title{Martin-Lof Type Theory}
|
||||
|
||||
\maketitle
|
||||
|
||||
\phantomsection
|
||||
\label{section-phantom}
|
||||
|
||||
\tableofcontents
|
||||
|
||||
\label{intro}
|
||||
|
||||
|
||||
\label{constructors-and-eliminators}
|
||||
|
||||
|
||||
|
||||
\end{document}
|
4
thesis/tags
Normal file
4
thesis/tags
Normal file
|
@ -0,0 +1,4 @@
|
|||
0001,mltt-section-phantom
|
||||
0002,mltt-intro
|
||||
0003,mltt-constructors-and-eliminators
|
||||
0004,intro-section-phantom
|
Loading…
Reference in a new issue