# Redefining and Conditional Defining of labels


• Is there a \providelabel macro that defines a label only if it has not yet been defined?

• Is there a \renewlabel macro that overwrites a label if it exists

This is (marginally) useful when many chapters are in separate tex files and sometimes compiled by themselves, sometimes together with others (into a complete book). I would like to providelabels from a grepped file from other aux files that fill in only when not already included.

• For the first issue, \usepackage{refcount} \newcommand\providelabel[1]{\ifnum\getrefnumber{#1}=0\relax\label{#1}\fi}. For the second, \label will overwrite the original label if it exists...of course, it will also generate a warning. – Steven B. Segletes Mar 12 at 18:22
• The \newlabel command is only used in .aux files. Never in documents. – egreg Mar 12 at 18:35