# Automatically add prefix to references from another document?

I'm using xr to reference equations in supplemental material to a paper. I'd like equations from the supplement referenced in the paper to automatically be prefixed with "S", so that Eq.~\ref{eqn:first} appears in the text as Eq. S1. Ideally this would be true in the supplemental document as well. How do I do this?

-
Why thank you!! –  David P May 6 '13 at 22:06

Here is a solution combining the xr and prettyref packages. The downside is that it forces you to use \prettyref instead of \ref, but you might benefit from the kind of automation provided by the prettyref package anyway :)

\documentclass{article}

\usepackage{xr}
\externaldocument[S]{myotherfile}

\usepackage{prettyref}
\newrefformat{Seq}{Eq.~S\ref{#1}}

\begin{document}
You can find more about \prettyref{Seq:myequation} in my other paper.
\end{document}


Contents of myotherfile.tex:

\documentclass{article}
\begin{document}
$$a=b \label{eq:myequation}$$
\end{document}


Output of the main file:

-
Thanks! If I also had \begin{algorithm} ... \label{alg:myalg} \end{algorithm} in myotherfile.tex and wanted to reference that, could I do \prettyref{Seq:myalg}, or do I have to preface everything with eq: in myotherfile.tex? –  David P May 6 '13 at 22:05
You have to prefix all references coming from myotherfile.tex by an S. You could add \newrefformat{Salg}{Algorithm~S\ref{#1}} in the main file and then use \prettyref{Salg:myagl}. –  Jubobs May 6 '13 at 22:06
\newcount\suppl
\suppl0
\def\Ref#1{\ifnum\suppl<1 \ref{#1} \else S\ref{#1}\fi}


And at the beginning of the supplement you should write \suppl1. Of course, you should write Eq.~\Ref{eqn:first} instead of Eq.~\ref{eqn:first}.

-