I have defined an Example environment that I use as follows to produce a numbered example and send the example title to an example index:
\begin{Example}[one]{Cooking eggs}
To cook an egg, ...
\end{Example}
But then, if I have another related example, and do
\begin{Example}[two]{Cooking eggs: microwave method}
To microwave an egg, ...
\end{Example}
I get separate index entries,
Cooking eggs 1
Cooking eggs: microwave method 1
But I'd rather have the second be a subentry (ie, use Cooking eggs!microwave method
for the index entry), yet still print the title as Cooking eggs: microwave method
Cooking eggs 1
microwave method 1
So, I'd rather redefine my Example environment to use it as something like:
\begin{Example}[two]{Cooking eggs}{microwave method}
To microwave an egg, ...
\end{Example}
or even (two avoid dealing with another optional argument, at the expense of parsing)
\begin{Example}[two]{Cooking eggs!microwave method}
To microwave an egg, ...
\end{Example}
How can I re-write the environment commands to do this?
Here is a MWE with my current definition of the Example environment:
\documentclass[12pt]{book}
\usepackage{index}
% Define a separate Examples Index
\newcommand{\ixe}[1]{\index[xmp]{#1}}
\newcommand{\ixeon}[1]{\ixe{#1|(}} % when not automatically done by Example
\newcommand{\ixeoff}[1]{\ixe{#1|)}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Numbered examples that can be referenced and produce index entries
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\newcounter{example}[chapter]
\renewcommand{\theexample}{\thechapter.\arabic{example}}
\newenvironment{Example}[2][\theexample]{%
\refstepcounter{example}%
\label{ex:#1}%
\def\theexamplename{#2}%
\begin{trivlist}%
\item[%
% \hskip-\labelsep % idiosyncrasy that needs learning
\textbf{\textsc{Example \theexample}:}] %
\textbf{#2}\par
\ixe{#2|(}%
}{%
\expandafter\ixe\expandafter{\theexamplename|)}% magic from Bernd
\hfill$\triangle$
\end{trivlist}%
}
\begin{document}
\chapter{First chapter}
\section{First section}
asdfasfasfs
\begin{Example}[one]{Cooking eggs}
To cook an egg, ...
\end{Example}
sfafsf
\begin{Example}[two]{Cooking eggs: microwave method}
To microwave an egg, ...
\end{Example}
\end{document}
\ixe
stuff seems to be complicated. I suggest to useimakeidx
and it's separate index features\begin{Example}[two]{Cooking eggs}{microwave method}
has one optional and two mandatory arguments, whicch is already supported by\newenviornment
Did you mean to use two optional arguments?\textbf{\textsc{}}
. The bold face will be applied only to the number and:
I guess.\textbf{\textsc{}}
but the default cm fonts don't have such a font so it substitutes, so it will work or not in the real document depending on font choice.