Showing posts with label XeLaTeX devanagari. Show all posts
Showing posts with label XeLaTeX devanagari. Show all posts

Wednesday, February 11, 2015

LaTeX Devanagari-III

Visit this post (click here) to see the final solution for LaTeX Devanagari.

This is the third article about LaTeX Devanagari. In the previous article about LaTeX Devanagari (click here for the article) I gave a code for a XeLaTeX book document. The code was customised to write a book in Marathi. But there were tips to change the customisation to any other devanagari using language. In the article I give a LaTeX code for the same document and discuss the differences. I would insist you to have a look at the last article before you start reading this.
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.

The best way to learn LaTeX is to play with it! :)

LaTeX Devanagari

  1. Create a new empty file in you LaTeX editor. Copy the code bellow and paste it to the file. Save the file in a folder. Name the file with a .dn ending and NOT with .tex. For example Devanagari-book.dn .  
  2. Save .png picture in the same folder and this .dn file. Name the picture Image.png.
  3. Open the terminal and type the command \devnag. Then tpye the path of the above file after the command. If that is hard, then simple drag the file from the folder and drop in front of the command.
  4. Press enter.
  5. Now a file with .tex ending can be seen the folder.
  6. Open this .tex file and run using LaTeX. Run it at least twice (may be thrice) to get a proper index in the output PDF.
  7. If you do not like the font either remove \dnpenbombay or replace it with \dnbombay.
  8. Important note(s): 

  • The file could have some typos, as I am not yet very comfortable with the Velthuis style of transliteration. But care should be taken for श which is written as "s  . Because, some editors change " to `` automatically. This makes the output look like "स् .
  • Remember, in XeLaTeX Devanagari a dot . means a full stop. But in LaTeX Devanagari . is a special character and having a single dot gives an error (but not for .s which stands for ष). The terminal would read, Illegal character . found on line number XYZ. The full stop for LaTeX Devanagari is dotdot, that is, .. This produces a stop.


The screenshots and explanations for this code are same as in the last article, excpet that the font changes. Click here for that. At the end we discuss differences between LaTeX and XeLaTeX codes.

LaTeX aslo sufferes from same nested list and page counting issues as XeLaTeX.

\documentclass{book}
\usepackage{devanagari}
\usepackage{graphicx}%package for including graphics
\usepackage{setspace}%to manage spacing between two lines
\usepackage{enumitem}

