Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LaTeX: better workaround for a Pygments LaTeXFormatter issue (with Pygments up to 2.7.4) #8879

Merged
merged 3 commits into from
Mar 12, 2021

Conversation

jfbu
Copy link
Contributor

@jfbu jfbu commented Feb 13, 2021

Fix #8874

Feature or Bugfix

  • Bugfix

Relates

The upstream Pygments issue is fixed in their master branch for next release (current is 2.7.4).

So this tests for Pygments version and applies the fix only if needed.

Previously the Sphinx fix corrected the line spacing issue (which is infrequent because one has to use a Pygments style which utilizes "border" for some tokens and a lexer which produces these token types; this is case for pygments style 'manni' in combination with the diff lexer, see pygments/pygments#1708), but in a way overwriting the style specification. This PR does it better in a way obeying the style, and it moves the fix to better location away from sphinx.sty.

@jfbu jfbu added this to the 4.0.0 milestone Feb 13, 2021
_LATEX_ADD_STYLES_FIXPYG = r'''
\makeatletter
% fix for Pygments <= 2.7.4
\let\spx@original@fcolorbox\fcolorbox
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means \fcolorbox (from color/xcolor package) must exist when sphinxhighlight.sty is loaded by sphinx.sty. But this is the case as color/xcolor is loaded very early by sphinx.sty, before handling options. So we are safe here. (this is true also on 3.x even though sphinxhighlight.sty is loaded earlier, but I feel now latex changes must only go to master). One could add some \AtBeginDocument to be extra safe if some package modifies \fcolorbox but I feel this is unnecessary. Besides in future, this patch will not be used when people have updated their Pygments version.

\makeatletter
% fix for Pygments <= 2.7.4
\let\spx@original@fcolorbox\fcolorbox
\def\spx@fixpyg@fcolorbox{\fboxsep-\fboxrule\spx@original@fcolorbox}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't have to insert here a \string -\fboxrule in place of -\fboxrule as was done at Pygments 2.8.1 to work-around a minted (latex package using Pygments) compatibility issue

@jfbu jfbu merged commit 3bbdc65 into sphinx-doc:master Mar 12, 2021
@jfbu jfbu deleted the latex_better_fix_pygments branch March 12, 2021 21:23
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant