Mapping Devanagari numerals with LuaLaTeX
The babel
package, running on LuaHBTeX (that is, LuaLaTeX from 2020 or later), supports this through the mapdigits
feature. This example will change the digits to Devanagari in page numbers, chapter numbers, the table of contents, etc., and in Marathi text, but not in English text or math mode.
%% This MWE requires LuaHBTeX 1.12.0 or later.
\tracinglostchars = 2 % Print a warning message if a character is missing.
\documentclass{article}
\usepackage[paperwidth=10cm]{geometry} % To format the MWE for TeX.SX
\usepackage[english, bidi=basic, layout=sectioning.counters]{babel}
\usepackage{fontspec}
\babelprovide[import, main, mapdigits]{marathi}
\defaultfontfeatures{Scale = MatchLowercase, Ligatures=TeX, Renderer = HarfBuzz}
\babelfont{rm}
[Scale = 1.0]{Shobhika}
\newcommand\textenglish[1]{\foreignlanguage{english}{#1}}
\newenvironment{english}{\begin{otherlanguage}{english}}{\end{otherlanguage}}
\begin{document}
\section{एक}
\textenglish{The number 42 in English. In math mode:} \(42\).
\section{दोन}
\textenglish{In Marathi:} 42.
\textenglish{This is Section} \arabic{section}.
\end{document}
If you are compiling with Babel and XeLaTeX, the sectioning=
package option will work for counters such as page and chapter numbers, and you can pass maparabic
instead of mapdigits
to \babelprovide
to make \arabic
counters such as numbered lists use different numerals. It also provides the command \marathidigits{42}
. Or you can just type in Marathi in your editor the way you normally do.
If the localized strings are unsatisfactory, you can override them by redefining \marathicontentsname
, \marathichaptername
, \marathiabstractname
, etc.
The polyglossia
package provides a similar command to map digits, \devanagaridigits
.