-
-
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
Fix #4249 by overriding Pygments latex formatter error highlighting #4250
Merged
Conversation
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
jfbu
force-pushed
the
4249_errhighlight
branch
from
December 6, 2017 08:43
86977a3
to
6cb517d
Compare
jfbu
added a commit
that referenced
this pull request
Dec 10, 2017
jfbu
added a commit
to jfbu/sphinx
that referenced
this pull request
Dec 30, 2017
This goes for the quick solution, hence uses the pre-existing architecture underlying the `\PYG` macro from the Pygments highlighting code. Each domain can add its own style to LaTeX by defining suitable macro for supporting css styles. For example, here we added \@namedef{PYG@tok@k-cpp}{% \def\PYG@tc##1{\textcolor[RGB]{0,0,"FF}{##1}}% }% to sphinx.sty to emulate the CSS code.k-cpp { color: #0000FF; } (previous commit uses `#0000AA` but I chose `#0000FF` for better seeing things...) For a fully developed example all the `\@namedef` would be in some `sphinxcpp.sty` style file and either the document will do `\usepackage{sphinxcpp.sty}` or `sphinx.sty` will do `\RequirePackage{sphinxcpp.sty}`. The user could override this file via `latex_additional_files`. In absence of such file, the macro definitions will be lacking but this will raise no error. For the example here (from last commit message) the latex output contains \PYG{d+k+k-cpp} and the `\PYG` macro nests "action of d(of k(of k-cpp...)))". Turns out that Pygments already has some macro for "k", which uses bold face (as can be seen in PDF output) and changes the text color, but has "k-cpp" is deeper nested it is executed last and sets the good text color. Thus it would perhaps be better if the latex writer produces something like \PYG{cssd+cssk+cssk-cpp} to avoid name clashes with Pygments pre-defined styles. Or here it is OK that "k" is styled boldface by Pygments in LaTeX. Important: class names must not contain the `+` character which is use by Pygments LaTeX code as separator. There are some issues in the Pygments code with the scope of some changes; this is already corrected by Sphinx (refs: sphinx-doc#4250), but some more scrutiny is perhaps needed because so far the Pygments code is exercised only inside Verbatim environments where each code-line is a scope in itself so border effects do not propagate, hence I have not checked closely the Pygments LaTeX code, but perhaps sphinx-doc#4250 fixes already all problems.
jfbu
added a commit
to jfbu/sphinx
that referenced
this pull request
Dec 30, 2017
This goes for the quick solution, hence uses the pre-existing architecture underlying the `\PYG` macro from the Pygments highlighting code. Each domain can add its own style to LaTeX by defining suitable macro for supporting css styles. For example, here we added \@namedef{PYG@tok@k-cpp}{% \def\PYG@tc##1{\textcolor[RGB]{0,0,"FF}{##1}}% }% to sphinx.sty to emulate the CSS code.k-cpp { color: #0000FF; } (previous commit uses `#0000AA` but I chose `#0000FF` for better seeing things... also syntax `\textcolor[HTML]{0000FF}` is possible)) For a fully developed example all the `\@namedef` would be in some `sphinxcpp.sty` style file and either the document will do `\usepackage{sphinxcpp}` or `sphinx.sty` will do `\RequirePackage{sphinxcpp}`. The user could override this file via `latex_additional_files`. In absence of such file, the macro definitions will be lacking but this will raise no error. For the example here (from last commit message) the latex output contains \PYG{d+k+k-cpp} and the `\PYG` macro nests "action of d(of k(of k-cpp...)))". Turns out that Pygments already has some macro for "k", which uses bold face (as can be seen in PDF output) and changes the text color, but as "k-cpp" is deeper nested it is executed last and sets the good text color. Thus it would perhaps be better if the latex writer produced something like \PYG{cssd+cssk+cssk-cpp} to avoid name clashes with Pygments pre-defined styles. Or here it is OK that "k" is styled boldface by Pygments in LaTeX. Important: class names must not contain the `+` character which is used by Pygments LaTeX code as separator. There are some issues in the Pygments code with the scope of some changes; this is already corrected by Sphinx (refs: sphinx-doc#4250), but some more scrutiny is perhaps needed because so far the Pygments code is exercised only inside Verbatim environments where each code-line is a scope in itself so border effects do not propagate, hence I have not checked closely the Pygments LaTeX code, but perhaps sphinx-doc#4250 fixes already all problems.
This was referenced Feb 12, 2021
Closed
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Relates
If an option is provided for Sphinx not to use
raiseonerror
Pygments filter, then issue #4249 needs a fix. This PR provides it.