I have the following LaTeX code:
% !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}
The code.py is the following (I've added comments to clarify the symbols used):
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″'))
However, XeLaTeX produces the following documents regardless of the listing package used:
There, at the line 25 and at the end of the line 26, there are extra prime marks that are not in the Python code. At the lines 28 and 30, the prime marks appeared before the numbers.
What is going on?

"after6.4and4.8are not an ascii doubleqoute but instead unicode double prime. That probably messes up everything. Listings can handle some utf8 if it can be mapped to latin1, this cannot. – daleif Jul 10 '20 at 08:24″as a listings literal and get it to work correctly (untested) – daleif Jul 10 '20 at 08:25alsoletter={″}causes an error in XeLaTeX. – StSav012 Jul 10 '20 at 08:26literate, see this answer, https://stackoverflow.com/questions/1116266/listings-in-latex-with-utf-8-or-at-least-german-umlauts, you'll have to specify what the latex equivalet for this char is. – daleif Jul 10 '20 at 08:36literateoption. – Ulrike Fischer Jul 10 '20 at 08:43literate={’}{{'}}1 {″}{{"}}1did nothing. @UlrikeFischer, your comment just blows my mind: > With xelatex + lualatex chars with unicode positions below 256 will work out of the box – StSav012 Jul 10 '20 at 08:56