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.

The quasi-MWE below uses the memoir class and works fine. It produces a document with the following structure:

  • ToC
  • Book
    • Part1
    • Chapter1
    • Part2
    • Chapter2
  • Index

Here, cross-references in the ToC and in the Index all work correctly. But I want to reset Chapter numbers back to "1" in each Part (and ultimately, in each Book, if there are many books). To do so, I uncomment the \counterwithin instructions in the preamble.

Now, depending on the value assigned to hyperref's hypertexnames option, I get the following behaviour:

  • if true, the ToC link to Chapter "2" in Part 2 (which is now renumbered to "1") does not works, but the Index link to AAAAA on page "5" does;

  • if false, the ToC link to Chapter "2" in Part 2 (which is now renumbered to "1") works, but the Index link to AAAAA on page "5" does not.

Am I doing something wrong?


\documentclass[a4paper,12pt]{memoir}

%\counterwithin*{chapter}{part}           % Restarts chapter count within Part.

\usepackage{hyperref}             
\hypersetup{
    hypertexnames=true,                
    linktocpage=false,
    colorlinks=true,                                        
}
\indexintoc
\makeindex[main]

\begin{document}
\frontmatter{}
\tableofcontents*
\mainmatter{}
\book{BookTitleA}
 \part{PartTitleA}
  \chapter{TitleA}
AAAAA\index[main]{AAAAA}.\\
 \part{PartTitleB}
  \chapter{TitleB}
BBBBB.
\backmatter
 \clearpage
 \printindex[main]
\end{document}
share|improve this question
    
\documentclass[a4paper,12pt]{memoir} %\counterwithin*{chapter}{part} % Restarts chapter count within Part. \usepackage{hyperref} \hypersetup{ hypertexnames=true, linktocpage=false, colorlinks=true, } \indexintoc \makeindex[main] \begin{document} \frontmatter{} \tableofcontents* \mainmatter{} \book{BookTitleA} \part{PartTitleA} \chapter{TitleA} AAAAA\index[main]{AAAAA}. \part{PartTitleB} \chapter{TitleB} BBBBB. \backmatter \clearpage \printindex[main] \end{document} –  Olivier Drolet Oct 19 '11 at 19:45
    
My apologies for my formatting failures. –  Olivier Drolet Oct 19 '11 at 19:51
    
If you need to modify your original question, click on the edit and add the relevant code, rather than posting uncommented code in a comment. Once you're done, clean up the comments section be removing the non-relevant ones. –  Werner Oct 19 '11 at 20:03
    
The latex code initially appeared mangled in my post. That's why I commented in order to fix it (I'll do what you suggest, from now on). However, I see that the code is now properly formatted, I just don't know why or how to ensure that it will be in future posts. –  Olivier Drolet Oct 19 '11 at 20:10
    
If you indent lines by 4 spaces, they'll be marked as a code sample. You can also highlight the code and click the "code" button (with "{}" on it). You can use backticks ` to mark your inline code‌​. The latter also holds for comments, as you already know. –  Werner Oct 19 '11 at 20:12
show 1 more comment

1 Answer

up vote 9 down vote accepted

Simply moving \counterwithin* after \hypersetup seems to solve the problem:

\usepackage{hyperref}             
\hypersetup{
    hypertexnames=true,                
    linktocpage=false,
    colorlinks=true,                                        
}
\counterwithin*{chapter}{part}
share|improve this answer
    
Indeed! Thank you. –  Olivier Drolet Oct 21 '11 at 23:17
    
I was searching for this solution for many hours now. There are lots of different tipps, but this is the only solution which worked for me! –  jrast May 25 '13 at 8:11
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.