# How to get correct counters/numbers with \catchfilebetweentags

I often need to include pieces of text from document A (my main manuscript) in document B (letter to the editor explaining how I revised the manuscript). Both documents are full fledged Latex documents, so \include is not an option. It seems that generally, \catchfilebetweentags is the way to go. I understand how I can use tags to "import" text blocks from A to B. However, the imported text does not show counters like numbered sections or figure numbers. Instead, it shows ??.

I found a related question, but I am not sure how I can apply the answer to my problem: “\input only part of a file” and keep numbering

Is there a way to "import" the correct counter numbers? Thanks for your help!

THE MAIN "MANUSCRIPT" main.tex

\documentclass{article}

\begin{document}

\section{Introduction} \label{introsection}

\begin{figure} \label{myfigure}
\caption{An empty figure.}
\end{figure}

%<*tag>
This is section \ref{introsection} of the main file. We present the results in Figure \ref{myfigure}.
%</tag>

\end{document}


THE "LETTER TO THE EDITOR"

\documentclass{article}

\ExecuteMetaData[main.tex]{#1} % call the package macro to
}

\begin{document}
The revised Introduction now reads as follows:

\end{document}


OUTPUT

Since there are references included, storing the counter values in another manner isn't necessary, as those values have been stored already. Use \usepackage{xr} (or with hyperref \usepackage{xr-hyper} to retrieve the 'counter' values (rather: the reference content) after saying

\externaldocument{main}

Here is the 'letter' file:

\documentclass{article}

\usepackage{xr}

\externaldocument{main}