# How can I get utf8 character

I want to make cross references for sections to be symbols but after using the description given I got error report saying keyboard character used is undefined in inputencoding 'utf8'. What might be the way out?

-
Welcome to TeX.SX! Can you please add an example of what you're trying to do? –  egreg Sep 1 '12 at 20:59
Does your editor support utf-8 code and have you activated it (for example TeXnicCenter shows the used font in his status line)? –  Kurt Sep 2 '12 at 3:03

If you attempt to typeset utf8 encoded test in LaTeX (with a standard TeX engine underneath) using the inputenc package then the following happens:

• LaTeX will parse an utf8 character by reading in the right number of 8bit characters which may be one or more, depending which character is in the document.
• This will give LaTeX a unicode character with a certain unicode number (after some calculation), say 00A1
• Now LaTeX will attempt to typeset this character, but for doing so, there needs to be a font (loaded) that actually contains the glyph representing the unicode character and ...
• LaTeX needs to know that fact.
• LaTeX learns about this through a fairly large number of declarations of the form: \DeclareUnicodeCharacter{00A1}{\textexclamdown}.
• This translates the unicode number to a LaTeX internal character representation (LICR).
• But this wouldn't be very helpful if there is no glyph that can be used to print this character. Therefore the inputenc package only sets up those unicode characters for which there are fonts loaded that contain them.
• For example, if you load T1 encoded fonts via \usepackage[T1]{fontenc} then internally LaTeX loads all the declarations defined in the file t1enc.dfu. (For every established LaTeX font encoding there is a corresponding .dfu file.)
• But unicode covers a huge number of characters, so if you happen to put one into your document that is not in any font encoding used by LaTeX, then you will end up with the error message telling you this unicode character is not set up.

So what can be done to resolve this for a particular document?

• first step is to identify the unicode number for the character that LaTeX doesn't know about (this should appear in the error message)
• second step, which is a bit more complicated, is to determine if there is any TeX font that actualy contains this character and what the encoding is that this font has. No good advice here, but there are some documents that describe the standard LaTeX font encodings.
• alternatively one can try to add at least the T1 and TS1 encodings to the document as this might resolve the issue (if it is a rather common "western" character).
• it might also be the case that you can "fake" the character, say if you have some kind of hyphen (of which there are several different ones in unicode) and your editor adds one which is not known by LaTeX you might add a \DeclareUnicodeCharacter declaration with the second argument containing a replacement character that does exist.

Otherwise I fear the only answer is use a different character or use a TeX-based engine that is fully unicode enabled and can access unicode fonts with large charactersets natively.

A more elaborate documentation on this can be found in the documented source code: utf8ienc.pdf which is either in the LaTeX distribution or can be generated from the .dtx file.

-

I had the same problem when a friend wanted to typeset a book on Latin poetry and wanted to directly use vowels with length marks such as ō and ŏ (longa and brevis).

The trick I found has been wrapped up in a package, newunicodechar.

Saying

\usepackage{newunicodechar}
\newunicodechar{ō}{\={o}}
\newunicodechar{ŏ}{\u{o}}


is exactly the same as doing

\DeclareUnicodeCharacter{014D}{\={o}}
\DeclareUnicodeCharacter{014F}{\u{o}}


but spares from the burden of hunting through the Unicode table.

Of course one has to make sure that what's in the replacement text can indeed be produced by the fonts we are loading, which might be the case for a "section mark".

Using this package has another advantage; suppose you want to switch to XeLaTeX or LuaLaTeX for processing the document; then a character such as 𝔽 may not correspond to something printable. This particular one depends whether you're loading unicode-math or not; let's assume you're not loading it. A declaration

\newunicodechar{𝔽}{\mathbb{F}}


will be correct in all cases: (pdf)LaTeX, XeLaTeX or LuaLaTeX.

-