I was unable to solve this by myself and by searching this wonderful site. The problem is with indexing. I still consider myself as a LaTeX newbie :)
The situation:
- I'm working on an english book about programming (300+ pages). For this I'm using makeidx and varindex packages; they are awesome and work well.
- In this book there are number of macros, like \type{std:integer}
, \var{variable}
, \const{SIZE}
, \kword{for}
, etc. They just provide correct text formatting, nothing magic.
What I want - These macros I would like to use to index all those words for one- or two-level indexing. Some questions are at the end of this post.
What I did:
- I changed all macros (\type{}
, \const{}
, etc.) to the versions, which include also \index{#1}
, which was quite simple. Here is the example:
\newcommand{\type}[1]{
\mbox{\texttt{#1}\index{#1}}
}
This gives me a simple index, and it is working well. However, in the Index I have very long lists of many variables, constants and types, all beginning with the same prefix, i.e. cl::Source
, cl::Program
, or CL_xxx
, CL_yyy
, etc.
My attempts:
I would like to make an index with main single word - cl:: and all words beginning with cl:: put as subitems under it. This can be done by hand, and much of editing, but I figured out the xstring package, and \StrBehind
function.
So, I defined the macro in the following way:
\newcommand{\typei}[1]{%
\IfBeginWith{#1}{cl}{%
\IfBeginWith{#1}{cl::}
{\mbox{\texttt{#1}}\index{cl::!\StrBehind{#1}{cl::}}}
{\mbox{\texttt{#1}}\index{cl!#1}}
}{%
\IfBeginWith{#1}{CL}{%
\IfBeginWith{#1}{CL\_}
{\mbox{\texttt{#1}}\index{CL\_!\StrBehind{#1}{CL\_}}}
{\mbox{\texttt{#1}}\index{CL!#1}}
}%
{%
\mbox{\texttt{#1}}\I{#1}%
}%
}%
}
This (probably) is causing LaTeX error:
! TeX capacity exceeded, sorry [input stack size=5000].
\reserved@a ->\def \reserved@a
*{\let \@xs@assign \@xs@expand@and@detokenize...
l.1127 ...nstructor of the type \typei{cl::Source}
and then the source is pa...
! ==> Fatal error occurred, no output PDF file produced!
So, I have a rather general questions:
How to define a macro which can index any word with given starting characters, which separates this start from the rest for two-level index? I mean the following:
\type{cl::Type}
will generate the effect like\texttt{cl::Type}\index{cl::!Type}
. And preferably the macro will by default separatecl::
from the rest, and should be working for any other word just like normal.How to make such macros for different types of usage? I'd like rather to avoid typing all very similar macros for
\kword
,\var
,\const
,\type
,\func
, etc. - they are all quite similar, and differ only in typography. Maybe it is a way to write something like a macro for generating another macros?The ideal solution will allow to index words with some predefined prefixes, like
std::
,cl::
, orCL_
... this would be very helpful.
Indexing such a book is huge task and I'm a bit overhelmed. Using only \index{}
command is messing the normal text also. The usage of varindex package greatly improves the indexing by defining circular references and cross-references, which are very customizable. The whole package is a bit difficult to understand but has a great number of possibilities. Maybe there is some hacky way to made this simple?
Sorry for such long post, I tried to make things as clear as possible. I count on your help, *TeX
hackers! :) You are my only HOPE! :)
\documentclass
so that those trying to help don't have to recreate it.%
at the end of the lines of the definition of\type
. See the difference between the output of\type{a}\type{b}
with and without the%
. As I had a similar error before with tex capacity exceeded if remove % after use of macro, so perhaps that is one cause of you problems.