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
Possible Bug in Pygments macro definition that prevents PDF compile #2172
Comments
cc @jfbu |
@birkenfeld The problem (cf sphinx-doc/sphinx#10506 (comment)) is that the We fixed it at Sphinx by redoing the
If you want to make a change upstream here at Pygments the diff would be: diff --git a/pygments/formatters/latex.py b/pygments/formatters/latex.py
index d33b686d..bc6ea96a 100644
--- a/pygments/formatters/latex.py
+++ b/pygments/formatters/latex.py
@@ -105,7 +105,7 @@ STYLE_TEMPLATE = r'''
\%(cp)s@tok{#1}\expandafter\%(cp)s@toks\fi}
\def\%(cp)s@do#1{\%(cp)s@bc{\%(cp)s@tc{\%(cp)s@ul{%%
\%(cp)s@it{\%(cp)s@bf{\%(cp)s@ff{#1}}}}}}}
-\def\%(cp)s#1#2{\%(cp)s@reset\%(cp)s@toks#1+\relax+\%(cp)s@do{#2}}
+\protected\def\%(cp)s#1#2{\%(cp)s@reset\%(cp)s@toks#1+\relax+\%(cp)s@do{#2}}
%(styles)s
On looking at this tonight I noticed related other potential issues of a subtle sort, with things such as The reason is that as Nota bene: this problem has not YET been reported at Sphinx. I discovered it theoretically now... I am not sure if you will want to consider this also a problem at Pygments level. ping @gpoore, @muzimuzhi is this relevant to "minted inline" usage? I initially thought about using
(in the above manual test the macros were For
Problem of this is that this is conditional on hyperref being loaded, and where are we going to execute it? For the So perhaps in the end
is the way to go. But very annoying to have to go into Well, I was verbose as usual (and spend actually quite some time on this now) and as explained above some of these problems are only virtual ones at Sphinx. But perhaps they exist already for https://github.com/gpoore/minted ? Nothing forbids a minted user to try to use it in titles? (I did not check documentation). |
Just a tiny little bit 😄 |
Apologies for my longish earlier comment. I should have paused and take time to investigate rather than doing some "on the fly live reporting" (which took quite some time on my side...).
This is unrelated to whatever happens here.
To sum up and try to dispel the discomfort that my too long and too TeXnical comment may have created: It would probably be better if Pygments defined However https://github.com/gpoore/minted is a priori not exposed to the reported issue, and Sphinx can, and has already started to handle addition of Thus, there is probably nothing to do here. Except if someone reports an issue from direct usage of the Pygmentize library. |
@jfbu Your summary of |
@gpoore thanks for info! At Sphinx I have pushed replacements to the Pygments escapes at sphinx-doc/sphinx@213c29b. These replacements are math mode and bookmarks compatible. |
@birkenfeld As I was anlyzing this "live" my opinion evolved. I don't recommend now to add |
OK, so you recommend to do nothing on the Pygments side, right? |
Well, I am looking at this from Sphinx, where the meaning of the LaTeX macros involved in the Pygments LaTeX Formatter output can be modified, so there is no urgency for us. The issue arose at Sphinx 5.0.0 as it has allowed Pygmentize for inline code snippets also for LaTeX output (removing the I feel I have a pretty good set of alternative definitions at sphinx-doc/sphinx@213c29b, with a slight problem with the Alternative definitions such as the ones in my Sphinx patch are necessary if the Pygments LaTeX escapes for special characters are one day to be used in sectioning titles and hyperref attempts to create bookmarks entries out of them. The compatibility with hyperref is a bit annoying because it means special approach In the absence of Pygments users complaining about the current state of affairs I can not push for you to backport my changes... as explained by @etpalmer63 , the issue arose from a Sphinx context, although a minimal example was provided which did not use it, but notice that the As this is not the case and as I don't have necessarily the knowledge of how Pygments LaTeX output is used "in the wild" I can only remain cautious and not insist on things changing here. |
Thanks for your very thorough analysis! Closing for now - can be reopened if the problem appears elsewhere. |
I encountered this bug when I was trying to render a Sphinx document as a pdf. For syntax highlighting that uses Pygments, the pygment macro causes an error when its included in figure text. The Sphinx team produced this snippet that recreates the error (after the rst has been converted to latex):
For more information, and better insight from the Sphinx team themselves, here is the original issue: sphinx-doc/sphinx#10506
Please let me know if any additional information would be helpful.
Thanks for checking this out,
Erik
The text was updated successfully, but these errors were encountered: