HowTo Latex & UTF-8

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
Code:
# 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
Code:
$ 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
Code:
\usepackage{xltxtra}
to preamble (before begin{document} after \documentclass ...) and use xelatex to compile my tex file, it works :D 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
 
I just put this at the top of my .tex files:
Code:
\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.
 
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
 
also for hyphenation to work I need to use
Code:
\usepackage[latvian]{polyglossia}
babel doesn't work for me, as it doesn't have latvian.sty and it doesn't support UFT-8 (AFAIK)
 
On my tex files, i use
Code:
\setmainfont[Mapping=tex-text]{DejaVuSans}
before the
Code:
\begin{document}
statement. So if you know which font has support for latvian, you can replace DejaVuSans with it.
 
Hi, to work with Spanish documents I use the following preamble

Code:
\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.
 
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.
 
Back
Top