# Incorrect index generation when used with babel [greek]

I am trying to index a document with several greek phrases. Using babel and \textgreek all went well ... until I got to the index. All entries from the \frontmatter (with roman page numbers) get lost.

Editing the .idx-files manually and freezing them, I can work around the problem, but this can't be the solution. Without the greek in the babel-options, the problem does not exist, but unfortunately I need it ...

Has anyone an idea how the the .idx could be generated correctly (without the unnecessary \fontencoding in the \indexentry)? Thanks a lot.

%TexLive 2018
%pdfLaTeX or luaLaTeX
%
%Index without greek:
% --------------
%Riesenindex
%Auszeichnung, 1         Seite, 2
%In Fussnote, iii        Text, ii, 1
%                        TEXT, iii
%
%Index with greek
% --------------
%Auszeichnung, 1         Text, 1
%Seite, 2

%first 3 lines of .idx with greek
% ------------------------------
%\indexentry{Text}{{\fontencoding  {OT1}\selectfont  ii}}
%\indexentry{Text@\textsc{Text}}{{\fontencoding  {OT1}\selectfont  iii}}
%\indexentry{In Fussnote}{{\fontencoding  {OT1}\selectfont  iii}}

%error message in .ilg with greek
% ------------------------------
%!! Input index error (file = IndexTstMaster.idx, line = x):
%   -- Illegal space within numerals in second argument.

% ------------------------------------------------------------------------------

\documentclass [paper=C5]{scrbook}

% ------------------------------------------------------------------------------
%\usepackage [ngerman]{babel}  % english
\usepackage [main=ngerman,greek.ancient]{babel}  % english
\usepackage{imakeidx}      % with xindy there is no improvement
\makeindex[title=Riesenindex]

\begin {document}
\frontmatter
Etwas Text\index{Text} hier;
\newpage
Etwas mehr Text\index{Text@\textsc{Text}} hier.%
\footnote {\index{In Fussnote}Eine Fussnote}
% ---
\mainmatter
\chapter {Kabidel}
Viel Text\index{Text} hier; \emph{Auszeichnung\index{Auszeichnung}}
\newpage
Auf neuer\index{Seite}.
%  \textgreek{Καὶ ταῦτα μὲν δὴ ταῦτα}{}.
Und so weiter.
% ---
\printindex
\end {document}


First advice: wherever possible, if you need Greek, use xetex or luatex instead of pdftex. See the page on Greek in the babel site.

But if you want to stick to pdftex, just restore the default definition of \@roman as follows, before \begin{document}:

\makeatletter
\def\@roman#1{\romannumeral #1}
\makeatother


The babel style for Greek redefines it even when Greek isn’t the main language, which doesn’t seem a good idea.

Second advice: main= should be used only when the default way to select the main language fails. The default way is:

\usepackage [greek.ancient, ngerman]{babel}


The main language is the last one.

Update. With xetex or luatex and if all you need is a few phrases, you don’t even need to declare explicitly the Greek language (see the babel manual and the section on “Mostly monolingual documents”). The default LaTeX font doesn’t contain Greek letters, so you must declare it:

\documentclass{article}

\usepackage[english]{babel}
\babelfont[ancientgreek]{rm}{NewComputerModern10}

\begin{document}

This is a piece of text from \foreignlanguage{ancientgreek}{Ὀδύσσεια},
taken from Wikisource: \foreignlanguage{ancientgreek}{Ἄνδρα μοι ἔννεπε,
Μοῦσα, πολύτροπον, ὃς μάλα πολλὰ πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον
ἔπερσε}.

\end{document}


• Thanks for the hints. I've already changed to XeTex. Feb 12 at 16:46
• Thx! So, the ultimate solution would be to let \@roman and \@Roman be changed only within the scope of the Greek language, wouldn't it? I've just created github.com/latex3/babel/issues/170 and informed the babel-greek maintainer. Feb 18 at 1:24
• @wasadu I’ve update my answer with a minimal example with xetex/luatex. Feb 18 at 16:24
• @Javier It's all correct and good advice; but, might you possibly have missed the point a bit? I never had any difficulty getting the greek text into the document. The real problem was the wrongly generated index in the area of the \frontmatter. Besides, with my installation, NewComputerModern10 is not known, and \foreignlanguage{ancientgreek}{...} produces a Babel warning: unknown language. @GeekestGeek: Thanks, perhaps I should have done that myself, but it didn't enter my head. Feb 21 at 10:09
• @wasadu Maybe a bit, but not quite. The point is, by using Greek in this way the ldf file for this language isn’t loaded at all and there are less chance of conflict. Feb 21 at 16:33

The only way I found to overcome the problem is to use XeLaTeX and manually specify a font for greek (which of course does not mean it is the only way). Either package babel or polyglossia will do in this case. [In my real project this was quite a bit of work ... and it compiles so utterly slow!]

% compile with XeLaTeX
\documentclass [paper=C5]{scrbook}

% ------------------------------------------------------------------------------
\usepackage {fontspec}
\usepackage [ngerman]{babel}  % english

\font\griik="[libertinusserif-regular.otf]" % any font with greek chars would do

\usepackage{imakeidx}      % mit xindy wird die Sache nicht besser
\makeindex[title=Riesenindex]

\begin {document}
\frontmatter
Etwas Text\index{Text} hier;
\newpage
Etwas mehr Text\index{Text@\textsc{Text}} hier.%
\footnote {\index{In Fussnote}Eine Fussnote}
% ---
\mainmatter
\chapter {Kabidel}
Viel Text\index{Text} hier; \emph{Auszeichnung\index{Auszeichnung}}
\newpage
Auf neuer\index{Seite}.
{\griik Καὶ ταῦτα μὲν δὴ ταῦτα}
%  \textgreek{Καὶ ταῦτα μὲν δὴ ταῦτα}{}.
Und so weiter.
% ---
\printindex
\end {document}