2

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

8
  • 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 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 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 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 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 at 12:57
3

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}}
1
  • Thanks for pointing out different options. I might consider them in the future, if needed. – Andreas L. Jan 13 at 16:50
0

As @Rmano pointed out correctly in the first command 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.