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

5
  • My new year resolution is to improve my TeX skills Jan 1, 2018 at 3: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}. Jan 1, 2018 at 4:10
  • See tex.stackexchange.com/questions/207310/… by the way. Jan 1, 2018 at 4: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. Jan 1, 2018 at 6:17
  • related tex.stackexchange.com/questions/199773/…
    – dexteritas
    Nov 22, 2022 at 15:37

1 Answer 1

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.
10
  • 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, 2021 at 9: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? Apr 12, 2021 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.) Apr 12, 2021 at 17:20
  • 1
    @JChat A web application is a good idea, thanks… I'll think about it. Apr 13, 2021 at 20:45
  • 1
    @ShreevatsaR I took some liberty to modify your gist, now it handles the nuqta gist.github.com/ritwikmishra/9f8d6de45aff8fbe959d4260269d9eeb
    – Ritwik
    Sep 5, 2021 at 18:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .