Concise question:

Is there any way to limit the scope in which a \label is visible to a \ref?


My current goal is to create a rather large document, containing many exercises and their associated proofs/solutions.

  • I'd like to be able to refer to any proof that I've completed before the current one. (i.e., if I've proved it, I wanna be able to use it!)
  • I'd like to be able to accumulate observations within the context of a proof and subsequently refer to them later in that proof. However, those observations (or assumptions, or introductions, etc.) don't need to be visible outside of that proof.

For example, in the following image of a sample Structured Derivation, I'd like to be able to label assumption #5 something like \label{x_is_nonneg}. But if I do that without any special packages or TeX-hackery, I'm unable to use "x_is_nonneg" as a label for any other object for the rest of the document, right? Which is too bad, because I'll often want to make very context-specific assertions, and it would be nice if I didn't have to name them something like \label{exer:8:asmp:5}.

a proof demonstrating local references

  • I'd say, the solution depends on your editor, at least a bit. Usually the editor offers completions of references. If this mechanism can not be adapted as well, any answer will not really help you! So: which editor are you using?
    – Keks Dose
    Oct 24, 2012 at 14:21

2 Answers 2


A solution: define two macros to add automatically a local prefix to your labels and references.

%%%%%%% in your preamble %%%%%%%%
% macro to define a local label

% macro to use a local reference

%%%%%% in your document %%%%%%
% define a current prefix whenever you start a new proof
   \def\currentprefix{proof:10} % choose a different prefix for each proof!

You could introduce the following new commands


and use it as \labellocal{x_is_nonneg} and refer to it with \reflocal{x_is_nonneg} or \eqreflocal{x_is_nonneg}.

Internally (globally) the label would be exer:8:x_is_nonneq.
You can, of course, use more distinguishing commands like \thesection to have a more local label style.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .