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: the fix to two minor Pygments LaTeXFormatter output issues ignore Pygments style #8874

Closed
jfbu opened this issue Feb 12, 2021 · 2 comments

Comments

@jfbu
Copy link
Contributor

jfbu commented Feb 12, 2021

Describe the bug
A clear and concise description of what the bug is.

\RequirePackage{sphinxhighlight}
% fix baseline increase from Pygments latex formatter in case of error tokens
% and keep \fboxsep's scope local via added braces
\def\PYG@tok@err{%
\def\PYG@bc##1{{\setlength{\fboxsep}{-\fboxrule}%
\fcolorbox[rgb]{1.00,0.00,0.00}{1,1,1}{\strut ##1}}}%
}
\def\PYG@tok@cs{%
\def\PYG@tc##1{\textcolor[rgb]{0.25,0.50,0.56}{##1}}%
\def\PYG@bc##1{{\setlength{\fboxsep}{0pt}%
\colorbox[rgb]{1.00,0.94,0.94}{\strut ##1}}}%
}%

goes some redefinition of latex macros from Pygments output. In the first case this is to keep baseline constant even in case of error tokens, in the second case to avoid a change to \fboxsep to propagate (I do not recall if this one is cosmetic only, but the first one is definitely needed).

But using for example pygments_style = 'autumn' in conf.py one sees that original pygments LaTeXFormatter output is

\def\PYG@tok@cs{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.00,0.00,0.67}{##1}}}
...
\def\PYG@tok@err{\def\PYG@tc##1{\textcolor[rgb]{1.00,0.00,0.00}{##1}}\def\PYG@bc##1{\setlength{\fboxsep}{0pt}\colorbox[rgb]{1.00,0.67,0.67}{\strut ##1}}}
...

(I have edited it to avoid irrelevant \expandafter\def\csname... low-level stuff which is a slight bug of Pygments because unneeded; the @ character must have been allowed in latex macro names here, from the fact that the mark-up uses for example \PYG@it with so scruples, so all the \expandafter\def... from Pygments output have no rationale; edit: it has rationale as some digits may creep in, but can be shortened to \@namedef )

So, the hard-coded fixes which are added after loading of sphinxhighlight.sty overwrite style specs such as colors, and here the usage of italics for Comment.Special Pygments token type.

By the way, a PR should be done at Pygments to work usptream around the bug(s) and thus make those redefinitions unnecessary.

Blame: 6cb517d (my bad, sorry, #4250)

Related

Environment info

  • Python version: 3.8.7
  • Pygments version: 2.7.4
  • Sphinx version: 3.4.3
  • Sphinx extensions: [e.g. sphinx.ext.autodoc, recommonmark]
  • Extra tools: [e.g. Browser, tex or something else]
@jfbu
Copy link
Contributor Author

jfbu commented Feb 12, 2021

Pygments has now fixed the issue pygments/pygments#1708, so we will in future drop this entirely after checking Pygments version. Till then, we have to handle this better and find a wayt to respect the pygments style choices but still fix the issue.

@jfbu
Copy link
Contributor Author

jfbu commented Mar 13, 2021

Fixed at 473718c

@jfbu jfbu closed this as completed Mar 13, 2021
@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

No branches or pull requests

1 participant