Skip to content

[Sphinx Extension] Include PDF build from Sphinx LaTeX #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions builder/build_cli.py
Original file line number Diff line number Diff line change
@@ -21,6 +21,8 @@
SPEC_LOCKFILE = "spec.lock"

def build_docs(root, builder, clear, serve, debug, spec_lock_consistency_check):
if builder == "pdf":
builder = "latex"
dest = root / "build"

args = ["-b", builder, "-d", dest / "doctrees"]
@@ -67,6 +69,12 @@ def build_docs(root, builder, clear, serve, debug, spec_lock_consistency_check):
],
check=True,
)
if builder == "latex":
subprocess.run(
["make", "-C", str(dest / "latex"), "all-pdf"],
check=True
)
print(f"PDF generated at: {dest/'latex'}")
except KeyboardInterrupt:
exit(1)
except subprocess.CalledProcessError:
@@ -132,7 +140,12 @@ def main(root):
"--check-links", help="Check whether all links are valid", action="store_true"
)
group.add_argument(
"--xml", help="Generate Sphinx XML rather than HTML", action="store_true"
"--output",
help="select output format: html, xml, or pdf",
choices=["html", "xml", "pdf"],
default="html",
metavar="FORMAT",
required=False,
)
group.add_argument(
"--debug",
@@ -145,6 +158,6 @@ def main(root):
update_spec_lockfile(SPEC_CHECKSUM_URL, root / "src" / SPEC_LOCKFILE)

rendered = build_docs(
root, "xml" if args.xml else "html", args.clear, args.serve, args.debug, not args.ignore_spec_lock_diff
root, args.output, args.clear, args.serve, args.debug, not args.ignore_spec_lock_diff
)

7 changes: 3 additions & 4 deletions exts/coding_guidelines/__init__.py
Original file line number Diff line number Diff line change
@@ -6,10 +6,9 @@
from . import std_role
from . import fls_linking

from sphinx_needs.api import add_dynamic_function
from sphinx.errors import SphinxError
from sphinx.domains import Domain

from docutils import nodes
import logging

# Get the Sphinx logger
@@ -33,8 +32,9 @@ def merge_domaindata(self, docnames, other):
pass # No domain data to merge

def setup(app):

app.add_domain(CodingGuidelinesDomain)
app.connect('env-check-consistency', fls_checks.check_fls)
app.add_config_value(
name="spec_std_docs_url",
default="https://doc.rust-lang.org/stable/std",
@@ -48,7 +48,6 @@ def setup(app):
default=True,
rebuild='env')

app.connect('env-check-consistency', fls_checks.check_fls)
app.connect('build-finished', write_guidelines_ids.build_finished)
app.connect('build-finished', fls_linking.build_finished)

22 changes: 22 additions & 0 deletions src/conf.py
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
copyright = '2025, Contributors to Coding Guidelines Subcommittee'
author = 'Contributors to Coding Guidelines Subcommittee'
release = '0.1'
language = 'en'

# -- General configuration ---------------------------------------------------

@@ -127,3 +128,24 @@
# Configure the theme
html_theme = 'sphinx_rtd_theme'
html_static_path = ['_static']

# -- Options for LaTex output -------------------------------------------------
latex_engine = 'xelatex' # or 'pdflatex', 'lualatex'
#latex_documents = [
# ('index', 'YourProject.tex', 'Your Project Title', 'Your Name', 'manual'),
#]

latex_toplevel_sectioning = 'section'
latex_show_urls = 'footnote' # or 'inline', 'no'
latex_elements = {
'classoptions': ',openany,oneside',
'preamble': r'''
\usepackage[most]{tcolorbox}
\usepackage{xcolor}
\let\cleardoublepage\clearpage
''',
'fontpkg': r'''
\setmainfont{DejaVu Serif}
''',
'figure_align': 'H',
}