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.

I have definitions as below:

\lstset{
    commentstyle = \color{gray},
    extendedchars = \true,
    inputencoding = utf8x,
    language = php,
    keepspaces = true,
    keywordstyle = \bfseries
}

And here's the code:

\begin{lstlisting}[language=PHP]
        function processRequest()
        {
            $req = $this->request;
            $view = $this->view;
            $view->addHeaderScript("scripts/jquery_addons.js");
            // doing smth...
            return $this->view;
        }

But only if, else and foreach keywords are highlighted. I want function and return keywords also to be highlighted.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

function and return seem not to be in the PHP keyword default list (which can be found in the file lstdrvrs); you can add them using morekeywords:

\documentclass{article}
\usepackage{xcolor}
\usepackage{listings}

\lstset{language=PHP,
    commentstyle = \color{gray},
    extendedchars = \true,
    inputencoding = utf8x,
    keepspaces = true,
    keywordstyle = \bfseries,
    morekeywords={function,return}
}

\begin{document}

\begin{lstlisting}
        function processRequest()
        {
            $req = $this->request;
            $view = $this->view;
            $view->addHeaderScript("scripts/jquery_addons.js");
            // doing smth...
            return $this->view;
        }
\end{lstlisting}

\end{document}

enter image description here

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.