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.


                                            
                                                                    ∆  ∆