I would like to produce an index that has italic entries with subitems, as outlined in this answer. But, I would like to add the italic format in the background, i.e. I would like to pass index!subitem and have that converted to index@\textit{index}!subitem@\textit{subitem} before being passed to \index.
Here's what I tried:
MWE:
\documentclass{book}
\usepackage{xparse}
\usepackage{makeidx}
\NewDocumentCommand{\italicise}{ >{\SplitList{!}} m }{%
\ixtestfalse
\ProcessList{#1}{\italiciseone}%
}
\newif\ifixtest
\NewDocumentCommand{\italiciseone}{m}{%
\ifixtest !\else\ixtesttrue\fi
#1@\textit{#1}}
\makeindex
\begin{document}
test
\index{Manual@\textit{Manual}!italics@\textit{italics}}
\index{\italicise{Automated!italics}}
\printindex
\end{document}
I think I'm halfway there, but it looks as if the \italicise command needs to be expanded when/before passed to \index, as the idx-file suggests:
\indexentry{Manual@\textit{Manual}!italics@\textit{italics}}{1}
\indexentry{\italicise{Automated!italics}}{1}
Output:
For sake of completeness, the ind-file:
\begin{theindex}
\item \italicise{Automated
\subitem italics}, 1
\indexspace
\item \textit{Manual}
\subitem \textit{italics}, 1
\end{theindex}
BTW, I don't have to use xparse, but these days, I always try that first.
EDIT
I now found a solution without using xparse, but I'd still be interested to see if this can be done via xparse or LaTeX3-Syntax.


xparse... – takrl Sep 11 '17 at 08:41