minted
minted copied to clipboard
[show-&-tell] ad-hoc adoptations from a different style to another one.
Prelude
I am using
- a language for interactive terminal sessions (like
console
orpsql
) -
style=bw
- and the output is tokenized as Generic.Output
i wanted to make the output tokens from style=bw to appear just like they do in default style, since:
- the output is not differentiated from the CLI in any way in
style=bw
, - unlike its distinct light grey color in default style.
- this makes it very hard to read.
If you really want gray comments, you'll have to customize the comment token macro. You'll need something like this in the preamble:
\makeatletter \appto{\minted@patch@PYGZhy}{% \def\PYG@tok@c{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.5,0.5,0.5}{##1}}}} \makeatother
Originally posted by @ gpoore in https://github.com/gpoore/minted/issues/366#issuecomment-1522747851
Details
So,
- i inspected the
_minted-*
directory of my existing project- I saw these terms at line start of
.pygtex
files\PYG{g+gp}
for promptGeneric.Prompt
, and\PYG{g+go}
before output linesGeneric.Output
, or sometimes even this\PYG{l+s+s1}
beforeBye
lolLiteral
+String
+ ? - i noticed that
\PYGZ*{}
is just like x/html character entities, so,gt >
,hy -
,bs \
,sq '
(single quotes)
- I saw these terms at line start of
- i created a Minimal working example actually, it was for asking the question, but it immediately led myself to discover the hack
- i inspected the same
_minted-*
dir of this MWE and- noticed the files
bw.pygstyle default.pygstyle *.pygtex
- noticed the files
- i immediately opened both style files and searched for
go
and found this following line indefault.pygstyle
defining the grayscale color (all 3 arguments to color of same value) - I guarded this inside
\makeat*
and pasted in my preamble. and voilla, it worked :)
\@namedef{PYG@tok@go}{\def\PYG@tc##1{\textcolor[rgb]{0.44,0.44,0.44}{##1}}}
Cons and Alternates
- i reckon that this will define & overwrite this for all the styles, which may not be desirable in general usecases.
- fortunately, it ain't a problem for me at this very moment.
- i thought about pasting this line verbatim in the
bw.pygstyle
but it would be very volatile and not very "setup once & forget" method - i tried
makeat
inside the\newmintedfile
's body, but it didn't compile
but anyhow, What better way of doing this would you suggest? 😃
MWE source
\begin{filecontents}[noheader, overwrite]{./test.mysql}
mysql-> select * from firstLine;
+--------------------+
| Database |
+--------------------+
mysql-> \help contents
mysql-> \h contents
You asked for help about help category: "Contents"
\end{filecontents}
\documentclass{article}
\usepackage{minted}
% \makeatletter
% \@namedef{PYG@tok@go}{\def\PYG@tc##1{\textcolor[rgb]{0.44,0.44,0.44}{##1}}}
% \makeatother
\begin{document}
\inputminted[autogobble]{psql}{test.mysql}
\inputminted[autogobble, style=bw]{psql}{test.mysql}
\end{document}
Screenshots
original screenshot
screenshot after modification:
References:
- https://github.com/gpoore/minted/issues/366#issuecomment-1522747851
- https://pygments-doc.readthedocs.io/en/latest/_modules/pygments/lexers/sql.html#PostgresConsoleLexer
- https://pygments.org/demo/
- https://pygments.org/docs/tokens/#generic-tokens
- https://github.com/gpoore/minted/blob/13e25d05cd382cf55f66636e0b1a91d94c2b4e4c/source/minted.sty#L494
Why not do this on Python side, by defining your own Pygments style, probably based on a builtin style?
- https://pygments.org/docs/styledevelopment/
- https://github.com/pygments/pygments/blob/master/pygments/styles/bw.py