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'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?

share|improve this question
    
It might be possible with the xr or the more modern zref-xr package (zref bundle). In this case How can I reference a table/figure/section in another document? and referencing labels from other files would be related, but not that useful to you. –  Martin Scharrer Sep 23 '11 at 8:01
    
yes, I know about the xr package, but how would I go about pointing it to the correct directory? Can I just use: \externaldocument{../DEEL1/DEEL1} or would this be too simple? –  romeovs Sep 23 '11 at 8:13
1  
I would say that is so simple, but accessing files in lower hierarchies (i.e. using the ..) might not be allowed by the security settings. –  Martin Scharrer Sep 23 '11 at 8:19
1  
@MartinScharrer It's forbidden to write in directories above or specified with an absolute path. Reading is usually allowed. –  egreg Sep 23 '11 at 9:08
    
Ok the xr package works! Great. Perhaps you should make it into an answer (I won't accept egregs answer, because part of it didn't work for me) –  romeovs Sep 24 '11 at 9:52

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
    
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 9:54

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.