Updated the tagger to scan all files.

This commit is contained in:
Bokuan Li
2025-12-21 03:10:32 -05:00
parent c021e0f27b
commit ba0cf9a315
2 changed files with 39 additions and 33 deletions

View File

@@ -35,7 +35,7 @@
\hi \hi
\end{lemma} \end{lemma}
\begin{proof} \begin{proof}
hihihihihihihi greetings fellow gamer
\[\xymatrix{ & Y_1 & \\ X \ar[ru]^{f_1} \ar[r]^{f_3} \ar[rd]_{f_2} & Y_3 \ar[u]_{a_{31}} \ar[d]^{a_{32}} & Y \ar[lu]_{s_1} \ar[l]_{s_3} \ar[ld]^{s_2} \\ & Y_2 & }\] \[\xymatrix{ & Y_1 & \\ X \ar[ru]^{f_1} \ar[r]^{f_3} \ar[rd]_{f_2} & Y_3 \ar[u]_{a_{31}} \ar[d]^{a_{32}} & Y \ar[lu]_{s_1} \ar[l]_{s_3} \ar[ld]^{s_2} \\ & Y_2 & }\]
\end{proof} \end{proof}

View File

@@ -4,64 +4,70 @@ import re
# no I, no O # no I, no O
CHARACTERS = "0123456789ABCDEFGHJKLMNPQRSTUVWXYZ" CHARACTERS = "0123456789ABCDEFGHJKLMNPQRSTUVWXYZ"
# convert integer to tag # convert integer to tag
def tobase(i): def tobase(i):
global CHARACTERS global CHARACTERS
assert i >= 0 assert i >= 0
if i < len(CHARACTERS):
return CHARACTERS[i]
else:
return tobase(i // len(CHARACTERS)) + CHARACTERS[i % len(CHARACTERS)]
if i < len(CHARACTERS):
return CHARACTERS[i]
else:
return tobase(i // len(CHARACTERS)) + CHARACTERS[i % len(CHARACTERS)]
def totag(i): def totag(i):
return tobase(i).rjust(4, "0") return tobase(i).rjust(4, "0")
# convert tag to integer # convert tag to integer
def toint(tag): def toint(tag):
global CHARACTERS global CHARACTERS
return sum([CHARACTERS.index(tag[i]) * len(CHARACTERS)**(4-i-1) for i in range(4)]) return sum(
[CHARACTERS.index(tag[i]) * len(CHARACTERS) ** (4 - i - 1) for i in range(4)]
)
tags = dict() tags = dict()
labels = dict() labels = dict()
inactive = [] inactive = []
try: try:
with open("tags") as f: with open("tags") as f:
for line in f: for line in f:
# actual tag # actual tag
if not line.startswith("#"): if not line.startswith("#"):
tags[line.split(",")[0]] = line.strip().split(",")[1] tags[line.split(",")[0]] = line.strip().split(",")[1]
labels[line.strip().split(",")[1]] = line.strip().split(",")[0] labels[line.strip().split(",")[1]] = line.strip().split(",")[0]
# check for inactive tags too # check for inactive tags too
elif len(line.split(",")) == 2 and len(line.split(",")[0]) == 4: elif len(line.split(",")) == 2 and len(line.split(",")[0]) == 4:
inactive.append(line.split(",")[0]) inactive.append(line.split(",")[0])
except FileNotFoundError: except FileNotFoundError:
pass pass
# determine last assigned tag # determine last assigned tag
try: try:
last = toint(sorted(list(tags.keys()) + inactive)[-1]) last = toint(sorted(list(tags.keys()) + inactive)[-1])
except IndexError: except IndexError:
last = -1 last = -1
#filenames = glob.glob("*.tex") filenames = glob.glob("*.tex")
filenames = ["document.tex"] # filenames = ["document.tex"]
# where we should start # where we should start
i = last + 1 i = last + 1
for filename in filenames: for filename in filenames:
with open(filename) as f: with open(filename) as f:
# do this line per line to deal with comments # do this line per line to deal with comments
for line in f: for line in f:
matches = re.findall("\\\\label{([^}]+)}", line.split("%")[0]) matches = re.findall("\\\\label{([^}]+)}", line.split("%")[0])
for label in matches: for label in matches:
if not label in labels: if not label in labels:
tag = tobase(i).rjust(4, "0") tag = tobase(i).rjust(4, "0")
print("%s,%s" % (tag, label)) print("%s,%s" % (tag, label))
i = i + 1 i = i + 1