%Changing the titles of standard parts in LaTeX to Devanagari
\def\abstractname{{\dn\dnpenbombay sArA.m"sa}}
\def\appendixname{{\dn\dnpenbombay pri"sI.s.ta}}
\def\contentsname{{\dn\dnpenbombay vi.saya sUcI}}
\def\chaptername{{\dn\dnpenbombay dha.dA}}
\def\tablename{{\dn\dnpenbombay taktA}}
\def\figurename{{\dn\dnpenbombay citra}}
\def\listfigurename{{\dn\dnpenbombay citrA.mcI yAdI}}
\def\listtablename{{\dn\dnpenbombay taktyA.mcI yAdI}}

%Changing the counter and the arabic numerals in the counter to the Devanagari numerals
\pagenumbering{devanagari} %page numbers
\renewcommand\thechapter{\devanagari{chapter}}
\renewcommand\thesection{\devanagari{chapter}. \devanagari{section}}
\renewcommand\thesubsection{\devanagari{chapter}. \devanagari{section}. \devanagari{subsection}}
\renewcommand\thefigure{\devanagari{chapter}. \devanagari{figure}}
\renewcommand\thetable{\devanagari{chapter}. \devanagari{table}}

%Document info
\title{\LaTeX{\dn\dnpenbombay{} devanAgarItIla pu.dhIla prayoga}}
\author{{\dn\dnpenbombay rohita dilIpa hoLakara}}
\datemodernhindi{\date{\today}} %I dont know if Marathi is available


%Page Layout
\usepackage[inner=2cm,outer=2cm]{geometry}%left-right margin

\onehalfspacing %increases spacing between two lines to 1.5

%Main document begins

\begin{document}
\let\MakeUppercase\relax
\maketitle %making the default title page
\tableofcontents % making the default table of contents


\chapter*{{\dn\dnpenbombay prastAvanA}}

\verb+\chapter{name of the chapter}+
{\dn\dnpenbombay kamA.m.da buka envhAyarname.n.tamaDeca vAparatA yete ni tI tIna kAme karate.. pahile kAma he, kI hI kamA.m.da }
Chapter
{\dn\dnpenbombay mha.najeca `prakara.na' ki.mvA `Da.dA' hA "sabda lihIte.. dusare ase, kI prakara.nAce nAva tI mo.thyA ak.sarAta A.ni vegaLyA u.mcIvara lihIte.. tisare ni mahatvAce kAma he, kI prakara.ne moja.nyAsa.thI tI kA{}un.tara surU karate.. yA tIna paikI dusare kAma spesi.mgace Ahe ni itara kAmA.mmaDe lipI mahatvAcI Ahe..}
\verb+\def\chaptername{{+\verb+\dn+\ \verb+name of your choice}}+
{\dn\dnpenbombay vAparUna `c~ap.tara' "sabdA{}aivajI kAya have te .tharavatA yete.. jase kI mI `Da.dA' hA "sabda vAparalA Ahe.. tumhAla have tara `prakara.na' ki.mvA `kavitA' vA `aDyAya', asA ko.natAhI "sabda vAparatA yeIla..}
\verb+\renewcommand\thechapter{\devanagari{chapter}}+
{\dn\dnpenbombay vAparUna kA{}u.m.tara devanAgarIta .tAkatA yeto..}

{\dn\dnpenbombay
prastAvanA lihI.nyAsA.thI nehamIpramA.ne}~\verb+\chapter+*~{\dn\dnpenbombay vAparAve.. tyAmuLe navIna prakara.nAsA.thIcAca mathaLA yeto, mAtra to mojalA jAta nAhI, tyaamuLe yA mathaLyaacyaa bAjulA Aka.de yeta nAhIta..}


\chapter{{\dn\dnpenbombay calA suruvAta karU}}

{\dn\dnpenbombay c~ap.taracI kamA.m.da ka"sI badalalI Ahe, he prastAvanetaca vi"sada kele Ahe.. iTe tIca kamA.m.da vAparalI Ahe, fakta prastAvaneta jI cA.mda.nI` *' vAparalI Ahe, tI eTe vAparalI nahI..  cA.mda.nI vAparalI kI kA{}u.m.tara ba.mda hoto..} 


\section{{\dn\dnpenbombay pahilA vibhAga}}
{\dn\dnpenbombay ithe kAhI citrehI .tAkalI Aheta..}
\begin{figure}[htb]
  \centering
\includegraphics[scale=0.1]{Image}
  \caption{{\dn\dnpenbombay taLe}}
\end{figure}

{\dn\dnpenbombay yA citrAkhAlI ``citra'' hA "sabda lihI.nyAkarItA pri{}embalamadhe } \verb+\renewcommand\thefigure{\devanagari{figure}}+ {\dn\dnpenbombay vAparale Ahe.. citrA.mcI moja.nI devanAgarIta kara.nyAkarItA}\verb+\renewcommand\thefigure{\devanagari{figure}}+ {\dn\dnpenbombay vAparuna kA{}U.m.tara devanAgarIta kelA Ahe.. nehamIpramA.ne `grAphiksa' p~akeja vAparuna citre .tAkatA yetAta.. likhA.nAcyA "sevA.tI} \verb+\listoffigures+ {\dn\dnpenbombay vAparUna citra.mcI yAdI karatA yete..}
\newpage

\subsection{{\dn\dnpenbombay pahilA upavibhAga}}

{\dn\dnpenbombay nehamIce} 
tabular
{\dn\dnpenbombay envhAyaranme.n.ta vAparUna khAlIla taktA banavalA Ahe..}

\begin{table}[htb]
  \centering
  \begin{tabular}[htb]{|c|c|c|}
\hline
{\dn\dnpenbombay sarvAta .dAvA ni sarvAta varacA koparA} & a & a\\
\hline
a & b & {\dn\dnpenbombay sarvAta ujavA ni taLatila koparA}\\
\hline
  \end{tabular}
  \caption{{\dn\dnpenbombay asAca eka taktA}}
  \label{tab:1}
\end{table}

{\dn\dnpenbombay yA taktyAkhAlI ``taktA'' ha "sabda lihI.nyAkarItA pri{}embalamadhe } \verb+\renewcommand\thetable{\devanagari{table}}+ {\dn\dnpenbombay vAparale Ahe.. prastAvanemaDe citr.mbaddala spa.s.tIkara.na dile Ahe.. citrA.mprama.neca taktyA.mcehI n.mbarI.mga kele Ahe ni "seva.tI taktA.mcI yAdI} \verb+\listoftables+ {\dn\dnpenbombay vAparUna banavalI Ahe..}


\section{{\dn\dnpenbombay dusarA vibhAga}}

{\dn\dnpenbombay citrA.mcI yAdI jarA vA.dhAvI mhAnUna ajUna eka citra .tAkUyAta!}
\begin{figure}[htb]
  \centering
\includegraphics[scale=0.1]{Image-2}
  \caption{{\dn\dnpenbombay taLe A.ni fule}}
\end{figure}


\chapter{{\dn\dnpenbombay dusarA Da.dA}}

{\dn\dnpenbombay To.de jAstIce sAhitya bharale tara anukrama.nikA barI disela ni kA{}u.n.taras{}ce kAma nI.ta pAhatA yeIla, mha.nUna he prakara.na suRu kele Ahe..}

\section{{\dn\dnpenbombay Da.dA dona maDIla eka viBaga}}
{\dn\dnpenbombay  
  \begin{center}
    yathA "sikhA mayUrA.nA.m nAgA.nA.m ma.nayo yathA |\\
    tathA vedA"nga "sAstrA.nA.m ga.nita.m mUrdhani sthitam ||
  \end{center}
}
As the (beautiful) crests (on the heads) of the peacocks and the (precious) stones (on the heads) of the (holy) cobras, Mathematics resides at the topmost position among all of the auxiliary disciplines\footnote{The Vedas have six auxiliary disciplines which are called the  ``\emph{Vedangashatrani}''. It is considered that the \emph{Vedangashatrani'} have all the knowledge, that describes the physical universe.} of the Vedas.

{\dn\dnpenbombay eka taktA..}

\begin{table}[htb]
  \centering
  \begin{tabular}[htb]{|c|c|c|}
\hline
hi & ha & hi\\
\hline
hi & ha & hi\\
\hline
  \end{tabular}
  \caption{{\dn\dnpenbombay asAca eka taktA}}
  \label{tab:2}
\end{table}

\section{{\dn\dnpenbombay kAhI "sere}}

\begin{figure}[htb]
  \centering
\includegraphics[scale=0.1]{Image-2}
  \caption{{\dn\dnpenbombay taLe A.ni fule}}
\end{figure}

{\dn\dnpenbombay Apa.na citre A.ni tAkte ka{}u.m.ta karatAnA ``Da.dA.. citrAca (taktyAcA) tyaa Da.dyAtIla kramA.mka'' asA ka{}u.m.tara se.ta kelA Ahe.. khalI kAhI "sere dile Aheta}:


\begin{enumerate}[label={\dn\arabic*}.]
\item {\dn\dnpenbombay ajunahI enyumare.ta envAyaraname.n.tacA kA{}u.m.tara se.ta kara.ne jamale nAhiye.. udAhara.nArTa iTe enumare.ta vAparatoya, pa.n .davIka.dIla a.mka mAtra arebIkaca Aheta.. mAtra he hoUna jAina ase disateya..}

\item {\dn\dnpenbombay prIambala maDe} \verb+\date+ {\dn\dnpenbombay vAparale tara te mahine hi.mdImaDe lihIte.. mara.thI kase karAyace ajuna samajale nAhI.. ya pra"snAkarItA, mara.thI sA.thi devanAgarI le.teka madhe kAhI khAsa se.tI.mga Aheta kA he pahAve lAgela..}

\begin{enumerate}[label={\alph*}]
    \item {\dn\dnpenbombay dusarA muddA}
    \item {\dn\dnpenbombay tisarA muddA}
    \item {\dn\dnpenbombay cauTA muddA}
\end{enumerate}
\item {\dn\dnpenbombay anukrama.nikA A.ni prastAvanA lihIlyAvara pAnacyA varIla koparyAvara `anukrama.nikA' ni `prastAvanA' ase Ale pAhIje.. mAtra eTe kAhItarI asa.mbaddha likhA.na disateya.. hA le.tekacA mUlabhuta pr~oblema disatoya.. so.dava.ne avagha.da disataya..}
\end{enumerate}


\listoffigures
\listoftables
\end{document}

The discussion

  1. In Devanagari LaTeX one has to creat a .dn file which needs to be processed by the terminal. Sometimes this file itself has few error and it is a cumbersome job to find them out and resolve them. Whereas in XeLaTeX it is simpler.
  2. The counting of parts of document (for example counting of chapter, pictures) has to manually adjusted. In XeLaTeX once you announce that the language is sanskrit or hindi, this issue is taken care of.
  3. Devanagari LaTeX has fewer fonts. I do not like the default one. \dnbombay is better. But XeLaTeX comes with more and better fonts. For example Sanskrit 2003 used in previous document is a good font.
  4. Writing the \dn command all the time is cumbersome in LaTeX. In XeLaTeX this is not an issue at all!
  5. One cannot give a Devanagari Unicode input in LaTeX. In XeLaTeX it is possible. See the last part of previous article.
  6. However, writing Mathematics is better in LaTeX. One can simply close the braces for \dn command and do the heavy mathematical writing. I do not know if this is so easy in XeLaTeX.
  7. Though the names and counter for table and picture can be customized for Devanagari, \ref does note work inside Devanagari command. One has to close the braces limiting the \dn command, then use \ref and again start with \dn. Which is indeed cumbersome.  
  8. The digit 8 in LaTeX is written in Hindi. In Marathi it is written as ८. The developers told me, now it is a hard job to change this shape.
  9. Package xindy-devanagari is developed by Zdenek Wagner (one of the developer of LaTeX Devanagari) for writing Glossaries. But the example files use XeLaTeX and babel.  I do not know if it can be used for LaTeX. (PS: Take care while using this package. There could be some issues.)   
Thus, LaTeX and XeLaTeX Devanagari both have certain benefits over one another. You may use the one that suits your needs. 

Zdenek Wagner advised me to try Polyglossia and XeLaTeX. The Polyglossia package documentation says that it supports Marathi, Bangla, Gurumikhi and many other Indian languages. Not only scripts but languages! However, I had some trouble with its Marathi translation. If I succeed to use it, I shall write an article.

If you come across some development, please update me by comment here.


                                            
                                                                    ∆  ∆


Wednesday, November 5, 2014

LaTeX Devanagari-II

 
In last article about LaTeX Devanagari (click here for the article) I explained how to make simple documents in Devanagari using LaTeX. However, the LaTeX users know that one of the biggest power of LaTeX is editing the documents efficiently. For example, if one wants to write a book using LaTeX, then, creating table of contents, chapter names or names of many parts of the book, listing tables or graphics, writing appendices, creating list of special words this all can be done by LaTeX within a stroke of line! Here I am giving and examples for writing a book in Deanagari using LaTeX and XeLaTeX. I try to incorporate as many features, as possible. In the end, I discuss some good and bad issues related to this piece of work.

XeLaTeX Devanagari

Following are the things I wish to achieve:
  1. Use the book environment for LaTeX Devanagari
  2. Include graphics, tables and customise their original commands so that the name the graphics and the tables appear in Devanagari. Then customise the commands \listoffiures and \listoftables for LaTeX Devanagari.
  3. Customise the frontmatter (the title page, the index, the preface part) and the backmatter (the appendices, various lists, glossaries for LaTeX Devanagari.
  4. Customize all numberings to Devanagari.
  5. Customise the mainmatter (chapter names, sections etc) for Devanagari.

Using XeLaTeX
The best way to learn LaTeX is play to with it! :) Following is my code for a XeLaTeX writing. Marathi readers, forgive me for so many typos in the tex file. I am still not very comfortable with the transliteration.

  1. Copy and paste the code to your LaTeX editor.  Save this file to a folder with an ending .tex . 
  2. Add a .png photo to this same folder. Rename the photo as Image.png
  3. Then set the editor to XeLaTeX. NOT on LaTeX or pdfLaTeX.
  4. Run the file two or three times, at least. See the beautiful output.
  5. Some precautions are:
  • There could be some typos. I shall keep updating the articles, until all the typos are eliminated. But take care about "s which stands for श्  . Few LaTeX editors change the character " to `` automatically. This produces ``s instead of "s and the output becomes "स् or ``स् .
  • The sixth line has command \setmainfont which sets the main font for whole of the document. The extra parameter Mapping in this command can take many values. And they all behave differently. For example, Mapping= devanagarinumerals would let you give the input in Devanagari Unicode itself! Which means to get an output रोहित I need not type rohita but simply type रोहित with a Unicode keyboard! 
  • However if you use some other mapping, then the rules of transliteration change! Click here to see the different types of mappings and the corresponding transliteration rules. 

Screenshots of this output are given bellow. Comments close to many commands explain what these commands are meant for.

\documentclass[a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fontspec}

\usepackage[english, hindi]{babel}
\setmainfont[Script=Devanagari,Mapping=velthuis]{Sanskrit 2003}
%\setmainfont[Script=Devanagari,Mapping=devanagarinumerals]{Sanskrit
%2003} this mapping let you give input in Devangari itself

%Changing the titles of standard parts in LaTeX to Devanagari

\addto\captionshindi{%
\renewcommand{\abstractname}{sArA.m"sa}%
\renewcommand{\contentsname}{ anukrama.nikA}%
\renewcommand{\chaptername}{dha.dA}%
\renewcommand{\tablename}{taktA}%
\def\appendixname{parI"sI.s.ta}%
%\def\figurename{}%
\def\listfigurename{citrA.mcI yAdI}%
\def\listtablename{taktyA.mcI yAdI}%
}
\catcode`\~=12

%Document Info
\author{rohita dilIpa hoLakara}
\title{ksele.tek ni bebela}
\date{phebruvarI 1, 2015}

%Page Layout
\usepackage[inner=2.4cm,outer=2cm]{geometry}%left-right margin
%\onehalfspacing %increases spacing between two lines to 1.5


\begin{document}
\let\MakeUppercase\relax
\frontmatter
\maketitle
\tableofcontents

\mainmatter
\chapter{eka}
\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. 
    \begin{enumerate}
       \item eka
       \item dona
           \begin{enumerate}
       \item he
       \item ase
       \item Ahe
    \end{enumerate}

       \item tina
    \end{enumerate}
    \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.nitacii 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 nityaacyaa 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}

\chapter{aseca}
astu, malA mAgIla drAvi.dI pra.nayAmAhUna hec bare va.tateya! varIla paikI pahilA pra"sna su.tela lavakara a"sI A"sA Ahe! ethe kAhI citre .takUna pAhUyAta kI tyA.mcI nAve ka"sI yetIla. "sIvAya eka taktAhI banavUna .takatoya, he.nekarUna takte A.ni tyA.ncI nAve nI.ta disatIla kI nAhI he kaLela. sarvAta "seva.tI \verb+\listoffigures+ A.ni \verb+\listoftables+ vAparUna citre ni takyA.mcI yAdI suddhA banavalI Ahe.

\begin{figure}[htb]
  \centering
\includegraphics[scale=0.1]{Image}
  \caption{eka citra}
\end{figure}

\begin{table}[htb]
  \centering
  \begin{tabular}[htb]{|c|c|c|}
\hline
hi & ha & hi\\
\hline
hi & ha & hi\\
\hline
  \end{tabular}  \caption{eka taktA}
  \label{tab:2}
\end{table}


\chapter{kAhItarI}
ethe bebela pyAkejamaDIla i.mgrajI BA.sA vAparUna  lihI.nyAcA prayatna
karatoya. matra kAhI sAdhya hota nAhIye.

 \begin{enumerate}
\item
\begin{verbatim} 
\foreignlanguage{english}{This text should be in English}
\end{verbatim}
vAparUna he miLateya,\\
\foreignlanguage{english}{This text should be in English}
\item 
\begin{verbatim}
\selectlanguage{english}{This text should be in English}
\end{verbatim}
vAparUna he miLateya,\\
\selectlanguage{english}{This text should be in English}
\item
\begin{verbatim}
\begin{otherlanguage}{english}
This text should be in English\end{otherlanguage}
\end{verbatim}
vAparUna he miLateya,\\
\begin{otherlanguage}{english}
This text should be in English
\end{otherlanguage}
\end{enumerate}

\chapter{"sere}
\label{cha:sere}

\begin{enumerate}
\item eTe bebela vAparale tarI i.mgrajI vA itara bhA.seta kase
  lihAyace hA pra''sna ajuna su.talA nAhIye.
\item inara lis.ta a, ba, ca, da, a"sIca ye.nare, kAra.na
  devanAgarIsa.thI ajuna k, kha, ga, ... a"sI inara lis.ta
  .devhalapararsanIca .tAkalI nahiye.
\item inara lis.ta prama.neca \verb+\frontmatter+ A.ni
  \verb+\backmatter+ maDila pAna.mce kramA.mka romana Aka.dyA.mce
  devanAgarI Ba.sA.mtara mhanu.naca ye.naret. tyAla kAhI upAya nAhI
\item appara kesa ril~aks kelI kI \verb+\today+ bebela hi.mdIsA.thI
  cAlate. matra bebela maDe ajuna mara.thI nahIye.
\item jhedneka vAgnerane pA.thavalele \verb+xindy+ vAparun pahAyace
  Ahe.
\item eka uttama bAba hI kI \verb+mapping=devanagarinumerals+
  karuna .teka fAIla maDe yuniko.da devanAgarI .tAkUna lihItA yete! he
  phAraca uttama Ahe!
\end{enumerate}


\backmatter
\appendix
\chapter{a}
iTe eka pari"sI.s.ta surU hote.

\listoffigures
\listoftables

\end{document}

Once you give the information \author, \title and \date the \maketitle produces this title page. The command \today for date produces a date in Hindi and not in other language, neither Sanskrit nor Marathi nor Nepali. Babel does not support Marathi yet.

Using Babel I have chosen Hindi as the main language of the text. The table of contents produces name विषय सूची, if \renewcommand{\contentsname}{anukrama.nikA}is not used. विषय सूची is fine for Marathi (as well as Nepali, if think!). But I want to use the work अनुक्रमणिका. The renewed command above does it for me. One had to run XeLaTeX twice or thrice to generate the index properly. LaTeX cannot produce detailed index in a single run.

Following is the first chapter. If you use \chapter*{prastavanA} in the front matter, it would produce the preface page. Using \chapter{eka} in the main matter gives following.  \renewcommand{\chaptername}{dha.dA} makes the name of a chapter appear as "धडा" a standard word for Chapter in Marathi. Changing dha.dA in the command to aDyAya would say अध्याय instead of धडा or pA.tha would yield पाठ. The listing is a problematic issue. For the first list, LaTeX counts properly in devanagari. But for inner lists, it simply translated the standard English innerlist numbers to devanagari. We count the second list as क, ख, ग, घ, च, ... or अ, आ, इ, ई, ... but here it counts as अ =a, ब =b, च =c, द् =d, ... The third list translation of roman counting numbers i, ii, iii,... I contacted the developers, but they replied that these lists we not added at all! They are like to add them now.


Here is an example of graphics and tables. As you can see, the name of the table and graphics as well as their counting appears in devanagari. See the preamble to observe how it is done.

Here I tried using English as a foreign language and I failed! I don't feel comfortable with Babel yet.  I shall try to fix this problem. If you come up with a solution please post here.
In the backmatter, adding \chapter after \appendix stops counting the chapter name, removes the word Chapter (here धडा) and makes only the title visible. Here is an appendix. Appendices are counted differently in the index.

\listoffigures and \listoftables is customized to produce चित्रांची यादी and तक्यांची यादी respectively. For Hindi the default is set but you may modify it to चित्रों की सूची and तालिकांओ की सूची.


Some remarks:

  1. In the Preamble, change \setmainfont [Script=Devanagari, Mapping=velthuis]{Sanskrit 2003} to \setmainfont [Script=Devanagari, Mapping=devanagarinumerals]{Sanskrit 2003}. Then remove all the text inside document. That is, write nothing between the commands \begin{document} and \end{document}. Then, use a unicode Devanagari keyboard and write and input in Devanagari. Then XeLaTeX it and see that LaTeX can process Devanagari input! This is cool. This would help me LaTeXify most of my writing. This is a very valuable feature of XeLaTeX. But use a good editor like Emacs or Aquamacs. Some editors might not like your input and give you errors. For example, on my machine, Aquamacs gives a nice output (its a sturdy editor) but TeXShop confuses!
  2. Devanagari LaTeX is unable to count nested lists as seen above. It does the same error for counting the pages in frontmatter and the backmatter. But these things need to be changed by the Developers. I do not know any other solution, at the moment.
  3. The command \today give only Hindi output. One of the developer told me that Polyglossia package can handle marathi, but I could not make it work for Marathi!
In the next article I shall post a code for LaTeX file and discuss few differences about XeLaTeX and LaTeX files.

                                            
                                                                    ∆  ∆






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 

∆  ∆