MCPcopy Create free account
hub / github.com/Overv/VulkanTutorial / build_pdf

Function build_pdf

build_ebook.py:154–195  ·  view source on GitHub ↗

Build combined Markdown file into a PDF.

(markdown_file: Path, pdf_file: Path, args: argparse.Namespace)

Source from the content-addressed store, hash-verified

152
153
154def build_pdf(markdown_file: Path, pdf_file: Path, args: argparse.Namespace) -> Path:
155 """Build combined Markdown file into a PDF."""
156
157 try:
158 subprocess.check_output(["xelatex", "--version"])
159 except FileNotFoundError:
160 raise RuntimeError(f"failed to build {pdf_file}: xelatex not installed")
161
162 try:
163 keys_values = [(arg, getattr(args, arg)) for arg in vars(args)]
164 opts = [f"{key}={val}" for key, val in keys_values if val != ""]
165 pandoc_args = [x for i in opts for x in ("-V", i)]
166
167 subprocess.check_output(
168 [
169 "pandoc",
170 markdown_file.as_posix(),
171 "-V",
172 "documentclass=report"
173 ]
174 +
175 pandoc_args
176 +
177 [
178 "-t",
179 "latex",
180 "-s",
181 "--toc",
182 "--listings",
183 "-H",
184 "ebook/listings-setup.tex",
185 "-o",
186 pdf_file.as_posix(),
187 "--pdf-engine=xelatex",
188 ]
189 )
190 except CalledProcessError as e:
191 raise RuntimeError(
192 f"failed to build {pdf_file}: pandoc failed: {e.output.decode()}"
193 )
194
195 return pdf_file
196
197
198def build_epub(markdown_file: Path, epub_file: Path) -> Path:

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected