From 7850dbd43210234f167f35ed5988cde1aa17ebd4 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Wed, 9 Feb 2022 01:19:57 +0100 Subject: [PATCH] Generate wrapper files --- .gitignore | 11 +++--- Makefile | 44 +++++++++++++++-------- python/{createDoc.py => createMainDoc.py} | 0 python/createWrapperDoc.py | 26 ++++++++++++++ python/{toTex.py => htmlToTex.py} | 0 requirements.txt | 2 ++ tex/frontpage.tex | 2 +- tex/wrapper.tex.template | 7 ++++ 8 files changed, 72 insertions(+), 20 deletions(-) rename python/{createDoc.py => createMainDoc.py} (100%) create mode 100644 python/createWrapperDoc.py rename python/{toTex.py => htmlToTex.py} (100%) create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore index f730eb9..951889a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,9 @@ build pdf -# TODO: fix - -# tex/**/* -# !tex/**/*.tex -# !tex/**/*.tex +# venv +bin +lib +lib64 +pyvenv.cfg +include \ No newline at end of file diff --git a/Makefile b/Makefile index d981b42..8e67132 100644 --- a/Makefile +++ b/Makefile @@ -1,24 +1,40 @@ +.PHONY: clean all -build: +all: wrapper-main.pdf wrapper-nx.pdf + +clean: + rm -r build pdf + +dirs: mkdir build mkdir build/texdata - -pdf: mkdir pdf -build/nx.tex: build - python python/toTex.py +build/texdata/nx.tex: dirs + python python/htmlToTex.py +build/nx.tex: build/texdata/nx.tex + python python/createMainDoc.py -tex/nx.tex: build/nx.tex - python python/createDoc.py - -main.pdf: tex/nx.tex pdf +main.pdf: build/nx.tex cd build; xelatex main.tex - mv build/*.pdf pdf -nx.pdf: tex/nx.tex pdf - cd build; for n in 5 4 3 2 1; do \ - xelatex ../tex/$$n.tex; \ +nx.pdf: build/nx.tex + cd build; for n in 5 4 3 2 1; do \ + xelatex n$$n.tex; \ done - mv build/*.pdf pdf + +wrapper-main.pdf: main.pdf + python python/createWrapperDoc.py main.pdf main-wrapper.tex + cd build; pdflatex main-wrapper.tex + mv build/main-wrapper.pdf pdf/main.pdf + +wrapper-nx.pdf: nx.pdf + for n in 5 4 3 2 1; do \ + python python/createWrapperDoc.py n$$n.pdf n$$n-wrapper.tex; \ + done; + + cd build; for n in 5 4 3 2 1; do \ + pdflatex n$$n-wrapper.tex; \ + mv n$$n-wrapper.pdf ../pdf/n$$n.pdf; \ + done; \ No newline at end of file diff --git a/python/createDoc.py b/python/createMainDoc.py similarity index 100% rename from python/createDoc.py rename to python/createMainDoc.py diff --git a/python/createWrapperDoc.py b/python/createWrapperDoc.py new file mode 100644 index 0000000..6e56878 --- /dev/null +++ b/python/createWrapperDoc.py @@ -0,0 +1,26 @@ +from sys import argv + +from PyPDF2 import PdfFileReader + +def inject_into_template( + output_file, + string, + template='tex/doc.tex.template', + replacement_char='###' +): + with open(template) as file: + content = file.read().replace(replacement_char, string) + + with open(output_file, 'w') as file: + file.write(content) + +if __name__ == "__main__": + pdfPath, outputPath = argv[1:3] + pdf = PdfFileReader(open(f'build/{pdfPath}','rb')) + pageNum = pdf.getNumPages() + + inject_into_template( + f'build/{outputPath}', + f'\\includepdf[pages=-,nup=1x2,signature={pageNum},landscape,booklet=true]{{{pdfPath}}}', + template="tex/wrapper.tex.template" + ) \ No newline at end of file diff --git a/python/toTex.py b/python/htmlToTex.py similarity index 100% rename from python/toTex.py rename to python/htmlToTex.py diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..8bc7297 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +lxml==4.7.1 +PyPDF2==1.26.0 diff --git a/tex/frontpage.tex b/tex/frontpage.tex index daf22a3..a008081 100644 --- a/tex/frontpage.tex +++ b/tex/frontpage.tex @@ -14,7 +14,7 @@ Data made by Jonathan Waller at \url{#1} \\ \vspace*{15mm} Project at \\ - { \Huge \faicon{github-square} } \url{https://github.com/h7x4abk3g} + { \Huge \faicon{github-square} } \url{https://github.com/h7x4ABk3g/tanos-japanese-word-books/} } \newcommand{\fullFrontpage}{ diff --git a/tex/wrapper.tex.template b/tex/wrapper.tex.template index e69de29..7c02911 100644 --- a/tex/wrapper.tex.template +++ b/tex/wrapper.tex.template @@ -0,0 +1,7 @@ +\documentclass[a4paper, twoside]{article} +\usepackage[T1]{fontenc} +\usepackage[utf8]{inputenc} +\usepackage{pdfpages} +\begin{document} + ### +\end{document} \ No newline at end of file