6. Number Lines booklet variationsο
6.1. Variationsο
The standard number line from -10 to 10 has 2 other variations:
0 to 20
-20 to 0
6.2. 0 to 20ο
nlBk_0to20_1_q.pdf
nlBk_0to20_1_ans.pdf
6.2.1. tex filesο
The python below requires 2 .tex files:
number_lines_booklet_template.tex
number_lines_0to20_blank_booklet_diagram_template.tex
6.2.2. pythonο
number_lines_0to20_blank_booklet_maker.py
1from pathlib import Path
2import subprocess
3import os
4import time
5
6
7currfile_dir = Path(__file__).parent
8tex_template_path = currfile_dir / "number_lines_booklet_template.tex"
9tex_diagram_template_path = currfile_dir / "number_lines_0to20_blank_booklet_diagram_template.tex"
10
11
12def convert_to_pdf(tex_path, outputdir):
13 tex_path = Path(tex_path).resolve()
14 outputdir = Path(outputdir).resolve()
15 # for testing
16 # print(f"tex_path: {tex_path}")
17 # print(f"outputdir: {outputdir}")
18 try:
19 # Generate the PDF
20 subprocess.run(["latexmk", "-pdf", "-outdir=" + str(outputdir), str(tex_path)], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
21 # # Clean auxiliary files after successful PDF generation
22 subprocess.run(["latexmk", "-c", "-outdir=" + str(outputdir), str(tex_path)], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
23 # for hosted remove stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL for debugging any errors
24 # Remove the .tex file manually
25 # if tex_path.exists():
26 # os.remove(tex_path)
27 except subprocess.CalledProcessError as e:
28 print(f"Error: {e}")
29
30
31def make1_diagram(tex_diagram_template_txt):
32 posttext = r"\vspace{1pt}"
33 return tex_diagram_template_txt + posttext
34
35
36def main():
37 numq = input("Enter the number of questions from 1 to 80, with 8 per page \n")
38 if numq.strip().isdigit():
39 numq = int(numq)
40 if not numq in range(1,81):
41 numq = 16 # random by default
42 else:
43 numq = 16 # random by default
44 #
45 filename = input("Enter the base filename to be added to the prefix nlBk_blank_0to20_: \n")
46 if not filename:
47 filename = "1"
48 # set names of files that are made
49 tex_output_path = currfile_dir / f"nlBk_blank_0to20_{filename}.tex"
50
51 # Read in the LaTeX template file
52 with open(tex_template_path, "r") as infile:
53 tex_template_txt = infile.read()
54
55 # Read in the LaTeX diagram template file
56 with open(tex_diagram_template_path, "r") as infile:
57 tex_diagram_template_txt = infile.read()
58
59 # <<diagrams>>
60 # generate diagrams text and text for answers
61 diagrams_text = ""
62 # add the headtext
63 headtext = r"\pagebreak ~ \newline ~ \newline"
64 for i in range(1, numq + 1):
65 img_tex = make1_diagram(tex_diagram_template_txt)
66 if i > 8 and i % 8 == 1:
67 diagrams_text += headtext
68 diagrams_text += img_tex
69
70 # Replace the <<diagrams>> placeholder in the LaTeX template with the generated diagrams
71 tex_template_txt = tex_template_txt.replace("<<diagrams>>", diagrams_text)
72
73 # Write the question tex to an output file
74 with open(tex_output_path, "w") as outfile:
75 outfile.write(tex_template_txt)
76
77 # Wait for the file to be created
78 time.sleep(2)
79 # Convert the LaTeX files to PDFs
80 convert_to_pdf(tex_output_path, currfile_dir)
81
82
83
84if __name__ == "__main__":
85 print("starting")
86 main()
87 print("finished")
6.3. Blank -10 to 10ο
nlBk_neg20to0_1_q.pdf
nlBk_neg20to0_1_ans.pdf
6.3.1. tex filesο
The python below requires 2 .tex files:
number_lines_booklet_template.tex
number_lines_neg20to0_blank_booklet_diagram_template.tex
6.3.2. pythonο
number_lines_neg20to0_blank_booklet_maker.py
1from pathlib import Path
2import subprocess
3import os
4import time
5
6
7currfile_dir = Path(__file__).parent
8tex_template_path = currfile_dir / "number_lines_booklet_template.tex"
9tex_diagram_template_path = currfile_dir / "number_lines_neg20to0_blank_booklet_diagram_template.tex"
10
11
12def convert_to_pdf(tex_path, outputdir):
13 tex_path = Path(tex_path).resolve()
14 outputdir = Path(outputdir).resolve()
15 # for testing
16 # print(f"tex_path: {tex_path}")
17 # print(f"outputdir: {outputdir}")
18 try:
19 # Generate the PDF
20 subprocess.run(["latexmk", "-pdf", "-outdir=" + str(outputdir), str(tex_path)], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
21 # # Clean auxiliary files after successful PDF generation
22 subprocess.run(["latexmk", "-c", "-outdir=" + str(outputdir), str(tex_path)], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
23 # for hosted remove stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL for debugging any errors
24 # Remove the .tex file manually
25 # if tex_path.exists():
26 # os.remove(tex_path)
27 except subprocess.CalledProcessError as e:
28 print(f"Error: {e}")
29
30
31def make1_diagram(tex_diagram_template_txt):
32 posttext = r"\vspace{1pt}"
33 return tex_diagram_template_txt + posttext
34
35
36def main():
37 numq = input("Enter the number of questions from 1 to 80, with 8 per page \n")
38 if numq.strip().isdigit():
39 numq = int(numq)
40 if not numq in range(1,81):
41 numq = 16 # random by default
42 else:
43 numq = 16 # random by default
44 #
45 filename = input("Enter the base filename to be added to the prefix nlBk_blank_neg20to0_: \n")
46 if not filename:
47 filename = "1"
48 # set names of files that are made
49 tex_output_path = currfile_dir / f"nlBk_blank_neg20to0_{filename}.tex"
50
51 # Read in the LaTeX template file
52 with open(tex_template_path, "r") as infile:
53 tex_template_txt = infile.read()
54
55 # Read in the LaTeX diagram template file
56 with open(tex_diagram_template_path, "r") as infile:
57 tex_diagram_template_txt = infile.read()
58
59 # <<diagrams>>
60 # generate diagrams text and text for answers
61 diagrams_text = ""
62 # add the headtext
63 headtext = r"\pagebreak ~ \newline ~ \newline"
64 for i in range(1, numq + 1):
65 img_tex = make1_diagram(tex_diagram_template_txt)
66 if i > 8 and i % 8 == 1:
67 diagrams_text += headtext
68 diagrams_text += img_tex
69
70 # Replace the <<diagrams>> placeholder in the LaTeX template with the generated diagrams
71 tex_template_txt = tex_template_txt.replace("<<diagrams>>", diagrams_text)
72
73 # Write the question tex to an output file
74 with open(tex_output_path, "w") as outfile:
75 outfile.write(tex_template_txt)
76
77 # Wait for the file to be created
78 time.sleep(2)
79 # Convert the LaTeX files to PDFs
80 convert_to_pdf(tex_output_path, currfile_dir)
81
82
83
84if __name__ == "__main__":
85 print("starting")
86 main()
87 print("finished")