-
Notifications
You must be signed in to change notification settings - Fork 5
/
sphinxmanual_mod.py
71 lines (55 loc) · 2.33 KB
/
sphinxmanual_mod.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
69
70
71
#!/usr/bin/env python
"""This file needs to be run in after Sphinx's tex generation but before the
latex or pdflatex calls."""
import re
# Remove the numbering and page style stuff in the toc redefintion in the class
# file. I'm setting these in the toc variable in conf.py.
with open('_build/latex/sphinxmanual.cls', 'r') as f:
text = f.read()
pattern = r"\\setcounter{page}\{1\}%\n \\pagebreak%\n \\pagestyle{plain}%"
replace = r"\pagebreak%"
fixed = re.sub(pattern, replace, text)
fixed = fixed.replace(r'\pagenumbering{arabic}', '')
fixed = re.sub(r' {\\em\\LARGE\\py@HeaderFamily \\py@release\\releaseinfo \\par}\n', '', fixed)
fixed = re.sub(r' \\rule{\\textwidth}{1pt}%\n', '', fixed)
fixed = re.sub(r' \\let\\footnotesize\\small\n',
r' \\setcounter{page}{3}\n \\let\\footnotesize\\small\n', fixed)
# if i try to add frontmatter to the title page to get a page number on the
# page but the the /marks seem to break in the document
#\\thispagestyle{frontmatter}\n
# or
# \\pagestyle{frontmatter}
fixed = fixed.replace(r'\@date', 'August 2012')
fixed = fixed.replace(r'\vfill\vfill', r'\vfill')
with open('_build/latex/sphinxmanual.cls', 'w') as f:
f.write(fixed)
# Add a new frontmatter header style to the sphinx style file.
with open('_build/latex/sphinx.sty', 'r') as f:
text = f.read()
pattern = (r" \\renewcommand{\\headrulewidth}{0pt}\n" +
r" \\renewcommand{\\footrulewidth}{0.4pt}\n }")
replace = \
r""" \\renewcommand{\\headrulewidth}{0pt}
\\renewcommand{\\footrulewidth}{0.4pt}
}
\\fancypagestyle{frontmatter}{
\\fancyhf{}
\\fancyfoot[CE,CO]{{--\\py@HeaderFamily\\thepage--}}
\\renewcommand{\\headrulewidth}{0pt}
\\renewcommand{\\footrulewidth}{0pt}
}"""
fixed = re.sub(pattern, replace, text)
fixed = re.sub(r', \\py@release', '', fixed)
fixed = re.sub(r'\\py@HeaderFamily \\@title}}\n',
r'\\py@HeaderFamily \\@title}}\n \\fancyhead[RE,LO]{{\\py@HeaderFamily \\@author}}\n',
fixed)
with open('_build/latex/sphinx.sty', 'w') as f:
f.write(fixed)
# Add the signature pages to the front of the document.
with open('_build/latex/HumanControlofaBicycle.tex', 'r') as f:
text = f.read()
fixed = re.sub(r'\\maketitle',
r'\\includepdf[pages={3,{}}]{../../data/ucd-pages.pdf}\n\\maketitle',
text)
with open('_build/latex/HumanControlofaBicycle.tex', 'w') as f:
f.write(fixed)