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: workaround minted incompatibility with Pygments 2.8.0 #1735

Merged
merged 1 commit into from Mar 5, 2021

Conversation

jfbu
Copy link
Contributor

@jfbu jfbu commented Mar 5, 2021

Fix: #1731
Fix: #1734

Upstream issue: gpoore/minted#294

%% workaround a minted <= v2.5 issue, which loads this file with - having
%% catcode letter; also with _ having catcode 11 but this does not affect us
\edef\%(cp)s@restore@catcode@of@minus@sign{\catcode`\noexpand\-=\the\catcode`\-\relax}
\catcode`\-=12
Copy link
Contributor Author

Choose a reason for hiding this comment

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

defining the restoring macro is for maximal compatibility but anyhow regarding minted problem with - of catcode 11 it seems it happens within a group so it is unneeded to restore at end of this style file the catcode - to its (erroneous) minted setting anyhow

@@ -129,6 +133,7 @@ def escape_tex(text, commandprefix):
\def\%(cp)sZlb{[}
\def\%(cp)sZrb{]}
\makeatother
\%(cp)s@restore@catcode@of@minus@sign
Copy link
Contributor Author

Choose a reason for hiding this comment

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

as commented above we could also decide to go for only \catcode`\-=12 approach because nobody in his/her right mind should input a TeX/LaTeX file of macros with any other catcode for - than 12

@birkenfeld
Copy link
Member

I think this should definitely be merged - I think tex package release cycles are quite long and we don't want to break minted.

@birkenfeld
Copy link
Member

@Anteru pick into a branch and make a 2.8.1?

@jfbu
Copy link
Contributor Author

jfbu commented Mar 5, 2021

@birkenfeld sorry for not having detected the problem at time of #1708, but I use only Sphinx! :-)

@Anteru
Copy link
Collaborator

Anteru commented Mar 5, 2021

@birkenfeld Yes, this seems important enough. I'd suggest to merge onto master and then cherry-pick into a 2.8 series branch.

@Anteru Anteru merged commit 4700c41 into pygments:master Mar 5, 2021
Anteru added a commit that referenced this pull request Mar 5, 2021
@Anteru
Copy link
Collaborator

Anteru commented Mar 5, 2021

Cherry picked as 500713d which can be used for a 2.8.1 release.

