views:

312

answers:

3

Is there a way I can reset the style of a certain character sequence? I'm using the listings package to display source code and the prebreak property to display a escape character \ to indicate that the current lines was broken. The problem is that sometimes the backslash is colored because of the syntax highlighting used.

So I need basically something like a resetstyle statement, as in the following imaginary example:

\textbf{Some bold text \resetstyle{not bold, no color} foo bar}

EDIT: Here are the settings that I'm using via lstset:

\lstset{
        extendedchars           = \true,
        inputencoding           = utf8,
        basicstyle              = \scriptsize\ttfamily,
        breaklines              = true,
        breakindent             = 10pt,
        breakatwhitespace       = true,
        breakautoindent         = true,                         
        prebreak                = \\,
        frame                   = leftline,
        showtabs                = true,                                                                                                    
        numbers                 = left,                                                                                                                                                
        stepnumber              = 2,
        numberstyle             = \footnotesize,
        numbersep               = 10pt,
        keywordstyle            = \color[RGB]{0,0,255},
        commentstyle            = \itshape\color[RGB]{120,120,120},
        stringstyle             = \color[rgb]{0.627,0.126,0.941},
        emphstyle               = {[0]\color[RGB]{236,0,168}},
        emphstyle               = {[1]\color[RGB]{34,139,34}\underbar},
        emphstyle               = {[2]\textbf}
}
A: 

You could try putting the text inside an mbox (untested, but works for math mode):

\textbf{Some bold text \mbox{not bold, no color} foo bar}

You will lose the ability for line breaks inside the text, but in this case that seems to be no problem.

Thomas
Doesn't work :/. Actually nothing happens.
watain
A: 
\def\resetstyle#1{{\normalsize\rm\color[rgb]{0,0,0}\noindent#1}}
Alexey Malistov
Doesn't work for me unfortunately, getting errors like `! Improper discretionary list.`. Maybe that's because it runs into conflicts together with the listing styles?
watain
May be. I need more complex sample to find out the problem.
Alexey Malistov
I added my `lstset` settings. Do you need more information?
watain
A: 

listings uses \discretionary. They say so in the documentation, with a warning not to use dynamic spaces. \color apparently qualifies, as trying to reset the colour failed for me too.

RojSmith