Hi Johannes_B, I actually did come up with the newtcblisting.
My reason for not using different colors and therefore putting the listing in the title slot is, that I have to write a report on about 80 pages using 7-8 different languages. It might be difficult remembering just what color is which language.
Using newtcblisting gives the same error, when I attempt to wrap it in a newcommand.
Her is my newtcblisting:
Code: Select all
\newtcblisting{code}[2]{%
title = {#1},
fonttitle=\sffamily,
listing only,
listing remove caption=false,
colframe = black,
colback = white,
left=6mm,
bottom=-1mm,
top=0mm,
enhanced,
boxrule=0.5pt,
attach boxed title to top left = {xshift=5mm, yshift=-3mm},
boxed title style={colback=white, colframe=white},
coltitle=black,
sharp corners,
listing options={style=#2}
}
My attempt to wrap it in a newcommand (which again gives file ended while scanning for use of \next):
Code: Select all
\newcommand{\codepseudo}[1]{
\begin{code}{Pseudocode}{pseudo}
#1
\end{code}}
\codepseudo{hello}
Johannes_B wrote:Code: Select all
\documentclass{article}
\usepackage[most]{tcolorbox}
\newtcblisting{ccode}[1]{title = {Listing \thetcblisting: #1},
listing only, colframe = blue!50!black,
colback = blue!10, enhanced,
}
\newtcblisting{latexcode}[1]{title = {Listing \thetcblisting: #1},
listing only, colframe = yellow!50!black,
colback = yellow!10, enhanced,
}
\begin{document}
\begin{ccode}{Print hello World}
print ''Hello World''
\end{ccode}
And now we wanna know something else
\begin{latexcode}{Generate a table of contents}
\tableofcontents
\end{latexcode}
\end{document}
Have a look at the tcolorbox documentation, there is much to discover.
The listings as they are now feel like blobs of stuff, closed within themselves. When i look at it, the caption seems lost in space, as if it were alone. Using different colors, one could imply the kind of code from the color and use the title slot for the caption.