Skip to content

Commit

Permalink
Fix sphinx-doc#10434: extra whitespace in pdf output for highlighted …
Browse files Browse the repository at this point in the history
…inline code

Related: sphinx-doc#10251
  • Loading branch information
jfbu committed May 8, 2022
1 parent f1061c0 commit 97f4a03
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions sphinx/writers/latex.py
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_build_latex.py
Expand Up @@ -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

0 comments on commit 97f4a03

Please sign in to comment.