Saturday, February 22, 2014

देवनागरी लेटेक, LaTeX Devanagari

Except the introduction, rest of the article is in English.
Visit this post (click here) to see the final solution for LaTeX Devanagari.  
 
गणिती सूत्रे, संज्ञा, आकृत्या ह्या नित्याच्या किबोर्डवर नसतात. आकडे सोडूनही बरेच काही गणिती लिखाणासाठी वापरले जाते. मायक्रोसोफ़्ट ऑफिस किंवा ओपन ऑफिस अशा नित्याच्या लेखन साधनांवरही हे लिखाण करणे जड असते. यावर उपाय म्हणून डोनाल्ड क्नुथ यांनी टेक (TeX) हा प्रोग्रॅम बनवला. पुढे TeX मध्ये काही सुधारणा करून लेज्ली ल्यम्पोर्ट (हा बुवा आहे, बर का!) LaTeX बनवले. च उच्चार टेक आणि चा उच्चार लेटेक असा करतात. गणिताचेच नाही तर इतरही लिखाण करणे, अतिशय उत्तम संपादन करता येणे, पारंपारिक फोन्ट आणि एडिटिंगच नव्हे तर हायपरलिंक, ग्राफिक्स, प्रोग्रामिंग या सोयीसुद्धा लेटेक मध्ये आहेत. गणित-फिजिक्स पुरते मर्यादित न राहता सध्या संशोधन क्षेत्रामध्ये जवळ जवळ सर्वच शाखा लेटेक चा वापार करू लागल्या आहेत. लेटेक मध्ये सर्व महत्वाच्या भाषा, (जवळ जवळ सर्व) युरोपियन भाषा लिहिता येतात. पण दोन वर्षांपूर्वी मी शोध घेतला तेव्हा लेटेक मध्ये देवनागरी कसे लिहायचे हे अगदी भारतामध्ये ही मला कोणी सांगू शकले नाही! मागे खटपट करून मी ते शिकलो. आताशा मला बरेच मित्र विचारू लागले आहेत आणि केवळ मी नाही तर अनेक जणांना हा प्रश्न पडला आहे म्हणून ठरवले की लेटेक देवनागरीवर लेख लिहायचा. त्यामुळे जर तुम्ही लेटेक वापरत नसाल तर लेख सोडून द्या. शिवाय लेटेक देवनागरी साठी सर्व भारतातून प्रश्न विचारले जात असल्याने मी हा लेख इंग्रजीत लिहायचे ठरवले आहे. जेणेकरून जास्तीत जास्त लोकांना फायदा होईल. गरजूंना पुढे पाठवला तर उत्तमच! अस्तु, सुरुवात करतो.
लेखाच्या शेवटी मी आणि अभयने देवनागरी लेटेक वापरून लिहीलेला एक लेख उदाहरणादाखल दिला आहे. या लेखाची टेम्पलेट मी बनवली होती, आणि बरचसे लिखाण अभयने केले आहे. खाली दिलेल्या गुगल  ड्राइव्हच्या लिंकवर जाऊन हे उदाहरण डाउनलोड करा. हात साफ करून घेण्यासाठी हा लेख पुरेसा आहे.

LaTeX Devanagari



(At the end of the article is a GoogleDrive link of a folder that contains an example of LaTeX Devanagari article. The readers may download and play around with the example.)

    We know that package Babel supports lots of languages in latex. It not only allows to insert special characters from foreign languages, but also edits the text according to rules for the language. A question many latex users in India ask is if LaTex provide the facility to write Devanagari? Answer to this question is positive. In this article I shall discuss two methods of writing devanagari text in LaTex. 

If you have heard about package Babel, the news is that Babel does support Devanagari Hindi. But devanagari for Marathi, Sanskrit (modern) and Nepali is not exactly same as devanagari Hindi. For example, अ in Marathi or Sanskrit looks like अ but in traditional Hindi it looks more like hybrid of प्र and त्र. Same for Nepali. Hindi uses फ as well as फ़. Where as neither Nepali or Sanskrit not Marathi have फ़. The full stop in Sanskrit, Hindi and Nepali is given by a दण्ड - the symbol । and in Marathi it is the usual dot. Due to these differences a good typography software for Devaganari must be clever enough to please users from different language. One should also consider the fact that each language has their own beloved fonts. For example Sanskrit look beautiful in quill pen font. Hence Babel is not the universal solution for Devanagari.

