-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompile.py
72 lines (60 loc) · 1.78 KB
/
compile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re, sys, os, getopt
from random import sample
ntickets = 22
nquestions = 4
texheader='\\documentclass[12pt]{extarticle}\n'\
+'\n\\usepackage[T2A]{fontenc}\n'\
+'\\usepackage[utf8]{inputenc}\n'\
+'\\usepackage[ukrainian]{babel}\n'\
+'\\usepackage{amssymb}\n'\
+'\\usepackage{amsmath}\n'\
+'\\usepackage[a4paper,text={19cm,27cm},centering]{geometry}\n'\
+'\\usepackage{dashrule}\n'\
+'\\pagestyle{empty}\n'\
+'\n\\begin{document}'
paper_template = '\\begin{center}\n'\
+'\\textbf{\\large Варіант №%s}\n'\
+'\\end{center}\n'\
+'\n'\
+'\\begin{enumerate}\n'\
+'\\item %s\n'\
+'\n'\
+'\\item %s\n'\
+'\n'\
+'\\item %s\n'\
+'\n'\
+'\\item %s\n'\
+'\n'\
+'\\end{enumerate}\n'\
+'\\vskip .3cm\n'\
+'\\hdashrule[0.5ex]{19cm}{1pt}{5pt 5pt}\n\n'
texfooter='\n\\end{document}\n\n'
outtext=texheader
reexer='Exercise}\n(.*?)\\\\end{Exercise'
findex=re.compile(reexer,re.DOTALL)
texts = ['' for i in xrange(nquestions)]
samples = []
for i in xrange(nquestions):
text=open('pr'+str(i+1)+'.tex',"r").read()
texts[i]=findex.findall(text)
if ntickets > len(texts[i]):
s = []
for j in xrange(ntickets % len(texts[i]) + 1):
s += sample(xrange(len(texts[i])),len(texts[i]))
samples.append(s)
else:
samples.append(sample(xrange(len(texts[i])),ntickets))
for i in xrange(ntickets):
exercises = [texts[j][samples[j][i]] for j in xrange(nquestions)]
outtext+=paper_template % tuple([str(i+1)] + exercises)
outtext+=texfooter
finaltext=open('Контрольна2.tex',"w")
finaltext.write(outtext)
finaltext.close()
sts = os.system("pdflatex Контрольна2.tex")
if sys.platform.startswith('linux'):
os.system('xdg-open "Контрольна2.pdf"')
else:
os.system('start "Контрольна2.pdf"')