Skip to content

Commit 68c99df

Browse files
authored
Updated din a libraries
Update din a graph paper
2 parents e779ef6 + a418374 commit 68c99df

20 files changed

Lines changed: 583 additions & 33 deletions

README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,32 @@ The pdf files are auto-generated and [released]((https://github.com/twihno/Print
2929

3030
## Contributing
3131

32-
Thank you for your interest! Everyone is invited to add their own templates.
32+
Thank you for your interest! Everyone is invited to add their own templates or improve existing templates.
3333

3434
The code was developed and tested on Ubuntu.
3535
It should run on every Linux distribution with XeLaTex and Python 3 support.
3636

3737
### Project structure
3838

39+
```
40+
..
41+
├ various files and folders (self-explaining or described below)
42+
└ templates
43+
└ groups (by paper size, e.g. DIN A)
44+
├ paperlibgroup.json (metadata)
45+
└ categories (by template category, e.g. graph paper or lined paper)
46+
├ paperlibcategory.json (metadata)
47+
└ template
48+
└ template_variations (optional)
49+
└ template_color_variations (optional)
50+
├ compile_template.py
51+
├ printablepaperlib.json
52+
└ template.latex_template
53+
```
54+
3955
Every template needs its own folder and three files:
4056

41-
- ```compile_template.py``` (this file generates the differnet latex files for the various page sizes)
57+
- ```compile_template.py``` (this file generates the different latex files for the various page sizes)
4258
- ```printablepaperlib.json``` (this file contains the name, the version and the supported paper sizes and orientations of the template)
4359
- ```template.latex_template``` (this file contains the the latex (jinja template) file used to generate the pdf files)
4460

create_release.sh

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@ print_return_value () {
99
fi
1010
}
1111

12+
# Checking/generating build name
13+
echo -e "\n\e[32m\e[1m*** Checking/generating build name ***\e[0m"
14+
15+
# Get build_name
16+
build_name=$1
17+
18+
if [ -z ${build_name} ]; then
19+
build_name="dev$(date +'%Y-%m-%d-%H:%M')"
20+
echo -e "\nGenerated build_name: $build_name"
21+
echo -e "\n ✅ \e[32m\e[1mGENERATED BUILD NAME\e[0m"
22+
else
23+
echo -e "\nFound build_name: $build_name"
24+
echo -e "\n ✅ \e[32m\e[1mBUILD NAME FOUND\e[0m"
25+
fi
26+
1227
# Create pdf files
1328
echo -e "\n\e[32m\e[1m*** Run build.sh ***\e[0m"
1429
./build.sh
@@ -25,7 +40,7 @@ print_return_value $?
2540
# Create zip file
2641
echo -e "\n\e[32m\e[1m*** Create zip file ***\e[0m"
2742
cd output
28-
zipname="PrintablePaper_$1.zip"
43+
zipname="PrintablePaper_$build_name.zip"
2944
zipname="${zipname//$'/'/'_'}" # Remove / from zipname
3045
zip -r $zipname *
3146
print_return_value $?

generate_pdf.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
TEMPLATE_DIR = 'templates'
99
RM_EXTENSIONS = ['.aux', '.latex', '.log', '.pdf']
10+
TOPLEVELDIR = ''
1011

1112

1213
def clean_templates():
@@ -42,9 +43,10 @@ def generate_pdf_files():
4243
os.chdir(os.path.abspath(subdir))
4344
for i in range(0, 2):
4445
return_value = os.system("xelatex -interaction=batchmode --halt-on-error \"" +
45-
str(file) + "\"")
46+
str(file) + "\"")
4647
if return_value != 0:
4748
sys.exit(1)
49+
os.chdir(TOPLEVELDIR)
4850

4951

5052
def move_pdf_files():
@@ -62,7 +64,7 @@ def move_pdf_files():
6264

6365

6466
if __name__ == "__main__":
65-
topleveldir = os.getcwd()
67+
TOPLEVELDIR = os.getcwd()
6668

6769
try:
6870

@@ -72,11 +74,11 @@ def move_pdf_files():
7274
print("\nGenerating latex files")
7375
generate_latex_files()
7476

75-
os.chdir(topleveldir)
77+
os.chdir(TOPLEVELDIR)
7678
print("\nGenerating pdf files")
7779
generate_pdf_files()
7880

79-
os.chdir(topleveldir)
81+
os.chdir(TOPLEVELDIR)
8082
print("\nMoving pdf files")
8183
move_pdf_files()
8284

generate_release_notes.py

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
TEMPLATE_DIR = "templates"
88

99
if __name__ == "__main__":
10+
# Load paperlibgroups
1011
paperlibgroups = []
1112

1213
for subdir, dirs, files in os.walk(TEMPLATE_DIR):
@@ -19,25 +20,49 @@
1920

2021
paperlibgroups.sort()
2122

23+
# Load paperlibcategories
24+
paperlibcategories = []
25+
26+
for subdir, dirs, files in os.walk(TEMPLATE_DIR):
27+
for file in files:
28+
if file == "paperlibcategory.json":
29+
with open(os.path.join(subdir, file), "r") as f:
30+
paperlibcategories_dict = json.load(f)
31+
paperlibcategories.append(
32+
[paperlibcategories_dict["category_name"],
33+
subdir,
34+
paperlibcategories_dict["description"]])
35+
36+
paperlibcategories.sort()
37+
2238
with open("./output/README.md", "w") as f:
2339
f.write("Version {}\n\n---\n\n".format(date.today().strftime("%Y-%m-%d")))
2440
f.write("# Included templates\n")
2541

2642
for lib in paperlibgroups:
27-
f.write("\n## {}\n{}\n\n".format(
43+
f.write("\n## {}\n{}\n".format(
2844
lib[0],
2945
lib[2]
3046
))
3147

32-
for subdir, dirs, files in os.walk(TEMPLATE_DIR):
33-
for file in files:
34-
if file == "printablepaperlib.json":
35-
if subdir.startswith(lib[1]):
36-
with open(os.path.join(subdir, file), "r") as j:
37-
printablepaperlib_dict = json.load(j)
38-
f.write(
39-
"- {} (v{})\n".format(
40-
printablepaperlib_dict["template_name"].replace(
41-
"_", "\\_"),
42-
printablepaperlib_dict["version"]
43-
))
48+
for cat in paperlibcategories:
49+
if not(cat[1].startswith(lib[1]+"/")):
50+
break
51+
52+
f.write("\n### {}\n{}\n\n".format(
53+
cat[0],
54+
cat[2]
55+
))
56+
57+
for subdir, dirs, files in os.walk(TEMPLATE_DIR):
58+
for file in files:
59+
if file == "printablepaperlib.json":
60+
if subdir.startswith(lib[1]+"/") and subdir.startswith(cat[1]+"/"):
61+
with open(os.path.join(subdir, file), "r") as j:
62+
printablepaperlib_dict = json.load(j)
63+
f.write(
64+
"- {} (v{})\n".format(
65+
printablepaperlib_dict["template_name"].replace(
66+
"_", "\\_"),
67+
printablepaperlib_dict["version"]
68+
))
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
"""Generate latex files"""
2+
3+
import json
4+
import os
5+
import traceback
6+
import sys
7+
from jinja2 import Environment, FileSystemLoader
8+
9+
if __name__ == "__main__":
10+
11+
# Change working directory to this directory
12+
abspath = os.path.abspath(__file__)
13+
dirname = os.path.dirname(abspath)
14+
os.chdir(dirname)
15+
16+
# Load printablepaperlib parameters
17+
try:
18+
with open('./printablepaperlib.json') as f:
19+
parameters = json.load(f)
20+
except FileNotFoundError:
21+
traceback.print_exc()
22+
sys.exit(1)
23+
24+
# Load paperlib
25+
TEMPLATE_SUBDIR = str(dirname).find(
26+
"/", str(dirname).find("templates/")+10)+1
27+
PAPERLIB_PATH = str(dirname)[0:TEMPLATE_SUBDIR] + "paperlib.json"
28+
29+
try:
30+
with open(PAPERLIB_PATH) as f:
31+
paperlib = json.load(f)
32+
except FileNotFoundError:
33+
traceback.print_exc()
34+
sys.exit(1)
35+
36+
# Load template
37+
38+
env = Environment(loader=FileSystemLoader(dirname))
39+
template = env.get_template('template.latex_template')
40+
41+
# printablepaperlib specific code
42+
43+
for page_size in parameters["page_sizes"]:
44+
page_size_name = paperlib[page_size]["displayname"]
45+
for orientation in parameters["orientations"]:
46+
FILENAME = "{}_{}_{}.latex".format(
47+
parameters["template_name"],
48+
page_size_name,
49+
orientation)
50+
51+
horizonzal_count = int(
52+
paperlib[page_size][orientation]["width"])-int(
53+
paperlib[page_size][orientation]["width"] % 10)
54+
55+
# Remove lines on the page borders
56+
if horizonzal_count == round(paperlib[page_size][orientation]["width"]):
57+
horizonzal_count -= 10
58+
59+
vertical_count = int(
60+
paperlib[page_size][orientation]["height"])-int(
61+
paperlib[page_size][orientation]["height"] % 10)
62+
63+
# Remove lines on the page borders
64+
if vertical_count == round(paperlib[page_size][orientation]["height"]):
65+
vertical_count -= 10
66+
67+
with open(FILENAME, "w") as f:
68+
f.write(template.render(
69+
paperformat=page_size,
70+
paperorientation=orientation,
71+
horizontal_10mm_count=horizonzal_count,
72+
vertical_10mm_count=vertical_count,
73+
))

templates/din_a/graph_paper/5mm/printablepaperlib.json renamed to templates/din_a/graph_paper/grid/10mm/black/printablepaperlib.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"template_name": "graph_paper_5mm",
2+
"template_name": "grid_black_10mm",
33
"version": "1.0.0",
44
"page_sizes": [
55
"a4paper",
@@ -8,7 +8,7 @@
88
"a1paper"
99
],
1010
"orientations": [
11-
"landscape",
12-
"portrait"
11+
"portrait",
12+
"landscape"
1313
]
1414
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
\documentclass{article}
2+
\usepackage[{{ paperformat }}, {{ paperorientation }}]{geometry}
3+
\usepackage{tikz}
4+
\usetikzlibrary{calc}
5+
6+
\newcommand*{\largelinewidth}{0.3mm}
7+
8+
\begin{document}
9+
\pagestyle{empty}
10+
\begin{tikzpicture}[remember picture,overlay]
11+
12+
% horizontal lines 10mm
13+
\foreach \i in {10,20,...,{{ vertical_10mm_count }}}{
14+
\draw[black, line width=\largelinewidth] ($(current page.north west)+(0,-\i mm)$) -- ($(current page.north east)+(0,-\i mm)$);}
15+
16+
% vertical lines 10mm
17+
\foreach \i in {10,20,...,{{ horizontal_10mm_count }}}{
18+
\draw[black, line width=\largelinewidth] ($(current page.north west)+(\i mm,0)$) -- ($(current page.south west)+(\i mm,0)$);}
19+
20+
\end{tikzpicture}
21+
22+
\end{document}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
"""Generate latex files"""
2+
3+
import json
4+
import os
5+
import traceback
6+
import sys
7+
from jinja2 import Environment, FileSystemLoader
8+
9+
if __name__ == "__main__":
10+
11+
# Change working directory to this directory
12+
abspath = os.path.abspath(__file__)
13+
dirname = os.path.dirname(abspath)
14+
os.chdir(dirname)
15+
16+
# Load printablepaperlib parameters
17+
try:
18+
with open('./printablepaperlib.json') as f:
19+
parameters = json.load(f)
20+
except FileNotFoundError:
21+
traceback.print_exc()
22+
sys.exit(1)
23+
24+
# Load paperlib
25+
TEMPLATE_SUBDIR = str(dirname).find(
26+
"/", str(dirname).find("templates/")+10)+1
27+
PAPERLIB_PATH = str(dirname)[0:TEMPLATE_SUBDIR] + "paperlib.json"
28+
29+
try:
30+
with open(PAPERLIB_PATH) as f:
31+
paperlib = json.load(f)
32+
except FileNotFoundError:
33+
traceback.print_exc()
34+
sys.exit(1)
35+
36+
# Load template
37+
38+
env = Environment(loader=FileSystemLoader(dirname))
39+
template = env.get_template('template.latex_template')
40+
41+
# printablepaperlib specific code
42+
43+
for page_size in parameters["page_sizes"]:
44+
page_size_name = paperlib[page_size]["displayname"]
45+
for orientation in parameters["orientations"]:
46+
FILENAME = "{}_{}_{}.latex".format(
47+
parameters["template_name"],
48+
page_size_name,
49+
orientation)
50+
51+
horizonzal_count = int(
52+
paperlib[page_size][orientation]["width"])-int(
53+
paperlib[page_size][orientation]["width"] % 10)
54+
55+
# Remove lines on the page borders
56+
if horizonzal_count == round(paperlib[page_size][orientation]["width"]):
57+
horizonzal_count -= 10
58+
59+
vertical_count = int(
60+
paperlib[page_size][orientation]["height"])-int(
61+
paperlib[page_size][orientation]["height"] % 10)
62+
63+
# Remove lines on the page borders
64+
if vertical_count == round(paperlib[page_size][orientation]["height"]):
65+
vertical_count -= 10
66+
67+
with open(FILENAME, "w") as f:
68+
f.write(template.render(
69+
paperformat=page_size,
70+
paperorientation=orientation,
71+
horizontal_10mm_count=horizonzal_count,
72+
vertical_10mm_count=vertical_count,
73+
))
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"template_name": "grid_grey_10mm",
3+
"version": "1.0.0",
4+
"page_sizes": [
5+
"a4paper",
6+
"a3paper",
7+
"a2paper",
8+
"a1paper"
9+
],
10+
"orientations": [
11+
"portrait",
12+
"landscape"
13+
]
14+
}

0 commit comments

Comments
 (0)