3

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}

\usepackage{catchfilebetweentags} % load the package

\newcommand{\loadRevision}[1]{ % define command to load figures
    \ExecuteMetaData[main.tex]{#1} % call the package macro to 
}

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

\loadRevision{tag}  
\end{document}

OUTPUT enter image description here

1 Answer 1

0

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{catchfilebetweentags} % load the package
\usepackage{xr}

\externaldocument{main}
\newcommand{\loadRevision}[1]{ % define command to load figures
    \ExecuteMetaData[main.tex]{#1} % call the package macro to 
}

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

\loadRevision{tag}  
\end{document}

enter image description here

1
  • 1
    Wow, works like a charm. So simple once you know it. Thank you!
    – user123951
    Jan 27, 2017 at 15:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .