add tag
samcarter
I would like to make a few tweaks to a minted style from within my latex document. Making these changed from within latex makes it easier to distribute the code, e.g. if I use the tweaked style for a package documentation I can just include the .tex file in my submissioin to CTAN and don't have to include a custom pygments style.

My current workaround is to use the `filecontents` environment to smuggle a modified `.style.minted` file into the minted cache directory. This method works, but is a bit limited in regards to the choice of names for the minted cache directory (e.g. I can't use a hidden folder without changing the security settings of my tex distribution).

Now I've come across a method for tweaking the style directly from within the latex document and thought I'd give it a try:

https://github.com/gpoore/minted/issues/380#issue-2026709744

The example seems to work well, but if I try to change the font for comments, I don't see any effect:

```
\documentclass{article}
\usepackage{minted}

\usemintedstyle{bw}

\makeatletter
\@namedef{PYG@tok@go}{\def\PYG@tc##1{\textcolor[rgb]{0.44,0.44,0.44}{##1}}}
\@namedef{PYG@tok@c}{\let\PYG@it=\textbf} % <- does not seem to have any effect
\makeatother

\begin{document}

\begin{minted}{psql}
mysql-> select * from firstLine;
+--------------------+
| Database           |
+--------------------+
mysql-> \help contents
mysql-> \h contents
You asked for help about help category: "Contents"
\end{minted}

\begin{minted}{latex}
% Quack
\duck
\end{minted}

\end{document}
```

![Screenshot 2024-09-30 at 15.04.35.png](/image?hash=3d011be5e8a114b9232760b3b7654056949bd8feff23f47f834d55517b5e82f8)

If I make the same change for `PYG@tok@c` in `bw.style.minted`, I do get an upright comment.

Does anybody know, why changing `PYG@tok@go` in the above example works, but changing `PYG@tok@c` doesn't seem to have an effect?  

(I'm using minted v3.0.0)
Top Answer
samcarter
... so, rubber duck debugging worked at its finest :duck:

The problem seems to have indeed been that the style file would overwrite my changes. If I smuggle them in later, I get the desired result. Thanks to all the ducks for listening :)

```
\documentclass{article}
\usepackage{minted}

\usemintedstyle{default}

\makeatletter
\AddToHook{env/MintedVerbatim/before}{%
  % optional arguments
  \@namedef{PYG@tok@na}{\def\PYG@tc##1{\textcolor{black}{##1}}}%
  % macros
  \@namedef{PYG@tok@k}{\def\PYG@tc##1{\textcolor{red}{\bfseries ##1}}}%
  % curly brakets
  \@namedef{PYG@tok@nb}{\def\PYG@tc##1{\textcolor{red}{\bfseries ##1}}}%
  % comments
  \@namedef{PYG@tok@c}{\def\PYG@tc##1{\textcolor{gray}{##1}}}%
}
\makeatother

\begin{document}

\begin{minted}{latex}
% a duck
\begin{tikzpicture}
  \duck[cake]
\end{tikzpicture}
\end{minted}

\end{document}
```

![Screenshot 2024-09-30 at 17.18.31.png](/image?hash=ea0d005a8d6faa3499579fcad0064e3f717084e0ecbbd14cbce8fedbdcfde61f)

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.