# Format \ref output from enumeration item to not include section name

I'm referencing items in an enumerated list from another document (requirements.tex). I can do that, but I get extraneous information I haven't been able to remove.

Requirements.tex:

\documentclass{article}
\usepackage{graphicx}
\usepackage{mathtools}
\usepackage{hyperref}
\usepackage{enumerate}
\begin{document}

\section{Engineering Requirements}
\begin{enumerate}
\item The system shall turn trees into money. \label{Req:treesToMoney}
\item The system must be able to process five trees per second. \label{Req:treeRate}
\end{enumerate}
\end{document}


design.tex:

\documentclass[hidelinks]{article}
\usepackage{graphicx}
\usepackage{geometry}
\usepackage{fancyhdr}
\usepackage{amsmath, amsthm ,amssymb}
\usepackage{graphicx}
\usepackage{xr}

\externaldocument{../requirements/Requirements}

\begin{document}
Requirement \ref{Req:treesToMoney} is a functional requirement.
\end{document}


The output from design.tex is something like:

Requirement 1Engineering RequirementsItem.1 is a functional requirement.

This output looks awful. Not only do I get the extraneous section name and Item.#, that information isn't separated by spaces.

Is there a way to format the output of \ref? Possibly to exclude the extraneous information but at-least to separate the different pieces of information by spaces.

## 2 Answers

The package xr was written long before hyperref. This package changes the way labels are stored in the .aux file, so xr finds improper values and does the best it can.

If you use hyperref in the Requirements.tex file, then you should use it also in design.tex and use xr-hyper instead of xr.

If you really don't want to use hyperref in design.tex, you can modify the workings of xr so that the correct \newlabel is called. Example of design.tex with a modified internal macro of xr:

\documentclass{article}
\usepackage{xr}
\makeatletter
\long\def\XR@test#1#2#3#4\XR@{%
\ifx#1\newlabel
\mod@newlabel{\XR@prefix#2}#3{}{}\@nil% changed line
\else\ifx#1\@input
\edef\XR@list{\XR@list#2\relax}%
\fi\fi
\ifeof\@inputcheck\expandafter\XR@aux
\else\expandafter\XR@read\fi}
% new macro
\def\mod@newlabel#1#2#3#4\@nil{\newlabel{#1}{{#2}{#3}}}
\makeatother

\externaldocument{Requirements}

\begin{document}
Requirement \ref{Req:treesToMoney} is a functional requirement.
\end{document}


The document Requirements.tex loads package nameref (via package hyperref) that changes the layout of the label data in the .aux file. Document design.tex does not use nameref and package xr does not know nameref. Sometimes xr-hyper can be used. In package zref-xr I have rewritten the algorithm to support label import from zref and LaTeX labels to zref and/or LaTeX labels with support for packages nameref/hyperref, titleref, and ntheorem.

Example file design.tex:

\documentclass{article}
\usepackage{graphicx}
\usepackage{geometry}
\usepackage{fancyhdr}
\usepackage{amsmath, amsthm ,amssymb}
\usepackage{graphicx}
\usepackage{zref-xr}
\zxrsetup{%
tozreflabel=false, % not needed, since zref is not used otherwise
toltxlabel=true, % classical LaTeX labels that can be referenced with \ref, \pageref
}
\zexternaldocument*{Requirements}% star form: only LaTeX labels are imported

\begin{document}
Requirement \ref{Req:treesToMoney} is a functional requirement.
\end{document}