% \iffalse meta-comment
% ======================================================================
% scrkernel-listsandtabulars.dtx
% Copyright (c) Markus Kohm, 2002-2025
%
% 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: scrkernel-listsandtabulars.dtx 4138 2025-02-10 13:55:51Z kohm $
%<option>%%%            (run: option)
%<body>%%%            (run: body)
%<*dtx>
\ifx\ProvidesFile\undefined\def\ProvidesFile#1[#2]{}\fi
\begingroup
  \def\filedate$#1: #2-#3-#4 #5${\gdef\filedate{#2/#3/#4}}
  \filedate$Date: 2025-02-10 14:55:51 +0100 (Mo, 10. Feb 2025) $
  \def\filerevision$#1: #2 ${\gdef\filerevision{r#2}}
  \filerevision$Revision: 4138 $
  \edef\reserved@a{%
    \noexpand\endgroup
    \noexpand\ProvidesFile{scrkernel-listsandtabulars.dtx}%
                          [\filedate\space\filerevision\space
                           KOMA-Script source
                           (lists and tabulars)]
  }%
\reserved@a
\documentclass[USenglish]{koma-script-source-doc}
\usepackage{babel}
\usepackage{hvlogos}
\setcounter{StandardModuleDepth}{2}
\begin{document}
\DocInput{scrkernel-listsandtabulars.dtx}
\end{document}
%</dtx>
% \fi
%
% \changes{v2.95}{2002/07/01}{first version after splitting \file{scrclass.dtx}}
% \changes{v3.36}{2022/02/15}{switch over from \cls*{scrdoc} to
%   \cls*{koma-script-source-doc}}
% \changes{v3.36}{2022/02/15}{whole implementation documentation in English}
% \changes{v3.40}{2023/04/17}{guide names changed}
%
% \GetFileInfo{scrkernel-listsandtabulars.dtx}
% \title{Code of Lists, Tabulars and Similar Objects of the
%   \href{https://komascript.de}{\KOMAScript} Classes}
% \author{\href{mailto:komascript@gmx.info}{Markus Kohm}}
% \date{Revision \fileversion{} of \filedate}
% \maketitle
% \begin{abstract}
%   \file{scrkernel-listandtabulars.dtx} provides mainly code for all kind of
%   lists namely \env{itemize}, \env{enumerate}, \env{description},
%   \env{labeling}, \env{quote}, \env{quotation} and \env{addmargin} for all
%   \KOMAScript{} classes. And because the code for \env{tabbing} and
%   \env{tabular} is only some lines, it is added here too.
% \end{abstract}
% \tableofcontents
%
% \section{User Manual}
%
% You can find the user documentation the commands implemented here in the
% \KOMAScript{} manual, either the German \file{scrguide-de.pdf} or the
% English \file{scrguide-en.pdf}.
%
% \MaybeStop{\PrintIndex}
%
% \section{Implementation of Lists}
%
% \subsection{Options}
%
% The environments do not depend on options.
%
% \subsection{List margins}
%
% \begin{length}{\leftmargini,\leftmarginii,\leftmarginiii,\leftmarginiv,
%                \leftmarginv,\leftmarginvi,\leftmargin}
% Usually lists can be nested at most six levels (but usually only four are
% used). So we have to define six different margins depending on the level
% (roman number added to \cs{leftmargin}):
%    \begin{macrocode}
%<*body>
%<*class>
%<*!letter>
\if@twocolumn
  \setlength{\leftmargini}{2em}
\else
%</!letter>
  \setlength{\leftmargini}{2.5em}
%<!letter>\fi
\setlength{\leftmarginii}{2.2em}
\setlength{\leftmarginiii}{1.87em}
\setlength{\leftmarginiv}{1.7em}
%<*!letter>
\if@twocolumn
  \setlength{\leftmarginv}{.5em}
  \setlength{\leftmarginvi}{.5em}
\else
%</!letter>
  \setlength{\leftmarginv}{1em}
  \setlength{\leftmarginvi}{1em}
%<!letter>\fi
\setlength{\leftmargin}{\leftmargini}
%    \end{macrocode}
% \end{length}^^A \leftmargini … \leftmarginvi,\leftmargin
%
%
% \subsection{List labels}
%
% \begin{length}{\labelsep,\labelwidth}
% If a list has a label we need a label width and a horizontal distance after
% the label.
%    \begin{macrocode}
\setlength{\labelsep}{.5em}
\setlength{\labelwidth}{\leftmargini}
\addtolength{\labelwidth}{-\labelsep}
%    \end{macrocode}
% \end{length}^^A \labelsep,\labewidth
%
%
% \subsection{List penalties}
%
% \begin{macro}{\@beginparpenalty,\@endparpenalty,\@itempenatly}
% Page breaks at the begin an end of lists or items are better than somewhere
% else but not much.
%    \begin{macrocode}
\@beginparpenalty=-\@lowpenalty
\@endparpenalty  =-\@lowpenalty
\@itempenalty    =-\@lowpenalty
%    \end{macrocode}
% \end{macro}
%
%
% \subsection{List items}
%
% \begin{command}{\theenumi,\theenumii,\theenumiii,\theenumiv}
% There are four levels of \env{enumerate} items with their numbers in Arabic,
% lower case letters, lowercase Roman numbers, uppercase letters.
%    \begin{macrocode}
\renewcommand*\theenumi{\@arabic\c@enumi}
\renewcommand*\theenumii{\@alph\c@enumii}
\renewcommand*\theenumiii{\@roman\c@enumiii}
\renewcommand*\theenumiv{\@Alph\c@enumiv}
%    \end{macrocode}
% \end{command}
%
% \begin{command}{\labelenumi}
% \begin{command}{\labelenumii}
% \changes{v2.4m}{1997/02/28}{opening brace removed}
% \changes{v3.44}{2025/02/10}{usage of font element}
% \begin{command}{\labelenumiii,\labelenumiv}
% \changes{v3.44}{2025/02/10}{usage of font element}
% The printed labels consist of the previously defined numbers followed by a
% dot or brace.
%    \begin{macrocode}
\newcommand*\labelenumi{\usekomafont{labelenumi}{\theenumi.}}
\newcommand*\labelenumii{\usekomafont{labelenumii}{\theenumii)}}
\newcommand*\labelenumiii{\usekomafont{labelenumiii}{\theenumiii.}}
\newcommand*\labelenumiv{\usekomafont{labelenumiv}{\theenumiv.}}
%    \end{macrocode}
% \end{command}
% \end{command}
% \end{command}
%
% \begin{macro}{\p@enumii,\p@enumiii,\p@enumiv}
% References to \env{enumerate} items are prefixed by the parent number and
% additional separation signs like braces.
%    \begin{macrocode}
\renewcommand*\p@enumii{\theenumi}
\renewcommand*\p@enumiii{\p@enumii(\theenumii)}
\renewcommand*\p@enumiv{\p@enumiii\theenumiii}
%    \end{macrocode}
% \end{macro}
%
% \begin{command}{\labelitemi,\labelitemii,\labelitemiii,\labelitemiv}
% \changes{v2.5g}{1999/10/09}{math mode eliminated}
% \changes{v3.33}{2021/02/15}{Usage of new font element}
% The characters used for \env{itemize} items. Again four levels are
% supported. All of them use a own font element.
%    \begin{macrocode}
\newcommand*\labelitemi{\usekomafont{labelitemi}{\textbullet}}
\newcommand*\labelitemii{\usekomafont{labelitemii}{\textendash}}
\newcommand*\labelitemiii{\usekomafont{labelitemiii}{\textasteriskcentered}}
\newcommand*\labelitemiv{\usekomafont{labelitemiv}{\textperiodcentered}}
%    \end{macrocode}
% \end{command}^^A \labelitemi … \labelitemiv
%
%
% \subsection{Definition of the environments}
%
% \begin{environment}{description}
% \begin{command}{\descriptionlabel}
% \changes{v3.36}{2022/02/15}{using \cs{usekomafont\{descriptionlabel\}} instead
%   of \cs{descfont}}
% This is used to describe a single term. The terms should be short, because
% line breaks inside the terms are not supported. The term is the optional
% argument of \cs{item}. It is printed with font of element \fnt{descriptionlabel}.
%    \begin{macrocode}
\newenvironment{description}{%
  \list{}{\labelwidth\z@ \itemindent-\leftmargin
    \let\makelabel\descriptionlabel}%
}{%
  \endlist
}
\newcommand*{\descriptionlabel}[1]{%
  \hspace{\labelsep}\usekomafont{descriptionlabel}{#1}%
}
%    \end{macrocode}
% \end{command}
% \end{environment}
%
% \begin{environment}{labeling}
% \begin{command}{\labelinglabel}
% \changes{v3.02}{2009/01/01}{using font elements \fnt{labelinglabel} and
%   \fnt{labelingseparator}}
% \changes{v3.02c}{2009/01/28}{using font elements \fnt{labelinglabel} and
%   \fnt{labelingseparator} also for the calculation of the width}
% \changes{v3.03a}{2009/04/02}{fixed argument in the label width calculation}
% The \env{labeling} environment is an extension of \env{description}. It has
% an optional separation string (\texttt{\#1}) added behind every label. The
% width of the labels are the width of the mandatory argument (\texttt{\#2}).
%    \begin{macrocode}
%</class>
\newenvironment{labeling}[2][]{%
  \def\sc@septext{#1}%
  \list{}{\settowidth{\labelwidth}{{%
        \usekomafont{labelinglabel}{#2%
          \usekomafont{labelingseparator}{\sc@septext}}%
      }}%
    \leftmargin\labelwidth \advance\leftmargin by \labelsep
    \let\makelabel\labelinglabel
  }%
}{%
  \endlist
}
\newcommand\labelinglabel[1]{%
  \usekomafont{labelinglabel}{#1\hfil
    \usekomafont{labelingseparator}{\sc@septext}}%
}
%<*class>
%    \end{macrocode}
% \end{command}
% \end{environment}
%
% \begin{environment}{verse}
% \changes{v2.3g}{1996/01/14}{\cs{item} does not wait for \texttt{[]}}
% The environment for short poems.
%    \begin{macrocode}
\newenvironment{verse}{%
  \let\\=\@centercr
  \list{}{\itemsep=\z@
    \itemindent=-1.5em
    \listparindent=\itemindent
    \rightmargin=\leftmargin
    \advance\leftmargin by1.5em
  }%
  \item\relax
}{%
  \endlist
}
%    \end{macrocode}
% \end{environment}
%
% \begin{environment}{quotation,quote}
% \changes{v2.3g}{1996/01/14}{\cs{item} does not wait for \texttt{[]}}
% Two environments for left and right indented text. The difference of both
% is: \env{quotation} works with paragraph indent (first line is indented),
% \env{quote} works with paragraph distance.
%    \begin{macrocode}
\newenvironment{quotation}{%
  \list{}{\listparindent 1em%
    \itemindent    \listparindent
    \rightmargin   \leftmargin
    \parsep        \z@ \@plus\p@
  }%
  \item\relax
}{%
  \endlist
}
\newenvironment{quote}{%
  \list{}{\rightmargin\leftmargin}%
  \item\relax
}{%
  \endlist
}
%    \end{macrocode}
% \end{environment}
%
% \begin{environment}{addmargin}
% \changes{v2.8q}{2001/11/29}{added}
% \changes{v2.95a}{2006-07-20}{\cs{@listdepth} reset}
% \begin{environment}{addmargin*}
% \changes{v2.8q}{2001/11/29}{added}
% \changes{v2.95a}{2006-07-20}{\cs{@listdepth} reset}
% \changes{v3.17}{2015/03/23}{improved handling of page breaks at the beginning}
% \changes{v3.22}{2016/08/02}{page break test for double-sided documents}
% Both environments are similar to \env{quote} and \env{quotation}, but the
% indent is not fix. If only the mandatory argument (\texttt{\#2}) is used, it
% is the left and right indent. If the optional argument (\texttt{\#1}) is
% also used, it is the left indent with \env{addmargin} resp. the inner indent
% with \env{addmargin*}. Note, negative indents will extend to the
% margins. Note, that page breaks inside \env{addmargin*} should be avoided,
% because they result in wrong margins at the second, fourth, sixth etc. page.
% \begin{macro}{\@addmargin}
% \changes{v2.8q}{2001/11/29}{added}
% \changes{v2.95}{2002/07/01}{\cs{item} does not wait for \texttt{[]}}
% \changes{v2.9q}{2003/03/24}{unchanged \len{labelsep}}
% \changes{v2.95a}{2006/07/20}{unchanged \cs{@tmpcnta}}
% \changes{v3.05b}{2010/04/29}{\len{partopsep} has to be 0 instead of
%   \len{parskip} because of adding \len{topsep}}
% \changes{v3.17}{2015/03/23}{improved handling of page breaks at the beginning}
% \changes{v3.28}{2019/11/19}{\cs{ifthispageodd} replaced by \cs{Ifthispageodd}}
% \begin{macro}{\scr@addmargin@startpage}
% \changes{v3.12}{2013/10/26}{added}
% \changes{v3.12}{2013/10/26}{page break test for \env{addmargin*}}
% \changes{v3.22}{2016/10/21}{unchanged \len{topsep} and \len{partopsep}}
%    \begin{macrocode}
%</class>
\newenvironment{addmargin}{%
  \@tempswafalse\@addmargin
}{%
  \advance\@listdepth\@ne
  \endlist
}
\newenvironment{addmargin*}{%
  \@tempswafalse
  \if@twoside\is@thispageodd[]\ifthispagewasodd\else\@tempswatrue\fi
    \edef\scr@addmargin@startpage{\csname tpo@\scr@tpo\endcsname}\fi
  \@addmargin
}{%
  \if@twoside
    \unskip\nobreak\Ifthispageodd{}{}%
    \expandafter\ifx\csname tpo@\scr@tpo\endcsname\scr@addmargin@startpage\else
%<class>      \ClassWarning{\KOMAClassName}{%
%<package>    \PackageWarning{scrextend}{%
        page break inside `addmargin*' environment.\MessageBreak
        A `addmargin*' environment starting on page
        \scr@addmargin@startpage\MessageBreak
        ends on page \csname tpo@\scr@tpo\endcsname.\MessageBreak
        This will result in potential wrong margins on\MessageBreak
        every other page.\MessageBreak
        So maybe you should change the `addmargin*'\MessageBreak
        environment, that ends%
      }%
    \fi
  \fi
  \advance\@listdepth\@ne
  \endlist
}
\newcommand*{\@addmargin}[2][\@tempa]{%
  \list{}{%
    \if@tempswa
      \def\@tempa{\leftmargin}%
      \setlength{\leftmargin}{#2}%
      \setlength{\rightmargin}{#1}%
    \else
      \def\@tempa{\rightmargin}%
      \setlength{\rightmargin}{#2}%
      \setlength{\leftmargin}{#1}%
    \fi
    \setlength{\listparindent}{\parindent}%
    \setlength{\itemsep}{\parskip}%
    \setlength{\itemindent}{\z@}%
    \setlength{\@tempskipa}{\topsep}%
    \setlength{\topsep}{\z@}%
    \setlength{\parsep}{\parskip}%
    \setlength{\@tempskipb}{\partopsep}%
    \setlength{\partopsep}{\z@}%
    \let\makelabel\@gobble
    \setlength{\labelwidth}{\z@}%
    \advance\@listdepth\m@ne
  }%
%<!v4>  \expandafter\ifnum\scr@v@is@ge{3.22}%
    \setlength{\topsep}{\@tempskipa}%
    \setlength{\partopsep}{\@tempskipb}%
%<!v4>  \fi
  \item\is@thispageodd@setlabel\nobreak\ignorespaces
}
%<*class>
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{environment}
% \end{environment}
%
%
% \subsection{Font elements of lists}
%
% \begin{fontelement}{descriptionlabel}
% \changes{v2.8o}{2001/09/14}{added}
% The font element is defined indirect by some macros to stay compatible with
% \KOMAScript{} before the design of font elements.
% \begin{macro}{\descfont}
% \changes{v3.20}{2016/01/29}{\cs{sffamily} replaced by \cs{@gr@gsffamily}}
% \changes{v3.39}{2023/04/04}{\cs{@gr@gsfamily} replaced by \cs{maybesffamily}}
% The font of the item labels of \env{description}. The command \cs{descfont}
% should not be used by users. Think of it as an internal macro. The user
% space name is because of compatibility to very old \KOMAScript{} versions.
%    \begin{macrocode}
\newcommand*\descfont{\maybesffamily\bfseries}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\scr@fnt@descriptionlabel}
% The font element uses \cs{descfont}.
%    \begin{macrocode}
\newcommand*{\scr@fnt@descriptionlabel}{\descfont}
%    \end{macrocode}
% \end{macro}
% \end{fontelement}
%
% \begin{fontelement}{labelitemi,labelitemii,labelitemiii,labelitemiv,itemizelabel}
% \changes{v3.33}{2021/02/15}{added}
% \begin{command}{\labelitemfont}
% \changes{v3.33}{2021/02/15}{added}
% Due to a change in the LaTeX kernel 2020/02/02 the \env{itemize} items
% react on font changes. For this the standard classes have been changed to
% set the item \emph{bullets} using \cs{labelitemfont} which is
% \cs{normalfont} by default. I've adapted this using also \cs{labelitemfont}
% for compatibility but only to store the font of font element
% \fnt{itemizelabel} which is the default of the level depending font
% elements. \fnt{itemlabelii} differs, because the default \cs{textendash}
% should be bold.
%    \begin{macrocode}
\newcommand*{\labelitemfont}{\normalfont}
\newcommand*\scr@fnt@itemizelabel{\labelitemfont}
\newkomafont{labelitemi}{\usekomafont{itemizelabel}}
\newkomafont{labelitemii}{\usekomafont{itemizelabel}\bfseries}
\newkomafont{labelitemiii}{\usekomafont{itemizelabel}}
\newkomafont{labelitemiv}{\usekomafont{itemizelabel}}
%</class>
%    \end{macrocode}
% \end{command}
% \end{fontelement}
%
% \begin{fontelement}{labelenumi,labelenumii,labelenumiii,labelenumiv,enumeratelabel}
% \changes{v3.44}{2025/02/10}{added}
% There has been a user request to add a font for \env{enumerate} items similar
% to the fonts for \env{itemize} items.
%    \begin{macrocode}
\newkomafont{enumeratelabel}{}
\newkomafont{labelenumi}{\usekomafont{enumeratelabel}}
\newkomafont{labelenumii}{\usekomafont{enumeratelabel}}
\newkomafont{labelenumiii}{\usekomafont{enumeratelabel}}
\newkomafont{labelenumiv}{\usekomafont{enumeratelabel}}
%    \end{macrocode}
% \end{fontelement}
%
% \begin{fontelement}{labelinglabel,labelingseparator}
% \changes{v3.02}{2009/01/01}{added}
% The \env{labeling} environment has two font elements, one for the whole
% label and one for the separator only. The default is no change.
%    \begin{macrocode}
\newkomafont{labelinglabel}{}
\newkomafont{labelingseparator}{}
%    \end{macrocode}
% \end{fontelement}
%
%
% \section{Implementation of Tabulars, Array etc.}
% 
% All these environments are implemented in the \LaTeX{} kernel already. We
% only need some configuration parameters.
%
% \begin{length}{\arraycolsep,\tabcolsep,\arrayrulewidth,\doublerulewidth,
%                \tabbingsep}
% These are the distances between columns in \env{array} and \env{tabular},
% the width of lines/rules independent from \env{array} or \env{tabular} and
% the distance of double lines/rules (two consecutive \cs{hline}). The last
% one, \cs{tabbingsep}, is the \cs{'} distance in \env{tabbing} environments.
% All values are same as in the standard classes.
%    \begin{macrocode}
%<*class>
\setlength\arraycolsep{5\p@}
\setlength\tabcolsep{6\p@}
\setlength\arrayrulewidth{.4\p@}
\setlength\doublerulesep{2\p@}
\setlength\tabbingsep{\labelsep}
%</class>
%    \end{macrocode}
% \end{length}^^A \arraycolsep … \tabbingsep
%
%
%    \begin{macrocode}
%</body>
%    \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:
