I want to highlight function name in code, which is a word that ends with left parenthesis, like sqrt(), but don't want to highlight the parenthesis.

Here is what I got so far, I learnt this from Listings - Only highlight between delimiters . It works fine until I indent the statement. And even there are no indent problem, it cannot work on C/C++ or Java where the type before function name is unfixed.

I found a way that can highlight words start with an uppercase here: Can the listings package highlight by regexp?

But I don't really understand the code, not to mention to change it the way I want.


\newcommand{\jsfunction}[1]{\textcolor{blue}{function} \textcolor{purple}{#1}(}
    basicstyle = \ttfamily,
    keywordstyle = \color{blue},
    keywords = {function, return},
    moredelim = [is][\jsfunction]{function\ }{(}


\begin{lstlisting}[style = js]
function foo() {
    function bar(){



enter image description here

  • Should this only work for identifiers that are immediately followed by (), or also for function calls with arguments like foo(x, y, 123)?
    – siracusa
    Jul 22, 2019 at 3:51


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.