1

I'm having problems with the lstlistings package. I need to create my own language definition in which I have the keyword 'test' but also need to escape the keyword highlighting in one particular spot where it's part of a name 'variable test'. I've set a delimiter but it doesn't work as I expected it to. 'test' still gets highlighted as keyword. I've already tried using invisible delimiters but with the same result.

\documentclass{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage{color}
\usepackage{listings}
\lstdefinelanguage{script}{
    keywords={test,
    },
    morecomment=[s]{'}{'},
    morestring=[b]",
    sensitive=false,
}
\lstdefinestyle{default}{
    inputencoding=utf8,
    extendedchars=\true,
    backgroundcolor=\color[HTML]{FEFDFF},
    breaklines=true,
    frame=single,
    keepspaces=true,
    keywordstyle=\color{blue},
    commentstyle=\color{orange}\emph,
    numbers=left,
    breakatwhitespace=false,
    moredelim=[s][basicstyle]{variable}{test},
}
\begin{document}
\begin{lstlisting}[style=default,language=script]
variable test
\end{lstlisting}
\end{document}

enter image description here

PS: I've basically just replaced the space with an underscore. It's not the most elegant solution, but it works.

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.