[Tex/LaTex] Automatically add prefix to references from another document

cross-referencingxr

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?

Best Answer

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}
\begin{equation}
    a=b \label{eq:myequation}
\end{equation}
\end{document}

Output of the main file:

enter image description here