Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
Why thank you!! –  David P May 6 '13 at 22:06

3 Answers 3

up vote 5 down vote accepted

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

share|improve this answer
    
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}.

share|improve this answer

Your need seems to be similar to the purpose of the package cleveref. I personally think these references here and there so simple and good for testing and feeling.

For example:

\documentclass[11pt]{article}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{cleveref}
\crefname{equation}{Eq. S}{equations}

\begin{document}
\begin{align}
y&=a_1x+b_1\label{eqn:1}
\end{align}
\noindent
Standard equation reference (\textbackslash ref): \ref{eqn:1}\\
Cleveref equation reference (\textbackslash cref): \cref{eqn:1}
\begin{figure}[ht]\centering\rule{0.5\linewidth}{0.1\linewidth}\caption{First figure}\label{fig:1}\end{figure}
\begin{equation}
\begin{array}{l}
\displaystyle \int 1 = x + C\\
\displaystyle \int x = \frac{x^2}{2} + C \\
\displaystyle \int x^2 = \frac{x^3}{3} + C
\end{array} 
\label{eq:xdef}
\end{equation}
\noindent
Standard figure reference (\textbackslash ref): \ref{fig:1}\\
Cleveref figure reference (\textbackslash cref): \cref{fig:1}\\
And here is the reference using cleveref: \cref{eq:xdef}
\end{document}

The output compiled this example is as below: Illustration of \cref of package cleveref

  • There are two forms of a reference instruction \cref and \Cref for adding lowercase and capital case respectively.
  • I customized the prefix Equation into Eq. S in the preamble section.
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.