Fix #10434: extra whitespace in pdf output for highlighted inline code

Related: #10251
This commit is contained in:
jfbu
2022-05-08 11:32:37 +02:00
parent f1061c012e
commit 97f4a036d1
2 changed files with 5 additions and 5 deletions

View File

@@ -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:

View File

@@ -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