5

I want to write in hindi in latex

मेरे माता और पिता को समर्पित|

I am using devanagri package and I want to put this in the document using the command {\dn .............}. If somebody can translate the above lines in Devanagari then i can put these in in the blank and get it to work. Also, if there i a tool readily available like google translate, it will be helpful if someone can point out

ShreevatsaR
  • 45,428
  • 10
  • 117
  • 149
  • My new year resolution is to improve my TeX skills – Sharabh Shukla Jan 01 '18 at 03:23
  • I know nothing about Devanagri. But have you tried either pdflatex and babel or xelatex with fontspec (with Devanagri-capable font) and polyglossia? In both cases you would probably be able to write directly in Devanagri in unicode using \usepackage[utf8x]{inputenc}. – Oleg Lobachev Jan 01 '18 at 04:10
  • See https://tex.stackexchange.com/questions/207310/devanagari-characters-and-pdflalitex by the way. – Oleg Lobachev Jan 01 '18 at 04:12
  • I tried using XeLatex or other compilers, it seems my project doesn't work at all, prints some gibberish. This is the only package that works. – Sharabh Shukla Jan 01 '18 at 06:17
  • related https://tex.stackexchange.com/questions/199773/how-to-type-hindi-words-in-latex – dexteritas Nov 22 '22 at 15:37

1 Answers1

11

Short answer: For the text in the question, you can use:

{\dn m\?r\? mAtA aOr EptA ko smEp\0t.}

Longer answer follows.


Recommended way (XeTeX and Unicode font)

In general, to type Devanagari in (La)TeX, it is best to use a Unicode-aware engine like XeTeX [or LuaTeX, but LuaTeX's support for Indic (and most non-Latin) scripts is rather poor]. For example, you can just compile the following with xelatex:

\documentclass{article}
\usepackage{fontspec}
\newfontfamily\hindifont{Noto Sans Devanagari}[Script=Devanagari] % Use any Devanagari font on your system

\begin{document}
This is Latin script and {\hindifont यह है देवनागरी}.
\end{document}

output with XeTeX

or for better results if you have a lot of Hindi text, it is recommended to use the polyglossia package too (for things like hyphenation and other language-specific rules):

\documentclass{article}
\usepackage{polyglossia} % Automatically loads fontspec
\setmainlanguage{english}
\setotherlanguages{hindi}
\newfontfamily\hindifont{Noto Sans Devanagari}[Script=Devanagari] % Use any Devanagari font on your system

\begin{document}
This is Latin script and \texthindi{यह है देवनागरी}.
\end{document}

Deprecated but still working way (non-Unicode font)

If for some reason you cannot use XeTeX, then you can use the old devanagari package. This requires two passes. First, you type everything into a .dn (not .tex) file, with the Devanagari parts inside {\dn ...}, using Velthuis encoding for the Devanagari text. (Invoke texdoc velthuis to read the manual for details.) Then you run devnag on this .dn file, to create a .tex file. Then you compile this .tex file.

For example, for the text in the question, you can create a .dn file with:

\documentclass{article}
\usepackage{devanagari}

\begin{document}
This is English. {\dn mere maataa aura pitaa ko samarpita|} English again.
\end{document}

Then running devnag file on this .dn file produces the following .tex file:

\def\DevnagVersion{2.17}\documentclass{article}
\usepackage{devanagari}

\begin{document}
This is English. {\dn m\?r\? mAtA aOr EptA ko smEp\0t.} English again.
\end{document}

Now you can compile this file with say pdflatex, to get:

dn/pdflatex

Tools

  • To go from the Devanagari to the required Velthuis transliteration (e.g. from मेरे माता और पिता को समर्पित to {\dn mere maataa aura pitaa ko samarpita}, you can use this tool I wrote a long time ago (or just learn the conventions from the documentation and type it manually).
  • To go from the .dn file to the .tex file, you need the devnag processor installed, which comes with TeX Live. If you're using a different distribution, it may be under a different name, or you may have to compile it yourself.
  • To go directly from Devanagari to the \dn convention and skip the previous two steps (e.g. from मेरे माता और पिता को समर्पित to {\dn m\?r\? mAtA aOr EptA ko smEp\0t.}, you may be able to use the Python script I wrote for another answer a few months ago.
ShreevatsaR
  • 45,428
  • 10
  • 117
  • 149
  • I know that this is an old question/answer, but this was really helpful for me as i also wanted something similar in my thesis. However, I am unable to figure out how to write "मेरी प्यारी दादी की याद में, और मेरे माता, पिता एवं दादाजी को समर्पित |". The {\dn m?r? mAtA aOr EptA ko smEp\0t.} bits work perfectly, but I would really appreciate if you could guide me on writing the above. Many thanks for your help, I am quite a novice with this package! @ShreevatsaR – JChat Apr 12 '21 at 09:28
  • 1
    @JChat You're welcome. Sure I can help, but first could you tell me what part of this answer was unclear? Apart from the xelatex/lualatex method (are you sure you can't use those instead of pdflatex?), the answer linked to two tools (one for going from Devanagari to Velthuis and then runningdevnag, and the other a Python script to bypass devnag directly)—which of the two tools did you try, and what happened? – ShreevatsaR Apr 12 '21 at 16:42
  • 1
    @JChat (BTW the answer to your question is that for मेरी प्यारी दादी की याद में, और मेरे माता, पिता एवं दादाजी को समर्पित | you can write {\dn m\?rF =yArF dAdF kF yAd m\?{\qva}{\rs ,\re} aOr m\?r\? mAtA{\rs ,\re} EptA ev\2 dAdAjF ko smEp\0t .} —try it and let me know—but I'd still like to know how I could make the answer clearer so that the reader has the ability to figure this out by themselves.) – ShreevatsaR Apr 12 '21 at 17:20
  • thanks - I am using Overleaf to write my thesis, so am having problems in utilising system-installed fonts (and it throws errors when writing directly in Hindi). Thereby, your short answer that uses non-unicode font worked like a charm for me. I appreciate the Python script - though is there any resource or web service/application for this which can directly translate from Hindi to the required format without executing the script locally (as it would be very helpful for users who use Overleaf)? Anyways, your answer worked perfectly for me, many thanks and cheers! – JChat Apr 13 '21 at 17:44
  • 1
    @JChat A web application is a good idea, thanks… I'll think about it. – ShreevatsaR Apr 13 '21 at 20:45
  • Actually a web application isn't so trivial because the Python script just calls either devnag or skt, i.e. that binary needs to run on the backend. May look into it nevertheless. – ShreevatsaR Apr 14 '21 at 06:04
  • The web application (for devnagri ---> Velthuis) you mentioned in your answer, leaves the nuqta out. For eg: [उन्हे नुक्कड़ नाटक के] --> unhe nukka.da़ naa.taka ke. Notice the nuqta at index 13. – Ritwik Sep 05 '21 at 11:43
  • @Ritwik Right, it was written for Sanskrit so I didn't pay much heed to the nuqta (looks like the manual uses "Ra" for "ड़", haven't tried it). – ShreevatsaR Sep 05 '21 at 14:17
  • 1
    @ShreevatsaR I took some liberty to modify your gist, now it handles the nuqta https://gist.github.com/ritwikmishra/9f8d6de45aff8fbe959d4260269d9eeb – Ritwik Sep 05 '21 at 18:09
  • @Ritwik Great, thanks. – ShreevatsaR Sep 05 '21 at 18:21