%%
%% This is file `undolabl.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% undolabl.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% Project: undolabl
%% Version: 2023-02-14 v1.0m
%% 
%% Copyright (C) 2010 - 2023 by
%%     H.-Martin Muench <Martin dot Muench at Uni-Bonn dot de>
%% Portions of code copyrighted by other people as marked.
%% 
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either
%% version 1.3c of this license or (at your option) any later
%% version. This version of this license is in
%%    https://www.latex-project.org/lppl/lppl-1-3c.txt
%% and the latest version of this license is in
%%    https://www.latex-project.org/lppl.txt
%% and version 1.3c or later is part of all distributions of
%% LaTeX version 2005-12-01 or later.
%% 
%% This work has the LPPL maintenance status "maintained".
%% 
%% The Current Maintainer of this work is H.-Martin Muench.
%% 
%% The main code of this package was invented by
%% Ulrich Diez (eu_angelion AT web DOT de)
%% and first published in the comp.text.tex newsgroup
%% at Sun, 20 Apr 2008 16:39:26 +0200, with subject:
%% Re: How to undefine/overwrite a label? (see e.g.
%% https://groups.google.com/g/comp.text.tex/c/MBiR-EpPceo/m/2pdwkZP-bK8J
%% ). While Ulrich Diez neither wanted to create a package himself yet
%% nor have one published under his name, he granted the
%% publication of his code. Therefore: Thanks!
%% 
%% This work consists of the main source file undolabl.dtx,
%% the README, and the derived files
%%    undolabl.sty, undolabl.pdf,
%%    undolabl.ins, undolabl.drv,
%%    undolabl-example.tex, undolabl-example.pdf.
%% 
%% In memoriam
%%  Claudia Simone Barth + 1996-01-30
%%  Tommy Muench         + 2014-01-02
%%  Hans-Klaus Muench    + 2014-08-24
%% 
\NeedsTeXFormat{LaTeX2e}[2022-11-01]
\ProvidesPackage{undolabl}[2023-02-14 v1.0m Overriding labels (HMM)]

\@ifl@t@r\fmtversion{2022/11/01}{% would have understood
 %   \IfFormatAtLeastTF{2022-11-01}{<true code>}{<false code>}
 }{\PackageError{undolabl}{%
      Newer LaTeX format needed or older undolabl package%
    }{Needed LaTeX format version: 2022-11-01 or newer.\MessageBreak%
      Found\space\space LaTeX format version: \fmtversion.\MessageBreak%
      Either update your TeX distribution\MessageBreak%
      or use an archived version of undolabl\MessageBreak%
      (see section History in the documentation).\MessageBreak%
     }
  }

\AddToHook{begindocument}{%
  \if@filesw%
  \else%
    \IfPackageLoadedTF{tikz}{%
      \PackageWarning{undolabl}%
        {The undolabl package was not allowed to write to an\MessageBreak%
         .aux file. This package does not work without access\MessageBreak%
         to an .aux file.\MessageBreak%
         It is OK if the .aux file was already updated\MessageBreak%
         by a previouse compiler run\MessageBreak%
         and would not have changed anyway.\MessageBreak%
        }%
    }{\PackageError{undolabl}{No writing to auxiliary file allowed}%
        {The undolabl package was not allowed to write to an .aux file.\MessageBreak%
         This package does not work without access to an .aux file.\MessageBreak%
         Press Ctrl+Z to exit.\MessageBreak%
         But it is OK if the .aux file was already updated\MessageBreak%
         by a previouse compiler run\MessageBreak%
         and would not have changed anyway.\MessageBreak%
        }%
     }%
  \fi%
  \IfPackageLoadedTF{acronym}%
   {\IfPackageAtLeastTF{acronym}{2015/03/21}{% later, OK
    }{\PackageError{undolabl}{Incompatible old acronym package detected}%
      {The undolabl package is not compatible with the acronym package%
       \MessageBreak%
       older than 2015/03/21 v1.41. Please update your acronym package!%
       \MessageBreak%
      }%
     }%
   }{% not loaded, OK
   }%
  }

\newcommand\overridelabel[1]{%
\@bsphack%
  \if@filesw%
    \protected@write\@auxout{}{\string\undonewlabel{#1}}%
    \@overriddenmessage s{#1}%
    \label{#1}%
  \fi%
\@esphack%
}

\newcommand\undonewlabel{\@und@newl@bel r}

\newcommand\@und@newl@bel[2]{%
  \@ifundefined{#1@#2}{%
    \PackageError{undolabl}{Label `#2' shall be overridden ^^J%
      although it does not yet exist}{%
      A label which does not exist cannot be overridden.}%
  }{%
    \expandafter\global
    \expandafter\let
    \csname #1@#2\endcsname\relax%
   }%
  }

\newcommand\@overriddenmessage[2]{%
  \@ifundefined{#1@#2}{\global\@namedef{#1@#2}{i}}{%
    \expandafter\g@addto@macro\csname #1@#2\endcsname{i}%
    }%
  \PackageWarning{undolabl}{Label `#2' overridden}%
  }

\newcommand\undolabl@testdef[3]{%
  \@ifundefined{s@#2}\@secondoftwo\@firstofone{%
    \expandafter\ifx\csname s@#2\endcsname\empty
      \expandafter\@firstofone
    \else%
    \expandafter\xdef\csname s@#2\endcsname{%
      \expandafter\expandafter
      \expandafter\@gobble
      \csname s@#2\endcsname
      }%
    \expandafter\@gobble
    \fi%
   }{\@testdef{#1}{#2}{#3}%
    }%
  }

\if@filesw\protected@write\@auxout{}{\string\reset@newl@bel}\fi

\newcommand\reset@newl@bel{%
  \ifx\@newl@bel\@testdef%
    \let\@newl@bel\undolabl@testdef%
    \let\undonewlabel\@gobble%
  \fi%
  }

\endinput
%%
%% End of file `undolabl.sty'.
