gpoore / minted

minted is a LaTeX package that provides syntax highlighting using the Pygments library. Highlighted source code can be customized using fancyvrb.
1.73k stars 125 forks source link

[show-&-tell] ad-hoc adoptations from a different style to another one. #380

Open goyalyashpal opened 7 months ago

goyalyashpal commented 7 months ago

Prelude

I am using * a language for interactive terminal sessions (like `console` or `psql`) * `style=bw` * and the output is tokenized as [Generic.Output](https://pygments.org/docs/tokens/#generic-tokens) 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,

  1. i inspected the _minted-* directory of my existing project
    • I saw these terms at line start of .pygtex files \PYG{g+gp} for prompt Generic.Prompt, and \PYG{g+go} before output lines Generic.Output, or sometimes even this \PYG{l+s+s1} before Bye lol Literal + String + ?
    • i noticed that \PYGZ*{} is just like x/html character entities, so, gt >, hy -, bs \, sq ' (single quotes)
  2. i created a Minimal working example actually, it was for asking the question, but it immediately led myself to discover the hack
  3. i inspected the same _minted-* dir of this MWE and
    • noticed the files bw.pygstyle default.pygstyle *.pygtex
  4. i immediately opened both style files and searched for go and found this following line in default.pygstyle defining the grayscale color (all 3 arguments to color of same value)
  5. 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

but anyhow, What better way of doing this would you suggest? 😃

MWE source

```latex \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:

muzimuzhi commented 7 months ago

Why not do this on Python side, by defining your own Pygments style, probably based on a builtin style?