我的定义如下:
\lstset{
commentstyle = \color{gray},
extendedchars = \true,
inputencoding = utf8x,
language = php,
keepspaces = true,
keywordstyle = \bfseries
}
代码如下:
\begin{lstlisting}[language=PHP]
function processRequest()
{
$req = $this->request;
$view = $this->view;
$view->addHeaderScript("scripts/jquery_addons.js");
// doing smth...
return $this->view;
}
但只有if
、else
和foreach
关键词被突出显示。我希望function
和return
关键词也能被突出显示。
答案1
function
并且return
似乎不在 PHP 关键字默认列表中(可以在文件中找到lstdrvrs
);您可以使用以下方式添加它们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}