-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
80 lines (70 loc) · 2.91 KB
/
Copy pathmain.py
File metadata and controls
80 lines (70 loc) · 2.91 KB
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
73
74
75
76
77
78
79
80
import os
from pylatex import Document, Command, Section, Subsection, VerticalSpace, Package, NoEscape
from pylatex import MiniPage
from random import randint
import classes.problems as problems
import classes.problem_preset as preset
from classes.environments import Multicols
# Parameters (edit here)
probs = [
[problems.RadicalEquationProblem(100, (-9, 9))]
] # outer list is section, inner list is problems within the section
prob_names = ["Test"] # name of each section
prob_insts = ["Solve the following triangles."] # instruction for each section
prob_cols = [1] # number of columns for each section
# If mix_up is True, questions are generated in mixed order for that section.
mix_up = [False]
title = "Test" # ignored if there's only one section
# Don't edit below
if len({len(probs), len(prob_names), len(prob_insts), len(prob_cols), len(mix_up)}) > 1:
raise ValueError("the number of sections do not agree")
nsec = len(probs)
doc = Document(geometry_options={"paper": "letterpaper", "margin": "0.8in"})
doc.packages.append(Package("graphicx,tikz"))
if nsec == 1:
title = prob_names[0] + " Practice"
doc.preamble.append(Command("usetikzlibrary", "angles,quotes,calc"))
doc.preamble.append(Command("title", title))
doc.preamble.append(Command("date", ""))
doc.append(Command("maketitle"))
def print_problems(i: int):
def helper():
q = 0
while len(probs[i]) > 0:
q += 1
probi = randint(0, len(probs[i]) - 1) if mix_up[i] else 0
prob = probs[i][probi]
qnum = f"Q {i+1}.{q}" if nsec > 1 else f"Q{q}"
with doc.create(Subsection(qnum, False)):
if not isinstance(prob, problems.WordProblem):
with doc.create(MiniPage()):
for elem in prob.get_problem():
if isinstance(elem, problems.DocInjector):
elem.inject(doc)
else:
doc.append(elem)
doc.append(VerticalSpace(prob.vspace))
else:
# page overflow should happen with word problems
doc.append(prob.get_problem()[0])
doc.append(VerticalSpace(prob.vspace))
if prob.num_quest == 0:
probs[i].pop(probi)
if prob_cols[i] == 1:
helper()
else:
with doc.create(Multicols(prob_cols[i])):
helper()
if len(probs) == 1:
doc.append(prob_insts[0])
print_problems(0)
else:
for sec in range(nsec):
with doc.create(Section(prob_names[sec], True)):
doc.append(prob_insts[sec])
print_problems(sec)
doc.append(VerticalSpace("1cm"))
output_dir = os.path.join(os.getcwd(), "document_output")
if not os.path.isdir(output_dir):
os.mkdir(output_dir)
doc.generate_tex(os.path.join(output_dir, prob_names[0] if len(probs) == 1 else title))