I'm trying to display some PHP code in a LaTeX document using the listings package. Other languages appear fine (HTML for instance) but PHP seems to be ignoring any strings within the code. The rest of the code appears fine which is what is throwing me off.
I've attached a sample of my document and a screenshot of the output. If anyone can help me I would be really grateful!
LaTeX:
\usepackage{listings}
\usepackage{courier}
\lstset{
basicstyle=\footnotesize\ttfamily,
numberstyle=\tiny,
numbersep=5pt,
tabsize=2,
extendedchars=true,
breaklines=true,
keywordstyle=\color{red},
frame=b,
stringstyle=\color{white}\ttfamily,
showspaces=false,
showtabs=false,
xleftmargin=17pt,
framexleftmargin=17pt,
framexrightmargin=5pt,
framexbottommargin=4pt,
%showstringspaces=false,
%escapeinside={}{}
}
\usepackage{caption}
\DeclareCaptionFont{white}{\color{white}}
\DeclareCaptionFormat{listing}{\colorbox[cmyk]{0.43, 0.35, 0.35,0.01}{\parbox{\textwidth}{\hspace{15pt}#1#2#3}}}
\captionsetup[lstlisting]{format=listing,labelfont=white,textfont=white, singlelinecheck=false, margin=0pt, font={bf,footnotesize}}
and then…
\lstset{language=PHP,caption=Example PHP Code,label=code:sample}
\begin{lstlisting}
public function execute_via_api($api) {
$api->require_authentication();
$total_messages_imported = $this->execute();
return $api->output(array('response'=>$total_messages_imported.' '.inflect($total_messages_imported,'message').' imported'));
} // end func: execute_via_api
\end{lstlisting}
Output:
Best Answer
The culprit is
stringstyle=\color{white}\ttfamily
. After all, seeing white text on a white background is rather hard :).Simply removing
\color{white}
or replacing it by some other color (e.g.,\color{blue}
) will solve the problem.