From 9d3087cc9257926f08616f65a941dc531d8797fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20B=2E?= <2589111+jfbu@users.noreply.github.com> Date: Sun, 11 Aug 2024 22:33:07 +0200 Subject: [PATCH] LaTeX: let latexpdf implement '-q' and '-Q' sphinx-build options (#12729) --- CHANGES.rst | 5 +++++ sphinx/cmd/make_mode.py | 29 ++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 073de1ddb59..e8ae58b425d 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -49,6 +49,11 @@ Bugs fixed Patch by Hugo van Kemenade. * #12645: Correctly support custom gettext output templates. Patch by Jeremy Bowman. +* #12717: LaTeX: let :option:`-q ` (quiet) option for + :program:`sphinx-build -M latexpdf` or :program:`make latexpdf` (``O=-q``) + get passed to :program:`latexmk`. Let :option:`-Q ` + (silent) apply as well to the PDF build phase. + Patch by Jean-François B. Testing ------- diff --git a/sphinx/cmd/make_mode.py b/sphinx/cmd/make_mode.py index 01929469cca..65df9f6227e 100644 --- a/sphinx/cmd/make_mode.py +++ b/sphinx/cmd/make_mode.py @@ -106,7 +106,34 @@ def build_latexpdf(self) -> int: raise RuntimeError('Invalid $MAKE command: %r' % makecmd) try: with chdir(self.builddir_join('latex')): - return subprocess.call([makecmd, 'all-pdf']) + if '-Q' in self.opts: + with open('__LATEXSTDOUT__', 'w') as outfile: + returncode = subprocess.call([makecmd, + 'all-pdf', + 'LATEXOPTS=-halt-on-error', + ], + stdout=outfile, + stderr=subprocess.STDOUT, + ) + if returncode: + print('Latex error: check %s' % + self.builddir_join('latex', '__LATEXSTDOUT__') + ) + elif '-q' in self.opts: + returncode = subprocess.call( + [makecmd, + 'all-pdf', + 'LATEXOPTS=-halt-on-error', + 'LATEXMKOPTS=-silent', + ], + ) + if returncode: + print('Latex error: check .log file in %s' % + self.builddir_join('latex') + ) + else: + returncode = subprocess.call([makecmd, 'all-pdf']) + return returncode except OSError: print('Error: Failed to run: %s' % makecmd) return 1