This is an extension to a previous question: Color alphabetically display the items in itemize. I would like to have color in my sorted items with indexes and footnotes. The solution provided by Schrödinger's cat works beautifully, but it seems when I have multiple items that start with the same letter, I get the following error:
! TeX capacity exceeded, sorry [input stack size=5000]. \reserved@a ->\def \reserved@a *{@sdtlgetdatatype }\reserved@a l.48 \end{sortedlist}
Here is a MWE:
\documentclass{article}
\usepackage{xcolor}
\usepackage{datatool}% http://ctan.org/pkg/datatool
\newcommand{\sortitem}[2][\empty]{%
\DTLnewrow{list}% Create a new entry
\DTLnewdbentry{list}{description}{#2}% Add entry as description
\DTLnewdbentry{list}{font}{#1}% Add entry as font
}
\newenvironment{sortedlist}{%
\DTLifdbexists{list}{\DTLcleardb{list}}{\DTLnewdb{list}}% Create new/discard old list
}{%
\DTLsort{description}{list}% Sort list
\begin{itemize}%
\DTLforeach*{list}{\theDesc=description,\myFont=font}{%
\item {\myFont\theDesc}}% Print each item
\end{itemize}%
}
\usepackage{makeidx} % Required to make an index
\makeindex % Tells LaTeX to create the files required for indexing
\usepackage{xcolor} % Required for specifying colors by name
% This is necessary to allow colorizing the mark for the footnotes, from https://tex.stackexchange.com/questions/26693/change-the-color-of-footnote-marker-in-latex
\definecolor{bondiblue}{rgb}{0.0, 0.58, 0.71} %use this color for footnotes.
\makeatletter
\renewcommand\@makefnmark{\hbox{\@textsuperscript{\normalfont\color{bondiblue}\@thefnmark}}}
\makeatother
\makeatletter
\newcommand\footnoteref[1]{\protected@xdef\@thefnmark{\ref{#1}}\@footnotemark}
\makeatother
\begin{document}
Sorted:
\begin{sortedlist}
\sortitem{ISDYNSTP and such:}
\sortitem[\protect\color{red}]{ZVAR is good\footnote{about zvar}\index{Zvar}}
\sortitem{ISCDCA:}
\sortitem{PFT}
\sortitem[\protect\color{orange}]{MVAR is okay too\footnote{about mvar}\index{mvar}}
\sortitem[\protect\color{blue}]{MCAR is fine\footnote{about mcar}\index{mcar}}
\sortitem{IS2TL}
\end{sortedlist}
\printindex % Output the index
\end{document}
The code above works if I remove either the 'MVAR' or 'MCAR' line, but I can't have both. It seems to have to do with the footnote and index.
If I have both 'MVAR' and 'MCAR' but no footnote or index for either, it works. But if I have an index or footnote for either 'MVAR' or 'MCAR' it doesn't work. Is there a way to fix this so that both appears? I would like to be able to have any number of items (with footnote and/or index) that begins with the same letter. Any help would be appreciated, thank you!

