-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
templates/din_a/graph_paper/grid/5+10mm/grey/compile_template.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
"""Generate latex files""" | ||
|
||
import json | ||
import os | ||
import traceback | ||
import sys | ||
from jinja2 import Environment, FileSystemLoader | ||
|
||
if __name__ == "__main__": | ||
|
||
# Change working directory to this directory | ||
abspath = os.path.abspath(__file__) | ||
dirname = os.path.dirname(abspath) | ||
os.chdir(dirname) | ||
|
||
# Load printablepaperlib parameters | ||
try: | ||
with open('./printablepaperlib.json') as f: | ||
parameters = json.load(f) | ||
except FileNotFoundError: | ||
traceback.print_exc() | ||
sys.exit(1) | ||
|
||
# Load paperlib | ||
TEMPLATE_SUBDIR = str(dirname).find( | ||
"/", str(dirname).find("templates/")+10)+1 | ||
PAPERLIB_PATH = str(dirname)[0:TEMPLATE_SUBDIR] + "paperlib.json" | ||
|
||
try: | ||
with open(PAPERLIB_PATH) as f: | ||
paperlib = json.load(f) | ||
except FileNotFoundError: | ||
traceback.print_exc() | ||
sys.exit(1) | ||
|
||
# Load template | ||
|
||
env = Environment(loader=FileSystemLoader(dirname)) | ||
template = env.get_template('template.latex_template') | ||
|
||
# printablepaperlib specific code | ||
|
||
for page_size in parameters["page_sizes"]: | ||
page_size_name = paperlib[page_size]["displayname"] | ||
for orientation in parameters["orientations"]: | ||
FILENAME = "{}_{}_{}.latex".format( | ||
parameters["template_name"], | ||
page_size_name, | ||
orientation) | ||
|
||
# 10mm lines | ||
|
||
py_horizonzal_10mm_count = int( | ||
paperlib[page_size][orientation]["width"])-int( | ||
paperlib[page_size][orientation]["width"] % 10) | ||
|
||
# Remove lines on the page borders | ||
if py_horizonzal_10mm_count == round(paperlib[page_size][orientation]["width"]): | ||
py_horizonzal_10mm_count -= 10 | ||
|
||
py_vertical_10mm_count = int( | ||
paperlib[page_size][orientation]["height"])-int( | ||
paperlib[page_size][orientation]["height"] % 10) | ||
|
||
# Remove lines on the page borders | ||
if py_vertical_10mm_count == round(paperlib[page_size][orientation]["height"]): | ||
py_vertical_10mm_count -= 10 | ||
|
||
# 5mm lines | ||
|
||
py_horizonzal_5mm_count = int( | ||
paperlib[page_size][orientation]["width"])-int( | ||
paperlib[page_size][orientation]["width"] % 5) | ||
|
||
# Remove lines on the page borders | ||
if py_horizonzal_5mm_count == round(paperlib[page_size][orientation]["width"]): | ||
py_horizonzal_5mm_count -= 5 | ||
|
||
py_vertical_5mm_count = int( | ||
paperlib[page_size][orientation]["height"])-int( | ||
paperlib[page_size][orientation]["height"] % 5) | ||
|
||
# Remove lines on the page borders | ||
if py_vertical_5mm_count == round(paperlib[page_size][orientation]["height"]): | ||
py_vertical_5mm_count -= 5 | ||
|
||
with open(FILENAME, "w") as f: | ||
f.write(template.render( | ||
paperformat=page_size, | ||
paperorientation=orientation, | ||
horizontal_5mm_count=py_horizonzal_5mm_count, | ||
vertical_5mm_count=py_vertical_5mm_count, | ||
horizontal_10mm_count=py_horizonzal_10mm_count, | ||
vertical_10mm_count=py_vertical_10mm_count, | ||
)) |
14 changes: 14 additions & 0 deletions
14
templates/din_a/graph_paper/grid/5+10mm/grey/printablepaperlib.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"template_name": "grid_grey_5+10mm", | ||
"version": "1.0.0", | ||
"page_sizes": [ | ||
"a4paper", | ||
"a3paper", | ||
"a2paper", | ||
"a1paper" | ||
], | ||
"orientations": [ | ||
"portrait", | ||
"landscape" | ||
] | ||
} |
34 changes: 34 additions & 0 deletions
34
templates/din_a/graph_paper/grid/5+10mm/grey/template.latex_template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
\documentclass{article} | ||
\usepackage[{{ paperformat }}, {{ paperorientation }}]{geometry} | ||
\usepackage{tikz} | ||
\usetikzlibrary{calc} | ||
|
||
\newcommand*{\largelinewidth}{0.3mm} | ||
\newcommand*{\smalllinewidth}{0.1mm} | ||
|
||
\begin{document} | ||
\pagestyle{empty} | ||
\begin{tikzpicture}[remember picture,overlay] | ||
|
||
\definecolor{line_color}{RGB}{128,128,128} | ||
|
||
% horizontal lines 5mm | ||
\foreach \i in {5,15,...,{{ vertical_5mm_count }}}{ | ||
\draw[line_color, line width=\smalllinewidth] ($(current page.north west)+(0,-\i mm)$) -- ($(current page.north east)+(0,-\i mm)$);} | ||
|
||
% vertical lines 5mm | ||
\foreach \i in {5,15,...,{{ horizontal_5mm_count }}}{ | ||
\draw[line_color, line width=\smalllinewidth] ($(current page.north west)+(\i mm,0)$) -- ($(current page.south west)+(\i mm,0)$);} | ||
|
||
% horizontal lines 10mm | ||
\foreach \i in {10,20,...,{{ vertical_10mm_count }}}{ | ||
\draw[line_color, line width=\largelinewidth] ($(current page.north west)+(0,-\i mm)$) -- ($(current page.north east)+(0,-\i mm)$);} | ||
|
||
% vertical lines 10mm | ||
\foreach \i in {10,20,...,{{ horizontal_10mm_count }}}{ | ||
\draw[line_color, line width=\largelinewidth] ($(current page.north west)+(\i mm,0)$) -- ($(current page.south west)+(\i mm,0)$);} | ||
|
||
|
||
\end{tikzpicture} | ||
|
||
\end{document} |