23

Editor's note:

This question addresses a specific case of UTF-8 character not working in LaTeX documents. Refer to Entering Unicode characters in LaTeX for other cases.


It's probably a stupid question, but I cannot find any easy answers online, and the answers are sometimes contradictory.

I am writing a document that uses a few strange alphabets. I want to use some LaTeX variant for typesetting, but nothing works. For example, if I take this document with four example words (one in Russian, one in Czech, one in latin with length indication, one in Vietnamese)

\documentclass[12pt,a4paper]{report}

\usepackage[utf8]{inputenc} \begin{document} Днепр kůň dominī Ngữ \end{document}

and put it through xelatex, which people recommend for Unicode, all I get is this

k domin Ng

which is not exactly what I want.

What is the easiest way of putting UTF-8 encoded file on one side and getting actual text on the other side?

edit:

To add more information.

I am using Ubuntu operating system, and I want to use some font appropriate for a bigger thesis (something like Computer Modern is fine, although I personally prefer Palatino-style fonts)

user202729
  • 7,143
  • 3
    With xelatex you don't load inputenc; but you must load fontspec and use a font that has the required glyphs. – egreg Apr 19 '14 at 22:30
  • ....OK, sorry it sounds stupid, but what does it actually mean? What fonts do I need (and how do I get them), and what language should I specify if I use more of them in the same document? – Karel Bílek Apr 19 '14 at 22:31
  • Instead of saying \usepackage[utf8]{inputenc}, say \usepackage{fontspec}\setmainfont{Arial Unicode}, for example. – Sean Allred Apr 19 '14 at 22:35
  • I will add that I use ubuntu and apt packages (I will add it to the question) – Karel Bílek Apr 19 '14 at 22:35
  • The fontspec package provides macros such as \setmainfont, with which you can select the font that should be used in the document. Do familiarize yourself with the user guide of the fontspec package. Just which font family, or families, you should use is hard to tell without more detailed knowledge of your typesetting needs. – Mico Apr 19 '14 at 22:36
  • @Mico: thanks for answer! I have added more info to the question – Karel Bílek Apr 19 '14 at 22:39
  • Related: https://tex.stackexchange.com/q/172421 https://tex.stackexchange.com/q/201622 https://tex.stackexchange.com/q/377613 https://tex.stackexchange.com/q/45796 https://tex.stackexchange.com/q/394094 https://tex.stackexchange.com/q/235421 – user202729 Sep 14 '21 at 00:25
  • 1
  • @StefanPinnow !? wrong flag, this one is XeLaTeX, the other one discuss pdflatex (although this one discuss Unicode-aware engines, it does not mention the actual issue in this question at all i.e. font does not contain character – user202729 Jun 02 '22 at 15:00
  • @StefanPinnow You are much too trigger-happy. You can't simply close a question with 44 k views. And I urge you to stop closing that much questions without considering the quality of the given answers to this questions. The other day you voted to close a question with an answer by Heiko Oberdieck which was much better than everything given before. – Keks Dose Jun 02 '22 at 15:27
  • @KeksDose • try not to use potentially insulting words. • there's nothing wrong with closing questions as duplicate, as long as the closure is correct. • yes, it's better to close the question with the worse answer as duplicate of the question with the better answer. • If you think the closure is wrong, raise it on meta. – user202729 Jun 02 '22 at 15:37
  • You may check this link. This document discusses the UTF-8 encoding of the ISO-8859-1 set and includes the Latex commands necessary to obtain all the characters in it. – Manuel J. Fernández Iglesias Jun 02 '22 at 10:52

2 Answers2

17

You can use XeLaTeX, but inputenc shouldn't be loaded. Instead use fontspec and define a font that has the required glyphs.

Say you have installed the XITS fonts on your system; then you can do

\documentclass[12pt,a4paper]{report}

\usepackage{fontspec}
\setmainfont[Ligatures=TeX]{XITS}

\begin{document}
Днепр kůň dominī Ngữ
\end{document}

If the font is not installed on the system, it's still possible to use it (you need a full TeX Live)

\documentclass[12pt,a4paper]{report}

\usepackage{fontspec}
\setmainfont[
  Ligatures=TeX,
  Extension=.otf,
  UprightFont=*-regular,
  ItalicFont=*-italic,
  BoldFont=*-bold,
  BoldItalicFont=*-bolditalic,
]{xits}

\begin{document}
Днепр kůň dominī Ngữ
\end{document}

Another easy choice is Linux Libertine:

\documentclass[12pt,a4paper]{report}

\usepackage{libertine} % also loads fontspec

\begin{document}
Днепр kůň dominī Ngữ
\end{document}

enter image description here

For getting real multilingual support, you still need either Polyglossia or babel.

egreg
  • 1,121,712
8

I don't use Ubuntu but Ubuntu should provide a package for Linux Libertine (if it is not installed by default) and that supports all of the languages:

Linux Libertine O

\documentclass[12pt,a4paper]{report}

\usepackage{fontspec}
\setmainfont{Linux Libertine O}

\begin{document}
Днепр kůň dominī Ngữ
\end{document}

To figure out which fonts were installed, I looked in /usr/share/fonts and paid particular attention to the opentype fonts there. I discovered a directory /usr/share/fonts/otf-linux-libertine-ibx/ which contained, for example, /usr/share/fonts/otf-linux-libertine-ibx/LinLibertine_R.otf. Yours will more likely be something like /usr/share/fonts/opentype/LinLibertine-R.otf.

To get basic information about the font, including the name to feed to fontspec:

otfinfo -i /usr/share/fonts/otf-linux-libertine-ibx/LinLibertine_R.otf 

which produced:

Family:              Linux Libertine O
Subfamily:           Regular
Full name:           Linux Libertine O
PostScript name:     LinLibertineO
Version:             Version 5.3.0 
Unique ID:           FontForge 2.0 : Linux Libertine O : 2-7-2012
Designer:            Philipp H. Poll
Designer URL:        http://www.linuxlibertine.org
Manufacturer:        Philipp H. Poll
Vendor URL:          http://www.linuxlibertine.org
Copyright:           Linux Libertine by Philipp H. Poll,
Open Font under Terms of following Free Software Licenses:
GPL (General Public License) with font-exception and OFL (Open Font License).
Created with FontForge (http://fontforge.sf.net)
Sept 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011,2012
License URL:         http://www.fsf.org/licenses/gpl.html AND http://scripts.sil.org/OFL
License Description: GPL- General Public License AND OFL-Open Font License
Vendor ID:           PfEd

To check which scripts (alphabets) the font supports:

otfinfo -s /usr/share/fonts/otf-linux-libertine-ibx/LinLibertine_R.otf 

which gave me:

DFLT            Default
cyrl            Cyrillic
cyrl.SRB        Cyrillic/Serbian
grek            Greek
hebr            Hebrew
latn            Latin
latn.AZE        Latin/Azeri
latn.CRT        Latin/Crimean Tatar
latn.DEU        Latin/German
latn.MOL        Latin/Moldavian
latn.ROM        Latin/Romanian
latn.TRK        Latin/Turkish
math            Mathematical Alphanumeric Symbols

To typeset the languages correctly, you will want to use either polyglossia or babel. It is probably better to try the former first but not all languages are supported. Read the documentation to figure out how to specify and call the languages you need. This will ensure that things like hyphenation are correctly tuned for each of the languages you use in the document.

EDIT

For Linux Libertine specifically, you may be best off loading libertine as explained in egreg's answer. But if you would prefer to use a font you've got which doesn't have a TeX package, you can use the above method to figure out if it is likely to work and how to specify it to fontspec.

cfr
  • 198,882
  • 1
    I have marked @egreg's answer, because the libertine package works the best in my case, but thanks for your answer too for all the info, it will be probably helpful too if I (or someone else looking at this question) will get into trouble later. – Karel Bílek Apr 19 '14 at 22:48
  • 1
    Thanks @KarelBílek. I am pretty sure libertine does some other stuff so it is definitely best to use that in this case. My answer would be more useful if you wanted to use a system font for which there is not a (fontspec-aware) LaTeX support package. I really picked Libertine because I figured you'd be sure to either have it or have easy access to it via apt. So it made a good illustration of how to find stuff out and apply it (should you need or wish to do so.) – cfr Apr 19 '14 at 23:12