2

Using imakeidx package, I am generating indices. When defining an index key, I want to use @ for the key as follows:

\index{@variable}

@variable is the index key. It seems like @ is deserved for some other usage. How may I use the @ symbol?

1
  • I believe it is \index{"@variable}. You should 'quote' in this way any of: @, !, and | according to the makeindex manual.
    – jon
    May 9, 2016 at 4:15

1 Answer 1

3

The @ character is indeed reserved for MakeIndex processing; it is used for entries such as

\index{abc@\textit{abc}}

where the text to be indexed has formatting and we want to specify a key for sorting purposes.

You have two possibilities. The first is quoting the @ by typing

\index{"@variable}

(but this may fail if you load babel and a language that makes " into a shorthand prefix).

The second strategy is adding

\begin{filecontents*}{\jobname.mst}
actual '='
\end{filecontents*}

at the very beginning of your main TeX file (before \documentclass is the best place).

This assumes = is never used in your entries. The “sort key” entries like the example above can be input using = instead of @

\index{abc=\textit{abc}}

and \index{@variable} will now be sorted among the symbols.

The trick is that the filecontents* environment will write a file named <jobname>.mst (where <jobname> is the main TeX file name) and MakeIndex looks for it when processing a file.

However, this will prevent loading an .ist files, so beware. If you pass no option to MakeIndex, the method will work.

You must log in to answer this question.

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