diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2022-05-08 13:02:05 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-08 13:02:05 +0300 |
commit | 4b28bdd83bd30cc05986b8573b348a9853fb44fe (patch) | |
tree | b88b8306de864b85245618aa7638007d36ad411f | |
parent | f1061c012e214f16fd8790dec3c283d787e3daa8 (diff) | |
parent | 97f4a036d1744fd8af8f7b85b01353d5a9ceb393 (diff) |
Merge pull request #10435 from jfbu/10434_latex_inlinecode
Fix #10434: extra whitespace in pdf output for highlighted inline code
-rw-r--r-- | sphinx/writers/latex.py | 6 | ||||
-rw-r--r-- | 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 e0c7d56f8..f275100e9 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -1710,11 +1710,11 @@ class LaTeXTranslator(SphinxTranslator): # 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 dd0db8aef..709dce05d 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 |