-
Notifications
You must be signed in to change notification settings - Fork 11
/
build-pdf.py
executable file
·68 lines (65 loc) · 1.96 KB
/
build-pdf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import re
import sys
os.chdir(os.path.join("pdf", "docs"))
with open(os.path.join("..", "..", "mlr-tutorial.md"), "w") as fd:
fd.write("""
---
title: mlr Tutorial
title-meta: mlr Tutorial
author:
- Julia Schiffner
- Bernd Bischl
- Michel Lang
- Jakob Richter
- Zachary M. Jones
- Philipp Probst
- Florian Pfisterer
- Mason Gallo
- Dominik Kirchhoff
- Tobias Kühn
- Janek Thomas
- Kira Engelhardt
- Teodora Pandeva
- Gunnar König
- Lars Kotthoff
---
""")
with open(os.path.join("..", "..", "mkdocs.yml"), "r") as fd2:
line = fd2.readline()
while line:
if('Appendix' in line):
break
elif('.md' in line):
m = re.search("[^']+\.md", line)
fname = m.group(0)
with open(fname, "r") as fd3:
for lin in fd3:
if fname != "index.md":
lin = re.sub(r'^(#+ [A-Za-z0-9])', '#\g<1>', lin)
fd.write(lin)
fd.write("\n")
if('index.md' in line):
fd.write("\n\n# Basics\n\n")
if('visualization.md' in line):
fd.write("\n\n# Advanced\n\n")
if('hyperpar_tuning_effects.md' in line):
fd.write("\n\n# Extend\n\n")
line = fd2.readline()
os.chdir(os.path.join("..", ".."))
def link_fixer(match):
file = match.group(1)
with open(os.path.join("pdf", "docs", file), 'r') as fd:
return "(" + re.sub(' ', '-', re.sub(' ', '', fd.readline().rstrip(), 1)).lower() + ")"
with open('mlr-tutorial.md', 'r+') as fd:
data = fd.read()
out = re.sub(r'\(([a-zA-Z0-9_]+\.md)\)', link_fixer, data)
fd.seek(0)
fd.write(out)
fd.truncate()
# In a new version of pandoc he only accepts --pdf-engine=xelatex (?)
retval = os.system("pandoc --number-sections --latex-engine=xelatex --variable colorlinks=\"true\" --listings -H latex-setup.tex --toc -f markdown+grid_tables+table_captions-implicit_figures -o mlr-tutorial-build.pdf mlr-tutorial.md")
if retval != 0:
sys.exit(1)