[Tex/LaTex] Problem with ẽ tilde and UTF8

font-encodingstildeunicode

I have a problem with the following character

ẽ: e with tilde

I am using UTF-8 encoding and I get the following error

! Package inputenc Error: Unicode char \u8:ẽ not set up for use with LaTeX.

I am aware of this solution: \~e but the problem is that the that concerns me is the name of an author that is inside a bibtex that is automatically generated by mendeley…

I could, however, modify it in mendeley and cahnge for \~e, but is not a very elegant solution…

Anyway, I can let go this and simply replace it for e if there is no solution. I am just curious as to why UTF-8 does not handle this? I thougth UTF-8 handled every possible character.

MWE:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\begin{document}

This does not work:  ẽ

This works: \~e

\end{document}

Best Answer

The range of Unicode characters is quite large. Therefore utf8.def limits itself to the characters that can be displayed using one of the font encodings that are loaded. The disadvantage that some characters, that can be constructed via accents can slip through. Therefore \DeclareUnicodeCharacter allows to add these characters:

\usepackage[utf8]{inputenc}
\DeclareUnicodeCharacter{1eBC}{\~E}
\DeclareUnicodeCharacter{1EBD}{\~e}

Addition (see egreg's comment):

Package newunicodechar provides \newunicodechar that declares the character without specifying its explicit code number:

\usepackage[utf8]{inputenc}
\usepackage{newunicodechar}
\newunicodechar{Ẽ}{\~E}
\newunicodechar{ẽ}{\~e}

Also version 1.3 of package selinput (updated on CTAN with next bundle release, .dtx is attached and the .sty file extracted by running plain tex on the .dtx file) provides this feature via \DeclareInputUnicodeChar. The following example adds a key value interface for setting the Unicode characters, making it easier to type, if lots of additional Unicode character declarations are needed:

\usepackage[utf8]{inputenc}
\usepackage{selinput}[2012/09/29]
\usepackage{kvsetkeys}
\makeatletter
\kv@parse{
  Ẽ=\~E,
  ẽ=\~e,
}\DeclareInputUnicodeChar
\makeatother

The new version 1.12 of inputenx will add support for these characters by

\usepackage[utf8]{inputenc}% or inputenx
\input{ix-utf8enc.dfu}% 2012/11/12 or later needed