Automate main document creation

This commit is contained in:
Oystein Kristoffer Tveit 2022-02-08 12:02:51 +01:00
parent 2bb0d90e8b
commit 1b0d5db395
14 changed files with 174 additions and 87 deletions

3
.gitignore vendored
View File

@ -1,4 +1,5 @@
data/tex
build
pdf
# TODO: fix

24
Makefile Normal file
View File

@ -0,0 +1,24 @@
build:
mkdir build
mkdir build/texdata
pdf:
mkdir pdf
build/nx.tex: build
python python/toTex.py
tex/nx.tex: build/nx.tex
python python/createDoc.py
main.pdf: tex/nx.tex pdf
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; \
done
mv build/*.pdf pdf

View File

@ -1,25 +0,0 @@
% !TeX program = xelatex
\documentclass[a5paper, twoside]{article}
\usepackage{xeCJK}
\usepackage{adjustbox}
\usepackage{graphicx}
\usepackage{tabu}
\usepackage{longtable}
\usepackage{makecell}
\usepackage[bindingoffset=0.5in]{geometry}
\setCJKmainfont{Noto Sans CJK JP}
\begin{document}
\renewcommand{\arraystretch}{2}
\input{tex/n5.tex}
\newline{}
\input{tex/n4.tex}
\newline{}
\input{tex/n3.tex}
\newline{}
\input{tex/n2.tex}
\newline{}
\input{tex/n1.tex}
\end{document}

55
python/createDoc.py Normal file
View File

@ -0,0 +1,55 @@
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)
def generateDoc(filename, items):
if items == '':
itemMap = {
5: True,
4: True,
3: True,
2: True,
1: True,
}
else:
itemMap = {
5: '5' in items,
4: '4' in items,
3: '3' in items,
2: '2' in items,
1: '1' in items,
}
innerContent = '\n'.join(f'\\input{{texdata/n{n}.tex}}' for n,v in itemMap.items() if v)
inject_into_template(filename, innerContent)
if __name__ == "__main__":
def inner(n):
return f"""
\\NXinnerpage{{{n}}}
\\input{{texdata/n{n}.tex}}
"""
inject_into_template('build/main.tex', f"""
\\fullFrontpage{{}}
{inner(5)}
{inner(4)}
{inner(3)}
{inner(2)}
{inner(1)}
""")
for n in range(1,6):
inject_into_template(f'build/n{n}.tex', f"""
\\NXfrontpage{{{n}}}
\\input{{texdata/n{n}.tex}}
""")

View File

@ -27,7 +27,7 @@ for n in reversed(range(1,6)):
return cellText
with open(f'./data/tex/n{n}.tex', 'w') as file:
with open(f'build/texdata/n{n}.tex', 'w') as file:
file.write('\\begin{longtabu} to \\textwidth {ll|l}\n')
file.write(
" \\\\\\hline\n".join(f'{makeMultiCellIfMultipleEntries(row[0])} & {makeMultiCellIfMultipleEntries(row[1])} & {makeMultiCellIfMultipleEntries(row[2], rowtype="e")}' for row in rows)

View File

@ -1,31 +0,0 @@
\usepackage{fontawesome}
\usepackage{hyperref}
\usepackage[
type={CC},
modifier={by},
version={3.0},
]{doclicense}
\newfontfamily\nscjksixty[SizeFeatures={Size=120}]{Noto Sans CJK JP}
\newcommand{\NXfrontpage}[1]{
{
\topskip0pt
\vspace*{\fill}
\begin{center}
{ \nscjksixty{ N#1 } } \\
\vspace*{5mm}
{ \Huge 単語帳 } \\
\vspace*{15mm}
\doclicenseImage \\
Data made by Jonathan Waller at \url{http://www.tanos.co.uk/jlpt/jlpt#1/} \\
\vspace*{10mm}
Project at \\
{ \Huge \faicon{github-square} } \url{https://github.com/h7x4abk3g}
\end{center}
\vspace*{\fill}
}
\newpage{}
}

View File

@ -7,14 +7,19 @@
\usepackage{tabu}
\usepackage{longtable}
\usepackage{makecell}
\usepackage[bindingoffset=0.5in]{geometry}
\input{common/frontPageNx.tex}
\usepackage[
bindingoffset=0.5in,
top=1cm,
bottom=1.5cm,
left=1cm,
right=1cm,
]{geometry}
\setCJKmainfont{Noto Sans CJK JP}
\input{../tex/frontpage.tex}
\begin{document}
\renewcommand{\arraystretch}{2}
\NXfrontpage{1}
\input{../data/tex/n1.tex}
###
\end{document}

82
tex/frontpage.tex Normal file
View File

@ -0,0 +1,82 @@
\usepackage{fontawesome}
\usepackage{hyperref}
\usepackage[
type={CC},
modifier={by},
version={3.0},
]{doclicense}
\newfontfamily\nscjksixty[SizeFeatures={Size=120}]{Noto Sans CJK JP}
\newcommand{\links}[1]{
\doclicenseImage \\
\vspace*{5mm}
Data made by Jonathan Waller at \url{#1} \\
\vspace*{15mm}
Project at \\
{ \Huge \faicon{github-square} } \url{https://github.com/h7x4abk3g}
}
\newcommand{\fullFrontpage}{
{
\topskip0pt
\vspace*{\fill}
\begin{center}
{ \nscjksixty{ JLPT } } \\
\vspace*{5mm}
{ \Huge 単語帳 } \\
\end{center}
\vspace*{\fill}
\newpage{}
\vspace*{\fill}
\begin{center}
\links{http://www.tanos.co.uk/jlpt/}
\end{center}
\vspace*{\fill}
}
\newpage{}
}
\newcommand{\NXfrontpage}[1]{
{
\topskip0pt
\vspace*{\fill}
\begin{center}
{ \nscjksixty{ N#1 } } \\
\vspace*{5mm}
{ \Huge 単語帳 } \\
\end{center}
\vspace*{\fill}
\newpage{}
\vspace*{\fill}
\begin{center}
\links{http://www.tanos.co.uk/jlpt/jlpt#1/}
\end{center}
\vspace*{\fill}
}
\newpage{}
}
\newcommand{\NXinnerpage}[1]{
{
\topskip0pt
\vspace*{\fill}
\begin{center}
{ \nscjksixty{ N#1 } } \\
\end{center}
\vspace*{\fill}
}
\newpage{}
}

View File

@ -1,24 +0,0 @@
% !TeX program = xelatex
\documentclass[a5paper, twoside]{article}
\usepackage{xeCJK}
\usepackage{adjustbox}
\usepackage{graphicx}
\usepackage{tabu}
\usepackage{longtable}
\usepackage{makecell}
\usepackage[bindingoffset=0.5in]{geometry}
\setCJKmainfont{Noto Sans CJK JP}
\begin{document}
\renewcommand{\arraystretch}{2}
\input{tex/n5.tex}
\newline{}
\input{tex/n4.tex}
\newline{}
\input{tex/n3.tex}
\newline{}
\input{tex/n2.tex}
\newline{}
\input{tex/n1.tex}
\end{document}

View File

View File

View File

View File