2

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}

3 Answers 3

2

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}

enter image description here

5
  • Thanks for the hints. I've already changed to XeTex.
    – wasadu
    Commented Feb 12, 2022 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.
    – user224332
    Commented Feb 18, 2022 at 1:24
  • @wasadu I’ve update my answer with a minimal example with xetex/luatex. Commented Feb 18, 2022 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.
    – wasadu
    Commented Feb 21, 2022 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. Commented Feb 21, 2022 at 16:33
0

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}
0

Mind, that the function \textgreek (similar to \textcyrillic) only changes the font encoding. It does not set the "Babel language" and does not select Greek hyphenation patterns!

If you only need some symbols or words in the Greek script (no hyphenation, no auto-strings, no enumerations, ...), the simplest solution is to load the textalpha package (from greek-fontenc) instead of using Babel's "greek" option. Then either just use Greek literal characters "anywhere" or replace \textgreek -> \ensuregreek.

For correct hyphenation, translation of auto-generated strings, Greek numerals instead of a transliteration of the Latin alphabet in the second level of enumerations, and fixes for issues with the non-standard LGR font encoding, you should use the Greek option and actually set the Greek \emph{language}, not just the emph{script}: \textgreek -> \foreignlanguage{greek}.

\documentclass{scrbook} 

\usepackage[ngerman]{babel}
\usepackage{textalpha}
\usepackage{imakeidx}
\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}.
   
   After loading \emph{textalpha}, you may use Greek literal characters
   anywhere in the document:
   This is fine for single upright symbols like π.
   
   For better kerning and to avoid needless font encoding switches, quotes
   should we wrapped in \verb|\ensuregreek|, if the document should be
   compiled with 8-bit TeX (pdftex).
   \ensuregreek{Καὶ ταῦτα μὲν δὴ ταῦτα.}

   % ---
   \printindex
\end {document}

The babel-greek development version allows to work around the issue in the original document with the new, provisional modifier local-LGR-fixes.

You must log in to answer this question.

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