What is it then? 
The answer is the Devanagari for TeX = devnag package. This package was developed by Frans Velthuis, University of Groningen, The Neatherlands.

I shall explain how to use this package using LaTeX and XeLeTeX.

Install the package: First check if your LaTeX already has this package. TeXLive on Windows, TeXShop on Mac or Kile in Ubuntu have their small programs that lists all the packages you have. As per my experience this package is included in the standard TeX setup. If not then it can be found on Comprehensive TeX archive network= CTAN. The original developer's page is Sarovar Devanagari. Both links are listed at the end of the article.

Using LaTeX

Step 1 (Writing the tex file): Open your text editor. Make a new a file. Copy paste the following matter in it:
\documentclass{article}
\usepackage{devanagari}
\begin{document}
  {\dn
maajhe devanaagarii le.tek devanagariice prayoga..

mere le.tek devanaagarii ke prayoga|
}
\end{document}
Save this document with an ending .dn, for example TrialDev.dn
TeX editors usually save file with .tex ending. Editors like Emacs ask you to put the ending. If your editor saves the file with .tex ending close the file in editor and change name form .tex to .dn.

Step 2 (Processing the file): Open terminal and process this file using command devnag. Those who do not know how to do it, just open the terminal in your system. Write devnag. Press space bar once. Then hold the file with cursor and drop it in front of devnag command. Now press enter. If drag-drop doesn’t work write the path to file manually.

This produces a file having same name as your .dn file but it has ending .tex in the same folder where the .dn file is kept. In our case we will get TrialDev.tex. You can see the tex file. It looks like:
\def\DevnagVersion{2.15}\documentclass{article}
\usepackage{devanagari}
\begin{document}
    {\dn
mAJ\? l\?V\?\qq{k} d\?vnAgrFc\? \3FEwyog\314w


m\?r\? l\?V\?\qq{k} d\?vnAgrF k\? \3FEwyog.
}
\end{document}
As you can see the tex file makes no sense.
Process this text file like usual using pdfLaTeX. This would produce following PDF:

How does it work?
The command \documentclass{article} is the usual command that tells TeX to write an article. The \usepackage tell that TeX should use the devanagari package. In the document environment the command \dn tells that the devanagari package should process only the text that is bound by the braces around \dn which means only the text inside {\dn ...} written where he three dots are will be processed by devnag. Outside that it behaves like usual TeX. So if you write outside it you shall get English document. You can use math mode here. Coming back to \dn. TeX does not support devanagari font. So we have to transliterate. How to transliterate? The rules are given in the manual on page 6. Manual can be found by command texdoc devanagari. Its link is also given bellow. So to get रोहित I type rohita because r = र्, o = काना+मात्रा or ओ,  h= ह्, i= र्हस्व वेलान्टी or इ , t= त् वेलान्टी ta= त. Look at the transliteration rules. They are very logical and resemble the ones we se on Google. But they are more acute than Google transliterator when it comes performance. Some exceptions are like ii is ई and I is also ई or aa and A both mean आ.

How to write ज्ञ? :)

Full stop is a special character for devanagari package-- .o stands for ॐ. So if a Marathi user uses '.' for fullstop he/she will get a error message. To get usual full stop write two dots-- '..' gives '.'  .

What are other usual characters which are special characters here? " ~
A good exercise would be-- find out how to write these character without using verbatim environment or verb command :) For example two dots give full stop, what gives inverted commas?

Analyze the example above. TeialDev.dn is file for devanagari package. TeX cannot process it directly. You can try following: change the .dn ending to .tex and process the file. What happens? Its crazy, right?

Terminal processes this file and gives a TeX processable file, namely, TrialDev.tex. This is the file which is understandable by TeX and its compilation gives the desired PDF output.

If you are a Mac user then instead of using this whole process you can use Bernard Desgraupes' small app called MacDevnag, the link is given bellow. After writing a mail last year Bernard Desgraupes was kind enough to update the old version which is now compatible to Mac OS Lion and onwards.

