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.

In book class, I want to redefine the \printindex command and change it to something like the following:

‎\addcontentsline{toc}{chapter}{‎Index}‎‎‎‎
‎\fancypagestyle{plain}{%‎
‎\fancyhf{}‎                        
‎\renewcommand{\headrulewidth}{0pt}‎
‎\renewcommand{\footrulewidth}{0pt}‎
}
‎\printindex‎

How can I do this?
My tex file is as follow:

\documentclass{‎book‎}‎‎
‎\usepackage{fancyhdr} ‎‎
‎\usepackage{makeidx}‎
‎\makeindex‎
‎‎\begin{document}‎‎
‎\tableofcontents‎
‎\chapter{One}‎‎
‎Hi!‎
\index{‎abc‎}
\index{‎def‎}‎‎
‎\addcontentsline{toc}{chapter}{‎Index}‎‎‎‎
‎\fancypagestyle{plain}{%‎
‎\fancyhf{}‎                        
‎\renewcommand{\headrulewidth}{0pt}‎
‎\renewcommand{\footrulewidth}{0pt}‎
}
‎\printindex‎
‎\end{document}
share|improve this question
    
the page style plain is the default for the index. Why do you want to redefine it? –  Herbert Feb 10 '11 at 16:23
    
@Herbert: I wanted to delete the page number on the first page. –  Vahid Damanafshan Feb 10 '11 at 19:48

1 Answer 1

up vote 4 down vote accepted

You can save a macro away using \let\origmacro\macro, where \origmacro is a name you can pick. Then your redefine the macro and call its original version internally, mostly at the very end:

\let\origprintindex\printindex‎
\renewcommand*{\printindex}{%
  \addcontentsline{toc}{chapter}{‎Index}‎‎‎‎%
  ‎\fancypagestyle{plain}{%‎
  ‎  \fancyhf{}‎%
    ‎\renewcommand{\headrulewidth}{0pt}‎%
    ‎\renewcommand{\footrulewidth}{0pt}‎%
  }%
  ‎\origprintindex‎
}

You might want to place all this into a group.

share|improve this answer
    
Thanks, this is exactly what I was looking for. BTW, is this method applicable for every command (e.g., ‎\tableofcontents‎)? –  Vahid Damanafshan Feb 10 '11 at 16:20
2  
@Vahid: It should work for all user macros. But you must be careful not to redefine a robust macro in a fragile way. I'm talking about macros which are written into to ToC and .aux files, e.g. the ones used inside section titles. Also problems arise when two people/packages redefine the same macro and use the same name for '\origmacro'. –  Martin Scharrer Feb 10 '11 at 16:27
    
Thanks, your explanation is quite clear. –  Vahid Damanafshan Feb 10 '11 at 19:46

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.