# Devanagari characters and pdflalitex

Running TexLive (most recent version) with local install at ~/texlive on Fedora 20.

MWE:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{helvet}
\renewcommand*{\rmdefault}{\sfdefault}
\begin{document}
करमल
Hello World!
\end{document}


Compiled using pdflatex produces a document with some funny characters viz. àd’Tàd’ˇ ̧ ràd’oàd’š ̋ followed by Hello World!

Obviously I am not doing something right vis-a-vis fonts. What do I need to do to successfully compile a multi-lingual document using pdflatex?

• The T1 font encoding only has 256 characters (all european) so is not suitable, pdflatex can only deal with 256 character 8bit fonts, so either you need a tex setup that exposes the alphabet in that way, or you may find it a lot easier to use xetex or luatex rather than pdflatex which can use system installed unicode fonts and process your utf8 input directly – David Carlisle Oct 15 '14 at 16:34
• @DavidCarlisle first, apologies, I am responding so late. Could you please make that comment as an answer? I can then accept it. – deshmukh Oct 30 '14 at 16:22
• Why you got that nonsensical output: the Unicode input करमल encoded as UTF-8, consists of the following codepoints: (1) DEVANAGARI LETTER KA, encoded as E0 A4 95 (2) DEVANAGARI LETTER RA, encoded as E0 A4 B0 (3) DEVANAGARI LETTER MA, encoded as E0 A4 AE (4) DEVANAGARI LETTER LA, encoded as E0 A4 B2. So what TeX sees are those 9 bytes, each of which it displays according to T1: E0 is à, A4 is ď, etc. – ShreevatsaR May 7 '17 at 0:27

As mentioned by others in this post, T1 fonts come with 256 code points; besides, to the best of my understanding you cannot use Unicode fonts that make use of CTL (Complex Text Layout) features with pdflatex. If your operating system is relatively new, in all probability it already supports Complex Text Layout (CTL). In such a case you may try using xelatex which not only supports CTL but also has built in support for and also OTF and TTF fonts.

If your OS does not support CTL (you see Devangari characters all mixed up like wrong positioning of hrasva-i-matra etc.) or if you want to use only pdflatex , you can still typeset Devanagari, but will a limited set of fonts.

Below are two examples, one for pdflatex and another for xelatex

This is for pdflatex

\documentclass{article}
\usepackage{devanagari}
\begin{document}
\end{document}


N.B. Some distributions have the devanagari package named as velthuis. be sure to check the name. Save the document with the extension .dn (important). run the commands in the order given

$devnag <document>.dn$pdflatex <document>.tex


you should see something similar to --

As for Xelatex -

\documentclass{article}
\usepackage{fontspec}
\setmainfont[Mapping=velthuis-sanskrit]{Sanskrit 2003}
\begin{document}
\end{document}


You can also use direct Unicode Input as in --

\documentclass{article}
\usepackage{fontspec}
\setmainfont{Sanskrit 2003}
\begin{document}
॥श्री-गणेश-शारदा-गुरुभ्यो नमः॥
\end{document}


This is a single go processing; so save the document with the regular .tex extension. xelatex <document>.tex should do the trick, assuming that you have XeTeX also installed (standard issue nowadays with TeXLive and MikTex distributions).

For the second option (with Unicode input) Just remember to delete the[Mapping=...] option or else this will give undesirable results.

Further if you want the standard quotation marks etc. in TeX to work, you will have to replace [Mapping=velthuis-sanskrit] with [Mapping=tex-text]. Also replace Sanskrit 2003 with what ever font you way (it has to installed in the system or in the same directory as your document. In case of the latter, you will have to add the extension aswell {Sanskrit 2003.ttf}

You will get an output similar to

For more information checkout the devanagari package at http://www.ctan.org/pkg/devanagari. This can be used for typesetting Sanskrit aswell as vernacular Languages like Hindi etc. Not sure if Marathi half-ra (chandra-ra) is there included(?).

If you are typesetting pure Sanskrit texts etc. you can also check out the sanskrit package by Charles Wiknet at http://www.ctan.org/pkg/sanskrit.

Preferably you should use modern typesetting tools that support Unicode. XeLaTeX with fontspec and polyglossia should work out of the box. See http://www.ctan.org/pkg/fontspec and http://www.ctan.org/pkg/polyglossia respectively.

Worth mentioning is one itrans(http://www.aczoom.com/itrans/) that came with custom mapping for major Indian languages. This package was used for years for typesetting Sanskrit etc. There are still many sites with Itrans encoded documents, but this package is now pretty much outdated and not maintained anymore; and it is suggested that you do not use it; especially for new documents.

The T1 font encoding only has 256 characters (all european) so is not suitable, pdflatex can only deal with 256 character 8bit fonts, so either you need a tex setup that exposes the alphabet in that way, or you may find it a lot easier to use xetex or luatex rather than pdflatex which can use system installed unicode fonts and process your utf8 input directly.

I'm going to post sample code from this blog post, which got me headed in the right direction.

% 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:
% At least *one* font family must be called \sanskritfont or \devanagarifont,
% so that XeTeX loads all hyphenation and other stuff for Sanskrit.
% Once the Sanskrit intelligence'' is loaded, it can be invoked at
% other places as needed using \selectlanguage{sanskrit}
%
% John Smith's Nakula, input using Velthuis transliteration
\newfontfamily
\sanskritfont [Script=Devanagari,Mapping=velthuis-sanskrit]{Nakula}
% John Smith's Sahadeva, input using Velthuis transliteration
\newfontfamily
% John's Sahadeva, input using scholarly romanisation in Unicode
\newfontfamily
% Microsoft's Mangal font (ugh!), input using standard romanisation in Unicode.
\newfontfamily
\mangalfont [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]{{{\selectlanguage{sanskrit}\sanskritfont #1}}}
\newcommand{\mangaluni}[1]{{{\selectlanguage{sanskrit}\mangalfont #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:
sugataatmajasa.mvaraavataara.m kathayi.syaami yathaagama.m samaasaat||} Bodhicaryāvatāra 1,1.
NB: automatic hyphenation.
\item[2]
A different Devanāgarī font:
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:
{\mangalfont आसीद्राजा नलो नाम वीरसेनसुतो बली|\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:
