[Tex/LaTex] `backgroundcolor` in `lstset` does not work

hebrewlistingslyx

When I use the backgroundcolor option in lstset, all I get is a colored line above the listing:

\lstset{%
    language=Matlab,
    backgroundcolor=\color{blue}
}

and in the document:

\L{\inputencoding{cp1255}
\begin{lstlisting}[basicstyle={\footnotesize\ttfamily}]
>> x(6)
ans =
 9
\end{lstlisting}
\inputencoding{utf8x}}

and the result:

enter image description here

How can I fix this issue?

I'm using LyX and therefore I'm not sure which lines of code are crucial here.


EDIT: Here's a complete example source as generated by LyX, edited down to make a MWE (the output is the same image as above):

\documentclass[hebrew]{article}
\usepackage[T1]{fontenc}
\usepackage[cp1255]{inputenc}
\usepackage{babel}
\usepackage{listings}
\usepackage{color}

\lstset{%
    language=Matlab,
    backgroundcolor=\color{blue}
}

\begin{document}
\L{
\begin{lstlisting}[basicstyle={\footnotesize\ttfamily}]
>> x(6)
ans =
     9
\end{lstlisting}
}
\end{document}

Best Answer

Amir, it seems as if the old fashioned cp1255/babel are not so robust. Here is an example using xetex. Perhaps you can start from it and work backwards to cp1255 and babel.

\documentclass{article}
\usepackage{listings}
\usepackage{xcolor}
\usepackage{polyglossia}
\setmainlanguage{hebrew}
\setmainlanguage{english}

\lstset{language=Matlab,backgroundcolor=\color{blue}}
\setmainfont{Comic Sans MS}

\newfontfamily\hebrewfont[Script=Hebrew]{Ezra SIL}
   \newfontfamily\listingsfont[
            Extension=.otf,
            UprightFont=*-Regular,
            BoldFont=*-Bold,
            ItalicFont=*-Italic,
            BoldItalicFont=*-BoldItalic,
]{UMTypewriter}

\begin{document}

\let\ttfamily=\listingsfont

\begin{lstlisting}[basicstyle={\footnotesize\ttfamily}]
>> x(6)
ans =
     9
\end{lstlisting}

\LR{
\begin{lstlisting}[basicstyle={\footnotesize\ttfamily}]
>> x(6)
ans =
     9
\end{lstlisting}
}

\lstdefinestyle{numbered}{
    backgroundcolor=\color{blue!20},
    numbers=right,
    stepnumber=1,
    numbersep=-6pt,
    xleftmargin=3ex,
    xrightmargin=3ex,
    numberblanklines=false,
    numberstyle=\tiny\bf,
    frame=trBL,
}
\begin{lstlisting}[style=numbered]
>> x(6)
ans =
     9
\end{lstlisting}
\end{document}

Output