5

When trying to build my LaTeX-file with latexmk in VS Code using Latex Workshop extension, the following error is thrown:

Package inputenc: Unicode character ≤ (U+2264) (inputenc) not set up for use with LaTeX.

This happens even though my LaTeX-file encoding is UTF-8, and the package inputenc is given the option utf8 (see following excerpt of my preamble):

\documentclass[a4paper,fleqn]{cas-sc}

%%%%%%%% SPRACH- UND FONTPAKETE %%%%%%%% \usepackage[english]{babel} \usepackage[utf8]{inputenc}

% * Declare special unicode characters which lead to errors otherwise * % % Docs: https://tex.stackexchange.com/questions/558402/elsevier-paper-article-class-does-not-work-with-all-ascii-characters-and-package \DeclareUnicodeCharacter{00B3}{\textsuperscript{3}} ...

As can be seen, I've already had a problem with another Unicode character 00B3. The character in question this time is "is less than or equal to", i.e. in LaTeX it'd be \leq, or in unicode U+2264.

The affected part in my LaTeX-script appears twice almost in the same way like so:

[...]
The measurement accuracy related to $\textrm{H}_{2}\textrm{S}$ is either $\leq
\pm 3 \, \%$ or $\leq \pm 0.5 \, \textrm{ppm}$, whichever is the greater value.
[...]

Moreover, the literal is present in a table like so:

%% Table containing the problematic literal `≤` %%
\begin{table}[ht]
    \caption{.....}
    \label{tab:...}
    \begin{tabular}{@{}lllllllll@{}}
        \cmidrule(r){1-5}
        ....
        Average percentage of measurements $≤ \, \nicefrac{\textrm{D}}{\textrm{T}} \, (\%)$   & 76.7    & 66.7    & 85.7    & 85.7       \\
        ....
    \end{tabular}
....

Trying to resolve this problem again in the same way as done with the other unicode character, declaring it specifically in my preamble, didn't work out this time:

\DeclareUnicodeCharacter{U+2264}{$\leq$}

I'd like to understand two things:

  1. Main question: how do I get rid of the error and make the LaTeX-file compile correctly?
  2. Optional question: why this error came about in the first place, when it had been working flawlessly all the time before?

System specifics:

Lubuntu 20.04 LTS, VS Code

  • 3
    You must have a literal "≤" in your input file... the $\leq$ will not trigger that error. Could you possibly post a MWE? – Rmano Jan 13 '21 at 12:25
  • 2
    You definitely shouldn't write \DeclareUnicodeCharacter{U+2264}{$\leq$}, but at most \DeclareUnicodeCharacter{2264}{\leq}. But as Rmano pointed out,the origin of the error is something else. – campa Jan 13 '21 at 12:28
  • 1
    @Rmano you were right, I hadn't noticed someone had sent me a word-table, which I converted to a LaTeX-table. Within that, there was a literal causing the issue. Now, I replaced it with $\leq$ and it works like a charm. – Andreas L. Jan 13 '21 at 12:48
  • note that \usepackage[utf8]{inputenc} (which isn't needed in current latex) specifies that latex should interpret the bytes in the file as UTF-8 which is why it recognises ≤ as the character U+2264 it does not mean that latex has rules and fonts loaded to typeset every Unicode character – David Carlisle Jan 13 '21 at 12:54
  • @DavidCarlisle the first part of your comment is clear to me, but the second part "it does not mean that latex has rules and fonts loaded to typeset every Unicode characte" is not. Could you please elaborate a little further what you mean by that? – Andreas L. Jan 13 '21 at 12:57
  • With utf8, LaTeX knows that U+2264 is a single character, but it (by default) done not know how to represent it (you need a suitable font and a suitable declaration, like \DeclareUnicodeCharacter{2264}{\ensuremath{\leq|| for example. Without utf8, latex would have read two characters with code 22 and 64 ... – Rmano Jan 13 '21 at 13:18
  • @campa I've just included the table containing the literal – Andreas L. Jan 13 '21 at 13:39
  • pdflatex has only 256 characters per font, In luatex (as on this website) for character U+2264 then just output that character in the current font, probably makes ≤ but in pdftex you need to know which math font to use and which position in that font, so easiest is not to output the character but outpit the classic markup \leq and then let the normal tex definitions make whatever character is needed. For leq the font is probably already loaded, you just need to map the unicode character correctly, but if you have 你好,世界 (hello world in Chinese) then loading fonts for pdftex is more involved – David Carlisle Jan 13 '21 at 14:02

2 Answers2

4

One solution is to replace your font packages with \usepackage{unicode-math} and compile with LuaLaTeX or XeLateX. This supports all of Unicode.

Another solution that’s compatible with any TeX engine is:

\usepackage{newunicodechar}

\newunicodechar{≤}{\ensuremath{\leq}}

Davislor
  • 44,045
1

As @Rmano pointed out correctly in the first comment of my question, there was an unnoticed literal within a value-table causing the issue.

This came about as I'd incorporated a Word-table which I converted into a LaTeX-table via the LaTeX-table-generator.

The only thing I had to do is replace the culprit literal with $\leq$ to make the document compile with errors.

So beware when inserting contents from external sources into your LaTeX-file as they could contain some unusual characters.

  • 1
    I had the same error, accidentally, when copying a formula I lost the ≤ symbol inside the $a≤5$, when I changed it to $a\leq 5$ the problem was solved. Thanks for the help! – Hugo Cornejo Oct 28 '22 at 14:59