-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,10 +8,12 @@ | |
:license: BSD, see LICENSE for details. | ||
""" | ||
|
||
from distutils.version import LooseVersion | ||
from functools import partial | ||
from importlib import import_module | ||
from typing import Any, Dict | ||
|
||
from pygments import __version__ as pygmentsversion | ||
from pygments import highlight | ||
from pygments.filters import ErrorToken | ||
from pygments.formatter import Formatter | ||
|
@@ -50,6 +52,20 @@ | |
_LATEX_ADD_STYLES = r''' | ||
\renewcommand\PYGZsq{\textquotesingle} | ||
''' | ||
# fix extra space between lines when Pygments highlighting uses \fcolorbox | ||
# add a {..} to limit \fboxsep scope, and force \fcolorbox use correct value | ||
# cf pygments #1708 which makes this unneeded for Pygments > 2.7.4 | ||
_LATEX_ADD_STYLES_FIXPYG = r''' | ||
\makeatletter | ||
% fix for Pygments <= 2.7.4 | ||
\let\spx@original@fcolorbox\fcolorbox | ||
\def\spx@fixpyg@fcolorbox{\fboxsep-\fboxrule\spx@original@fcolorbox} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we don't have to insert here a |
||
\def\PYG#1#2{\PYG@reset\PYG@toks#1+\relax+% | ||
{\let\fcolorbox\spx@fixpyg@fcolorbox\PYG@do{#2}}} | ||
\makeatother | ||
''' | ||
if tuple(LooseVersion(pygmentsversion).version) <= (2, 7, 4): | ||
_LATEX_ADD_STYLES += _LATEX_ADD_STYLES_FIXPYG | ||
|
||
|
||
class PygmentsBridge: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.