-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_pdf.py
More file actions
50 lines (41 loc) · 1.44 KB
/
generate_pdf.py
File metadata and controls
50 lines (41 loc) · 1.44 KB
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
import os
import pypandoc
# Define the directory containing the markdown files
md_dir = '_monographtypos'
# Define the output filenames
combined_md_file = 'combined.md'
output_pdf_file = 'output.pdf'
def strip_yaml_header(content):
"""Strip YAML header from the content."""
if content.startswith('---'):
parts = content.split('---', 2)
if len(parts) == 3:
return parts[2].strip()
return content
# Combine content from all markdown files
combined_content = ""
file_order = [
'Introduction.md',
'ChebyshevAcceleration.md',
'NonlinearAcceleration.md',
'NesterovAcceleration.md',
'ProximalAccelerationandCatalyst.md',
'RestartSchemes.md',
'UsefulInequalities.md',
'VariationsonNesterovAcceleration.md',
'OnWorst-caseAnalysesforFirst-orderMethods.md',
'Acknowledgements.md',
'References.md'
]
for filename in file_order:
filepath = os.path.join(md_dir, filename)
with open(filepath, 'r', encoding='utf-8') as file:
content = file.read()
content_without_header = strip_yaml_header(content)
combined_content += content_without_header + "\n\n"
# Write the combined content to a markdown file
with open(combined_md_file, 'w', encoding='utf-8') as file:
file.write(combined_content)
# Convert the combined markdown file to PDF using pypandoc
pypandoc.convert_file(combined_md_file, 'pdf', outputfile=output_pdf_file)
print(f'PDF generated: {output_pdf_file}')