You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Just for the record, to help others with similar requirements in future.
I saw a question on CTAN's google group, in which OP wanted to change the highlighting color for numbers when pygments style friendly is used.
Under that post, I gave following workaround
\documentclass{article}
\usepackage{minted}
\usemintedstyle{friendly}
\newenvironment{myspec}
{\VerbatimEnvironment\begin{minted}{haskell}}
{\end{minted}}
\makeatletter\newif\ifminted@color@patched\def\PYGfriendly@change@color{%% test if style `friendly` is loaded\ifdefined\PYGfriendly@tok@m% patch only once since any pygments style is loaded only once\ifminted@color@patched\else\minted@color@patchedtrue% redefine highlighting style for token type `mi` (Number.Integer)\def\PYGfriendly@tok@mi{%\def\PYGfriendly@tc####1{\textcolor{green}{####1}}%
}%% redefine highlighting style for token type `mf` (Number.Float)\def\PYGfriendly@tok@mf{%\def\PYGfriendly@tc####1{\textcolor{green}{####1}}%
}%\fi\fi
}
% append \PYGfriendly@change@color into beginning of `Verbatim` environment\fvset{codes*={\PYGfriendly@change@color}}
\makeatother\begin{document}
\begin{myspec}
menuSlideIn = linearTo (menu . width) (For 0.5) (To 75)
appFadeOut = linearTo (obscuringBox . alpha) (For 0.5) (To 0.65)
\end{myspec}
\end{document}
Here is an example changing color for token types Number.Integer and Number.Float to green.
[example]
minted use python library pygments to do syntax highlighting. pygments firstly splits code snippet into tokens, then apply a style to highlight it.
For LaTeX use, every style has a corresponding <style name>.pygsty stored in cache directory used by minted.
In the friendly.pygsty file, you will find macro definitions for every token type. For example, token type Number.Integer has short name mi, hence its macro definition begins with \expandafter\def\csname PYGfriendly@tok@mi\endcsname .... For a complete list of token types and their short names, see https://github.com/pygments/pygments/blob/master/pygments/token.py
For example, in definition of \PYGfriendly@tok@mi in file friendly.pygsty, you will find the color used is [rgb]{0.25,0.63,0.44}, which corresponds to Number: "#40a070" in source code of friendly style (see its link at the beginning of my reply). You can think Number.Integer is a subtype of Number, hence inherits highlighting style from Number.
Therefore in LaTeX, to change the color is to redefine the corresponding macro (this is done in macro \PYGfriendly@change@color in my above example), and apply that redefinition afterxxx.pygsty is loaded. That's why I use a test \ifdefined\PYGfriendly@tok@m and sets \fvset{codes*={\PYGfriendly@change@color}}.
If you want to change other token (sub)types of Number, you can add redefinitions into \PYGfriendly@change@color by yourself.
The text was updated successfully, but these errors were encountered:
Just for the record, to help others with similar requirements in future.
I saw a question on CTAN's google group, in which OP wanted to change the highlighting color for numbers when pygments style
friendly
is used.Under that post, I gave following workaround
and words
The text was updated successfully, but these errors were encountered: