# Manually set reference values

I'm working on a large-ish Latex document (my dissertation) in which each chapter has its own .tex file. For various reasons, I have two master files: one that includes all chapters and one that I modify over time to compile whatever chapter I happen to be working on at the time.

For the most part, the chapters are independent and resolving references isn't a big deal. But, there's a handful of important results that need to get referenced across chapters and a few times when I need to refer to another chapter, i.e., In Chap.~\ref{ch:other_chapter}, we discuss X, Y, and Z.. As-is, that of course results in "Chap. ??" in the compiled document. I'd really like to be able to hand off a PDF of a single chapter to someone else to review without a bunch of "??" references (and not have to wait for the whole document to compile).

SO.. Supposing that there's only a handful of such references so that it's manageable to do this manually, and supposing that I don't mind if their values aren't quite right, is there a simple way to manually set the label values in my single-chapter master file so that my compiled document a) doesn't have a bunch of undefined references and b) doesn't include an empty chapter that's just there to populate the reference.

I tried something like

% the chapter I'm currently working on
\include{the_chapter}

% so I can reference the next chapter without having to compile it
\setcounter{chapter}{2}
\label{ch:other_chapter}


But then \ref{ch:other_chapter} resolves itself as a Section of the chapter before it.

I don't want to do this:

\include{the_chapter}

\chapter{The other chapter}
\label{ch:other_chapter}


Because this will actually generate a new chapter in the text, TOC, etc.

-
Do you use \includeonly? –  Gonzalo Medina Mar 19 '12 at 18:08
I think once you have learned about \includeonly, then your question will evaporate. –  Seamus Mar 19 '12 at 18:08
I am building a catalogue of exercises which reference each other, and this question applies to references between exercise sheets. Using \includeonly is not practical for several reasons; each sheet needs to be its own document. –  Raphael Dec 11 '12 at 15:03

I don't think you should bother with this problem, as it will be solved once you'll have everything in place.

If you really want to set manually references, you can say in your preamble

\makeatletter
\newcommand{\manuallabel}[2]{\def\@currentlabel{#2}\label{#1}}
\makeatother


and then use

\manuallabel{ch:other_chapter}{2}


so that \ref{ch:other_chapter} will print "2". In the second argument you can put whatever you want.

-
Note to anyone else who stumbles on this: this answers the question directly, but @Seamus' answer is really the right way to go. (Thanks) –  dantswain Mar 19 '12 at 18:42
How do you set the value printed by \nameref? –  Raphael Dec 20 '12 at 10:08
@Raphael That's much more difficult. And, as I said in my answer, quite pointless. –  egreg Dec 20 '12 at 11:33
@egreg It may be pointless here, but as I said in my comment, there are use cases. –  Raphael Dec 20 '12 at 12:31
@Raphael The xr or zref-xr packages could be the answer for those use cases –  egreg Dec 20 '12 at 12:34
show 1 more comment

The problem you have encountered is a common one, and there is a much better solution than manually fixing the references. With the one master file you can use \includeonly{chap-foo} to compile only the one chapter. This way, references to other chapters will work perfectly.

This requires that the other chapters have been compiled in the past. What \ref{foo} points to is determined by something in the .aux file for the file where the \label{foo} is defined. So as long as you don't go deleting all your .aux files too regularly, this is a good way to crossreference chapters that don't get compiled. Because even if you aren't compiling bar.tex, bar.aux is still read by latex and so it knows what \refs that are \label-ed in bar.tex are supposed to look like.

-
provided the other .aux files exist –  cmhughes Mar 19 '12 at 18:19
Doesn't it have to compile the other chapters to resolve the references, though? –  dantswain Mar 19 '12 at 18:21
(Yes, a recompile of the entire document is required.) I gave @egreg answer credit because it answers the question directly, and upvoted this because it will ultimately be more useful. Thank you. –  dantswain Mar 19 '12 at 18:42