2

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.

ivo Welch
  • 3,766
  • 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 '21 at 18:22
  • 1
    The \newlabel command is only used in .aux files. Never in documents. – egreg Mar 12 '21 at 18:35
  • Maybe this is of interest to you: https://tex.stackexchange.com/questions/554052/deactivating-hyperlinks-to-external-documents-with-cleveref I used it to pull labels from .aux files when separately compiling chapters of lecture notes. – Benjamin Aug 12 '21 at 06:29

0 Answers0