# Transliteration of sanskrit or devanagari texts using polyglossia or other packages

I wanted to know if there is a way to transliterate devanagari texts within LaTeX itself. I have been using the wonderful polyglossia package, and I am able to enter Unicode devanagari texts into LaTeX and compile them. No problems. However, I was wondering if there is a way for LaTeX to convert Unicode devanagari fonts into romanized transliteration? The rules for devanagari transliteration are pretty well standardized, but I have not seen a package that does the transliteration in LaTeX--so that I don't have to keep making adjustments to both the devanagari and the transliteration each time.

If anyone has any suggestions about doing this in LaTeX, or even best practices outside of LaTeX, I would really appreciate it.

-
Welcome to TeX.sx! –  Torbjørn T. Jan 5 '12 at 22:06

You can use xetex input mapping feature. It is used to typeset transliterated devanagari. Other example is RomDev, for input in unicode transliteration. I haven't find any map file for conversion in the opposite direction, but it was not difficult to modify the RomDev map to go in the other way.

teckit_compile DevRom.map


Copy the resulting file DevRom.tec somewhere xetex can find it and run texhash.

Usage sample:

\documentclass{standalone}
\usepackage{polyglossia}
\setdefaultlanguage{english}
\setotherlanguage{sanskrit}
\usepackage{xltxtra}
\usepackage{fontspec}
\setmainfont{Gentium}
\newfontfamily\devanagarifont[Script=Devanagari]{nakula.ttf}
\newfontfamily\devtransl[Script=Roman,Mapping=DevRom]{Gentium}
\begin{document}
\def\devanagarisample{%
उदु ज्योतिरमृतं विश्वजन्यं विश्वानरः सविता देवो अश्रेत् ।
क्रत्वा देवानामजनिष्ट चक्षुराविरकर्भुवनं विश्वमुषाः ॥ १ ॥
प्र मे पन्था देवयाना अदृश्रन्नमर्धन्तो वसुभिरिष्कृतासः ।
अभूदु केतुरुषसः पुरस्तात्प्रतीच्यागादधि हर्म्येभ्यः ॥ २ ॥
}
%\devscript
\noindent\textsanskrit\devanagarisample

\devtransl
\noindent\devanagarisample
\end{document}


Output:

Important lines are

\newfontfamily\devanagarifont[Script=Devanagari]{nakula.ttf}
\newfontfamily\devtransl[Script=Roman,Mapping=DevRom]{Gentium}


where we define font command for print devanagari using polyglossia and command for printing of the transliteration.

If you want output using another transliteration method, you can easily adjust map method yourself there are lines in the form

U+093D <> U+0027 ;unstyled apostrophe


where is the input code, then output code and comment after the semicolon. Just swap input and output code.

-
Oh excellent. Thanks so much. I will let you know how it goes. –  krishnab Jan 13 '12 at 17:37
To make it visually pretty and scroll easily can you crop the .png and update your post. Thanks –  texenthusiast Jan 8 '13 at 18:06
pdfcrop fileName.pdf at the command line terminal generates cropped pdf fileName-crop.pdf. Other approach might be to use standalone class instead of article class. It generates cropped pdf automatically generally used for Tikz Pictures. –  texenthusiast Jan 9 '13 at 5:46