4

This code

% !TEX encoding = UTF-8 Unicode
% !TEX TS-program = pdflatex
\documentclass{article}
    \usepackage{siunitx}
    \usepackage[utf8]{inputenc}
        \DeclareUnicodeCharacter{2190}\leftarrow % ←
\begin{document}
    $←$
\end{document}

generates error

Undefined control sequence \textleftarrow 

How can this (that is redefined as textleftarrow) happen without any warning?

Symbol 1
  • 36,855
  • Thanks @marmot. Thanks @PhelypeOleinik; and it seems SIunits defines as well; just it does not overwrite my DeclareUnicodeCharacter. – Symbol 1 Sep 27 '18 at 23:16

1 Answers1

2

This happens because siunitx uses the TS1 encoding for some symbols. Somewhere in siunitx.sty you have:

\AtBeginDocument {
  \cs_if_free:cT { T@TS1 }
    {
      \DeclareFontEncoding { TS1 } { } { }
      \DeclareFontSubstitution { TS1 } { cmr } { m } { n }
    }
}

and this loads the ts1enc.dfu file which contains:

\DeclareUnicodeCharacter{2190}{\textleftarrow}

which redefines the arrow, as you diagnosed.

In fact, without siunitx, the utf8 macro for is:

\u8:← ->\IeC {\leftarrow }

and with siunitx is is changed to:

\u8:← ->\IeC {\textleftarrow }

A hackish way of preventing siunitx from loading ts1enc.dfu is by tricking the \cs_if_free:cT with something like:

\def\T@TS1{\NothingUseful}

but right before posting the above as an answer, I found this another answer by Joseph Wright saying that if you load textcomp, siunitx will no longer load ts1enc.dfu, so you have:

% !TEX encoding = UTF-8 Unicode
% !TEX TS-program = pdflatex
\documentclass{article}
\usepackage{textcomp}
\usepackage{siunitx}
\usepackage[utf8]{inputenc}
\DeclareUnicodeCharacter{2190}\leftarrow % ←
\begin{document}
    $←$
\end{document}
  • I am satisfied with your explanation. Although I do not quite understand why ts1enc.dfu uses \textleftarrow as a substitute while the later is undefined. – Symbol 1 Sep 27 '18 at 23:50
  • @Symbol1 Curious indeed... Maybe it's supposed to be used by font packages which define \textleftarrow. – Phelype Oleinik Sep 27 '18 at 23:53