GeneralBasic problem with frontmatter/backmatter and the hyperref package

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Basic problem with frontmatter/backmatter and the hyperref package

Post by Cham »

Arrgh ! I thought that I was understanding this basic thing with the book class. Apparently, I'm doing something obviously wrong. The following MWE code reproduce my issue (the console isn't clear about the cause of the problem) :

Code: Select all

\RequirePackage[l2tabu,orthodox]{nag}
\documentclass[11pt,twoside]{book}
\usepackage[]{hyperref}

\begin{document}

\title{Title}\author{Thyrion Lanister}\date{1472}
\maketitle
\thispagestyle{empty}

\cleardoublepage
\pagestyle{plain}

\frontmatter

\section*{\centering Introduction} % Probably the wrong way to add an introduction (preface).

Some introduction.

\tableofcontents

\mainmatter

\chapter{A funny title}

Some boring text in the first chapter.

\end{document}
The error stops the compilation, and is clearly related to the hyperref package and is about referencing items. I have seen this problem a long time ago, but don't remember how it was fixed.

I'm getting this error message in the console :
pdfTeX warning (ext4): destination with the same identifier (name{page.1}) has been already used, duplicate ignored
<to be read again>
\relax
l.28 \end{document}
So what is wrong with the code above?

And what is the proper way in defining a "preface" (or "foreword"), which should be a centered title, without a chapter style?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Basic problem with frontmatter/backmatter and the hyperref package

Post by Cham »

Argh again! Pretty obvious in a way : I had to put the \frontmatter command just after the \begin{document}, not later in the code. Appears to solve the issue. I was obviously forgetting things! :oops:

Still not sure of the way I should define the introduction (preface), though.
Last edited by Cham on Mon Dec 04, 2017 9:59 pm, edited 1 time in total.
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Basic problem with frontmatter/backmatter and the hyperref package

Post by Johannes_B »

Your titlepage is part of the document. It is, in case, the very first page. Page number one.
But later, there is another page numbered one, so package hyperref gets confused where to put the links.

Either, except that the titlepage is a physical page and has a number and that the introduction is on paage 5 (or whatever), or use a differet numbering screen, such as alph. The pages have no (visible) page number anyway.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Basic problem with frontmatter/backmatter and the hyperref package

Post by Cham »

Thanks Johannes. But I solved the issue : as you said, the title page is a physical page number 1 in the document, so \frontmatter should be declared before it.

I'm wondering : How would you define a "foreword" (or preface) in a book class ? The way I've done it feels like a hack! :oops:
Post Reply