Devanagari package offers many fonts like bombay (good for Marathi, Sanskrit users), calcutta (Hindi and north Indian Sanskrit style), nepali (for Nepali) and calligraphy like penbombay.

One of the beauty of this package is that it offers those beautiful Vedic macros. They allow to have Anudattas or even count value of a place like in Samaveda (see manual).
Shanti matra written using Vedic macros

Using XeLaTeX

 XeLaTeX is a variant of TeX which is now available on all standard editors like Emacs, Aquamacs, TexShop. On the header of your editor you can see LaTeX tab somewhere. Click it and it should show options like Bibtex, XeLaTex, LuaTeX. From the choose XeLaTeX. Following is the minimal Preamble I have found out to process a devanagari file.
\documentclass[a4paper]{article}
\usepackage{fontspec}
\usepackage[hindi]{babel}
\setmainfont[Script=Devanagari,Mapping=velthuis]{Font}
\catcode`\~=12
Replace Font by the font of your choice. Some of the available fonts are Sanskrit 2003, Sahadeva, Nakul. Write this preamble and write a transliterated document as above. Do not write \dn command. The preamble says that the whole contents inside is a feed to devnag package.Save this file with a .tex ending. Now simply process it using XeLaTex (usual processing cmmand just instead of LaTex use XeLaTeX). And there you go... the pdf is produced!
Example: To get this output:
Sorry as this example is in Marathi. This is one of the old trail example.
I was lazy enough to translate it :/


I used this contents (copy paste this content and execute XeLaTeX command):
\documentclass[a4paper]{article}

\usepackage{fontspec}
\usepackage[english, hindi]{babel}
\setmainfont[Script=Devanagari,Mapping=velthuis-sanskrit]{Sanskrit 2003}
%\mangalfont [Script=Devanagari,Mapping=RomDev]{Mangal}
%Bihani, Kirati, Kruti Dev Display 440, DevLys 380 Condensed Regular
\catcode`\~=12

\begin{document}
\section{vibhAga}
mitraho, malA uttara sApa.dale Ahe. udAhara.nAdakhala he likhA.na pa.thavata Ahe.\\
hyA .tAIpase.tI.mgacA phAyadA.
\begin{enumerate}
    \item kI ithe sArakhe  devanAgarIcI kamA.m.da dyAvI lAgata nAhI. 
    \item sagaLe Aka.de devanAgarIta yetAheta. 
    \item phAIla .tarmInalavara vegaLI ka.mpAIla karAyacI garaja nAhI.
    \item bharapUra phA/.ta upalabdha Aheta (hA sa.msk.rta 2003 Ahe).
    \item pur.navirAmAcA pra"sna su.talAya! :)
        \begin{enumerate}
        \item A.ni hI eka bhArI bAta, ekAta eka Aka.de Ale kI barobara na.mbarI.mga badalate!
        \item ithe ga.nitachii sutre lihi.nyaabaabata maatra tho.daa
go.mdhaLa aahe. kaara.na khaaliila sutra uttama disate,
\[
\int f(x)\, d(x) = \phi^{k(t)^2}
\]
para.mtu nityaachyaa niyamaapramaane jara ".dii" laa .teks.ta-apa kele tara maatra haa go.mdhaLa hoto,
\[
\int f(x)\, \textup{d}(x) = \phi^{k(t)^2}
\]
      \end{enumerate} 
\end{enumerate}

