Latex rendering unicode plus minus (±) symbol incorrectly

unicode

From what I understand modern latex programs should be able to render unicode characters without any issue. However, the following MWE renders the ± (ord 177 PLUS-MINUS SIGN) character as the ś chracter (ord 347: LATIN SMALL LETTER S WITH ACUTE).

\documentclass{article}%
\usepackage[T1]{fontenc}%
\usepackage[utf8]{inputenc}%
\usepackage{lmodern}%
\usepackage{textcomp}%
\usepackage{parskip}%
%
\usepackage{graphicx}%
%
\begin{document}%
\pagestyle{empty}%
\normalsize%
13.787±0.020%
\end{document}

Running the command:

lualatex --interaction=nonstopmode document.tex

The PDF renders as:

enter image description here

I've also tried:

latexmk --pdf --interaction=nonstopmode document.tex

and

xelatex --interaction=nonstopmode document.tex

And I'ved tried changing \usepackage[utf8]{inputenc} to \usepackage[utf8x]{inputenc}.
The result is the same. Any idea what I'm doing wrong?

For my use-case I'm auto generating a document with pylatex, so it's not as simple as replace the unicode character with \textpm{}. I really do want to be able to render unicode character as-is.

Best Answer

With lualatex you shouldn't set the encoding to T1, also don't load inputenc and textcomp. If you remove everything it will work:

\documentclass{article}%
\usepackage{parskip}%
\usepackage{graphicx}%
\begin{document}%
\pagestyle{empty}%

13.787±0.020%
\end{document}

enter image description here

Related Question