Tell me more ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question

1 Answer

\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}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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