During my last experiences with cross-referencing on total counts between different files, a problem of carrying counters over to another file appears. Somehow there is an error when I use for these purposes xr and refcount packages given by Werner, see, please, here
The error appears on the line \externaldocument[file1:]{myfile1} which is written in myfile1/userpackages.tex: Incomplete \ifx; all text was ignored after line 27. \input{myfile1/userpackages}.
I guess, that the reason can be because of using \input command or perhaps because of some unexpected conflicts with other packages. So, I need an alternative way of carrying counters over to another file, as presented here.
The question is how to get a counter value generated by \zref in a counter mycntr in file2.tex?
Here is my MWE:
file1.tex (server):
\documentclass{article}
\usepackage{zref-abspage, zref-lastpage}
\makeatletter
\zref@newprop{msection}[0]{\thesection}
\zref@addprops{LastPage}{msection}
\zref@newprop{mequation}[0]{\theequation}
\zref@addprops{LastPage}{mequation}
\makeatother
\newcounter{mycntr}
\begin{document}
\section{my section1}
\begin{equation}
\label{eq1}
\end{equation}
\newpage
\section{my section2}
Some text
\newpage
Some text
\end{document}
file2.tex (client):
\documentclass{article}
\usepackage{refcount,zref-xr,zref-user}
\newcommand*{\getcounter}[3]{%
\setcounterref{#1}{#2}% Retrieve label value and store it in a counter
}
\zexternaldocument[file1:]{file1}
\newcounter{mycntr}
\begin{document}
We can use zref counters directly: file1.tex has \zref[abspage]{file1:LastPage} pages and
\zref[mequation]{file1:LastPage} equations and
\zref[msection]{file1:LastPage} sections.
%get function takes wrong value from \zref
My counter reflects pages value: \getcounter{mycntr}{\zref[abs]{file1:LastPage}}\themycntr \par
My counter reflects equations value: \getcounter{mycntr}{\zref[mequation]{file1:LastPage}}\themycntr \par
My counter reflects sections value: \getcounter{mycntr}{\zref[mequation]{file1:LastPage}}\themycntr
\end{document}
A screenshot of file2.pdf with highlighted part of text, which should be correct.
UPT:
Werner's answer is working fine with MWE! To avoid two errors in tex-files with counting: Missing number, treated as zero. ...ycntr}{\zref@extract{file1:LastPage}{abspage}} and package calc error: \let is invalid at this point. ...ycntr}{\zref@extract{file1:LastPage}{abspage}} one should wrap Werner's hint by \makeatletter and \makeatother commands in the following way:
\makeatletter
\setcounter{mycntr}{\zref@extract{file1:LastPage}{abspage}}
\makeatother


Missing number, treated as zero. ...ycntr}{\zref@extract{file1:LastPage}{abspage}}and package calc error:\let is invalid at this point. ...ycntr}{\zref@extract{file1:LastPage}{abspage}}one should wrap your hint by\makeatletterand\makeatothercommands. The question is updated. – Vladimir Parkhomenko Nov 05 '16 at 09:24