在列表环境中发表评论
Comment in listings environment
当我在列表环境中编写我的代码并尝试将“评论”写为评论时,我在我的 pdf 中看到了这个:
breaking#breakingcomment
我想要一个简单的评论作为“#comment”
我不知道为什么,也不知道如何解决问题。
这是我的开始声明:
\lstdefinelanguage{Python}
{
morekeywords={from, import, def, return},
morecomment=[l]{\#},
morestring=[b]",
alsodigit={-},
alsoletter={&}
}
\lstdefinestyle{custompython}{
language=Python,
frame=tlrb,
aboveskip=3mm,
belowskip=5mm,
backgroundcolor=\color{gray},
showstringspaces=true,
columns=flexible,
basicstyle={\small\ttfamily},
numbers=left,
numberstyle=\tiny\color{orange}\ttfamily,
numbersep=5pt,
keywordstyle=\color{Green},
commentstyle=\color{orange},
stringstyle=\color{purple},
commentstyle=\small\color{red}\ttfamily
breaklines=false,
breakatwhitespace=true
tabsize=5
}
这是我在 listings 环境中写的:
\begin{lstlisting}[language=Python, style=custompython, label=code:source, caption = Code]
sers_ind, q, re = 4, 0.7, 1
srcx, srcy = 0, 0
ammasso = lens #comment
sorgente = serSource
\end{lstlisting}
您在 commentstyle
键后缺少 ,
:
\documentclass{article}
\usepackage{listings}
\usepackage{xcolor}
\lstdefinelanguage{Python}
{
morekeywords={from, import, def, return},
comment=[l]{\#},
morestring=[b]",
alsodigit={-},
alsoletter={&},
}
\lstdefinestyle{custompython}{
language=Python,
frame=tlrb,
aboveskip=3mm,
belowskip=5mm,
backgroundcolor=\color{gray},
showstringspaces=true,
columns=flexible,
basicstyle={\small\ttfamily},
numbers=left,
numberstyle=\tiny\color{orange}\ttfamily,
numbersep=5pt,
keywordstyle=\color{Green},
commentstyle=\color{orange},
stringstyle=\color{purple},
commentstyle=\small\color{red}\ttfamily,
breaklines=false,
breakatwhitespace=true,
tabsize=5
}
\begin{document}
\begin{lstlisting}[language=Python, style=custompython, label=code:source, caption = Code]
sers_ind, q, re = 4, 0.7, 1
srcx, srcy = 0, 0
ammasso = lens #comment
sorgente = serSource
\end{lstlisting}
\end{document}
当我在列表环境中编写我的代码并尝试将“评论”写为评论时,我在我的 pdf 中看到了这个:
breaking#breakingcomment
我想要一个简单的评论作为“#comment” 我不知道为什么,也不知道如何解决问题。 这是我的开始声明:
\lstdefinelanguage{Python}
{
morekeywords={from, import, def, return},
morecomment=[l]{\#},
morestring=[b]",
alsodigit={-},
alsoletter={&}
}
\lstdefinestyle{custompython}{
language=Python,
frame=tlrb,
aboveskip=3mm,
belowskip=5mm,
backgroundcolor=\color{gray},
showstringspaces=true,
columns=flexible,
basicstyle={\small\ttfamily},
numbers=left,
numberstyle=\tiny\color{orange}\ttfamily,
numbersep=5pt,
keywordstyle=\color{Green},
commentstyle=\color{orange},
stringstyle=\color{purple},
commentstyle=\small\color{red}\ttfamily
breaklines=false,
breakatwhitespace=true
tabsize=5
}
这是我在 listings 环境中写的:
\begin{lstlisting}[language=Python, style=custompython, label=code:source, caption = Code]
sers_ind, q, re = 4, 0.7, 1
srcx, srcy = 0, 0
ammasso = lens #comment
sorgente = serSource
\end{lstlisting}
您在 commentstyle
键后缺少 ,
:
\documentclass{article}
\usepackage{listings}
\usepackage{xcolor}
\lstdefinelanguage{Python}
{
morekeywords={from, import, def, return},
comment=[l]{\#},
morestring=[b]",
alsodigit={-},
alsoletter={&},
}
\lstdefinestyle{custompython}{
language=Python,
frame=tlrb,
aboveskip=3mm,
belowskip=5mm,
backgroundcolor=\color{gray},
showstringspaces=true,
columns=flexible,
basicstyle={\small\ttfamily},
numbers=left,
numberstyle=\tiny\color{orange}\ttfamily,
numbersep=5pt,
keywordstyle=\color{Green},
commentstyle=\color{orange},
stringstyle=\color{purple},
commentstyle=\small\color{red}\ttfamily,
breaklines=false,
breakatwhitespace=true,
tabsize=5
}
\begin{document}
\begin{lstlisting}[language=Python, style=custompython, label=code:source, caption = Code]
sers_ind, q, re = 4, 0.7, 1
srcx, srcy = 0, 0
ammasso = lens #comment
sorgente = serSource
\end{lstlisting}
\end{document}