\subsection{upa-vibhAga}
dona mahAtvAce pra"sna rAhileta.
\begin{enumerate}
    \item devanAgarI ni ii.mgrajI kase ekatra lihAyace he malA  ajuna kaLale nahIye.
    \item durdaivane hyA paddhatInehI "bImara" devanAgarImadhe banavAtA yeta nahIye! :(
    
\end{enumerate}
astu, mala mAgIla dravi.dI pra.nayAmAhUna hec bare va.tateya! varIla paikI pahilA pra"sna su.tela lavakara a"sI A"sA Ahe!
\end{document}
   This is an easier way. In the preamble you may use the standard XeLaTeX packages like xltxtra. I am not yet very familiar to XeLaTeX. But you may go through its manual. It have beautiful fonts available. Note that in this example I have used I instead of ii, A instead of aa at some places.

 Dominik Wujastyk gives an example exhibiting power of XeLaTeX devanagari. See bellow. Unfortunately, have not been able to work out his example completely.

Comparing Devanagari LaTeX and XeLaTeX

    LaTeX Devanagari and XeLaTeX Devanagari both have some benefits and losses. First obvious one is that the way of processing document in LaTeX is surely more cumbersome than the one offered by XeLaTeX. The fullstops in LaTeX freak me out, as I am not used to type one dot as a full stop. One can make sections, subsections, chapter names in Devanagari using LaTeX Devanagari. Advance users can also reset the counters so that page numbering, (sub)sections, chapter are numbered in Devanagari. I haven’t tried resetting numbering in enumerate though. But this all needs lots of efforts. Where as, an example above shows, XeLaTeX takes care of the numbering, page layout without efforts. This is really nice. Plus XeLaTeX has a bigger collection of modern fonts like Nakul, Sahadeva. It can also accept input written in devanagari as Dominik shows.

    The problems in LaTeX devanagari can be overcome easily once you have a nice Preamble made for yourself. For example define newcommands like: \dnbp for \dn\dnpenbomay  or \dnsection for
\renewcommand\thesection{\devanagari{section}}, reset counters in preamble itself and then life would be very easy.

The biggest drawback of XeLaTeX for me is that I have not yet been able to insert math mode in devanagari environment perfectly (see above example). This is better in LaTeX. One can use command {\dn ...} and outside it its normal LaTeX. So you can add math things there and then come back again to Devanagari. Not only Math mode but it allows you to write any foreign language in the same document-- just add babel package and use \foreiglanguage command. I don't know how to do this is XeLaTeX. One should also remember that XeLaTeX is still though of as an experimental variant. Both the programs cannot use Devanagari characters for variables in math mode.

What I do is, for purely Devanagari writings I use XeLaTeX and for abstracts for Marathi talks or documents which need only my name, I use LaTeX to add Devanagari.

Abhijeet once told me that he wants to write preface for his thesis in Marathi or Sanskrit. A solution would be make the introduction page in English. Then use LaTeX to add your Devanagari preface on one of the page. Then get the corresponding tex file and keep using it for later work. Just take care that you do not touch the material influenced by \dn command. Other who are interesting in this could also use this trick.


Links to resources

  1. Devanagari at CTAN: https://www.ctan.org/tex-archive/language/devanagari/velthuis/?lang=en
  2. Sarovar Project: http://devnag.sarovar.org/
  3. Manuals and examples: ftp://ftp.tex.ac.uk/tex-archive/language/devanagari/velthuis/doc/generic/velthuis/
  4. MacDevnag of Bernard Desgraupes: http://bdesgraupes.pagesperso-orange.fr/sanskrit.html
  5. Dominik Wujastyk's XeLaTeX example at Chikitsa: http://cikitsa.blogspot.de/2010/07/xelatex-for-sanskrit.html 

∆  ∆

Friday, February 21, 2014

लेखमलिकेस एक वर्ष पूर्ण झाले! (आणि पहिला व्हिडीओ!)

लेखमलिकेस एक वर्ष पूर्ण झाले!

ही मालिका का सुरु केली?
मराठीच का?
असल्या लिखाणासाठी प्रोत्साहन देण्याचा विचारही कोणत्या "नगांनी"  केला? 
वाचकांचा प्रतिसाद कसा आहे?
पुढील बेत?


या प्रश्नांची उत्तरे खालील चित्रफीत  देइन. साधारण पावणे आठ मिनीटांची आहे ती:


पहिलाच प्रयोग आहे, बर्याच चुका दिसताहेत. पुढे त्या सुधरण्याचा प्रयत्न करीन. बोलताना "कंटेंट" कडे बरेच ध्यान द्यावे लागेल नि व्हिडीयो जास्त स्पष्ट दिसेल असे करावयास हवे.

अस्तु, हॅव अ मस्त रवीवार!