# Listings package: including punctuation in “emph” list

I'm typesetting some examples of a system which has this sort of look:

In:  2+2
Out: 4


and I'd like to emphasis the "In:" and "Out": This works:

\begin{lstlisting}[basicstyle=\ttfamily,emph={In,Out},emphstyle=\bfseries]
In:  2+2
Out: 4
\end{lstlisting}


but this:

\begin{lstlisting}[basicstyle=\ttfamily,emph={In:,Out:},emphstyle=\bfseries]
In:  2+2
Out: 4
\end{lstlisting}


where I want to include the colons in the emphasis, doesn't. I've experimented with including alsoletter={:} in the options, to no effect.

Is there a simple way to achieve this?

Note, I am in fact using listings as part of a new environment defined with the tcolorbox package. So:

\newenvironment{pyth}{%
\tcblisting{listing only,colback=vlgray,colframe=vlgray,enhanced,
overlay={\node[draw,fill=black,xshift=-10pt,yshift=4pt,left,text=white,
anchor=east,font=\footnotesize\bfseries]
at (frame.south east) {Python};},%
listing options={alsoletter={:},emph={In:,Out:},emphstyle=\bfseries,
basicstyle=\small\ttfamily,breaklines=true,language=Python},}}
{\endtcblisting}


and then in my text:

\begin{pyth}
In:  2+2
Out: 4
\end{pyth}


In this particular environment alsoletter appears to have no effect.

-
Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. –  Jubobs May 5 at 11:22

alsoletter={:} does work:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{listings}
\usepackage{beramono}

\begin{document}

\begin{lstlisting}[basicstyle=\ttfamily,alsoletter={:},emph={In:,Out:},emphstyle=\bfseries]
In:  2+2
Out: 4
\end{lstlisting}

\end{document}


## Update after the question edit:

Specify the language first:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{beramono}
\usepackage[many]{tcolorbox}
\tcbuselibrary{listings}

\colorlet{vlgray}{gray}% just for the example, since the original definition was not included

\newenvironment{pyth}
{%
\tcblisting{
listing only,
colback=vlgray,
colframe=vlgray,
enhanced,
overlay={
\node[
draw,
fill=black,
xshift=-10pt,
yshift=4pt,
left,
text=white,
anchor=east,
font=\footnotesize\bfseries
]
at (frame.south east) {Python};
},%
listing options={
language=Python,
alsoletter={:},
emph={In:,Out:},
emphstyle=\bfseries,
basicstyle=\small\ttfamily,
breaklines=true,
},
}
}
{\endtcblisting}

\begin{document}

\begin{pyth}
In:  2+2
Out: 4
\end{pyth}

\end{document}


I used the beramono package in my example just to have a mono-spaced boldfaced font. I used \colorlet{vlgray}{gray} for the example, since the original definition was not included in the question.

-
Thanks, I've added more info to my original post which may explain a bit better why I'm not getting the output I want. –  Alasdair May 4 at 4:43
@Alasdair please see my updated answer showing a possible solution using your settings. –  Gonzalo Medina May 4 at 5:03
Thank you! Putting the language first works perfectly. Thank you again for your time and trouble! –  Alasdair May 4 at 5:20
@Alasdair Be aware that making : a "letter" has consequences. For instance, if you've defined for to be a keyword, then listings won't highlight it in for:. –  Jubobs May 4 at 10:44