28

I have learn LaTeX for a while. Now, I want to type Indic scripts using Tex and I found that XeTeX is the best because it supports unicode and opentype fonts. But the problem is there are not any single tutorial which gives on how to get XeTeX working. Normally, when a Unicode text file is sent for XeTeX it works but all ligatures and conjuncts are NOT considered. After a long search I found one which uses a mix of romanized way and original devangari, when is posted below as example 1. I just want to type in display as english character are typed for the .tex file as example 2.

Example 1: Using a mix of romanized mapping or something like that.

% This is a Unicode file.
\documentclass[12pt]{article}
\usepackage{multicol} % just to get narrow columns on one page
\usepackage{polyglossia} % the multilingual support package
% for XeLaTeX - includes Sanskrit.
% Next, from the polyglossia manual:
\setdefaultlanguage{english} % this is mostly going to be English text, with
\setotherlanguage{sanskrit} % some Sanskrit embedded in it.
% These will call appropriate hyphenation.
\usepackage{xltxtra} % standard for nearly all XeLaTeX documents
\defaultfontfeatures{Mapping=tex-text} % ditto
\setmainfont{Gandhari Unicode} %could be any Unicode font
% Now define some Devanagari fonts:
% John Smith's Nakula, input using Velthuis transliteration
\newfontinstance
\velthuis [Script=Devanagari,Mapping=velthuis-sanskrit]{Nakula}
% John Smith's Sahadeva, input using Velthuis transliteration
\newfontinstance
\sahadeva [Script=Devanagari,Mapping=velthuis-sanskrit]{Sahadeva}
% John's Sahadeva, input using scholarly romanisation in Unicode
\newfontinstance
\sahadevaunicode [Script=Devanagari,Mapping=RomDev]{Sahadeva}
% Microsoft's Mangal font (ugh!), input using standard romanisation in Unicode.
\newfontinstance
\mangal [Script=Devanagari,Mapping=RomDev]{Mangal}
% Somdev's RomDev.map is used above to get the mapping
% from Unicode -> Devanāgarī. Zdenek Wagner's velthuis-sanskrit.map
% is used to get the Velthuis->Devanāgarī mapping. These are the files
% that XeTeX uses to make all the conjunct consonants without needing
% any external preprocessor (like the old devnag.c program).
% % Set up the font commands:
%
\newcommand{\velt}[1]{{\velthuis \textsanskrit{#1}}}
\newcommand{\saha}[1]{{\sahadeva\textsanskrit{#1}}}
\newcommand{\sahauni}[1]{{\sahadevaunicode\textsanskrit{#1}}}
\newcommand{\mangaluni}[1]{{\mangal\textsanskrit{#1}}}
% \textssanskrit, above, is a Polyglossia command that gets Sanskrit hyphenation right.
% ... and here we go!
\begin{document}
\begin{multicols}{2} % narrow cols to force plenty of hyphenation
\large % ditto.
\begin{enumerate}
\item[1]
With Xe\LaTeX\ it's easy to typeset Velthuis encoded Devanagari like the following example, without using a preprocessor:
\velt{sugataan sasutaan sadharmakaayaan pra.nipatyaadarato 'khilaa.m"sca vandyaan|
sugataatmajasa.mvaraavataara.m kathayi.syaami yathaagama.m samaasaat||} Bodhicaryāvatāra 1,1.
NB: automatic hyphenation.
\item[2]
A different Devanāgarī font:
\saha{sugataan sasutaan sadharmakaayaan pra.nipatyaadarato 'khilaa.m"sca vandyaan|
sugataatmajasa.mvaraavataara.m kathayi.syaami yathaagama.m samaasaat||} Bodhicaryāvatāra 1,1.
\item[3]
Another sentence: \saha{ratnojjvalastambhamanorame.su muktaamayodbhaasivitaanake.su|
svacchojjvalasphaa.tikaku.t.time.su sungandhi.su snaanag.rhe.su te.su||} 2,10.
\item[4]
Now, thanks to Somdev's RomDev.map, we can input in Unicode, using standard scholarly transliteration, and get Devanāgarī generated for us automatically:
\sahauni{āsīdrājā nalo nāma vīrsenasuto balī||\par }
\item[5]
Plain Unicode input, no tricks:
āsīdrājā nalo nāma vīrsenasuto balī||
\item[6]
Plain Unicode romanisation input, no tricks:
\mangaluni{āsīdrājā nalo nāma vīrsenasuto balī||\par }
Plain Unicode Devanāgarī input, no tricks:
{\mangal आसीद्राजा नलो नाम वीरसेनसुतो बली|\par}
\end{enumerate}
\end{multicols}

\noindent
English and Devanāgarī are both doing okay. The only thing that isn't hyphenating well yet is Sanskrit in roman transliteration.

Other nice stuff becomes easy. E.g., define a command \verb|\example| that prints a romanised word in Nāgarī, and then repeats it in romanisation, in parentheses:

\verb|\newcommand\example[1]{\sahauni{#1}~(\emph{#1})}|\newcommand\example[1]{\sahauni{#1}~(\emph{#1})}

Input: \verb|\example{ekadhā}|

Output: \example{ekadhā}
\end{document}
%that's all folks!

Example 2: What I want tutorial to focus on to be like ?

As in standard latex

\documentclass{article}
\begin{document}
\section{संस्कृतम्}
जीवनस्य लक्ष्यमेव संस्कृतस्य वर्धनम्
\subsection{कोऽम्}
संस्कृतं (Sanskrit) पृथिव्‍यां प्राचीना समृद्घा शास्त्रीया च भाषा मन्‍यते। विश्‍ववाङ्‌मयेषु संस्‍कृतं श्रेष्‍ठरत्‍नम्‌ इति न केवलं भारते अपि तु समग्रविश्‍वे एतद्‌विषये निर्णयाधिकारिभि: जनै: स्‍वीकृतम्‌। महर्षिणा पाणिनिना विरचितम् "अष्‍टाध्‍यायी" इति संस्‍कृतव्‍याकरणम्‌ अधुनापि भारते विदेशेषु च भाषाविज्ञानिनां प्रेरणास्‍थानं वर्तते। संस्‍कृतशब्‍दान् एव उत्तरभारते दक्षिणभारते च स्वमातृभाषास्य संयोजयन्‍ति। संस्कृतात् प्राय: सर्वा अपि भारतीयभाषाः उद्भूताः।
\end{document}

What i really what to focus is input of devangari letters in same as that of english letters.

I don't want to write saṁskr̥taṁ (or any romanized tricks) to get संस्कृतं as output.

I just that I type संस्कृतं to get संस्कृतं and you type english in latex to get english as output.

So guys, thanks in advance for reading this much. Is there any nice tutorial and any help for me to get started typesetting devangari unicode with xetex?

  • 1
    I know what i have asked is possible because check this showcase of XeTeX at Sil website at bit.ly/a74MKO . And that is exactly what I wanted. I just want tutorials and help to get started. – Ujjwol Aug 31 '10 at 14:01
  • Hi Ujjwol, admire your "जीवनस्य लक्ष्यम्". :-) For completeness, example 1 is from here, right? You can just link to it here, so that this question is shorter and just asks about the thing you want. – ShreevatsaR Aug 31 '10 at 17:40
  • Could someone translate what the example text means? – Caramdir Aug 31 '10 at 18:35
  • You may have better luck searching the internet using the more common transliteration of the name of the script, "devanagari", instead of your version, which lacks the "a" between "n" and "g". I also suggest changing your post to say devanagari instead, so that searches from Google or on this site will lead to this post. – Willie Wong Aug 31 '10 at 23:27
17

Well example 1 makes quite a great effort (with all this mapping directives) to enable a romanized input. If you don't want this ignore all this code and simply start writing e.g. use something like this

\documentclass{article}
\usepackage{fontspec}
\setmainfont[Script=Devanagari]{your font}
\begin{document}
\section{संस्कृतम्}
जीवनस्य लक्ष्यमेव संस्कृतस्य वर्धनम्
\subsection{कोऽम्}
\end{document}

If you want to write also english (or another script) you will perhaps have to insert font switching commands at the language boundaries.

  • Great ! This is what I was looking for. Thanks again. – Ujjwol Aug 31 '10 at 16:02
10

Use fontspec and polyglossia:

\documentclass{article}

% The fontspec package provides a nice interface to font loading.
\usepackage{fontspec}

% standard packages for XeLaTeX
\usepackage{xunicode}
\usepackage{xltxtra}

% The polyglossia package lets us easily use several languages.
\usepackage{polyglossia}

% Define the used fonts. Replace Nakula and XITS by your font choice.
\newfontfamily\devanagarifont[Script=Devanagari]{Nakula}
\newfontfamily\englishfont[Script=Latin]{XITS}

\setmainlanguage{sanskrit}
\setotherlanguages{english}

% Display counters with Devanagari digits
\makeatletter
\def\devanagarinumber#1{\devanagaridigits{\number#1}}
\let\orig@arabic\@arabic
\let\@arabic\devanagarinumber
\makeatother

\begin{document}

\section{संस्कृतम्}
जीवनस्य लक्ष्यमेव संस्कृतस्य वर्धनम्
\subsection{कोऽम्}
संस्कृतं \textenglish{(Sanskrit)} पृथिव्‍यां प्राचीना समृद्घा शास्त्रीया च भाषा मन्‍यते। विश्‍ववाङ्‌मयेषु संस्‍कृतं श्रेष्‍ठरत्‍नम्‌ इति न केवलं भारते अपि तु समग्रविश्‍वे एतद्‌विषये निर्णयाधिकारिभि: जनै: स्‍वीकृतम्‌। महर्षिणा पाणिनिना विरचितम् "अष्‍टाध्‍यायी" इति संस्‍कृतव्‍याकरणम्‌ अधुनापि भारते विदेशेषु च भाषाविज्ञानिनां प्रेरणास्‍थानं वर्तते। संस्‍कृतशब्‍दान् एव उत्तरभारते दक्षिणभारते च स्वमातृभाषास्य संयोजयन्‍ति। संस्कृतात् प्राय: सर्वा अपि भारतीयभाषाः उद्भूताः।

\end{document}

This renders as (compiled with xelatex)

rendered example

I can’t verify whether the output is correct, but it seems to be fine (Latin ligatures work).

You might want to define a shortcut for \textenglish, e.g.

\newcommand\eng[1]{\textenglish{#1}}

NOTE: If you are using a binary package installation of TeX Live, like in Debian/Ubuntu, you will need to replace

\newfontfamily\englishfont[Script=Latin]{XITS}

with

\newfontfamily\englishfont[Script=Latin]{xits-regular.otf}

Original solution, expanded on Ulrike’s answer:

\documentclass{article}

% The fontspec package provides a nice interface to font loading.
\usepackage{fontspec} 

% Set the main font to Nakula (a Devanagari font I found on my system).
\setmainfont[Script=Devanagari]{Nakula}

% Define the \latinfont command to switch to the XITS font for Latin text
\newfontfamily\latinfont[Script=Latin]{XITS}
% Define the \eng command as a localized version of \latinfont
\newcommand\eng[1]{{\latinfont #1}}

\begin{document}

\section{संस्कृतम्}
जीवनस्य लक्ष्यमेव संस्कृतस्य वर्धनम्
\subsection{कोऽम्}
संस्कृतं \eng{(Sanskrit)} पृथिव्‍यां प्राचीना समृद्घा शास्त्रीया च भाषा मन्‍यते। विश्‍ववाङ्‌मयेषु संस्‍कृतं श्रेष्‍ठरत्‍नम्‌ इति न केवलं  भारते अपि तु समग्रविश्‍वे एतद्‌विषये निर्णयाधिकारिभि: जनै: स्‍वीकृतम्‌। महर्षिणा पाणिनिना विरचितम् "अष्‍टाध्‍यायी" इति संस्‍कृतव्‍याकरणम्‌ अधुनापि भारते विदेशेषु च भाषाविज्ञानिनां प्रेरणास्‍थानं वर्तते। संस्‍कृतशब्‍दान् एव उत्तरभारते दक्षिणभारते च स्वमातृभाषास्य संयोजयन्‍ति। संस्कृतात् प्राय: सर्वा अपि भारतीयभाषाः उद्भूताः।

\end{document}
  • The ligatures is perfect. The output is great ! I checked with different Sanskrit OpenType Fonts, it is awesome. Hope it will get me started. – Ujjwol Aug 31 '10 at 16:06
  • But when I changed the first line to \documentclass[a4paper,40pt]{article} there was no changes reflected in the document. – Ujjwol Aug 31 '10 at 16:07
  • And even I need to change the section number to Devangari like instead of 1 संस्कृतम् it should be १ संस्कृतम् । Any fix for this. – Ujjwol Aug 31 '10 at 16:08
  • What if I don't what that Devangari Unicode font to be main font for the document ? If I need to just add two three lines in that font when all other text is Latin ? – Ujjwol Aug 31 '10 at 16:19
  • 1
    The standard article class only supports 10pt, 11pt and 12pt. If you want to use anything else, classes like memoir or the KOMA-Script classes are preferable. – Caramdir Aug 31 '10 at 16:24
1

Look at the following example:

    \documentclass{article}
    \usepackage{polyglossia}
    \setdefaultlanguage{sanskrit}
    \setmainfont[Script=Devanagari, Mapping=devanagarinumerals]{Devanagari font of your choice}
    \setotherlanguage{english}
    \newfontfamily\englishfont{Latin font of your choice}
    \newcommand\eng[1]{\textenglish{#1}}
    \begin{document}
    जीवनस्य लक्ष्यमेव संस्कृतस्य वर्धनम्
    \subsection{कोऽम्}
    संस्कृतं \eng{(Sanskrit)} पृथिव्‍यां प्राचीना समृद्घा शास्त्रीया च भाषा मन्‍यते।
    विश्‍ववाङ्‌मयेषु संस्‍कृतं श्रेष्‍ठरत्‍नम्‌ इति न केवलं भारते अपि तु समग्रविश्‍वे एतद्‌विषये
    निर्णयाधिकारिभि: जनै: स्‍वीकृतम्‌। महर्षिणा पाणिनिना विरचितम् "अष्‍टाध्‍यायी"
    इति संस्‍कृतव्‍याकरणम्‌ अधुनापि भारते विदेशेषु च भाषाविज्ञानिनां प्रेरणास्‍थानं वर्तते।
    संस्‍कृतशब्‍दान् एव उत्तरभारते दक्षिणभारते च स्वमातृभाषास्य संयोजयन्‍ति। संस्कृतात्
    प्राय: सर्वा अपि भारतीयभाषाः उद्भूताः।
  \end{document}

I think, that this is the simplest example that usage polyglossia and which

  • allows to use Sanskrit as the main language of your document, and English as other language,
  • tells fontspec that the script of the main font is Devanagari, thus, Devanagari ligatures are chosen,
  • chooses Devanagari numerals everywhere except inside the math environments and \eqref command; please let me know if there some other environment that chooses the Arabic numerals in this setting (to get Devanagari numerals in the math environment and \eqref command, use \setdefaultlanguage[numerals=devanagari]{sanskrit}).

Now you are ready to go with typing a Sanskrit-document! After this, you may use other packages like fontspec and xltxtra. While using some fonts, e.g. Mukta, you may come across the issue that the footnote numbers do not behave appropriately. In this case, add the parameter no-sscript to the package xltxtra. You may have a look at the handbook that describes the use of Polyglossia for Indian languages; the handbook it is written in Marathi using Polyglossia itself.

Since the ldf files for most of the Indian languages, including Sanskrit, are complete one has to complete them, as much as possible, on ones machine to use Polyglossia smoothly.

Finally, I would like to add a remark: using a language for setting a (Xe)LaTeX document is more advisable than using a script (unless it is unnecessary).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.