[Tex/LaTex] Package inputenc: Unicode character ≤ (U+2264) (inputenc) not set up for use with LaTeX – Error caused by unnoticed literal “≤”

compilation errorinput-encodingsmath-operatorsunicode

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

Best Answer

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}}