% \iffalse meta-comment
% ======================================================================
% scrextend.dtx
% Copyright (c) Markus Kohm, 2002-2022
%
% This file is part of the LaTeX2e KOMA-Script bundle.
%
% This work may be distributed and/or modified under the conditions of
% the LaTeX Project Public License, version 1.3c of the license.
% The latest version of this license is in
%   http://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 and of this work.
%
% This work has the LPPL maintenance status "author-maintained".
%
% The Current Maintainer and author of this work is Markus Kohm.
%
% This work consists of all files listed in MANIFEST.md.
% ======================================================================
%%% From File: $Id: scrextend.dtx 3874 2022-06-05 10:38:02Z kohm $
%<preidentify>%%%            (run: preidentify)
%<prepare>%%%            (run: prepare)
%<option>%%%            (run: option)
%<*dtx>
\ifx\ProvidesFile\undefined\def\ProvidesFile#1[#2]{}\fi
\begingroup
  \def\filedate$#1: #2-#3-#4 #5${\gdef\filedate{#2/#3/#4}}
  \filedate$Date: 2022-06-05 12:38:02 +0200 (So, 05. Jun 2022) $
  \def\filerevision$#1: #2 ${\gdef\filerevision{r#2}}
  \filerevision$Revision: 3874 $
\endgroup
\ProvidesFile{scrextend.dtx}[\filedate\space\filerevision\space
                             KOMA-Script package source
                             (extend other classes)]
\documentclass{koma-script-source-doc}
\usepackage[USenglish]{babel}
\setcounter{StandardModuleDepth}{2}
\begin{document}
  \DocInput{scrextend.dtx}
