1

I've began adding an index to my Latex project using imakeidx and have run into a small problem:

When writing the code

\index{\texttt{float} data type}

my index shows up as the following:

wrong index

It is showing the keyword in a new "Symbols" section which is not what I want. I assume this happens because \makeindex sees the \ and assumes it is not a regular word.

I've tested this by simply reverting back to

\index{float data type}

and it indexes just fine

correct index without monospace

but now my word is no longer monospaced which I desire.

Here is the relevant code:

\documentclass{article}
\usepackage{imakeidx}

...

\makeindex[columns=2, intoc]

\begin{document}
    ....

    The \texttt{float} data type\index{\texttt{float} data type} is the smallest
    real type, if they differ at all.

    ...

    \printindex
\end{document}

and the following .mst file:

headings_flag 1
heading_prefix "{\\Large\\textbf{"
heading_suffix "}}\\vspace{1mm}\\nopagebreak\n"
delim_0 "\\dotfill"
delim_1 "\\dotfill"
delim_2 "\\dotfill"

How can I have a monospaced font in my index while simultaneously putting it under the correct letter?

2
  • 1
    \index{float data type@\texttt{float} data type}
    – egreg
    Commented Dec 20, 2019 at 12:03
  • @egreg Thank you! Is much easier than I expected.
    – user202587
    Commented Dec 20, 2019 at 18:01

1 Answer 1

3

How egreg said, use the argument @ in index entry:

\index{<sort>@<word>}

<sort> is how to sort the term and <word> is how the term should appear in the index.

If you will index more data types, maybe will be interesting you treat it with subentries. To do this, you use the argument !:

\index{<main entry>!<subentry>}

In your case, I think this will be good:

\index{data type!float@\texttt{float}}

enter image description here

1
  • Thank you! I didn't realise it would be so easy.
    – user202587
    Commented Dec 20, 2019 at 18:01

You must log in to answer this question.