使用列表导入带有 unicode 的代码文件

使用列表导入带有 unicode 的代码文件

我用 Python 编写了一个程序,总共约 2500 行,我希望将其中的片段包含到我的报告中。通常我都会这样做,listings但在这种情况下,.py文件包含许多 unicode 字符,这些字符对于理解文件是必需的。

这些字符,例如⇒,会导致 latex 中出现这些错误

! Package inputenc Error: Unicode char �\lst@FillFixed@ (U+5B4) (inputenc) not set up for use with LaTeX.
! Package inputenc Error: Keyboard character used is undefined (inputenc) in inputencoding `utf8'.

梅威瑟:

\documentclass[a4paper, 11pt]{report}

\usepackage[utf8]{inputenc} 
\usepackage[english]{babel} % English language/hyphenation
\usepackage{xcolor}
\usepackage{listings}
\usepackage[T1]{fontenc}

\begin{document}
\chapter{Fists Chapter}
Some text
\lstinputlisting[language=Python, inputencoding=utf8, extendedchars=true]{code.py}
\end{document}

.py 文件

def Code(self):
    print("Some code with comments"):
    # Comments with unicode characters 
    # β∠ζπ⇒

相关内容