I am trying to create a command TESTCMD which creates a tcolorbox containing text provided as argument.
Additionally, the command uses \index to include the argument in the index at the end of the document.
Interestingly, there is no text shown in the colorbox, but the text is listed in the index.
If the instruction \index{#1} is replaced by {#1} (that is: \index is omitted}, it works as expected (but of course, the index it not built then).
I compile the code with the sequence pdflatex, then makeindex and then pdflatex again.
Find the code below; any help appreciated.
-- Christoph
Code: Select all
\documentclass{book}
\usepackage[many]{tcolorbox}
\usepackage{imakeidx}
\makeindex
\newcommand{\TESTCMD}[1]{
\tcbset{
enhanced,colframe=white,coltitle=black,%sharp corners,
frame style={top color=red!30,bottom color=white},
fonttitle=\bfseries,interior hidden,title hidden,
}
\begin{tcolorbox}
{\bf \underline{\index{#1}}}
\end{tcolorbox}
}
\begin{document}
\TESTCMD{The text is swallowed}
\printindex
\end{document}