# HowTo Latex & UTF-8



## graudeejs (May 30, 2010)

Yesterday I started installing TexLive 2009 (http://code.google.com/p/freebsd-texlive/)
Finally today it was finished, so I had a chance to test my test.tex file 

*Problem*
I'm native Latvian speaker so I need Latvian character (Ä“Å«Ä«ÄÅ¡Ä£Ä·Ä¼Å¾ÄÅ†) support in my UTF-8 tex files. I was battling this for few hours. *tex just didn't want to cooperate.

The real problem is that LaTeX don't have proper fonts to render my characters, or it has, but I don't know how to load them (yet)


*Solution 1*
So I figured 1st way around:
I figure, if latex can compose characters lets use sed to translate Latvian UTF-8 characters to codes, that latex understands.

lv-uft8.sed

```
# Ar Å¡Ä« faila un sed komandas  palÄ«dzÄ«bu var vienkÄrÅ¡Ä veidÄ piespiest
# LaTeX saprast latvieÅ¡u simbolus failÄ ar UTF-8 kodÄ“jumu
# LietoÅ¡anas piemÄ“rs
# 	sed -f lv-uft8.sed in.tex > out.tex
# PÄ“c komandas izpildÄ«Å¡anas, out.tex var nodot LaTeXam
#
# Izveidoja:	Aldis Berjoza <aldis@bsdroot.lv>
# Datums:	30.05.2010

s/Ä“/\\={e}/g
s/Å«/\\={u}/g
s/Ä«/\\={\\i}/g
s/Ä/\\={a}/g
s/Å¡/\\v{s}/g
s/Ä£/\\v{g}/g
s/Ä·/\\c{k}/g
s/Ä¼/\\c{l}/g
s/Å¾/\\v{z}/g
s/Ä/\\v{c}/g
s/Å†/\\c{n}/g
s/Ä’/\\={E}/g
s/Åª/\\={U}/g
s/Äª/\\={I}/g
s/Ä€/\\={A}/g
s/Å /\\v{S}/g
s/Ä¢/\\c{G}/g
s/Ä¶/\\c{K}/g
s/Ä»/\\c{L}/g
s/Å½/\\v{Z}/g
s/ÄŒ/\\v{C}/g
s/Å…/\\c{N}/g
```
so now I could

```
$ sed -f lv-uft8.sed in.tex > out.tex
$ pdflatex out.tex
```
and it worked. The solution is far from perfect, but this will work with any older latex realisation. It will also work, if you don't have proper fonts to render correct characters (this doesn't work for Chinese however  )

*PROS:*
* Will work probably on any LaTeX, even on old ones

*CONS:*
* works only for latin
* hyphenation won't work for word, where "special" characters are used

*Solution 2 - recommended*
About hour later I found the real solution to the problem.
I found out, that If I add

```
\usepackage{xltxtra}
```
to preamble (before *begin{document}* after *\documentclass* ...) and use xelatex to compile my tex file, it works  I could see my native characters on resulting pdf. As I understand this lets xelatex use system fonts to render characters

for hyphenation use *\usepackage[latvian]{polyglossia}* {replace latvian with your lang}

*Resources:*
http://wiki.lyx.org/LyX/XeTeX

See also:
http://en.wikibooks.org/wiki/LaTeX/Accents
http://spectroscopy.mps.ohio-state.edu/symposium_53/latexinstruct.html


----------



## Oxyd (May 30, 2010)

I just put this at the top of my .tex files:
	
	



```
\usepackage[czech]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
```
And it just works. (I save the .tex file as UTF-8.) Even hyphenation is done correctly, including words with our national characters and obeying our Czech hyphenation rules. I'm using print/teTeX -- don't know about other flavours of TeX, though.


----------



## graudeejs (May 30, 2010)

with texlive it doesn't work for me.
Ant it seams it still doesn't have Latvian hypen... support in bable.... grrrrrrrrrr will have to fix that


also tetex in base was no go when I tried it few years a go. I was lucky I managed to get it working with Latin 15 char set


----------



## graudeejs (May 31, 2010)

also for hyphenation to work I need to use

```
\usepackage[latvian]{polyglossia}
```
babel doesn't work for me, as it doesn't have latvian.sty and it doesn't support UFT-8 (AFAIK)


----------



## vrachil (Jun 1, 2010)

On my tex files, i use

```
\setmainfont[Mapping=tex-text]{DejaVuSans}
```
before the 

```
\begin{document}
```
statement. So if you know which font has support for latvian, you can replace DejaVuSans with it.


----------



## jm2dev (Jun 3, 2011)

Hi, to work with Spanish documents I use the following preamble 


```
\documentclass[10pt,a4paper]{article}
\usepackage[utf8x]{inputenc}
\usepackage{ucs}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{eurosym}
\usepackage[spanish]{babel}
\usepackage[pdftex]{graphicx}
```

saving documents in utf-8.


----------



## mix_room (Jun 10, 2011)

Perhaps this is of help to you? 

http://home.lu.lv/~drikis/TeX/



			
				killasmurf86 said:
			
		

> with texlive it doesn't work for me.
> And it seams it still doesn't have Latvian hypen... support in bable.... grrrrrrrrrr will have to fix that



Fixing Babel doesn't seem too hard. After having a look at the German one, it seems as though it is mainly a question of replacing some lines in a text file.


----------

