4

Perl uses '#' as an introduction for a comment, but also as a format specification. This produces problems in the syntax highlighting in the listings-package. How can I fix it?

\documentclass{article}
\usepackage{listings}
\usepackage{xcolor}
\begin{document}
\lstset{language=perl,commentstyle=\color{red}}
\begin{lstlisting}
#this is a comment
my $n=89;
#the "@###.####" is NOT a comment
format OUT=
@###.#####                         
$n
.
\end{lstlisting}
\end{document}
1

1 Answer 1

2
\documentclass{article}
\usepackage{listings}
\usepackage{xcolor}
\begin{document}

\lstset{language=perl,morecomment=[l][keywordstyle]{@\#},commentstyle=\color{red}}
\begin{lstlisting}
#this is a comment
my $n=89;
#the "@###.####" is NOT a comment
format OUT=
@###.#####
$n
.
\end{lstlisting}
\end{document}
1
  • Perhaps basicstyle should be preferred to keywordstyle here.
    – jub0bs
    Mar 7, 2014 at 11:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .