列表显示斜体引号 - 如何以常规形式打印它们?

列表显示斜体引号 - 如何以常规形式打印它们?

我使用该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}

答案1

引号不是斜体打印的,而是被替换为(右双引号,U+201D)。这是因为您被告知fontspec要为等宽字体启用 TeX 连字,而这些所谓的连字之一正是进行这种替换的。字符(U+201D) 在您选择的字体中呈现为倾斜的引号(不仅如此)。和(右单引号,U+2019)也是如此。'

如果注释掉 选项Ligatures = TeX\setmonofont您将得到以下输出:

在此处输入图片描述

相关内容