我有以下 LaTeX 代码:
% !TeX TS-program = xelatex
\documentclass{article}
\usepackage[EU1]{fontenc}
\usepackage{fontspec}
\setmainfont{Times New Roman}
\setsansfont{Arial}
\setmonofont{Courier New}
\usepackage{listings} % or listingsutf8
\lstset{%
language=Python,
basicstyle=\small\ttfamily,
numbers=left,
tabsize=4,
showstringspaces=false,
firstnumber=last,
frame=leftline,
inputencoding=utf8,
}
\begin{document}
\lstinputlisting[linerange={1-24}]{./code.py}
\lstinputlisting[linerange={25-31}]{./code.py}
\end{document}
如下所示code.py
(我添加了注释以澄清所使用的符号):
class Config:
@staticmethod
def _unit_to_inches(s: str) -> float:
s = s.strip()
conversions: Final[Dict[str, float]] = {
'″': 1.0, # one double prime mark (U+2033)
'′′': 1.0, # two prime marks (U+2032)
'"': 1.0, # quotation mark (U+0022)
"''": 1.0, # two apostrophes (U+0027)
'in': 1.0,
'inch': 1.0,
'inches': 1.0,
'ft': 1.0 / 12.0,
'yd': 1.0 / 36.0,
'mm': 25.4,
'cm': 2.54,
'm': 0.0254,
'pt': 72.0,
}
for key, value in conversions.items():
if s.endswith(key):
return float(s[:-len(key)].strip()) / value
return float(s)
def __init__(self, config_filename: Union[str, Path]):
self.averaged_peak_plots_width: Final[float] = \
self._unit_to_inches(c.get('averaged peaks plots', 'width', fallback='6.4″'))
self.averaged_peak_plots_height: Final[float] = \
self._unit_to_inches(c.get('averaged peaks plots', 'height', fallback='4.8″'))
但是,无论使用哪种列表包,XeLaTeX 都会生成以下文档:
在那里,第 25 行和第 26 行末尾,出现了 Python 代码中没有的额外撇号。在第 28 行和第 30 行,撇号出现在数字之前。
到底是怎么回事?