%% workaround a minted <= v2.5 issue, which loads this file with - having
%% catcode letter; also with _ having catcode 11 but this does not affect us
\edef\%(cp)s@restore@catcode@of@minus@sign{\catcode`\noexpand\-=\the\catcode`\-\relax}
\catcode`\-=12
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As minted loads this file with \endlinechar=-1 setting it would have been better here to add explicitly \relax after 12. This is cosmetic as next line starts with a \def which does not expand hence the TeX parsing of the digits will end correctly.

Just mentioning this out of professional sense of duty... (there is no higher level LaTeX interface to set a catcode, so I used the core level TeX syntax, but one has to be aware of some things) (I would have probably used core TeX syntax anyhow anyway as I like it)

Copy link
Member

Choose a reason for hiding this comment

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

It's certainly interesting to read 😆

jfbu added a commit to jfbu/pygments that referenced this pull request Mar 5, 2021
@jfbu jfbu mentioned this pull request Mar 5, 2021
@jfbu
Copy link
Contributor Author

jfbu commented Mar 5, 2021

There was a silly oversight (they all are silly) in my latex code, which I fixed at #1736. Sorry for all the trouble! @birkenfeld

jfbu added a commit to jfbu/pygments that referenced this pull request Mar 5, 2021
This reverts already merged pygments#1735 (after a commit from pygments#1736 to fix it)
and applies the first envisioned method discussed in pygments#1734.

The reason is that the pygments#1735-pygments#1736 method only partially repairs the
minted compatibility.  Minted queries from Pygments the stylesheet
with a command prefix equal to the style name, which may contain
(at least, so far) characters such as - and _, which are not normally
allowed in LaTeX macros.  So it modifies the meaning of - and _ before
telling LaTeX to input the Pygments provided stylesheet.  Thus, retoring
the normal meaning of - e.g. must be done slightly differently than in
be defined using the weird minted -.

The pygments#1735-pygments#1736 method did fix compatibility with minted but *only* for
those style names not using a -, and it creates another issue if used with
style "paraiso-dark" e.g. which has a - character in its name.

"De guerre lasse", I feel it is simpler to use the somewhat strange
very localized hotfix of prefixing - by \string at the one spot where
we need it to be its normal self.  Hence this PR.

Fix pygments#1734.
jfbu added a commit to jfbu/pygments that referenced this pull request Mar 5, 2021
This reverts already merged pygments#1735 (after a commit from pygments#1736 to fix it)
and applies the first envisioned method discussed in pygments#1734.

The reason is that the pygments#1735-pygments#1736 method only partially repairs the
minted compatibility.  Minted queries from Pygments the stylesheet
with a command prefix equal to the style name, which may contain
(at least, so far) characters such as - and _, which are not normally
allowed in LaTeX macros.  So it modifies the meaning of - and _ before
telling LaTeX to input the Pygments provided stylesheet.  Thus, restoring
the normal meaning of - e.g. must be done slightly differently than in
be defined using the weird minted -.

The pygments#1735-pygments#1736 method did fix compatibility with minted but *only* for
those style names not using a -, and it creates another issue if used with
style "paraiso-dark" e.g. which has a - character in its name.

"De guerre lasse", I feel it is simpler to use the somewhat strange
very localized hotfix of prefixing - by \string at the one spot where
we need it to be its normal self.  Hence this PR.

Fix pygments#1734.
jfbu added a commit to jfbu/pygments that referenced this pull request Mar 5, 2021
This reverts already merged pygments#1735 (after a commit from pygments#1736 to fix it)
and applies the first envisioned method discussed in pygments#1734.

The reason is that the pygments#1735-pygments#1736 method only partially repairs the
minted compatibility.  Minted queries from Pygments the stylesheet
with a command prefix equal to the style name, which may contain
(at least, so far) characters such as - and _, which are not normally
allowed in LaTeX macros.  So it modifies the meaning of - and _ before
telling LaTeX to input the Pygments provided stylesheet.  Restoring
the normal meaning of - from inside the stylesheet must be carefully
localized: at top and bottom of stylesheets some macros will use in
their names the - and there the - must be the weird minted one, not
the normal one.

The pygments#1735-pygments#1736 method thus does fix compatibility with minted but *only*
for those style names not using a -, but it creates another issue if
used with e.g. style "paraiso-dark" which has a - character in its name.

"De guerre lasse", I feel it is simpler to use the somewhat strange
very localized hotfix of prefixing - by \string at the one spot where
we need it to be its normal self.  Hence this PR.

Fix pygments#1734.
@jfbu jfbu mentioned this pull request Mar 5, 2021
Anteru pushed a commit that referenced this pull request Mar 6, 2021
* Fix #1735 pull request

* LaTeX: workaround to ensure compatibility with minted

This reverts already merged #1735 (after a commit from #1736 to fix it)
and applies the first envisioned method discussed in #1734.

The reason is that the #1735-#1736 method only partially repairs the
minted compatibility.  Minted queries from Pygments the stylesheet
with a command prefix equal to the style name, which may contain
(at least, so far) characters such as - and _, which are not normally
allowed in LaTeX macros.  So it modifies the meaning of - and _ before
telling LaTeX to input the Pygments provided stylesheet.  Restoring
the normal meaning of - from inside the stylesheet must be carefully
localized: at top and bottom of stylesheets some macros will use in
their names the - and there the - must be the weird minted one, not
the normal one.

The #1735-#1736 method thus does fix compatibility with minted but *only*
for those style names not using a -, but it creates another issue if
used with e.g. style "paraiso-dark" which has a - character in its name.

"De guerre lasse", I feel it is simpler to use the somewhat strange
very localized hotfix of prefixing - by \string at the one spot where
we need it to be its normal self.  Hence this PR.

Fix #1734.
Anteru added a commit that referenced this pull request Mar 6, 2021
* Fix #1735 pull request

* LaTeX: workaround to ensure compatibility with minted

This reverts already merged #1735 (after a commit from #1736 to fix it)
and applies the first envisioned method discussed in #1734.

The reason is that the #1735-#1736 method only partially repairs the
minted compatibility.  Minted queries from Pygments the stylesheet
with a command prefix equal to the style name, which may contain
(at least, so far) characters such as - and _, which are not normally
allowed in LaTeX macros.  So it modifies the meaning of - and _ before
telling LaTeX to input the Pygments provided stylesheet.  Restoring
the normal meaning of - from inside the stylesheet must be carefully
localized: at top and bottom of stylesheets some macros will use in
their names the - and there the - must be the weird minted one, not
the normal one.

The #1735-#1736 method thus does fix compatibility with minted but *only*
for those style names not using a -, but it creates another issue if
used with e.g. style "paraiso-dark" which has a - character in its name.

"De guerre lasse", I feel it is simpler to use the somewhat strange
very localized hotfix of prefixing - by \string at the one spot where
we need it to be its normal self.  Hence this PR.

Fix #1734.
@jfbu jfbu deleted the minted_workaround branch December 14, 2021 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Latex unable to render
3 participants