I would like to use I macro I have defined (including mathematical symbols) within a listing environment. However, the following code prints "\foo{x}" rather than "bar(x)". Is there any way of achieving the latter output?
\documentclass{article}
\usepackage{listings}
\begin{document}
\newcommand{\foo}[1]{$bar(#1)$}
\begin{lstlisting}
\foo{x}
\end{lstlisting}
\end{document}
bar
and not\bar
?\overbar
or something like that.\overbar
over thex
or even over the parentheses too?