1

I'm using imakeidx package in a document for learning programming. I have two separate indexes: one for the general concepts, one for all of the commands, functions, modules, etc. I use a separate index_cmd_style.istfile to set up the layout of the second index. I would like to use \ttfamily to format each entry of the commands index and leave general index entries as default.

I tried to use \indexsetup{othercode=\ttfamily} but it changed the font for both indexes.

If I use \index[cmd]{\texttt{while}}, it sorts the entry under Symbols. If I use \index[cmd]{\ttfamily while}, its sort also this entry under Symbols and in addition it format the page number.

However, if I do NOT use the index_cmd_style.ist file, \index[cmd]{\texttt{while}} does the trick!

Anyone has an idea how to still use a *.ist file to format the layout but change the font of each entry of one particular index?

Thank you for answering, Sylvain

Here is my MWE:

\documentclass[a4paper]{article}
\usepackage{imakeidx}

\makeindex[title=General Index]
\makeindex[name=cmd, title=Index of Commands, options= -s index_cmd_style.ist]


\begin{document}

For a loop\index{loop} one can use the \texttt{while}\index[cmd]{while} command. 

One could also use \texttt{for}\index[cmd]{\ttfamily for} or \texttt{do \dots{} while}\index[cmd]{\texttt{do \dots{} while}}.


\printindex
\printindex[cmd]

\end{document}

Here is my index_cmd_style.ist file content:

headings_flag 1
heading_prefix "{\\large\\sffamily\\bfseries "
heading_suffix "}\\nopagebreak\n"
delim_0 " \\dotfill "
delim_1 " \\dotfill "
delim_2 " \\dotfill "
2

\indexsetup does general settings for all index lists, not for a particular one.

It's better, in my point of view, to change the \item_0 style within .ist to use \ttffamily explicitly.

\documentclass[a4paper]{article}
\usepackage{imakeidx}

\makeindex[title=General Index]
\makeindex[name=cmd, title=Index of Commands, options= -s index_cmd_style.ist]


\begin{document}

For a loop\index{loop} one can use the \texttt{while}\index[cmd]{while} command. 

\index[cmd]{loop}

One could also use \texttt{for}\index[cmd]{for} or \texttt{do \dots{} while}\index[cmd]{do \dots{} while}.


\printindex
\printindex[cmd]

\end{document}

Modified index_cmd_style.ist

headings_flag 1
heading_prefix "{\\large\\sffamily\\bfseries "
heading_suffix "}\\nopagebreak\n"
item_0 "\n \\item \\ttfamily "
delim_0 " \\dotfill "
delim_1 " \\dotfill "
delim_2 " \\dotfill "

enter image description here

  • Thank you ! It does almost what I was expected. However, the font for the page number is affected by the \ttfamily also... Maybe an other parameter such as item_0 exists to access the font of the page number? I did not find any documentation about these parameters in the official doc of imakeidx. How do you know about these parameters? – Sylvain Chambon Oct 3 '15 at 12:37
  • Replace delim_0 " \\dotfill " by delim_0 " \\normalfont\\dotfill ". Neither makeidx or imakeidx provide information on the parameters since the index generator is an external programme, called makeindex. If you have a copy of the LaTeX Companion, you will find some explanations. – user31729 Oct 3 '15 at 13:06
  • irrelevant to answer, but for nicer (more symmetric) spacing, use a backslash after \dots instead of {} in the "do ... while" line. – barbara beeton Oct 3 '15 at 15:27
  • @barbarabeeton: That's code from the O.P., not mine. I won't change anything -- the question was about the font settings, but thanks – user31729 Oct 3 '15 at 17:01
  • @ChristianHupfer -- no problem; your answer shows output, the question has only code. (easier to notice this in the output.) – barbara beeton Oct 3 '15 at 18:24

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.