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}
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}
  • Perhaps basicstyle should be preferred to keywordstyle here. – jub0bs Mar 7 '14 at 11:06

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.