Discussion:
Minted numberstyle
(too old to reply)
p***@gmail.com
2020-08-04 08:01:04 UTC
Permalink
Dear TeX experts,

Kindly refer the my tex file below. Here in the environment "myspec" i want to change the color of the numbers. Say e.g. 0.5 and 75 from light green to other color.

Can anyone suggest the possibility


\documentclass{llncs}

\usepackage{minted}
\usemintedstyle{friendly}
\newenvironment{myspec}{\VerbatimEnvironment\begin{minted}{haskell}}{\end{minted}}

\usepackage[misc]{ifsym}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{tipa}
\usepackage{fontawesome}

\newcommand{\dsl}{PaSe}

\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}

Regards
SudhaV
Muzzi
2020-08-04 15:47:37 UTC
Permalink
Post by p***@gmail.com
Dear TeX experts,
Kindly refer the my tex file below. Here in the environment "myspec" i want to change the color of the numbers. Say e.g. 0.5 and 75 from light green to other color.
Can anyone suggest the possibility
\documentclass{llncs}
\usepackage{minted}
\usemintedstyle{friendly}
\newenvironment{myspec}{\VerbatimEnvironment\begin{minted}{haskell}}{\end{minted}}
\usepackage[misc]{ifsym}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{tipa}
\usepackage{fontawesome}
\newcommand{\dsl}{PaSe}
\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}
Regards
SudhaV
Default color scheme of "friendly" pygments style is hardcoded in
https://github.com/pygments/pygments/blob/master/pygments/styles/friendly.py
and in converted `friendly.pygsty` located in minted's cache directory.

Here is an example changing color for token types `Number.Integer` and `Number.Float` to `green`.

\documentclass{article}
\usepackage{minted}
\usemintedstyle{friendly}
\newenvironment{myspec}{\VerbatimEnvironment\begin{minted}{haskell}}{\end{minted}}

\makeatletter
\newif\***@color@patched

\def\***@change@color{%
% test if style `friendly` is loaded
\ifdefined\***@tok@m
% patch only once since any pygments style is loaded only once
\***@color@patched
\else
\***@color@patchedtrue
% redefine highlighting style for token type `mi` (Number.Integer)
\def\***@tok@mi{%
\def\***@tc####1{\textcolor{green}{####1}}%
}%
% redefine highlighting style for token type `mf` (Number.Float)
\def\***@tok@mf{%
\def\***@tc####1{\textcolor{green}{####1}}%
}%
\fi
\fi
}

% append \***@change@color into beginning of `Verbatim` environment
\fvset{codes*={\***@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}

Some explanations:
- `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 ***@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 `\***@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 `\***@change@color` in my above example), and apply that redefinition _after_ `xxx.pygsty` is loaded. That's why I use a test `\ifdefined\***@tok@m` and sets `\fvset{codes*={\***@change@color}}`.

If you want to change other token (sub)types of `Number`, you can add redefinitions into `\***@change@color` by yourself.
Muzzi
2020-08-04 15:49:09 UTC
Permalink
Post by Muzzi
Post by p***@gmail.com
Dear TeX experts,
Kindly refer the my tex file below. Here in the environment "myspec" i want to change the color of the numbers. Say e.g. 0.5 and 75 from light green to other color.
Can anyone suggest the possibility
\documentclass{llncs}
\usepackage{minted}
\usemintedstyle{friendly}
\newenvironment{myspec}{\VerbatimEnvironment\begin{minted}{haskell}}{\end{minted}}
\usepackage[misc]{ifsym}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{tipa}
\usepackage{fontawesome}
\newcommand{\dsl}{PaSe}
\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}
Regards
SudhaV
Default color scheme of "friendly" pygments style is hardcoded in
https://github.com/pygments/pygments/blob/master/pygments/styles/friendly.py
and in converted `friendly.pygsty` located in minted's cache directory.
Here is an example changing color for token types `Number.Integer` and `Number.Float` to `green`.
\documentclass{article}
\usepackage{minted}
\usemintedstyle{friendly}
\newenvironment{myspec}{\VerbatimEnvironment\begin{minted}{haskell}}{\end{minted}}
\makeatletter
% test if style `friendly` is loaded
% patch only once since any pygments style is loaded only once
\else
% redefine highlighting style for token type `mi` (Number.Integer)
}%
% redefine highlighting style for token type `mf` (Number.Float)
}%
\fi
\fi
}
\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}
- `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`.
https://github.com/pygments/pygments/blob/master/pygments/token.py
hmmm... Google removes all the code indentation (leading spaces).
Peter Flynn
2020-08-04 16:21:32 UTC
Permalink
Post by p***@gmail.com
Dear TeX experts,
Kindly refer the my tex file below. Here in the environment "myspec"
i want to change the color of the numbers. Say e.g. 0.5 and 75 from
light green to other color.
Can anyone suggest the possibility.
Your document wants me to install Python and Pygmentize. Here's a
simpler version just using standard LaTeX packages.

\documentclass{article}
\usepackage[svgnames]{xcolor}
\usepackage{listings}
\lstset{defaultdialect=Haskell}
\lstset{basicstyle=\small\color{Black}\ttfamily\spaceskip.5em}
\lstset{keywordstyle=\color{DarkCyan}\bfseries,
identifierstyle=\color{DarkRed},
commentstyle=\color{Gray}\upshape,
stringstyle=\color{DarkBlue}\upshape,
emphstyle=\color{DarkGreen}\upshape,
showstringspaces=false,
columns=fullflexible,
keepspaces=true}
\lstset{literate=%
{0}{{{\color{Blue}0}}}1
{1}{{{\color{Blue}1}}}1
{2}{{{\color{Blue}2}}}1
{3}{{{\color{Blue}3}}}1
{4}{{{\color{Blue}4}}}1
{5}{{{\color{Blue}5}}}1
{6}{{{\color{Blue}6}}}1
{7}{{{\color{Blue}7}}}1
{8}{{{\color{Blue}8}}}1
{9}{{{\color{Blue}9}}}1
}
\begin{document}
Here we go with a listing in Haskell:
\begin{lstlisting}
menuSlideIn = linearTo (menu . width) (For 0.5) (To 75)
appFadeOut = linearTo (obscuringBox . alpha) (For 0.5) (To 0.65)
\end{lstlisting}

\end{document}

Loading...