0

I am typesetting a multilingual book with xetex, using polyglossia for different fonts. Since the index contains different languages I need to use a main font which contains both languages. But one chapter contains trans i, can I change the index font for a specific chapter? I tried using the idxlayout package and this command in the preamble: (\englishfont is defined using \newfontfamily command)

\renewcommand*{\indexfont}{\englishfont}

but when I try to change that to another font in a \begingroup it is not working.

\begingroup 
\renewcommand*{\indexfont}{\malayalamfont}
\KOMAoptions{fontsize=11pt}
സ്വകാര്യവ്യക്തിബോധം, രേഖീയയുക്തി,
ഭാഷാദേശീയത, ഗദ്യത്തിന് കൈവന്ന മേൽക്കൈ, പൊതുമണ്ഡലനിർമ്മിതി
തുടങ്ങിയവയ്ക്കെല്ലാം പിന്നിൽ അച്ചടിയുണ്ടായിരുന്നു. മാധ്യമചിന്തകനായ
മാർഷൽ മക് ലൂഹൻ\index{മാർഷൽ മക് ലൂഹൻ} `ഗുട്ടൻബർഗ്ഗ് ഗാലക് സി'\index{ഗുട്ടൻബർഗ്ഗ് ഗാലക് സി} എന്ന് വിശേഷിപ്പിച്ച പുതിയ
ലോകസന്ദർഭത്തിന്റെയും ജീവിതാവബോധത്തിന്റെയും കേന്ദ്രമായി അത് നിലനിന്നു.
\endgroup

This encounter has since passed into the folklore of the coming of print to Bengal. Carey's own arrival in India had been in November 1793 and from the very beginning, his one aim had been to translate and print the gospels in Bengali. As early as in January 1794, Carey's associate John Thomas\index{Thomas, John} consulted a printer in Calcutta about the costs of printing a Bengali Bible. But financial hardship sent Carey all the way up to Madnabati in Malda district, where an indigo planter by the name of George Udny provided employment to both Carey and Thomas. All along, Carey continued to learn Bengali from his \textit{munshi} Ramram Basu,\index{Basu, Ramram} \printindex

Is there any way to change the index font inside \begingroup? I want the index in the English part to be in englishfont and the other language part's index in a different font. I can only choose one font with \renewcommand*{\indexfont}{\englishfont}. I want to change the index font inside \begingroup.

Ingmar
  • 6,690
  • 5
  • 26
  • 47
  • 1
    it is very hard to understand your example the code fragment can't be used by anyone, you ask about index but the example has no \index commands but does have a \subsection did you mean to ask about table of contents? In either case can you make a small but complete example that shows the problem. – David Carlisle Nov 17 '21 at 07:51
  • i edited the question. it is about index. i want different fonts for index – Mujeebcpy Nov 17 '21 at 08:36
  • 1
    the font setting in the document does nothing try \index{ഗുട്ടൻബർഗ്ഗ് ഗാലക്‌സി@{\malayamfont ഗുട്ടൻബർഗ്ഗ് ഗാലക്‌സി}} – David Carlisle Nov 17 '21 at 08:51
  • well, that helps. but lot of work if i want to change the whole chapters – Mujeebcpy Nov 17 '21 at 10:36
  • 1
    you could define \newcommand\mindex[1]{\index{#1@{\malayamfont#1}}} then you just need \index{abc} for Latin scipts and \mindex{ഗുട്ടൻബർഗ്ഗ് ഗാലക്‌സി} for Malayalam – David Carlisle Nov 17 '21 at 11:22
  • Thank you. this is exactly what i want. should come as an answer. – Mujeebcpy Nov 17 '21 at 12:40

1 Answers1

3

makeindex supports a form \index{sort-text@typset version} unfortunately, unlike formatting page numbers if the typeset version is a styled version of the text used for sorting you need to repeat it however you can do

\newcommand\mindex[1]{\index{#1@{\malayamfont#1}}}

then you just need \index{abc} for Latin scipts and \mindex{ഗുട്ടൻബർഗ്ഗ് ഗാലക്‌സി} for Malayalam.

Alternatively if you are using lualatex you could keep the version as you had it. babel does have code to switch the font/language depending on the script used in the input so then explicit font switching wouldn't be needed. See

Is it possible to typeset Unicode input in multiple language scripts automatically without inserting special commands?

David Carlisle
  • 757,742
  • 4
    I’d just like to point out the support for language/font switching in babel is not experimental, but stable. See for example https://tex.stackexchange.com/questions/449764/is-it-possible-to-typeset-unicode-input-in-multiple-language-scripts-automatical/449791#449791 . – Javier Bezos Nov 17 '21 at 16:21
  • @JavierBezos ah thanks I'll edit (at least I remembered it was there!) – David Carlisle Nov 17 '21 at 17:03
  • @JavierBezos thanks I updated the answer. – David Carlisle Nov 17 '21 at 17:04