Generate wrapper files

main
Oystein Kristoffer Tveit 2022-02-09 01:19:57 +01:00
parent 1b0d5db395
commit 7850dbd432
8 changed files with 72 additions and 20 deletions

11
.gitignore vendored
View File

@ -1,8 +1,9 @@
build
pdf
# TODO: fix
# tex/**/*
# !tex/**/*.tex
# !tex/**/*.tex
# venv
bin
lib
lib64
pyvenv.cfg
include

View File

@ -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;

View File

@ -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"
)

2
requirements.txt Normal file
View File

@ -0,0 +1,2 @@
lxml==4.7.1
PyPDF2==1.26.0

View File

@ -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}{

View File

@ -0,0 +1,7 @@
\documentclass[a4paper, twoside]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{pdfpages}
\begin{document}
###
\end{document}