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.

I have the next defined command:

\def\underscore{\_\nobreak\hfil\protect\penalty0\hfilneg}

Then I want to set some text that usese my command into index:

\index{Items! New\underscore\Item}

I get incorrect reflection in Index part of my document:

Items

   M Item

I cannot understand what I do wrong?

share|improve this question
    
Please add a minimal working example (MWE) that illustrates your problem. It is considered a lot better to put in some code that will compile, as it makes it a lot easier for us to copy it into our text editor and work with it, and see exactly what it is you are trying to do. –  Heiko Oberdiek Nov 13 '12 at 17:12
add comment

1 Answer

up vote 2 down vote accepted

you probably need to put \protect before \underscore in the \index entry.

commands are expanded when written out to the .idx file, and since the expansion of \underscore contains an @ sign, it won't behave properly when it's read back in. the \protect ensures that the protected command goes into the .idx file as a literal, and will remain so when converted to the .ind file to be used by (la)tex to produce the index.

share|improve this answer
add comment

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.