I’m looking for any possible clues in trying to track down a cause for the following error while writing or processing the .ind file for a memoir class document (using latexmk with pdflatex):

\mathit allowed only in math mode

This is occurring, in the first instance with .ind entry

\item \idxmark{Urysohn Metrization Theorem}, \hyperpage{506}, 

The function \mainref is defined as:


But the error occurs even if I change \mainref to: \newcommand{\mainref}[1]{#1}

The log shows:

./book.ind:1772: LaTeX Error: \mathit allowed only in math mode.


l.1772 \item \idxmark{Urysohn Metrization Theorem}
                                                  , \hyperpage{502},

The preamble invokes hyperref as follows:

  colorlinks, citecolor=red, filecolor=black, linkcolor=blue, urlcolor=blue,
  linktocpage=true,linktoc=all, %

The portion of doc.ind around the cited line is:

\item \idxmark{upper semicontinuous map}, \hyperpage{317}, 
\item \idxmark{Urysohn Metrization Theorem}, \hyperpage{502}, 
\item \idxmark{Urysohn's Lemma}, \hyperpage{200}, \hyperpage{577}, 
        \mainref{577}, \hyperpage{578}
\item \idxmark{usual ordering}, \hyperpage{12--13}

And the end of book.idx is:

\indexentry{Urysohn's Lemma|mainref}{585}
\indexentry{Urysohn's Lemma|hyperpage}{585}
\indexentry{Urysohn's Lemma|)hyperpage}{586}
\indexentry{Tietze Extension Theorem|mainref}{586}
\indexentry{normal space!and Tietze Extension Theorem|hyperpage}{586}
\indexentry{normal space|)hyperpage}{586}
\indexentry{Urysohn Metrization Theorem|mainref}{586}

The document’s .ist file is:

item_0  "\n\\item \\idxmark{"
delim_0 "}, "
% not forgetting the subitem case
item_x1 "} \n \\subitem "
headings_flag 1
heading_prefix "{\\medskip\\hfill\\large\\textsf{\\textbf{"
heading_suffix "}}\\hfill}\\medskip\\nopagebreak\n"

where \idxmark is defined in my preamble by:


The purpose of \idxmark is to cause the header on each Index page to show the first and last entries on the page (except for the first page).

If I comment out the \index entries for that “Urysohn Metrization Theorem”, then the same error occurs for other entries or subentries.

I can (awkwardly) work around the error by ignoring it and processing the source once more with pdflatex, but clearly something is wrong.

In case it helps, the index entry in question appears on the final page of output, shown here:

End of index includes entry causing error

Likely resolution:

The error arises from my improper use of the repeatindex package, in that I did not modify index entries by causing index entries to be created in the form \item [Main Item A], 1, 3, 6 ). And that can be accomplished by using makeindex -s repeatindex, that is, by using the file repeatindex.ist that is part of the repeatindex package. But this may conflict with my existing custom .ist file shown above. I have deferred asking about that to How modify custom .ist to incorporate repeatindex.

I apologize for not yet providing a complete, minimal working example for reproducing the error, but I think some clue might help me devise such. The document in question is of book length, with a complex source structure that includes multiple style files constituting the preamble.

  • 1
    can't say much without an example, but is the error you show the first error or did an earlier error (eg from a mis-placed ^) start an unexpected math mode somewhere Feb 14 '20 at 21:48
  • 1
    Is there a page break around this place? Feb 14 '20 at 21:50
  • add \tracingmacros=1 a bit before the index entry and then show in the log-file. Feb 14 '20 at 22:02
  • @UlrikeFischer: I'm not seeng any page break around the \index entry in source or in the corresponding output.
    – murray
    Feb 14 '20 at 22:09
  • well there is a column break. Where are the dots from? Feb 14 '20 at 22:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.