Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Friends, as a follow up to Overlapping TikZ nodes to look as a tape strip, I added a TikZ code to an index entry using the splitidxpackage. Consider this code:

\documentclass{article}

\usepackage[useindex]{splitidx}

\newindex[Index of Foo]{iof}

\makeindex

\usepackage{tikz}
\usetikzlibrary{chains,backgrounds}

\usepackage{xstring}

\tikzset{
    tape node/.style={
        on chain,
        draw,
        inner sep=1pt,
        outer xsep=0pt,
        minimum height=0.2cm,
        minimum width=0.2cm
    }
}

\newcommand*\myblackbox[1]{%
    \node[
        tape node
    ] {\tiny\tt\raisebox{0pt}[\height][0pt]{#1}};
}

\newcommand*\mygraybox[1]{%
    \begin{pgfonlayer}{background}
        \node[
            tape node,
            gray!60
        ] {\color{gray!60}\tiny\tt\raisebox{0pt}[\height][0pt]{#1}};        \end{pgfonlayer}
}

\DeclareRobustCommand*\drawboxes[1]{%
\begin{tikzpicture}[
        start chain=going right,
        node distance=0pt
    ]
    \IfSubStr{#1}{A}{\myblackbox{A}}{\mygraybox{A}}%
    \IfSubStr{#1}{N}{\myblackbox{N}}{\mygraybox{N}}%
    \IfSubStr{#1}{C}{\myblackbox{C}}{\mygraybox{C}}%
    \IfSubStr{#1}{Q}{\myblackbox{Q}}{\mygraybox{Q}}%
    \IfSubStr{#1}{P}{\myblackbox{P}~}{\mygraybox{P}~}
\end{tikzpicture}
}

\begin{document}

\sindex[iof]{\drawboxes{AC} Oranges}
\sindex[iof]{\drawboxes{ANCQ} Grapes}
\sindex[iof]{\drawboxes{CP} Bananas}
\sindex[iof]{\drawboxes{Q} Avocado}
\sindex[iof]{\drawboxes{P} Strawberry}

\printindex*

\end{document}

It works like a charm, but unfortunately, due to the TikZ code added to the beginning of the entry, the alphabetical order is lost:

List of foo

I have a wild guess: by passing some regular expression pattern to the splitindex parser tool, I could somehow make the generated index ignore the TikZ code at the beginning of the entry.

If possible, I'd like to stick with the splitidx package, as it can handle several indices I have in the document. Any help is appreciated.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

It's standard makeindex syntax:

\sindex[iof]{Oranges@\drawboxes{AC} Oranges}
\sindex[iof]{Grapes@\drawboxes{ANCQ} Grapes}
\sindex[iof]{Bananas@\drawboxes{CP} Bananas}
\sindex[iof]{Avocado@\drawboxes{Q} Avocado}
\sindex[iof]{Strawberry@\drawboxes{P} Strawberry}
share|improve this answer
    
Fantastic, egreg! I had no idea of this syntax. Thanks! –  Paulo Cereda Jul 15 '11 at 10:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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