This is a fairly unimportant itch, but if it is easy/exists, please let me know. The \newlabel macro defines a label and warns if another label wants to overwrite it. In analogy with \newcommand / \renewcommand / \providecommand,

  • 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.

  • 2
    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
  • 1
    The \newlabel command is only used in .aux files. Never in documents. – egreg Mar 12 at 18:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.