I've got a study book split into multiple individual books. To continue chapter and part numbers across volumes, I've used the solution by Werner provided here: Carrying counters over to another file
It's excellent! One problem: the command to store counters generates output in the document. The command works for my situation, but it produces extra output upon saving the counters. My question is: how can I get rid of the extra output?
MWE (which gives a "Missing number, treated as zero" error but does produce a PDF if you power through by pressing enter):
\documentclass[a4paper,10pt,fleqn,openany]{book}
% ---------------------------------------------------------------------------
% load chapter/part counters from previous workbooks
% https://tex.stackexchange.com/questions/129312/carrying-counters-over-to-another-file
% ===========================================================================
\usepackage{refcount,xr}
\externaldocument{book1}
\externaldocument{book3}
% ---------------------------
% command for storing part/chapter counters
% ---------------------------
\makeatletter
\newcommand*{\storecounter}[2]{%
% updated as per egreg's comment
\edef\@currentlabel{\the\value{#1}}% Store current counter value in \@currentlabel
\label{#2}% Store label
}
\makeatother
% command to get value of counters
% ---------------------------
\newcommand*{\getcounter}[2]{%
\setcounterref{#1}{#2}% Retrieve label value and store it in a counter
}
% have a counter for chapters and for parts from volume 1
% ---------------------------
\newcounter{bookonecounter}
\getcounter{bookonecounter}{parts}
\setcounter{part}{\thebookonecounter}
\begin{document}
\part{A part}
\part{Another part}
% ===========================================================================
% Save chapter/part counters for use in further volumes
% XXX: this currently outputs "value in X"
% ---------------------------
\setcounter{bookonecounter}{\thechapter}\storecounter{bookonecounter}{chapters}
\setcounter{bookonecounter}{\thepart}\storecounter{bookonecounter}{parts}
% ===========================================================================
\end{document}
Using this example (volume 2) when you have volume 1 as "book1.tex" will correctly continue the part number. E.g., for a book1.aux that contains
\newlabel{chapters}{{4}{154}}
\newlabel{parts}{{2}{154}}
it compiles (with the complaint as noted above) into a pdf which continues the count. However, it adds a page to the end of the PDF which contains IV:

Commenting out the two setcounter/storecounter lines removes this from the pdf.
edit: egreg's proposal is definitely an improvement. The screenshot is the result of using his definition. Unfortunately, there's still an extra, unwanted page with some text on it on account of the \setcounter..\storecounter lines.
Any ideas on how to prevent the lines with \setcounter{}..\storecounter to produce an extra page?
book1.texandbook3.tex. Could you give a hint at what crucial commands might be inbook1.tex? – Mico Jun 29 '16 at 16:36\setcounter{bookonecounter}{\theparts}won't work if\thepartis defined to use\Roman, i.e. it will use I, II, III, not 1, 2, 3.... the same problem arises with\getcounter{bookonecounter}{parts}then! – Jun 29 '16 at 17:49\edef\@currentlabel{\csname the#1\endcsname}into\edef\@currentlabel{\the\value{#1}}– egreg Jun 29 '16 at 20:21\newlabel{chapters}{{4}{154}} \newlabel{parts}{{2}{154}}– Hugo Jonker Jun 29 '16 at 21:55