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:
- Main question: how do I get rid of the error and make the LaTeX-file compile correctly?
- 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
\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≤causing the issue. Now, I replaced it with $\leq$ and it works like a charm. – Andreas L. Jan 13 '21 at 12:48\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:54utf8, 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. Withoututf8, latex would have read two characters with code 22 and 64 ... – Rmano Jan 13 '21 at 13:18≤– Andreas L. Jan 13 '21 at 13:39\leqand 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