Cross-reference between two tex files WITHOUT preamble?

I have a "structure" file paper.tex that inputs two section .tex files, A.tex and B.tex.

Both A.tex and B.tex do not have any preambles. i.e. they are simply two snippets. All the preambles are in paper.tex.

I now wish to cross-refer a figure in A.tex from B.tex. How may I do this?

\usepackage{xr}
\externaldocument{chapterI}

But I think it won't work in my case, as the preambles are not allowed in A.tex and B.tex.

• If they are both included into the main file, there is no problem. Near all is as if all three be in a common file. No packages are needed. – Przemysław Scherwentke Dec 7 '13 at 4:28

If they are both included into the main file, there is no problem. Near all is as if all three be in a common file. No packages are needed. (Said Przemysław Scherwentke, hence the community wiki)

Let's take an example:

% paper.tex
\documentclass{article}
\begin{document}
\input{A}
\input{B}
\end{document}

and A.tex:

% A.tex
\begin{figure}
\centering
\rule{4cm}{3cm}
\caption{Dummy Figure}\label{fig:dummy_figure}
\end{figure}

and then, B.tex:

% B.tex
Figure \ref{fig:dummy_figure} is a dummy figure.

This is the output:

• sorry I have a question, what if A and B are not in the same folder ? – Nizar Sep 7 '17 at 8:23
• @Nizar \input{/path/to/A} and then \input{/path/to/B}. – Ch'en Meng Sep 7 '17 at 8:30