So I'm trying to render something beautiful for my PHP code using the \lstdefinestyle command.
I think the basic configuration is good, but I would like to highlight the function name to render it in the color normal.
Here is my code:
\documentclass[10pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{listings} % to insert code
\usepackage{xcolor}
\definecolor{background}{RGB}{40, 44, 52} % gris foncé
\definecolor{comment}{RGB}{92, 99, 112} % gris clair
\definecolor{keyworld}{RGB}{86, 182, 194} % cyan
\definecolor{string}{RGB}{152, 195, 121} % vert
\definecolor{identifier}{RGB}{198, 120, 221} % mauve
\definecolor{classic}{RGB}{224, 108, 117} % genre de rouge
\definecolor{normal}{RGB}{171, 178, 191} % blanc
\definecolor{specialkeyworld}{RGB}{229, 192, 123} % jaune orange
\definecolor{veridad}{RGB}{209, 154, 102} % orange jaune
\lstdefinestyle{myPHP}{
language=PHP,
backgroundcolor=\color{background},
basicstyle=\footnotesize\ttfamily\color{normal} ,
keywordstyle=\color{keyworld},
commentstyle=\color{comment},
numberstyle=\color{background},
identifierstyle=\color{classic},
stringstyle=\color{string},
emph =[1]{function,try,return,catch, new},
emphstyle =[1]\color{identifier},
emph =[2]{Exception, PDO},
emphstyle =[2]\color{specialkeyworld},
emph =[3]{true, false},
emphstyle =[3]\color{veridad},
emph =[4]{connectAccess},
emphstyle =[4]\color{normal},
stringstyle=\color{string},
breakatwhitespace=false,
breaklines=false,
keepspaces=true,
numbers=left,
numbersep=4pt,
showspaces=false,
showstringspaces=false,
}
\begin{document}
\begin{lstlisting}[style=myPHP]
/**
* Connect an Access database
* @param string $path Name of the database you want to connect to
* @return PDO object initialise
*/
function connectAccess($path){
try {
$db = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb)}; Dbq=$path;");
return $db;
} catch (Exception $e) {
echo 'Connection failed: ' . $e->getMessage();
return false;
}
}
\end{lstlisting}
\end{document}
and the result :
I would like to replace the two lines
emph =[4]{connectAccess},
emphstyle =[4]\color{normal},
with something that will highlight what is between function and ( without selecting those two, because I will be displaying a lot of code in my document and I dont want to escape the function name each time.
I've tried moredelim=[is][\color{normal}\ttfamily]{function}{(}, but it render like this :
with moredelim=[s][\color{normal}\ttfamily]{function}{(}, the 'function' selector is also rendered in the \color{normal} font...
and I have pretty much the same results with morecomment.
What am I doing wrong? aren't moredelim and morecomment the right parameters to use? if not, what are the original purpose of these two?
Is there a(nother) way to do it or will I have to escape the function name each time?
Thank you for your time and answer, Guillaume


(:– ebosi May 09 '16 at 09:14ty for the typo, it will certainly avoid some ragesearch.
Ok, so neither
moredelimormorecommentwill do it but do you think something else can do the trick?I am quite new to latex so my problem is not only that I do not know where to look, but I don't even know what to look for; but I have faith something exists, in the shadow of my ignorance, and it will answer my needs :-)
– guillaume latour May 09 '16 at 09:29(I wasn't sure the title was relevant so I wanted some confirmation before changing anything)
– guillaume latour May 09 '16 at 09:34