\end{document}
%</dtx>
% \fi
%
% \changes{v3.00}{2008/05/01}{new package}
% \changes{v3.36}{2022/01/31}{switched from \cls*{scrdoc} to
%   \cls*{koma-script-source-doc}}
% \changes{v3.36}{2022/01/31}{whole implementation documentation in English}
%
% \GetFileInfo{scrextend.dtx}
% \title{Extending Non-\href{https://komascript.de}{\KOMAScript} Classes by
%   some \href{https://komascript.de}{\KOMAScript} Class Features using
%   \href{https://komascript.de}{\KOMAScript} Package \pkg*{scrextend}}
% \author{\href{mailto:komascript@gmx.info}{Markus Kohm}}
% \date{Revision \fileversion{} of \filedate}
% \maketitle
% \begin{abstract}
%   The purpose of this package is to provide \KOMAScript{} class features to
%   other classes, i.\,e., the standard classes too. On the other hand it does
%   not make sense to nor should you load this package, if you are using a
%   \KOMAScript{} class.
% \end{abstract}
%
% \tableofcontents
%
% \section{User Manual}
%
% You can find the user manual of \pkg{scrextend} in the \KOMAScript{} manual,
% either the German \file{scrguide} or the English \file{scrguien}.
%
% \MaybeStop{\PrintIndex}
%
% \section{Implementation}
%
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
%
% \subsection{Before the identification of the package}
%
% Just before the identification of the package, we have to take care, that it
% is not loaded with a \KOMAScript{} class. If so, we output a warning an
% terminate.
%
% \changes{v3.30}{2020/02/25}{Using \cs{PackageWarningNoLine} instead of
%   \cs{PackageWarning} with final \cs{@gobble}}
%    \begin{macrocode}
%<*preidentify>
\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname KOMAClassName\endcsname\relax\else
  \PackageWarningNoLine{scrextend}{%
    This package was made to extend other classes but\MessageBreak
    KOMA-Script classes by some features of the\MessageBreak
    KOMA-Script classes.\MessageBreak
    It should never be used with a KOMA-Script class.\MessageBreak
    Loading of the package will be aborted%
  }%
  \expandafter\endinput
\fi
%</preidentify>
%    \end{macrocode}
%
%
% \subsection{Package identification}
%
% We use the major \KOMAScript{} version for this package, because it uses
% several main parts of the classes of the same version.
%
%    \begin{macrocode}
%<*identify>
\ProvidesPackage{scrextend}[%
%!KOMAScriptVersion
  package (extend other classes with features of KOMA-Script classes)%
]
%</identify>
%    \end{macrocode}
%
%
% \subsection{Preparation of options}
%
% The preparation state is used before the option handling. To allow
% definition of optional features. Such definitions are used in other parts of
% the \KOMAScript{} classes. For example \file{scrkernel-title.dtx} defines
% the \optvalue{title} \opt{feature}.
%
% Note: The method used here is very fragile, i.\,e., the definition of
% feature code with arguments needs to be adapted for \pkg{scrextend}. So
% there is a big fat
% \begin{description}
% \item[ToDo:] Reimplementation of the optional features should simplify the
%   definition of such features a lot in other files. Best would be to have a
%   kind of start command and a kind of end command without the need to change
%   anything in between, if the package instead of a class is defined. But
%   this is hard to reach, because of usage of \cs{ClassError}
%   vs. \cs{PackageError}, \cs{ClassWarning} vs. \cs{PackageWarning}. So at
%   least these commands have to be dependent. Nevertheless the need to
%   change, e.g., |#1| into |##1|, |#2| into |##2| etc. for \pkg{scrextend} is
%   annoying. Moreover the whole usage of \cs{scr@extend@activate@\dots} and
%   \cs{sr@extend@immediate@\dots} is very complicated and currently I'm even
%   not sure, that is always works as expected. Maybe a less complicated
%   feature implementation could be found.
% \end{description}
%
% \begin{macro}{\scr@ext@activate,\scr@ext@activateable,
%               \scr@ext@addto@activateable}
% One special feature of this package is, to provide some \KOMAScript{}
% features only, if they have been activated explicitly. To do so
% \begin{quote}
%   \cs{scr@ext@activateable}\marg{feature}\marg{definition}
% \end{quote}
% is used. This macro defines \cs{scr@ext@activate@\meta{feature}}. There is
% also a
% \begin{quote}
%   \cs{scr@ext@addto@activateable}\marg{feature}\marg{definition}
% \end{quote}
% that does append \meta{definition} to the already existing code of
% \cs{scr@act@activate@\meta{feature}}, if it already exists, or define it
% new, if is does not exist already.
% \begin{quote}
%   \cs{scr@ext@activate}\marg{feature}
% \end{quote}
% is used to \emph{activate} a \meta{feature}. That means: If there is a
% \cs{scr@ext@activate@\meta{feature}} it is executed and afterwards
% \cs{scr@ext@activate@\meta{feature}} is destroyed making it \cs{relax}. But
% if there is not yet a \cs{scr@ext@activate@\meta{feature}} a
% \cs{scr@ext@immediate@\meta{feature}} is defined. The definition of this
% is, to redefine itself to be \cs{scr@ext@activate@\meta{feature}}.
%    \begin{macrocode}
%<*prepare>
\newcommand*{\scr@ext@activate}[1]{%
  \scr@ifundefinedorrelax{scr@ext@activate@#1}{%
    \@namedef{scr@ext@immediate@#1}{%
      \expandafter\let\csname scr@ext@immediate@#1\endcsname\relax
      \csname scr@ext@activate@#1\endcsname
    }%
  }{%
    \csname scr@ext@activate@#1\endcsname
    \expandafter\let\csname scr@ext@activate@#1\endcsname\relax
  }%
}
\newcommand*{\scr@ext@activateable}[1]{%
  \expandafter\newcommand\expandafter*\csname scr@ext@activate@#1\endcsname
}
\newcommand*{\scr@ext@addto@activateable}[1]{%
  \scr@ifundefinedorrelax{scr@ext@activate@#1}{%
    \expandafter\newcommand\expandafter*\csname scr@ext@activate@#1\endcsname
  }{%
    \expandafter\g@addto@macro\csname scr@ext@activate@#1\endcsname
  }%
}
%</prepare>
%    \end{macrocode}
% \end{macro}
%
%
% \subsection{Options}
%
% Now, after the preparation, the universal option that enables optional
% features can defined. This option can be used while loading the package
% only. Later activation of features is currently not supported.
%
% \begin{option}{extendedfeature}
% \changes{v3.12}{2013/03/05}{using state signaling with \cs{FamilyKeyState}}
% \changes{v3.17}{2015/03/09}{internal value storage}
%    \begin{macrocode}
%<*option>
\KOMA@key{extendedfeature}{%
  \scr@ext@activate{#1}%
  \AtEndOfPackage{%
    \scr@ifundefinedorrelax{scr@ext@immediate@#1}{}{%
      \PackageWarningNoLine{unkown extended feature `#1'\MessageBreak
        You have used option `extendedfeature' to\MessageBreak
        activate an extended feature `#1',\MessageBreak
        but there is no such extended feature.\MessageBreak
        See the KOMA-Script manual for more\MessageBreak
        information about known activatable\MessageBreak
        extended features%
      }%
    }%
  }%
  \FamilyKeyStateProcessed
  \KOMA@kav@xadd{.scrextend.sty}{extendedfeature}{#1}%
}
\AtEndOfPackage{%
  \KOMA@key{extendedfeature}{%
    \def\FamilyKeyState{Option `extendedfeature' too late}%
  }%
}
%</option>
%    \end{macrocode}
% \end{option}
%
%    \begin{macrocode}
%</package>
%    \end{macrocode}
%
% \Finale
% \PrintChanges
% 
\endinput
% Local Variables:
% mode: doctex
% ispell-local-dictionary: "en_US"
% eval: (flyspell-mode 1)
% TeX-master: t
% TeX-engine: luatex-dev
% eval: (setcar (or (cl-member "Index" (setq-local TeX-command-list (copy-alist TeX-command-list)) :key #'car :test #'string-equal) (setq-local TeX-command-list (cons nil TeX-command-list))) '("Index" "mkindex %s" TeX-run-index nil t :help "makeindex for dtx"))
% End:

