Perl 使用“#”作为注释的引言,同时也作为格式规范。这会导致 listings-package 中的语法高亮出现问题。我该如何修复它?
\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
\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}