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 need to set up two types of appendixes: Appendixes and Annexes

They must appear as "Appendix A - Title of Appendix A", etc, and "Annex A - Title of Annex A", etc. in the chapter head (which I managed to do with a \renewcommand{\appendixname}{Annex}.)

I also need that they appear that way in the table of contents... but a \renewcommand{\cftappendixname}{Annex} works globally...

share|improve this question
    
Welcome to tex.sx! A tip: you can use backticks ` to mark your inline code as I did in my edit –  Gonzalo Medina Jun 1 '11 at 0:12

2 Answers 2

up vote 5 down vote accepted

My browser does not like the forms on this site, so I'll answer here.

\cftinserthook{toc}{AAA}

inserts a hook command into the toc file at the time where the command is placed in the document. The corersponding hook code does not need to be defined, if not it is silently ignored.

In our case we could simply define the hook in the preamble as

\cftinsertcode{AAA}{\renewcommand*{\cftappendixname}{Annex}}

The nice thing about this is that then one does not need to worry about \protect

share|improve this answer
    
Thanks, it worked fine! I just messed myself up at first (my bad), adding \cftinserhookto the preamble... The solution was to add \cftinsertcodein the preamble and telling the \annex command I mentioned before to \cftinserthook –  henrique Jun 1 '11 at 15:01
    
I just forgot to mention that the hyperref problem persisted... I managed to "fix" it, so to speak, by adding a \phantomsection to the chapter style (with \renewcommand{\printchaptername}{\phantomsection\chapnamefont \@chapapp}) –  henrique Jun 1 '11 at 15:15

This sort of thing is often awkward, because you need the change to occur while \tableofcontents is doing its work. A dirty trick is to put the command that changes the appendix name used by the table of contents inside the .toc file.

\documentclass{memoir}
%
\makeatletter
\newcommand\@switch[1]{ \@writefile{toc}{\renewcommand*{\cftappendixname}{#1 \space}} }
\newcommand{\switchchapname}[1]{ \protected@write \@auxout {}{\string\@switch{#1} }}
\makeatother
%
\begin{document}
\renewcommand*{\cftappendixname}{Appendix \space}
\tableofcontents
\chapter{A chapter}
text.
\appendix
\chapter{An appendix}
more text.
\switchchapname{Annex}% Corrected from \switchapname → \switchchapname
\renewcommand{\appendixname}{Annex}
\chapter{An annex}
Yet more text.
\switchchapname{Another name}% Corrected from \switchapname → \switchchapname
\renewcommand{\appendixname}{Another name}
\chapter{Something else}
Yet more text.
\end{document}
share|improve this answer
1  
you might need to add more \appendix in order to reset the chapter counter. Also note the it may not work well with hyperref. Also \cftinsertcode and \cftinserthook might be useful in this case. –  daleif Jun 1 '11 at 11:01
    
@Ian-Thompson: It did work, thanks. I've created a command \annexthat comprises both changes: \cftappendixnameand \switchchapname, besides starting a new \appendix. @daleif: About hyperref, it wasn't working well already... But I wouldn't know how to use \cftinsertcode to do so. –  henrique Jun 1 '11 at 12:28

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.