# How can I tell lstlisting to use sans-serif when escaping to math mode?

Title says it all, an example follows:

\lstset{
mathescape=true,
basicstyle = \sffamily
}

\begin{lstlisting}
func($x_0$)
\end{lstlisting}


Where and how can I set the math font used here to be sans-serif italic?

-

\documentclass[a4paper]{article}
\DeclareMathVersion{sans}
\SetSymbolFont{operators}{sans}{OT1}{cmbr}{m}{n}
\SetSymbolFont{letters}  {sans}{OML}{cmbrm}{m}{it}
\SetSymbolFont{symbols}  {sans}{OMS}{cmbrs}{m}{n}

\usepackage{listings}
\lstnewenvironment{sflisting}[1][]
{\lstset{#1}\mathversion{sans}}{}

\begin{document}

\lstset{
mathescape=true,
basicstyle = \sffamily
}

\begin{sflisting}[caption=Function]
func($x_0$)
\end{sflisting}
\end{document}


This uses the CMBright fonts, which are mostly compatible with CM Sans.

-
 Looks like the right approach, but using it the caption and label doesn't work anymore, see here. "Package Listings Warning: Text dropped after begin of listing on input line 26." – neo Jun 21 '11 at 0:26 @neo: define the environment like this: \lstnewenvironment{sflisting}[2] {\mathversion{sans},\lstset{caption=\lstname#1,label=#2}}{} and use it like: \begin{sflisting}{}{
show 1 more comment
\documentclass[a4paper]{article}
\usepackage{sansmath}
\usepackage{listings}
\lstnewenvironment{sflisting}[1][]
{\lstset{mathescape,basicstyle=\sffamily,#1}\sansmath}
{}
\begin{document}

\begin{sflisting}[caption=Function]
func($\frac1x \mathrm{d}x$)
\end{sflisting}

\end{document}


-
 Works quite good, although sansmath doesn't use sans greek letters which I need. The documentation says to use [eulergreek] to get those in sans, but then unfortunately greek letters are always non-italic, maybe a bug? – neo Jun 21 '11 at 10:39 @neo: with option [eulergreek] they are upright, compare the \beta` symbol with and without the option. – Herbert Jun 21 '11 at 11:10