我正在尝试获取绿色注释和蓝色 javadocs。
但是使用此代码我无法获得蓝色的 javadocs,我总是得到所有绿色的注释:
\usepackage{color}
\definecolor{gray97}{gray}{.97}
\definecolor{gray75}{gray}{.75}
\definecolor{gray45}{gray}{.45}
\definecolor{red}{rgb}{0.6,0,0} % strings
\definecolor{green}{rgb}{0.25,0.5,0.35} % comments
\definecolor{purple}{rgb}{0.5,0,0.35} % keywords
\definecolor{blue}{rgb}{0.25,0.35,0.75} % doc
\usepackage{listings}
\lstset {
frame = Ltb,
framerule = 0pt,
aboveskip = 0.5cm,
framextopmargin = 3pt,
framexbottommargin = 3pt,
framexleftmargin = 0.4cm,
framesep = 0pt,
rulesep = .4pt,
backgroundcolor = \color{gray97},
rulesepcolor = \color{black},
%
stringstyle = \color{red},
showstringspaces = false,
basicstyle = \ttfamily\small,
commentstyle = \color{green},
morecomment = [s][\color{blue}]{/**}{*/},
keywordstyle = \color{purple}\bfseries,
%
numbers = left,
numbersep = 15pt,
numberstyle = \tiny,
numberfirstline = false,
breaklines = true,
}
我使用此代码来打印代码示例:
\begin{lstlisting}[language=C]
/* Includes */
#include <stdio.h>
int main(int argc, char* argv[]) {
puts("Hola mundo!"); // Text console
}
\end{lstlisting}
那我错了吗?谢谢
答案1
这是因为选择language=C
会覆盖您的morecomment
设置。正如列表文档所述:
请记住,两个“额外”注释都必须在正常注释之后定义,因为分隔符是和
/*
的子字符串。/*+
/*-
\lstset
要修复此问题,请在设置之前设置语言morecomment
,morecomment
在使用lstlisting
环境时设置值,或者为设置语言后应用的设置定义一种样式(例如\begin{lstlisting}[language=C,style=mystyle]
)