listings provides the possibility to escape to LaTeX inside a listing, see section 5.12 Escaping to LaTeX of the manual for details. The basic idea is to set an escapechar which switches to LateX and back:
escapechar=<tokens> which sets one or more characters
<tokens> for starting and ending the escape you can also use
escapebegin=<tokens1>,escapeend=<tokens2> if you want two different characters/strings
<tokens2> for begin and end.
<tokens2> also can be the same tokenlist. (Tests suggest that if
<tokens> is longer than one token it cannot only contain the same token – I haven't determined a definite pattern behind this behaviour, though, and the manual doesn't seem to say anything about it.)