Here is one way. In this MWE, I save two counters to an external file: \thesection
and \theequation
. Obviously, you can expand the solution to include saving whatever status variables you need to transfer from one document to the next (such as \thepage
, etc.).
I have created two commands: \recallstatus
and \savestatus
that should be invoked, respectively, at the beginning of the document part (except for part 1) and at the end of the document part. In this MWE, I define them in each preamble, but it would be easier to stuff them into a multipart.sty
or some name like that for which you could just \usepackage
.
Here is part 1 of the document
\documentclass{article}
\newcounter{docpart}
\def\savestatus{%
\newwrite\tempfile%
\immediate\openout\tempfile=docstatus\arabic{docpart}.dat%
\immediate\write\tempfile{\thesection}%
\immediate\write\tempfile{\theequation}%
\immediate\closeout\tempfile%
}
\newcounter{olddocpart}
\def\recallstatus{%
\setcounter{olddocpart}{\arabic{docpart}}
\addtocounter{olddocpart}{-1}
\newread\rtempfile%
\openin\rtempfile=docstatus\arabic{olddocpart}.dat%
\read\rtempfile to \tmp%
\setcounter{section}{\tmp}
\read\rtempfile to \tmp%
\setcounter{equation}{\tmp}%
\closein\rtempfile%
}
\setcounter{docpart}{1}
\begin{document}
\section{The First Section}
\begin{equation}
y = x
\end{equation}
\begin{equation}
y = 1/x
\end{equation}
\savestatus
\end{document}
The \savestatus
at the end creates a file docstatus1.dat
that contains the data (current section and equation):
1
2
Here is part 2 of the document:
\documentclass{article}
\newcounter{docpart}
\def\savestatus{%
\newwrite\tempfile%
\immediate\openout\tempfile=docstatus\arabic{docpart}.dat%
\immediate\write\tempfile{\thesection}%
\immediate\write\tempfile{\theequation}%
\immediate\closeout\tempfile%
}
\newcounter{olddocpart}
\def\recallstatus{%
\setcounter{olddocpart}{\arabic{docpart}}
\addtocounter{olddocpart}{-1}
\newread\rtempfile%
\openin\rtempfile=docstatus\arabic{olddocpart}.dat%
\read\rtempfile to \tmp%
\setcounter{section}{\tmp}
\read\rtempfile to \tmp%
\setcounter{equation}{\tmp}%
\closein\rtempfile%
}
\setcounter{docpart}{2}
\begin{document}
\recallstatus
\section{The Second Section}
\begin{equation}
y = x^2
\end{equation}
\begin{equation}
y = 1/x^2
\end{equation}
\savestatus
\end{document}
The first thing it does is read the part 1 data file to reset the appropriate counters. As you see from the output, it picks up the sectioning and equation numbers where it left off. At the end, I do another \savestatus
(which writes docstatus2.dat
) to prepare for part 3.
Here is the document image from part 1:
and here it is from part 2:
Obviously, if you modify a counter in part 1, parts 2, 3, etc. all have to be successively recompiled in order that their counters get updated.