我使用该listings
包来显示源代码。我刚刚意识到,双引号和单引号打印在斜体- 应打印在常规的相反...问题出在哪里?是否有我忽略的配置?
有什么想法吗?感谢您的意见!
我定义了自己的列表样式如下:
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{HTML}{F5F5F5}
\lstdefinestyle{codestyle}{
backgroundcolor=\color{backcolour},
commentstyle=\color{codegreen},
keywordstyle=\color{magenta},
numberstyle=\tiny\color{codegray},
stringstyle=\color{codepurple},
basicstyle=\ttfamily,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
numbers=left,
numbersep=5pt,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=2
}
\lstset{style=codestyle}
我还加载了 Jetbrains-MonoFont(可以下载这里):
%JetBrains Mono-Font für Code
\setmonofont{JetBrains Mono}[
Path = ./Fonts/Code/,
Extension = .ttf,
UprightFont = *-Regular,
BoldFont = *-Bold,
ItalicFont = *-Italic,
BoldItalicFont = *-BoldItalic,
Contextuals = Alternate,
Ligatures = TeX,
]
\lstset{
basicstyle = \ttfamily,
columns = flexible,
}
\makeatletter
\renewcommand*\verbatim@nolig@list{}
\makeatother
完整文档:
\documentclass[a4paper, liststotoc]{scrreprt}
%Packages
\usepackage[bmargin=4cm,tmargin=2cm,headheight=5cm]{geometry} %Seitenränder definieren
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[ngerman, english]{babel}
\usepackage{glossaries}
\usepackage[colorlinks, urlcolor=blue, linkcolor=black, citecolor=black]{hyperref}
\usepackage[german, noabbrev, nameinlink]{cleveref} %Automatische Verweise mit \cref{} oder \cpageref{} auf \label{}. Bei englischer Arbeit muss "german" durch "english" ersetzt werden.
\usepackage{float} %Unterdrückt das Fliessen eines Bildes wenn statt "h" "H" als float angegeben wird.
\usepackage{pdfpages}
\usepackage{amstext}
\usepackage{lineno}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{makeidx}
\usepackage{listings}
\usepackage[round, comma, sort&compress]{natbib} %Bibliografie
\usepackage{fancyhdr}
\usepackage{lipsum}
\usepackage{fontspec}
\usepackage{listings}
%------------------------------------------------------------------------------------------------%
%Konfigurationen
%JetBrains Mono-Font für Code
\setmonofont{JetBrains Mono}[
Path = ./Fonts/Code/,
Extension = .ttf,
UprightFont = *-Regular,
BoldFont = *-Bold,
ItalicFont = *-Italic,
BoldItalicFont = *-BoldItalic,
Contextuals = Alternate,
Ligatures = TeX,
]
\lstset{
basicstyle = \ttfamily,
columns = flexible,
}
\makeatletter
\renewcommand*\verbatim@nolig@list{}
\makeatother
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{HTML}{F5F5F5}
\lstdefinestyle{codestyle}{
backgroundcolor=\color{backcolour},
commentstyle=\color{codegreen},
keywordstyle=\color{magenta},
numberstyle=\tiny\color{codegray},
stringstyle=\color{codepurple},
basicstyle=\ttfamily,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
numbers=left,
numbersep=5pt,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=2
}
\lstset{style=codestyle}
%------------------------------------------------------------------------------------------------%
\begin{document}
\begin{lstlisting}[language=Python, caption=Python example]
import numpy as np
@property
def serialize(self):
"""Return object data in easily serializeable format"""
return {
'id': self.id,
'name': self.name,
'description': self.description,
'program_type': self.program_type,
'url': self.url,
'auth': self.auth.serialize
}
\end{lstlisting}
\end{document}