3

In the example document below the second index entry produces the warning

!! Input index error (file = j.idx, line = 2):
   -- Extra `@' at position 11 of first argument.

on running makeglossaries corresponding to

\indexentry{A@\( \mathbb A \)}{1}
\indexentry{R@\( \math@bb  R \)}{1}
\indexentry{B@\( B \)}{1}

in the .idx file. As a result the second entry is rejected and does not appear in the .ind file or index.

As the first entry shows, a work around is to move the \index command outside of \emph. But swapping the fourier package for amssymb demonstrates that it is not necessary in general.

Is there a way to modify the behaviour of the fourier package so such index entries work inside \emph?

\documentclass{article}

\usepackage{fourier}
%\usepackage{amssymb}

\usepackage{makeidx}
\makeindex

\begin{document}

The \index{A@\( \mathbb A \)}%
\emph{\index{R@\( \mathbb R \)}%
\index{B@\( B \)}real numbers \( \mathbb R \)}.

\printindex
\end{document}
Andrew Swann
  • 95,762

2 Answers2

2

For some reasons, fourier.sty doesn't do

\DeclareSymbolFontAlphabet{\mathbb}{Ufutm}

but

\DeclareSymbolFontAlphabet{\math@bb}{Ufutm}
\AtBeginDocument{%
  \let\mathbb\math@bb
  [...<code omitted>...]
}

so the first level expansion of \mathbb becomes \protect\math@bb and the latter macro name gets written in the .idx file.

Workaround:

\documentclass{article}

\usepackage{fourier}

\makeatletter
\AtBeginDocument{\protected\def\mathbb{\math@bb}}
\makeatother

\usepackage{makeidx}
\makeindex

\begin{document}

The \index{A@\( \mathbb{A} \)}%
\emph{\index{R@\( \mathbb{R} \)}%
\index{B@\( B \)}real numbers \( \mathbb{R} \)}.

\printindex
\end{document}

This is the .idx file

\indexentry{A@\( \mathbb{A} \)}{1}
\indexentry{R@\( \mathbb {R} \)}{1}
\indexentry{B@\( B \)}{1}

Note, however, that you as usual risk different entries for those \index commands that are inside arguments to macros.

Avoid it, if you can. Otherwise do

\newcommand{\asindex}[1]{\index{#1}}

or add \string in front of the control sequences in the argument to \index when the command is in the argument to another one.

Andrew Swann
  • 95,762
egreg
  • 1,121,712
1

You can use

\emph{\index{R@\( \protect\mathbb R \)}%

Normally \index is read verbatim, but that does not work inside the argument of another command.

David Carlisle
  • 757,742