I met one problem(maybe three, I will describe them in detail), I'm trying to add code list in latex with listings package. First with limit configuration:
\usepackage{listings}
\definecolor{myblue}{RGB}{20,105,176}
\lstset{ %
language=C, % choose the language of the code
basicstyle=\footnotesize, % the size of the fonts that are used for the code
numbers=left, % where to put the line-numbers
numberstyle=\footnotesize, % the size of the fonts that are used for the line-numbers
stepnumber=1, % the step between two line-numbers. If it is 1 each line will be numbered
numbersep=5pt, % how far the line-numbers are from the code
backgroundcolor=\color{white}, % choose the background color. You must add \usepackage{color}
identifierstyle=\bfseries\color{black},
directivestyle=\bfseries\color{violet},
tabsize=4, % sets default tabsize to 2 spaces
% captionpos=b, % sets the caption-position to bottom
breaklines=true, % sets automatic line breaking
escapeinside={\%*}{*)}, % if you want to add a comment within your code
% Define TYPE-1 Keywords
keywords={},
otherkeywords={\%s, \%d},
keywordstyle=\bfseries\color{violet},
% Define TYPE-2 Keywords
keywordstyle=[2]\bfseries\color{blue}\ttfamily,
keywords=[2]{
auto,break,case,char,const,continue,default,do,double,%
else,enum,extern,float,for,goto,if,int,long,register,%
void,volatile,while,return},
% literate=
% {\{}{{{\color{white}{\{}}}}{1}
% {\}}{{{\color{white}{\}}}}}{1}
% {(}{{{\color{white}{(}}}}{1}
% {)}{{{\color{white}{)}}}}{1}
% {>}{{{\color{white}{$>$}}}}{1}
% {=}{{{\color{white}{$=$}}}}{1}
% {;}{{{\color{white}{$;$}}}}{1},
stringstyle=\color{red}\ttfamily,
commentstyle=\color{blue}\ttfamily,
directivestyle=\bfseries\color{violet},
morecomment=[l][\color{magenta}]{\#}
% escapeinside=!!
}
I show my code above. Use this configuration, everything works fine. Then I need change the background to black, therefore I just change:
backgroundcolor=\color{black},
identifierstyle=\bfseries\color{white},
in above config, but after change, the {, },(,), and other like operators: =, can't be displayed and I think the colour of them keep in black. Therefore, I open the config for literate:
literate=*%
{\{}{{{\color{white}{\{}}}}{1}
{\}}{{{\color{white}{\}}}}}{1}
{(}{{{\color{white}{(}}}}{1}
{)}{{{\color{white}{)}}}}{1}
{>}{{{\color{white}{$>$}}}}{1}
{=}{{{\color{white}{$=$}}}}{1}
{;}{{{\color{white}{$;$}}}}{1},
after this modification, I have one problem, the ) colour can't be changed. therefore, I found some topics here and I found some of people write literate as:
literate=*%
{\{}{{\color{white}{\{}}}{1}
{\}}{{\color{white}{\}}}}{1}
{(}{{\color{white}{(}}}{1}
{)}{{\color{white}{)}}}{1}
{>}{{\color{white}{$>$}}}{1}
{=}{{\color{white}{$=$}}}{1}
{;}{{\color{white}{$;$}}}{1},
with one Pair of { } less in each line. I applied this and it do changed the ) colour, but it makes all rest characters can't be displayed, also the line number display has problem:
I type some characters here and no problem to display
\begin{lstlisting}
\end{lstlisting}
I type some characters here and it can NOT be displayed and I think colour of these characters changed to white.
how can I modify the configuration of listing and solve this issue?
===============UPDATE===============
I just shared a sample code which can reproduce this issue:
\documentclass[a4paper,11pt]{book}
\usepackage{caption}
\DeclareCaptionFont{white}{\color{white}}
\DeclareCaptionFormat{listing}{\colorbox{gray}{\parbox{\textwidth}{#1#2#3}}}
\captionsetup[lstlisting]{format=listing,labelfont=white,textfont=white}
\usepackage{xcolor,colortbl}
\usepackage{listings}
\usepackage{listings}
\definecolor{myblue}{RGB}{20,105,176}
\lstset{ %
language=C, % choose the language of the code
basicstyle=\footnotesize, % the size of the fonts that are used for the code
numbers=left, % where to put the line-numbers
numberstyle=\footnotesize, % the size of the fonts that are used for the line-numbers
stepnumber=1, % the step between two line-numbers. If it is 1 each line will be numbered
numbersep=5pt, % how far the line-numbers are from the code
backgroundcolor=\color{black}, % choose the background color. You must add \usepackage{color}
identifierstyle=\bfseries\color{white},
directivestyle=\bfseries\color{violet},
% showspaces=false, % show spaces adding particular underscores
% showstringspaces=false, % underline spaces within strings
% showtabs=false, % show tabs within strings adding particular underscores
% frame=signal, % adds a frame around the code
tabsize=4, % sets default tabsize to 2 spaces
% captionpos=b, % sets the caption-position to bottom
breaklines=true, % sets automatic line breaking
% breakatwhitespace=false, % sets if automatic breaks should only happen at whitespace
escapeinside={\%*}{*)}, % if you want to add a comment within your code
% Define TYPE-1 Keywords
keywords={},
otherkeywords={\%s, \%d},
keywordstyle=\bfseries\color{violet},
% Define TYPE-2 Keywords
keywordstyle=[2]\bfseries\color{yellow}\ttfamily,
keywords=[2]{
auto,break,case,char,const,continue,default,do,double,%
else,enum,extern,float,for,goto,if,int,long,register,%
void,volatile,while,return},
literate=*%
{\{}{{\color{white}{\{}}}{1}
{\}}{{\color{white}{\}}}}{1}
{(}{{\color{white}{(}}}{1}
{)}{{\color{white}{)}}}{1}
{>}{{\color{white}{$>$}}}{1}
{=}{{\color{white}{$=$}}}{1}
{;}{{\color{white}{$;$}}}{1},
stringstyle=\color{red}\ttfamily,
commentstyle=\color{green}\ttfamily,
directivestyle=\bfseries\color{violet},
morecomment=[l][\color{magenta}]{\#}
% escapeinside=!!
}
\begin{document}
I type some characters here and no problem to display
\begin{lstlisting}[frame=single, label=118x_power_off,caption=213x platform power ON event detection]
int main(/*@ unused @*/int argc, /*@ unused @*/char *argv[]) //comment for lint
{
#if defined(test) //howchen, for SHUTDOWN module
/* test comment, (, ), >, <, -, =, .*/
/* test keyword */
auto,break,case,char,const,continue,default,do,double,
else,enum,extern,float,for,goto,if,int,long,register,
void,volatile,while,return;
item.a[1] = 0;
item->b[1] = 1;
foo();
/* test string */
printf(" >> test <<\r\n");
return 0;
#endif
}
\end{lstlisting}
I type some characters here and it can NOT be displayed and I think colour of these characters changed to white.
\end{document}
pls use above code to see the result.

you can find characters after \end{lstlisting} can't be displayed and line number stop at 1
