I have the idea to combine minted
with tcolorbox
.
At first, I have created my own minted environments:
\newminted[mycsharp]{csharp}{tabsize=2,fontsize=\footnotesize}
\newminted[myjson]{js}{tabsize=2,fontsize=\footnotesize}
\newminted[myxml]{xml}{tabsize=2,fontsize=\footnotesize}
\newminted[myshell]{shell-session}{tabsize=2,fontsize=\footnotesize}
\newminted[mycode]{text}{tabsize=2,fontsize=\footnotesize}
With them I do highlight my code:
\begin{myshell}
[root@localhost ~]# vi /etc/sysconfig/network
\end{myshell}
\captionof{listing}{Load network configuration with vi}
So I get the following:
Now I want to have a nice frame around. Since minted is not so powerful here, I want to use tcolorbox, so I did this:
\begin{tcolorbox}
\begin{myshell}
[root@localhost ~]# vi /etc/sysconfig/network
\end{myshell}
\end{tcolorbox}
\captionof{listing}{Load network configuration with vi}
And I get this one here:
This is nice, but not what I want. After looking in the package documentation of tcolorbox
I found out that it supports titles:
It's getting better. After reading some more, tcolorbox
also has supported for auto numbered titles and a "list of"-support. Unfortunately the provided examples in the documentation do not work, but that's another question.
Okay, now. What do I want to have?
I want to have something like:
\begin{listingsbox}{myshell}{A nice title}
[root@localhost ~]# vi /etc/sysconfig/network
\end{listingsbox}
to get the following output:
Unfortunately I'm not able to write this by self. I tried it using the \newenvironment
macro, but after googeling, it is not easy to integrate minted into a new environment.
Can anyone help me out here?
Best Answer
I had some trouble setting up
minted
with pygments on Windows, but now it seems to run. So, this is my firstminted
text - so, please, forgive me, if I'm doing some nonsense here. Nevertheless, I have found something which may be a ground to build on. The following code uses not exactly your syntax, but creates amyshellbox
instead. Basically, I use thelistings
features oftcolorbox
and trickminted
in at some point:EDIT: It should me mentioned that the created
myshellbox
environment takes an optional parameter, where further options can be put in, e.g.minted language=<something>
orlisting option=<something>
.EDIT: The second solution is a combination of my first solution with Marco Daniel's answer:
Update: Newer versions of
tcolorbox
have integrated support forminted
. Therefore, a more elegant solution with the same output is possible now. I also added a macro\mynewminted
which creates a style fortcolorbox
plus an equally namedminted
environment, if this is needed somewhere else.