-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmd2pdf.py
executable file
·41 lines (36 loc) · 1.08 KB
/
md2pdf.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
import os
import subprocess
input_dir = "chapters"
output_dir = "my_book"
# Ensure the output directory exists
os.makedirs(output_dir, exist_ok=True)
# List all files in the input directory and sort them numerically based on the prefix
input_files = sorted(
[
os.path.join(input_dir, file)
for file in os.listdir(input_dir)
if os.path.isfile(os.path.join(input_dir, file))
],
key=lambda x: int(os.path.splitext(os.path.basename(x).split("-")[0])[0]),
)
# # Build the pandoc command
pandoc_cmd = [
"pandoc",
*input_files,
"--toc",
"--number-sections",
"--resource-path=.",
"--metadata-file", "metadata.yml",
"--include-in-header", "main.tex",
"--highlight-style", "pygments.theme",
"-V", "toc-title=Table of contents",
"-V", "linkcolor:blue",
"-V", "geometry:a4paper",
"-V", "geometry:margin=1.8cm",
"-V", "mainfont=DejaVu Serif",
"-V", "monofont=SauceCodePro Nerd Font",
"--pdf-engine=xelatex", "-o",
os.path.join(output_dir, "book_output.pdf"),
]
# Run the pandoc command
subprocess.run(pandoc_cmd)