2

I am typesetting a Hindi book with multiple indexes and Devanagari chapter/section/page numbers. I want to use HarfBuzz rendering with LuaLaTeX, which enables error-free copy-pasting of Devanagari text from PDFs as discussed here. Unfortunately HarfBuzz rendering with XeLaTeX does not give the desired results. So I have to use LuaLaTeX. I tried an example with LuaLaTeX compiler from TexLive 2020 (on Overleaf).

This is my latexmkrc file.

add_cus_dep( 'adx', 'and', 0, 'ndx2nnd' );
sub ndx2nnd {return system( "makeindex -o \"$_[0].and\" \"$_[0].adx\"" );}
push @generated_exts, 'adx', 'and'; 

Attempt 1: With polyglossia

The following file compiles fine with LuaLaTeX and gives me two indexes, but with Western Arabic chapter/section/page numbers. This seems to be a known issue here.

\documentclass[twoside]{book}
\usepackage{polyglossia}
\setmainlanguage{hindi}
\newfontfamily\devanagarifont[Renderer=HarfBuzz,Script=Devanagari,Mapping=devanagarinumerals]{Noto Serif Devanagari}
\newfontfamily\englishfont{Noto Serif}
\usepackage{index}
\makeindex
\newindex{top}{adx}{and}{विषयसूची}
\newindex{aut}{adx}{and}{लेखकसूची}
\begin{document}
\chapter{प्रस्तावना}
\section{परिचय}
हम किंकर्तव्यविमूढ हैं।
\index[top]{विषय १}
\index[aut]{लेखक १}
\printindex[top]
\printindex[aut]
\end{document}

Attempt 2: With babel

The following file compiles fine with LuaLaTeX and gives me Devanagari chapter/section/page numbers, but no index.

\documentclass[twoside]{book}
\usepackage{babel}
\usepackage{fontspec}
\babelprovide[mapdigits,maparabic,main]{hindi}
\defaultfontfeatures{Renderer=Harfbuzz,Script=Devanagari}
\babelfont{rm}{Noto Serif Devanagari}
\usepackage{index}
\makeindex
\newindex{top}{adx}{and}{विषयसूची}
\newindex{aut}{adx}{and}{लेखकसूची}
\renewcommand\hindichaptername{अध्याय}
\begin{document}
\chapter{प्रस्तावना}
\section{परिचय}
हम किंकर्तव्यविमूढ हैं।
\index[top]{विषय १}
\index[aut]{लेखक १}
\printindex[top]
\printindex[aut]
\end{document}

I can use either polyglossia or babel, would prefer polyglossia. So appreciate any help to make either of the two examples above work. The one with polyglossia is missing Devanagari numbers and the one with babel is missing the two indexes.

2
  • The babel version fails because page numbers are converted at the TeX level (with maparabic) to the Devanagari forms, which makeindex doesn't understand. Isn't mapdigits enough? At least with this example the result seems fine if I remove maparabic. Commented May 29, 2021 at 9:52
  • (a) Both indexes are writing to the same .adx file. Use different file extensions for each index: like .and, .adx, .tdx, .tnd. (b) fontspec's mapping (as called by polyglossia only works in xelatex; lualatex has an error message in the log.
    – Cicada
    Commented May 29, 2021 at 10:52

1 Answer 1

2

Thanks to answers by Javier Bezos and Cicada, I was able to find out the problems in my code. Here are the fixes that need to be made.

In the latexmkrc file, we need configurations for two indexes. So this is now the latexmkrc file should look like.

add_cus_dep( 'adx', 'and', 0, 'ndx2nnd' );
add_cus_dep( 'ndx', 'nnd', 0, 'ndx2nnd' );
sub ndx2nnd {return return Run_subst( "makeindex -o %D %S" );}
push @generated_exts, 'ndx', 'nnd', 'adx', 'and';

In the main.tex file, we need to make two fixes: (1) change \babelprovide[mapdigits,maparabic,main]{hindi} to just \babelprovide[mapdigits,main]{hindi} (2) change \newindex{aut}{adx}{and}{लेखकसूची} to \newindex{aut}{ndx}{nnd}{लेखकसूची}. The final main.tex file which will work with the above indexmkrc file

\documentclass[twoside]{book}
\usepackage{babel}
\usepackage{fontspec}
\babelprovide[mapdigits,main]{hindi}
\defaultfontfeatures{Renderer=Harfbuzz,Script=Devanagari}
\babelfont{rm}{Noto Serif Devanagari}
\usepackage{index}
\makeindex
\newindex{top}{adx}{and}{विषयसूची}
\newindex{aut}{ndx}{nnd}{लेखकसूची}
\renewcommand\hindichaptername{अध्याय}
\begin{document}
\chapter{प्रस्तावना}
\section{परिचय}
हम किंकर्तव्यविमूढ हैं।
\index[top]{विषय १}
\index[aut]{लेखक १}
\printindex[top]
\printindex[aut]
\end{document}

Thanks again to Javier and Cicada for their help.

You must log in to answer this question.

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