3

I'm working on a text that has to be split up in 4 parts, with each part containing it's own table of contents and it's own appendix. Four separate pdf's are needed.

The page numbers and section numbering has to be continued from one part to the other though, so eg. if DEEL1 (in english: PART1) ends at page 10, DEEL2 has to continue at page 11. Since I know the length of each document I have done this manually using \setcounter{page}{10} (same goes for sectioning, although I'm not sure of how to let the appendix sectioning work).

My directory is split up into folders for each part.

DELEN
├── DEEL1
├── DEEL2
├── DEEL3
└── DEEL4

Now I'd like to be able to reference something that isn't in that particular part. Eg.: if \label{prt1:sec:section2} is in part one, I would like to be able to use \ref{prt1:sec:section2} in parts two, three and four too.

Is this possible?

romeovs
  • 9,102

1 Answers1

2

File deel1.tex in directory deel1

\documentclass[a4paper]{article}
\usepackage{lastpage,xr,refcount,etoolbox}
\externaldocument{../deel2/deel2}
\externaldocument{../deel3/deel3}

\makeatletter
\patchcmd{\lastpage@putl@bel}{LastPage}{LastPage1}{}{}
\makeatother

\begin{document}
\tableofcontents

\section{First deel1}\label{first1}

\section{Second deel1}\label{second1}

\ref{first1} at page \pageref{first1}

\ref{second1} at page \pageref{second1}

\ref{first2} at page \pageref{first2}

\ref{second2} at page \pageref{second2}

\ref{first3} at page \pageref{first3}

\ref{second3} at page \pageref{second3}

\end{document}

File deel2.tex in directory deel2

\documentclass[a4paper]{article}
\usepackage{lastpage,xr,refcount,etoolbox}
\externaldocument{../deel1/deel1}
\externaldocument{../deel3/deel3}

\makeatletter
\patchcmd{\lastpage@putl@bel}{LastPage}{LastPage2}{}{}
\makeatother

\begin{document}
\setcounter{page}{\getpagerefnumber{LastPage1}}
\stepcounter{page}
\tableofcontents

\section{First deel2}\label{first2}

\section{Second deel2}\label{second2}

\ref{first1} at page \pageref{first1}

\ref{second1} at page \pageref{second1}

\ref{first2} at page \pageref{first2}

\ref{second2} at page \pageref{second2}

\ref{first3} at page \pageref{first3}

\ref{second3} at page \pageref{second3}

\end{document}

File deel3.tex in directory deel3

\documentclass[a4paper]{article}
\usepackage{lastpage,xr,refcount,etoolbox}
\externaldocument{../deel1/deel1}
\externaldocument{../deel2/deel2}

\makeatletter
\patchcmd{\lastpage@putl@bel}{LastPage}{LastPage3}{}{}
\makeatother

\begin{document}
\setcounter{page}{\getpagerefnumber{LastPage2}}
\stepcounter{page}
\tableofcontents

\section{First deel3}\label{first3}

\section{Second deel3}\label{second3}

\ref{first1} at page \pageref{first1}

\ref{second1} at page \pageref{second1}

\ref{first2} at page \pageref{first2}

\ref{second2} at page \pageref{second2}

\ref{first3} at page \pageref{first3}

\ref{second3} at page \pageref{second3}

\end{document}

Notes

We have to patch \lastpage@putl@bel in order to have different labels in different documents (the "prefix" strategy provided by xr would be more cumbersome). The command to patch if hyperref is used is \lastpage@putl@belhyper (same code).

The same scheme will work for citations if the xcite package is used.

egreg
  • 1,121,712
  • I'd like to thank you for your effort using the patched lastpage command. For some reason this didn't work though. Even so, you inspired me to create a simpler solution: put \label{LAST1} on the end of DEEL1.tex and use \setcounter{page}{\getpagerefnumber{LAST1}} in DEEL2.tex. Not as elegant but at least I know what's happening. – romeovs Sep 24 '11 at 09:54