From 97f4a036d1744fd8af8f7b85b01353d5a9ceb393 Mon Sep 17 00:00:00 2001 From: jfbu <2589111+jfbu@users.noreply.github.com> Date: Sun, 8 May 2022 11:32:37 +0200 Subject: [PATCH] Fix #10434: extra whitespace in pdf output for highlighted inline code Related: #10251 --- sphinx/writers/latex.py | 6 +++--- tests/test_build_latex.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index e0c7d56f8ec..f275100e9d7 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -1710,11 +1710,11 @@ def visit_literal(self, node: Element) -> None: # TODO: Use nowrap option once LaTeX formatter supports it # https://github.com/pygments/pygments/pull/1343 hlcode = hlcode.replace(r'\begin{Verbatim}[commandchars=\\\{\}]', - r'\sphinxcode{\sphinxupquote{') + r'\sphinxcode{\sphinxupquote{%') # get consistent trailer - hlcode = hlcode.rstrip()[:-14] # strip \end{Verbatim} + hlcode = hlcode.rstrip()[:-15] # strip \n\end{Verbatim} self.body.append(hlcode) - self.body.append('}}') + self.body.append('%' + CR + '}}') raise nodes.SkipNode def depart_literal(self, node: Element) -> None: diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py index dd0db8aeffd..709dce05db4 100644 --- a/tests/test_build_latex.py +++ b/tests/test_build_latex.py @@ -1623,7 +1623,7 @@ def test_latex_code_role(app): r'\PYG{p}{)}' r'\PYG{p}{:} ' r'\PYG{k}{pass}') - assert (r'Inline \sphinxcode{\sphinxupquote{' + '\n' + - common_content + '\n}} code block') in content + assert (r'Inline \sphinxcode{\sphinxupquote{%' + '\n' + + common_content + '%\n}} code block') in content assert (r'\begin{sphinxVerbatim}[commandchars=\\\{\}]' + '\n' + common_content + '\n' + r'\end{sphinxVerbatim}') in content