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.

When I ad an index entry using \index with all the options available for the "format" and "see", and cross-reference, I'd like to see at the place where I make the index entry how this specific entry will/would appear in the index, i.e.

  • Is it bold here?
  • How is it sorted?
  • Will the number be bold?
  • Does it point elsewhere with "see"?

Currently I write the text in the margin with \marginpar but I am not quite satisfied with this. Maybe there is a better way that someone else already uses?

share|improve this question
1  
Related Question: Mark indexed entries in the text itself?. –  Peter Grill Aug 18 at 6:49
    
@PeterGrill Whow. Had I only known. I put my own tikz macro in place, doing exactly that. –  towi Aug 18 at 13:22
    
Well, that is a new question. Perhaps you can post an answer using your tikz macros. –  Peter Grill Aug 18 at 17:30

1 Answer 1

You can automatize the generation of the marginal note:

\usepackage{etoolbox}

\makeindex
\makeatletter
\pretocmd\@wrindex
  {\marginpar{\begingroup\catcode`\{=12\catcode`\}=12 \texttt{\scantokens{#1}}\endgroup}}
  {}{}
\makeatother

Thus each \index command will print in the margin the argument "as is". I believe this is better than trying to replicate the final aspect: all the information is there and in a very distinctive way.

The patching can be made depend on the draft option but not in a very robust way, as that option, in the standard classes, just sets \overfullrule:

\usepackage{etoolbox}

\makeindex
\makeatletter
\ifdim\overfullrule>\z@
  \pretocmd\@wrindex
    {\marginpar{\begingroup\catcode`\{=12\catcode`\}=12 \texttt{\scantokens{#1}}\endgroup}}
    {}{}
\fi
\makeatother

A more robust way might be to check if draft appears in the expansion of \@classoptionslist or putting the code inside a personal package, say margind.sty:

\ProvidesPackage{margind}
\@tempswafalse
\DeclareOption{draft}{\@tempswatrue}
\ProcessOptions\relax

\RequirePackage{etoolbox}

\if@tempswa
\pretocmd\@wrindex
  {\marginpar{\begingroup\catcode`\{=12\catcode`\}=12
     \texttt{\scantokens{#1}}\endgroup}}{}{}
\fi

A possible "definitive" solution that takes into account the suggestions in comments could be

\usepackage{ifdraft}
\usepackage{etoolbox}

\makeatletter
\def\margin@index#1{\marginpar{\texttt{\detokenize{#1}}}}
\ifdraft{}{\let\margin@index\@gobble}
\pretocmd{\@wrindex}{\margin@index{#1}}
\makeatother

The argument to the \index command will be written in the margin only when the documentclass option draft is specified.

share|improve this answer
    
Is there an easy way to make this depend to the "draft" documentclass option? –  Alessandro Cuttin Nov 6 '11 at 12:04
    
There’s also the ifdraft package which makes it maybe easier (i.e. more readable) to test if one is in draft mode or not. –  Tobi Nov 6 '11 at 13:16
1  
@egreg: The \ifdraft syntax is not \ifdraft then \else else \fi but \ifdraft{ then }{ else } –  Schweinebacke Nov 6 '11 at 15:18
    
@Schweinebacke Thanks! –  egreg Nov 6 '11 at 15:20
1  
@egreg: BTW: Why not \marginpar{\begingroup\texttt{\detokenize{#1}}\endgroup}? –  Schweinebacke Nov 6 '11 at 15:24

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.