Skip to content

Commit fad2e12

Browse files
committed
Started tags infrastructure
new file: scripts/add_tags.py modified: scripts/functions.py new file: tags/initial_tags new file: tags/tags
1 parent e039253 commit fad2e12

File tree

4 files changed

+3150
-0
lines changed

4 files changed

+3150
-0
lines changed

scripts/add_tags.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from functions import *
2+
3+
path = get_path()
4+
5+
tags = get_tags(path)
6+
7+
new_tags = get_new_tags(path, tags)
8+
9+
print "Writing ",
10+
print len(new_tags),
11+
print " new tags."
12+
13+
write_new_tags(path, new_tags)

scripts/functions.py

+94
Original file line numberDiff line numberDiff line change
@@ -296,3 +296,97 @@ def new_command(new, commands):
296296
m = m + 1
297297
return 1
298298

299+
# Structure of tags:
300+
# Already created tags are listed in the file tags/tags
301+
# Each line of tags/tags is of the form
302+
# tag,full_label
303+
# with no spaces and where
304+
# tag: the actual tag
305+
# full_label: label with "name-" prepended if the label occurs
306+
# in the file name.tex
307+
# See also the file tags/tags for an example.
308+
# We can also have lines starting with a hash # marking comments.
309+
# We may want to change the name/label if a result moves from one file to
310+
# another, or if we split a long file into two pieces. We may also
311+
# sometimes change the label of a result (eg if there is a typo in the
312+
# label itself). But the tags should never change.
313+
314+
# The first tag is 0000 and the last tag is ZZZZ
315+
def next_tag(tag):
316+
next = list(tag)
317+
S = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
318+
i = 3
319+
while i >= 0:
320+
n = S.find(next[i])
321+
if n == 35:
322+
next[i] = '0'
323+
else:
324+
next[i] = S[n + 1]
325+
break
326+
i = i - 1
327+
return next[0] + next[1] + next[2] + next[3]
328+
329+
def get_tag_line(line):
330+
line = line.rstrip()
331+
return line.split(",")
332+
333+
def get_tags(path):
334+
tags = []
335+
tag_file = open(path + "tags/tags", 'r')
336+
for line in tag_file:
337+
if not line.find("#") == 0:
338+
tags.append(get_tag_line(line))
339+
tag_file.close()
340+
return tags
341+
342+
def new_label(tags, label):
343+
n = 0
344+
new = 1
345+
while new and n < len(tags):
346+
if tags[n][1] == label:
347+
new = 0
348+
n = n + 1
349+
return new
350+
351+
def get_all_labels(path, name):
352+
labels = []
353+
tex_file = open(path + name + ".tex", 'r')
354+
for line in tex_file:
355+
label = find_label(line)
356+
if label:
357+
label = label.rstrip("}")
358+
label = label.lstrip("{")
359+
label = name + "-" + label
360+
labels.append(label)
361+
tex_file.close()
362+
return labels
363+
364+
def get_new_tags(path, tags):
365+
last_tag = tags[-1][0]
366+
lijstje = list_text_files(path)
367+
new_tags = []
368+
for name in lijstje:
369+
labels = get_all_labels(path, name)
370+
n = 0
371+
while n < len(labels):
372+
if new_label(tags, labels[n]):
373+
last_tag = next_tag(last_tag)
374+
new_tags.append([last_tag, labels[n]])
375+
n = n + 1
376+
return new_tags
377+
378+
def print_new_tags(new_tags):
379+
n = 0
380+
while n < len(new_tags):
381+
print new_tags[n][0] + "," + new_tags[n][1]
382+
n = n + 1
383+
return
384+
385+
def write_new_tags(path, new_tags):
386+
tag_file = open(path + "tags/tags", 'a')
387+
n = 0
388+
while n < len(new_tags):
389+
tag_file.write(new_tags[n][0] + "," + new_tags[n][1] + "\n")
390+
n = n + 1
391+
tag_file.close()
392+
return

tags/initial_tags

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# List of current tags in the stacks project
2+
# Each line is of the form
3+
# tag,full_label
4+
# where full label is the label as it occurs in book.tex
5+
# this means that if you see a line
6+
# \label{lemma-separated}
7+
# in the file schemes.tex then the full_label is
8+
# schemes-lemma-separated
9+
0000,introduction-section-phantom

0 commit comments

Comments
 (0)