4

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.

8
  • 1
    I get his from your example i.stack.imgur.com/qaATU.png. Is your tex system up-to-date? (side remark: with a current latex neither inputenc not textcomp are needed) Dec 18, 2021 at 18:04
  • 2
    Oh, you are using lualatex. Then don't use \usepackage[T1]{fontenc}, that is the wrong encoding for lualatex. Dec 18, 2021 at 18:14
  • It's relatively recent: Running lualatex --version I get: This is LuaHBTeX, Version 1.12.0 (TeX Live 2020/Debian). Do you have a newer version? The textcomp and inputenc are coming from pylatex, but that's good to know. I did try manually without them and I got the same result. Marjin's answer works for me though.
    – Erotemic
    Dec 18, 2021 at 18:15
  • I am away from computer but just tried your example on overleaf and got a plusminus symbol Dec 18, 2021 at 18:15
  • @DavidCarlisle lualatex not pdflatex ... Dec 18, 2021 at 18:16

1 Answer 1

6

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

4
  • It would be nice if fontenc would show a warning about this though.
    – Marijn
    Dec 18, 2021 at 18:21
  • All of your near-real-time responses has been amazing 🚅! Thank you ♥
    – Erotemic
    Dec 18, 2021 at 18:23
  • 1
    For anyone else using pylatex, removing these packages can be accomplished via kwargs of Document: e.g. pylatex.Document(fontenc=None, lmodern=False, textcomp=False)
    – Erotemic
    Dec 18, 2021 at 18:25
  • 1
    @Erotemic pylatex should probably not add them by default if it's using luatex Dec 19, 2021 at 0:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .