提问人:Gabriele Troviso 提问时间:1/15/2022 最后编辑:ppperyGabriele Troviso 更新时间:1/26/2022 访问量:2439
列表环境中的评论 [已关闭]
Comment in listings environment [closed]
问:
当我在列表环境中编写代码并尝试将“注释”写为注释时,我在我的 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
}
这是我在列表环境中写的:
\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}
答:
1赞
samcarter_is_at_topanswers.xyz
1/15/2022
#1
您缺少密钥之后的密钥:,
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}
评论
0赞
Gabriele Troviso
1/19/2022
幸运的是,这是一个简单的错误。谢谢!
0赞
samcarter_is_at_topanswers.xyz
1/19/2022
@GabrieleTroviso 不客气!
评论