Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
1  
give a complete example not only fragments. –  Herbert Mar 7 '11 at 17:31
    
@Herbert here you go –  Amir Rachum Mar 7 '11 at 17:39
1  
I made the MWE smaller by removing all unrelated stuff. It seems that whatever babel does for Hebrew causes the problem (also my computer complains about missing jerus10 font; no idea whether that is related). –  Caramdir Mar 7 '11 at 23:34
    
You might be interested in the matlab-prettifier package; see this answer. –  Jubobs Apr 28 at 15:39

1 Answer 1

up vote 2 down vote accepted

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.