I would like to draw a picture in which a line connects two points. Along this line, there should be a text "x", where x is the number of a specific equation in another document. Unfortunately, I am not able to realize this idea. So far, I have a main document (main.tex) and a figure document (figure.tex). I first compile main.tex, then I compile figure.tex. Using references as node labels in the figure seems fine. However, for text decorations they seem to totally lock up the pdflatex application. Here is a minimum working example:
main.tex
\documentclass{standalone}
\begin{document}
% the equation of interest
\begin{equation} \label{x}
x = 42
\end{equation}
% the figure of interest
\includegraphics{figure.pdf}
\end{document}
figure.tex
\documentclass{standalone}
\usepackage{xr} % edit: this line and the next allow for cross-referencing
\externaldocument{main}
\usepackage{tikz}
\usetikzlibrary{decorations.text}
\begin{document}
\begin{tikzpicture}
\draw[] (0,0) node[] (A) {\ref{x}}; % this works
\draw[] (1,1) node[] (B) {x}; % this also works
\draw[decoration={text along path,text align={align=center},%
text={\ref{x}}},postaction={decorate}] (A) -- (B); % does not compile, i. e., pdflatex seems to be in an infinite loop
\draw[decoration={text along path,text align={align=center},%
text={x}},postaction={decorate}] (A) -- (B); % does compile, but is useless
\end{tikzpicture}
\end{document}
So my questions are as follows:
1.) (Solved?) How do I have to configure the compiling procedure to be able to use references from main.tex in figure.tex? Ideally, I would like to use externalization to produce the figures in figure.tex. This is my motivation for using two different files in the first place.
Edit: I think I can answer this question for myself now using the answer to this question: By adding
\usepackage{xr} \externaldocument{main}
to figure.tex, referencing from figure.tex to main.tex should work! If this should be a bad style, please correct me. Question 2 remains unsolved though.
2.) How can I use a reference as a text decoration? I have no idea why this fails.

externalTiKZ library? – cfr Feb 10 '15 at 01:35xrpackage,\ref{x}is expanded to1\hbox {}that is not a correct content fortext along path. – Paul Gaborit Feb 11 '15 at 00:22\ref, use\getrefnumberfromrefcountpackage (cf. How to compare the output of \ref to a number?). – Paul Gaborit Feb 11 '15 at 00:30