% \iffalse meta-comment
% ======================================================================
% scrjura.dtx
% Copyright (c) Markus Kohm, 2007-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.
%
% The KOMA-Script bundle consists of all files listed in MANIFEST.md.
% ======================================================================
%%% From File: $Id: scrjura.dtx 3991 2022-11-16 07:13:45Z kohm $
%<identify>%%%            (run: identify)
%<init>%%%            (run: init)
%<options>%%%            (run: options)
%<postoptions>%%%            (run: postoptions)
%<body>%%%            (run: body)
%<final>%%%            (run: final)
%<*dtx>
\begingroup
  \def\filedate$#1: #2-#3-#4 #5${\gdef\filedate{#2/#3/#4}}
  \filedate$Date: 2022-11-16 08:13:45 +0100 (Mi, 16. Nov 2022) $
  \def\filerevision$#1: #2 ${\gdef\filerevision{r#2}}
  \filerevision$Revision: 3991 $
\endgroup
\expandafter\ifx\csname ProvidesFile\endcsname\relax
\def\ProvidesFile#1[#2]{}
\fi
\ProvidesFile{scrjura.dtx}[\filedate\space\filerevision\space
%</dtx>
%<package&identify>\NeedsTeXFormat{LaTeX2e}[1995/06/01]
%<package&identify>\ProvidesPackage{scrjura}[%
%<*dtx|(package&identify)>
%!KOMAScriptVersion
  package
%<*dtx>
  source
%</dtx>
  (for jurists)
]
%</dtx|(package&identify)>
%<*dtx>
\ifx\documentclass\undefined
%</dtx>
%<*ins>
  \input scrdocstrip.tex
  \@@input scrkernel-version.dtx
  \@@input scrstrip.inc
  \KOMAdefVariable{COPYRIGHTFROM}{2007}
  \generate{\usepreamble\defaultpreamble
    \file{scrjura.ins}{%
      \from{scrjura.dtx}{ins}%
    }%
    \file{scrjura.sty}{%
      \from{scrjura.dtx}{package,identify}%
      \from{scrjura.dtx}{package,init}%
      \from{scrjura.dtx}{package,options}%
      \from{scrjura.dtx}{package,postoptions}%
      \from{scrjura.dtx}{package,body}%
      \from{scrjura.dtx}{package,final}%
      \from{scrlogo.dtx}{logo}%
    }%
  }%
  \@@input scrstrop.inc
%</ins>
%<*dtx>
\else
  \let\endbatchfile\relax
\fi
%</dtx>
%<*ins>
\endbatchfile
%</ins>
%<*dtx>
\documentclass{koma-script-source-doc}
\usepackage[USenglish]{babel}
\setcounter{StandardModuleDepth}{2}
\begin{document}
  \DocInput{scrjura.dtx}
\end{document}
%</dtx>
% \fi
%
% \changes{v3.36}{2022/01/25}{switch over from \cls*{scrdoc} to
%   \cls*{koma-script-source-doc}}
%
% \GetFileInfo{scrjura.dtx}
% \title{\KOMAScript{} in the Law Office\\
%   with Package \pkg*{scrjura}}
% \date{Version \fileversion{} of \filedate}
% \author{\href{mailto:komascript@gmx.info}{Markus Kohm}}
% \maketitle
% \begin{abstract}
% The \pkg*{scrjura} package is intended for cautelar jurisprudence.  It is
% intended to provide flexible help for lawyers and notaries in drafting
% contracts, statutes and legal commentaries.  It has been developed in
% cooperation with Dr.\,Alexander Willand, and is still in the process of
% development.
% \end{abstract}
%
% \tableofcontents
%
% \section{User Manual}
%
% You can find the user manual of \pkg*{scrjura} in the \KOMAScript{} manual,
% either the German \file{scrguide} or the English \file{scrguien}.
%
% \MaybeStop{\PrintIndex}
%
% \section{Implementation}
%
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
%
% \changes{v0.7b}{2014/11/11}{General renaming of ``Paragraph'' into
%   ``Clause''}
%
% \subsection{Cooperation with \pkg*{hyperref}}
%
% If \pkg{hyperref} has already loaded before \pkg*{scrjura} the package cannot
% work correctly. So we throw an error. Maybe it would be a good idea to make
% this error fatal. But currently it is only an error.
%    \begin{macrocode}
%<*init>
\@ifpackageloaded{hyperref}{%
  \PackageError{scrjura}{Package hyperref already loaded}{%
    If you want to use package scrjura with package hyperref, you have
    to\MessageBreak
    load package scrjura before package hyperref.\MessageBreak
    To solve the problem, you just should move the loading of package
    hyperref\MessageBreak
    behind the loading of package scrjura.}%
}
%</init>
%    \end{macrocode}
%
% \subsection{Prerequisites}
%
% We need package \pkg*{scrkbase}. We could load this also together with
% \pkg*{tocbasic}, which is loaded later. But loading it on its own, we can
% require a minimum version.
%    \begin{macrocode}
%<*init>
\RequirePackage{scrkbase}[2013/03/26]
%</init>
%    \end{macrocode}
%
% And now, \pkg*{tocbasic}.
%    \begin{macrocode}
%<*init>
\RequirePackage{tocbasic}
%</init>
%    \end{macrocode}
%
% \subsection{Options}
%
% \begin{option}{contract}
% \begin{macro}{\if@documentcontract,
%               \@documentcontractfalse,\@documentcontracttrue}
% \changes{v3.36}{2022/01/25}{switched to a \KOMAScript{} option}
% Option \opt{contract} can be used to make the whole document to be a
% contract. But in this case you are not allowed to reuse the \env{contract}
% environment in the document. Now it is allowed to stop or restart the
% contract. With older \LaTeX{} this is done by adding \cs{contract} to the
% end of \cs{document}. With an up to date \LaTeX{} we us a hook.
%    \begin{macrocode}
%<*options>
\KOMA@ifkey{contract}{@documentcontract}
\IfLTXAtLeastTF{2020/10/01}{%
  \AddToHook{begindocument/end}{%
    \RelaxFamilyKey[.scrjura.sty]{KOMA}{contract}%
    \if@documentcontract\expandafter\contract\fi
  }%
}{%
  \g@addto@macro\document{%
    \RelaxFamilyKey[.scrjura.sty]{KOMA}{contract}%
    \if@documentcontract\expandafter\contract\fi
  }%
}
%</options>
%    \end{macrocode}
% \end{macro}
% \end{option}
%
% \begin{option}{juratotoc}
% \changes{v3.39}{2022/11/11}{initial dot in member argument of option storage
%   commands removed}
% Allow to set the toc level of the entries. Value \optvalue{true} is the same 
% like \optvalue{2}, value \optvalue{false} is the same like \cs{maxdimen}.
% \changes{v0.7}{2013/11/04}{usage of renewed interface with
%   \cs{FamilyKeyState}}
% \changes{v0.9a}{2015/03/09}{internal value storage}
% \begin{macro}{\if@juratotoc}
% \changes{v0.6}{2011/09/29}{replaced by counter}
% \begin{counter}{juratoclevel}
% \changes{v0.6}{2011/09/29}{definition moved}
% \changes{v3.27}{2019/02/25}{removed}
% \begin{macro}{\toclevel@cpar}
% \changes{v0.7}{2013/06/09}{new, because of \pkg{hyperref}}
% \changes{v3.27}{2019/02/25}{handled by \pkg*{tocbasic}}
%    \begin{macrocode}
%<*options>
\KOMA@key{juratotoc}[true]{%
  \KOMA@set@ifkey{juratotoc}{@tempswa}{#1}%
  \ifx\FamilyKeyState\FamilyKeyStateProcessed
    \if@tempswa
      \DeclareTOCStyleEntry[level=2]{default}{cpar}%
    \else
      \DeclareTOCStyleEntry[level=\maxdimen]{default}{cpar}%
    \fi
  \else
    \DeclareTOCStyleEntry[level=#1]{default}{cpar}%
  \fi
  \KOMA@kav@xreplacevalue{scrjura.sty}{juratotoc}{\cpartocdepth}%
}
\KOMA@kav@xadd{scrjura.sty}{juratotoc}{\cpartocdepth}%
%</options>
%    \end{macrocode}
% \end{macro}
% \end{counter}
% \end{macro}
% \end{option}
%
% \begin{option}{juratocnumberwidth,juratocindent}
% \changes{v0.6}{2011/09/29}{new}
% \changes{v0.7}{2013/11/04}{usage of renewed interface with
%   \cs{FamilyKeyState}}
% \changes{v0.9a}{2015/03/09}{internal value storage}
% \changes{v3.39}{2022/11/11}{initial dot in member argument of option storage
%   commands removed}
% \begin{ilength}{\cpar@numberwidth,\cpar@indent}
% \changes{v0.6}{2011/09/29}{new}
% \changes{v3.27}{2019/02/25}{replaced by usage of \cs{DeclareTOCStyleEntry}}
% Indent and number width of the toc entries.
%    \begin{macrocode}
%<*options>
\KOMA@key{juratocnumberwidth}{%
  \DeclareTOCStyleEntry[numwidth=#1]{default}{cpar}%
  \FamilyKeyStateProcessed
  \KOMA@kav@replacevalue{scrjura.sty}{juratocnumberwidth}{#1}%
}
\KOMA@kav@add{scrjura.sty}{juratocnumberwidth}{2em}
\KOMA@key{juratocindent}{%
  \DeclareTOCStyleEntry[indent=#1]{default}{cpar}%
  \FamilyKeyStateProcessed
  \KOMA@kav@replacevalue{scrjura.sty}{juratocindent}{#1}%
}
\KOMA@kav@add{scrjura.sty}{juratocindent}{1.5em}%
%</options>
%    \end{macrocode}
% \end{ilength}
% \end{option}
%
% \begin{option}{juratitlepagebreak}
% \changes{v0.5b}{2010/04/05}{new}
% The options sets the boolean \cs{if@juratitlepagebreak}.
% \begin{macro}{\if@juratitlepagebreak,
%               \@juratitlepagebreaktrue,\@juratitlepagebreakfalse}
% If the boolean is \cs{iftrue} page breaks inside clause headings are
% allowed (which is not recommended).
%    \begin{macrocode}
%<*options>
\KOMA@ifkey{juratitlepagebreak}{@juratitlepagebreak}
%</options>
%    \end{macrocode}
% \end{macro}
% \end{option}
%
% \begin{option}{parnumber}
% \changes{v0.6}{2011/09/29}{new}
% \changes{v0.6a}{2012/10/15}{value mistake message changed}
% \changes{v0.7}{2013/11/04}{usage of renewed interface with
%   \cs{FamilyKeyState}}
% \changes{v0.9a}{2015/03/09}{internal value storage}
% \changes{v3.28}{2019/11/18}{\cs{ifstr} renamed into \cs{Ifstr}}
% \changes{v3.39}{2022/11/11}{initial dot in member argument of option storage
%   commands removed}
% The options switches the (automatic) paragraph numbering.
%    \begin{macrocode}
%<*options>
\newif\ifparnumber
\KOMA@key{parnumber}[true]{%
  \Ifstr{#1}{auto}{%
    \AutoPar
    \FamilyKeyStateProcessed
    \KOMA@kav@remove{scrjura.sty}{parnumber}{manual}%
    \KOMA@kav@remove{scrjura.sty}{parnumber}{auto}%
    \KOMA@kav@add{scrjura.sty}{parnumber}{auto}%
  }{%
    \Ifstr{#1}{manual}{%
      \ManualPar
      \FamilyKeyStateProcessed
      \KOMA@kav@remove{scrjura.sty}{parnumber}{manual}%
      \KOMA@kav@remove{scrjura.sty}{parnumber}{auto}%
      \KOMA@kav@add{scrjura.sty}{parnumber}{manual}%
    }{%
      \KOMA@set@ifkey{parnumber}{parnumber}{#1}%
      \KOMA@kav@replacebool{scrjura.sty}{parnumber}{parnumber}%
    }%
  }%
}
\KOMA@kav@add{scrjura.sty}{parnumber}{true}
\KOMA@kav@add{scrjura.sty}{parnumber}{auto}
%</options>
%    \end{macrocode}
% \end{option}
%
% \begin{option}{paragraphmark,clausemark}
% \changes{v0.9h}{2016/04/11}{\opt{paragraphmark} renamed to \opt{clausemark}}
% \changes{v0.7}{2013/11/04}{usage of renewed interface with
%   \cs{FamilyKeyState}}
% \changes{v0.9a}{2015/03/09}{internal value storage}
% \changes{v3.39}{2022/11/11}{initial dot in member argument of option storage
%   commands removed}
% \begin{option}{markright,markboth}
% \changes{v0.7}{2013/11/04}{deprecated}
% \changes{v3.39}{2022/11/16}{only with \KOMAScript~3}
% \begin{command}{\Clausemark}
% \changes{v0.5e}{2011/08/31}{support for \cs{MakeMarkcase}}
% The options are used to activate either \cs{markright} or \cs{markboth} for
% clauses. \cs{Clausemark} expects not only the title but also the
% number. So it differs from, e.g., \cs{chaptermark}, which uses the counter
% automatically. But maybe I will change this some time.
%    \begin{macrocode}
%<*options>
\newcommand*{\Clausemark}[1]{}
\KOMA@key{clausemark}{%
  \begingroup
    \KOMA@set@ncmdkey{clausemark}{@tempa}{%
      {false}{0},{off}{0},{no}{0},%
      {forceright}{1},%
      {forceboth}{2},%
      {right}{3},%
      {both}{4}%
    }{#1}%
  \ifx\FamilyKeyState\FamilyKeyStateProcessed
    \ifcase\number\@tempa
      \endgroup
      \let\Clausemark\@gobble
    \or
      \endgroup
      \renewcommand*{\Clausemark}[1]{%
        \markright{\csname MakeMarkcase\endcsname{##1}}}%
    \or
      \endgroup
      \renewcommand*{\Clausemark}[1]{%
        \markboth{\csname MakeMarkcase\endcsname{##1}}%
                 {\csname MakeMarkcase\endcsname{##1}}}%
    \or
      \endgroup
      \renewcommand*{\Clausemark}[1]{%
        \ifx
          \@mkboth\@gobbletwo
        \else
          \markright{\csname MakeMarkcase\endcsname{##1}}%
        \fi}%
    \or
      \endgroup
      \renewcommand*{\Clausemark}[1]{%
        \@mkboth{\csname MakeMarkcase\endcsname{##1}}%
                {\csname MakeMarkcase\endcsname{##1}}}%
    \else
      \endgroup
    \fi
    \FamilyKeyStateProcessed
  \else
    \endgroup
    \FamilyKeyStateUnknownValue
  \fi
  \KOMA@kav@xreplacevalue{scrjura.sty}{clausemark}{#1}%
}
\KOMA@kav@add{scrjura.sty}{clausemark}{false}
\@ifundefined{KOMA@DeclareDeprecatedOption}{}{%
  \KOMA@DeclareDeprecatedOption[scrjura]{markright}{clausemark=forceright}%
  \KOMA@DeclareDeprecatedOption[scrjura]{markboth}{clausemark=forceboth}%
}
\KOMA@key{paragraphmark}{%
  \PackageWarningNoLine{scrjura}{%
    You've used obsolete option `paragraphmark'.\MessageBreak
    Usage of this option is deprecated.\MessageBreak
    You should simply replace `paragraphmark'\MessageBreak
    by `clausemark'%
  }%
  \KOMAExecuteOptions[.scrjura.sty]{clausemark=#1}%
}
%</options>
%    \end{macrocode}
% \end{command}
% \end{option}
% \end{option}
%
% \begin{option}{ref}
% \changes{v0.5d}{2010/06/07}{new values \optvalue{nopar},
%   \optvalue{nosentence}, \optvalue{OnlyParagraph}}
% \changes{v0.7}{2013/11/04}{usage of renewed interface with
%   \cs{FamilyKeyState}}
% \changes{v0.9a}{2015/03/09}{internal value storage}
% \changes{v3.39}{2022/11/11}{initial dot in member argument of option storage
%   commands removed}
% \begin{option}{parcitename,sentencecitename}
% \changes{v0.5d}{2010/06/07}{deprecated}
% \changes{v3.39}{2022/11/16}{only with \KOMAScript~3}
% The formatting of the references of paragraphs and sentences. There are a
% long a short and a numeric form.
% \begin{macro}{\parcite@format,\sentencecite@format}
% Default is the long form. Corresponding values of the two helper macros are:
% 0 = long, 1 = short, 2 = numerical, -1 = nothing.
%    \begin{macrocode}
%<*options>
\newcommand*{\parcite@format}{0}
\newcommand*{\sentencecite@format}{0}
%    \end{macrocode}
% \end{macro}
% The options can be used to change the default.
%    \begin{macrocode}
\KOMA@key{ref}{%
  \begingroup
    \KOMA@set@ncmdkey{ref}{@tempa}{%
      {parlong}{1},{longpar}{1},{ParL}{1},%
      {parshort}{2},{shortpar}{2},{ParS}{2},%
      {parnumeric}{3},{numericpar}{3},{ParN}{3},%
      {paroff}{4},{nopar}{4},%
      {sentencelong}{10},{longsentence}{10},{SentenceL}{10},%
      {sentenceshort}{20},{shortsentence}{20},{SentenceS}{20},%
      {sentencenumeric}{30},{numericsentence}{30},{SentenceN}{30},%
      {sentenceoff}{40},{nosentence}{40},%
      {long}{11},%
      {short}{22},%
      {numeric}{33},%
      {paragraphonly}{44},{onlyparagraph}{44},%
      {ParagraphOnly}{44},{OnlyParagraph}{44}%
    }{#1}%
    \ifx\FamilyKeyState\FamilyKeyStateProcessed
      \aftergroup\FamilyKeyStateProcessed
      \@tempcnta=\@tempa\relax
      \@tempcntb=\z@
      \@whilenum \@tempcnta>9 \do{%
        \advance\@tempcnta -10\relax
        \advance\@tempcntb \@ne\relax
      }%
      \ifcase \@tempcnta
      \or
        \aftergroup\def\aftergroup\parcite@format
        \aftergroup{\aftergroup0\aftergroup}%
      \or
        \aftergroup\def\aftergroup\parcite@format
        \aftergroup{\aftergroup1\aftergroup}%
      \or
        \aftergroup\def\aftergroup\parcite@format
        \aftergroup{\aftergroup2\aftergroup}%
      \or
        \aftergroup\def\aftergroup\parcite@format
        \aftergroup{\aftergroup-\aftergroup1\aftergroup}%
      \fi
      \ifcase \@tempcntb
      \or
        \aftergroup\def\aftergroup\sentencecite@format
        \aftergroup{\aftergroup0\aftergroup}%
      \or
        \aftergroup\def\aftergroup\sentencecite@format
        \aftergroup{\aftergroup1\aftergroup}%
      \or
        \aftergroup\def\aftergroup\sentencecite@format
        \aftergroup{\aftergroup2\aftergroup}%
      \or
        \aftergroup\def\aftergroup\sentencecite@format
        \aftergroup{\aftergroup-\aftergroup1\aftergroup}%
      \fi
    \else
      \aftergroup\FamilyKeyStateUnknownValue
    \fi
  \endgroup
  \ifx\FamilyKeyState\FamilyKeyStateProcessed
    \KOMA@kav@removekey{scrjura.sty}{ref}%
    \ifcase\parcite@format
      \KOMA@kav@add{scrjura.sty}{ref}{parlong}%
    \or
      \KOMA@kav@add{scrjura.sty}{ref}{parshort}%
    \or
      \KOMA@kav@add{scrjura.sty}{ref}{parnumeric}%
    \or
      \KOMA@kav@add{scrjura.sty}{ref}{paroff}%
    \fi
    \ifcase\sentencecite@format
      \KOMA@kav@add{scrjura.sty}{ref}{sentencelong}%
    \or
      \KOMA@kav@add{scrjura.sty}{ref}{sentenceshort}%
    \or
      \KOMA@kav@add{scrjura.sty}{ref}{sentencenumeric}%
    \or
      \KOMA@kav@add{scrjura.sty}{ref}{sentenceoff}%
    \fi
  \fi
}
\KOMA@kav@add{scrjura.sty}{ref}{parlong}%
\KOMA@kav@add{scrjura.sty}{ref}{sentencelong}%
\@ifundefined{KOMA@DeclareDeprecatedOption}{}{%
  \KOMA@DeclareDeprecatedOption[scrjura]{parcitename}{ref=parlong}
  \KOMA@DeclareDeprecatedOption[scrjura]{sentencecitename}{ref=sentencelong}
}
%</options> 
%    \end{macrocode}
% \end{option}
% \end{option}
%
% Execute the options.
%    \begin{macrocode}
%<*postoptions>
\KOMAProcessOptions\relax
%</postoptions>
%    \end{macrocode}
%
% \subsection{Deprecated paragraph commands}
%
% All these commands are deprecated and now generate error messages instead of
% code.
%
% \begin{command}{\Paragraph,\SubParagraph,\refParagraph,\refParagraphN,
%                 \DeprecatedParagraph,\ParagraphCompatibilityHacks}
% \changes{1.0}{2014/11/22}{throw error for deprecated commands but only once}
%    \begin{macrocode}
%<*body>
\providecommand*{\DeprecatedParagraph}{%
  \PackageError{scrjura}{modification of old document needed}{%
    It seem that this document was made for scrjura up to version
    0.7a.\MessageBreak
    Since scrjura version 0.9 \string\Paragraph, \string\SubParagraph, and all
    depending\MessageBreak
    commands, options, and counters have been renamed.\MessageBreak
    You should replace the terms `Paragraph' and `paragraph` by `Clause`
    and\MessageBreak
    `clause` if they are part of the name of a scrjura feature, otherwise
    this\MessageBreak
    document may produce severall additional error messages and maybe the
    wrong\MessageBreak
    result. Sorry for the inconvenience.%
  }%
  \ParagraphCompatibilityHacks
}
\newcommand*{\ParagraphCompatibilityHacks}{%
  \PackageWarning{scrjura}{compatibility hacks for `\string\Paragraph'
    executed.\MessageBreak
    There is no support for documents using these hacks!\MessageBreak
    There is no warranty for real compatibility!\MessageBreak
    Even if the LaTeX run of the document doesn't report\MessageBreak
    any error, the result may be completely wrong.\MessageBreak
    Therefore it is recommended to solve the problem,\MessageBreak
    instead of trying to work around using the\MessageBreak
    compatibility hacks%
  }%
  \gdef\Paragraph{\Clause}%
  \gdef\SubParagraph{\SubClause}%
  \gdef\c@Paragraph{\c@Clause}%
  \gdef\cl@Paragraph{\cl@Clause}%
  \gdef\c@SubParagraph{\c@SubClause}%
  \gdef\cl@SubParagraph{\cl@SubClause}%
  \gdef\theParagraph{\theClause}%
  \gdef\theSubParagraph{\theSubClause}%
  \gdef\refParagraph{\refClause}%
  \gdef\refParagraphN{\refClauseN}%
  \aliaskomafont{Paragraph}{Clause}%
  \scr@ifundefinedorrelax{Paragraphmark}{}{%
    \global\let\Clausemark\Paragraphmark
  }%
}
\providecommand*{\Paragraph}{\DeprecatedParagraph\Paragraph}
\providecommand*{\SubParagraph}{\DeprecatedParagraph\SubParagraph}
\providecommand*{\refParagraph}{\DeprecatedParagraph\refParagraph}
\providecommand*{\refParagraphN}{\DeprecatedParagraph\refParagraphN}
%</body>
%    \end{macrocode}
% \end{command}
%
%
% \subsection{Contracts, clauses, paragraphs and sentences}
%
%
% \begin{macro}{\scrjura@env@type}
% \changes{v0.5d}{2010/04/28}{new}
% \changes{v0.7b}{2014/11/03}{renamed}
% This macro shows the currently active \pkg*{scrjura} environment.
%    \begin{macrocode}
%<*body>
\newcommand*{\scrjura@env@type}{}
%</body>
%    \end{macrocode}
% \end{macro}
%
%
% \begin{command}{\ellipsispar}
% \changes{v0.7}{2013/05/02}{new}
% \changes{v0.7b}{2014/11/03}{\cs{thecontractAbsoluteClause} made more
%   flexible}
% \changes{v0.9g}{2016/03/25}{write to \file{aux}-file only \cs{if@filesw}}
% \begin{command}{\parellipsis}
% \changes{v0.7}{2013/05/02}{new}
% Count one or more paragraphs given by the optional argument but print
% \cs{parellipsis} instead of a real paragraph. The default is either
% \cs{dots} or \cs{textellipsis} if available.
% \changes{v0.7}{2013/05/02}{new}
%    \begin{macrocode}
%<*body>
\newcommand*{\ellipsispar}[1][1]{%
  \begingroup
    \KOMAoptions{parnumber=manual}\parellipsis\par
    \addtocounter{par}{#1}%
    \if@filesw
      \protected@write\@auxout{}{%
        \string\newmaxpar{\scrjura@env@type}%
                         {\csname the\scrjura@env@type 
                           AbsoluteClause\endcsname}%
                         {\thepar}%
      }%
    \fi
  \endgroup
  \addtocounter{par}{-1}\refstepcounter{par}%
  \ignorespaces
}
\newcommand*{\parellipsis}{%
  \scr@ifundefinedorrelax{textellipsis}{\dots}{\textellipsis}%
}
%</body>
%    \end{macrocode}
% \end{command}
% \end{command}
%
% \begin{environment}{contract}
% \changes{v0.5d}{2010/04/28}{missing error message added}
% \changes{v0.5d}{2010/04/28}{not self-redefining any more}
% \changes{v0.5d}{2010/04/28}{defining \cs{jura@env@type}}
% \changes{v3.36}{2022/01/25}{defining an environment (because of hooks)}
% \begin{counter}{contractClause}
% \begin{command}{\thecontractClause}
% \changes{v0.9b}{2015/05/01}{must use counter \cnt{Clause} instead of
%   \cnt{contractClause}}
% \begin{macro}{\contract@Clauseformat}
% \begin{command}{\Clauseformat,\paragraphformat}
% \changes{v0.6b}{2013/04/16}{redefinition of \cs{paragraphformat}}
% \begin{counter}{contractSubClause}
% \changes{v0.9b}{2015/05/01}{must use counter \cnt{SubClause} instead of
%   \cnt{contractSubClause}}
% \begin{command}{\thecontractSubClause}
% \begin{counter}{contractAbsoluteClause}
% \changes{v0.7}{2013/04/18}{new (internal) counter for all clauses to make
%   it possible to reset the users clause counter}
% It is not allowed to nest the \env{contract} environments, but you can end
% them and start them new. But this would not end the contract and start a new
% contract but only delay it for some other code.
%    \begin{macrocode}
%<*body>
\newenvironment{contract}{%
  \ifx\scrjura@env@type\@empty
    \let\@doendpe\scrjura@doendpe
    \let\Clause\contract@paragraph
    \let\c@Clause\c@contractClause
    \edef\cl@Clause{\cl@Clause\cl@contractClause}%
    \let\SubClause\contract@subparagraph
    \let\c@SubClause\c@contractSubClause
    \edef\cl@SubClause{\cl@SubClause\cl@contractSubClause}%
    \let\Sentence\contract@sentence
    \renewcommand*{\scrjura@env@type}{contract}%
    \aliaskomafont{Clause}{contract.Clause}%
  \else
    \PackageError{scrjura}{nested `contract` detected}{%
      You may not use a `contract' environment inside\MessageBreak
      a `\scrjura@env@type' environment or after loading\MessageBreak
      package `scrjura' with option `\scrjura@env@type'!}%
  \fi
}{}
\let\if@scrjura@skiphyperref\iftrue
\let\cl@Clause\@empty
\let\cl@SubClause\@empty
\newcounter{contractClause}
\renewcommand*{\thecontractClause}{%
  {\contract@Clauseformat{\arabic{Clause}}}}
\DeclareRobustCommand*{\contract@Clauseformat}[1]{\Clauseformat{#1}}
\newcommand*{\Clauseformat}[1]{\S~#1}
\newcounter{contractSubClause}
\@addtoreset{SubClause}{Clause}
\renewcommand*{\thecontractSubClause}{%
  {\theClause\alph{SubClause}}}
\newcounter{contractAbsoluteClause}
%</body>
%    \end{macrocode}
% \end{counter}
% \end{command}
% \end{counter}
% \end{command}
% \end{macro}
% \end{command}
% \end{counter}
% \end{environment}
%
% \begin{command}{\DeclareNewJuraEnvironment}
% \changes{v0.9}{2014/11/12}{new}
% \changes{v0.9h}{2016/04/12}{\cs{@ifnextchar} replaced by
%   \cs{kernel@ifnextchar}}
% Using \cs{@defjuraenvironment} to define a new juristic environment. This
% can be done only in document preamble.
%    \begin{macrocode}
%<*body>
\newcommand*{\DeclareNewJuraEnvironment}[1]{%
  \@ifundefined{#1}{\expandafter\let\csname #1\expandafter\endcsname
    \csname end#1\endcsname}{}%
  \@ifundefined{#1}{\let\reserved@defjuraenvironment\@defjuraenvironment}{%
    \PackageError{scrjura}{ignorring declaration of `#1'}{%
      You've tried to declare jura environment `#1', but
      environment\MessageBreak
      `#1' or command
      \expandafter\string\csname #1\endcsname\space or
      \expandafter\string\csname end#1\endcsname\MessageBreak
      already exists.\MessageBreak
      Declaration will be ignored}%
    \long\def\reserved@defjuraenvironment##1[##2]##3##4{}%
  }%
  \kernel@ifnextchar [%]
    {\reserved@defjuraenvironment{#1}}{\reserved@defjuraenvironment{#1}[]}%
}
\@onlypreamble\DeclareNewJuraEnvironment
%    \end{macrocode}
% \begin{macro}{\@defjuraenvironment}
% \changes{v0.9}{2014/11/04}{new}
% \changes{v3.25}{2017/12/08}{new command options \opt{ClauseFont}}
% \changes{v3.25}{2017/12/08}{\cs{reserved@defjuraenvironment} set back to
%   \cs{relax}}
% \changes{v3.25}{2017/12/08}{using local instead of global command options}
% This command is used to define a new \pkg*{scrjura} environment like
% \env{contract}. Several options are provided (see the user manual for
% details).
%    \begin{macrocode}
\DefineFamily{KOMAarg}
\DefineFamilyMember{KOMAarg}
\newcommand{\@defjuraenvironment}{}
\long\def\@defjuraenvironment#1[#2]#3#4{%
  \let\reserved@defjuraenvironment\relax
%    \end{macrocode}
% The counters:
%    \begin{macrocode}
  \newcounter{#1Clause}%
  \newcounter{#1AbsoluteClause}%
  \newcounter{#1SubClause}%
  \FamilyCSKey[.scrjura.sty]{KOMAarg}{Clause}{#1@Clause}%
  \FamilyCSKey[.scrjura.sty]{KOMAarg}{SubClause}{#1@SubClause}%
  \FamilyCSKey[.scrjura.sty]{KOMAarg}{Sentence}{#1@Sentence}%
  \DefineFamilyKey[.scrjura.sty]{KOMAarg}{ClauseNumberFormat}{%
    \expandafter\def\csname #1@Clauseformat \endcsname####1{##1{####1}}%
    \expandafter\edef\csname #1@Clauseformat\endcsname{%
      \noexpand\protect\expandafter\noexpand\csname #1@Clauseformat \endcsname
    }%
    \FamilyKeyStateProcessed
  }
  \DefineFamilyKey[.scrjura.sty]{KOMAarg}{ClauseFont}{%
    \IfExistskomafont{#1.Clause}{%
      \IfIsAliaskomafont{#1.Clause}{%
        \expandafter\let\csname scr@fnt@instead@#1.Clause\endcsname\relax
        \newkomafont{#1.Clause}{##1}%
      }{\setkomafont{#1.Clause}{##1}}%
    }{%
      \newkomafont{#1.Clause}{##1}%
    }%
  }
  \FamilyExecuteOptions[.scrjura.sty]{KOMAarg}{#2}%
  \RelaxFamilyKey[.scrjura.sty]{KOMAarg}{ClauseFont}%
  \RelaxFamilyKey[.scrjura.sty]{KOMAarg}{ClauseNumberFormat}%
  \RelaxFamilyKey[.scrjura.sty]{KOMAarg}{Sentence}%
  \RelaxFamilyKey[.scrjura.sty]{KOMAarg}{SubClause}%
  \RelaxFamilyKey[.scrjura.sty]{KOMAarg}{Clause}%
  \@ifundefined{#1@Clauseformat}{%
    \expandafter\DeclareRobustCommand\expandafter*%
    \csname #1@Clauseformat\endcsname[1]{\Clauseformat{##1}}%
  }{}%
%    \end{macrocode}
% \changes{v0.9c}{2015/05/13}{defining \cs{the\dots Clause}}
% \changes{v0.9f}{2016/02/24}{\cs{protect}\cs{\@nameuse} instead of
%     \cs{csname}\dots\cs{endcsname}}
%    \begin{macrocode}
  \expandafter\renewcommand\expandafter*\csname the#1Clause\endcsname{%
    \protect\@nameuse{#1@Clauseformat}{\arabic{#1Clause}}}%
%    \end{macrocode}
% Environment:
%    \begin{macrocode}
  \newenvironment{#1}{%
    \par
    \ifx\scrjura@env@type\@empty
      \edef\scrjura@env@type{#1}%
      \let\@doendpe\scrjura@doendpe
      \expandafter\let\expandafter\c@Clause\csname c@#1Clause\endcsname
      \edef\cl@Clause{\cl@Clause\csname cl@#1Clause\endcsname}%
      \expandafter\let\expandafter\c@SubClause
        \csname c@#1SubClause\endcsname
      \edef\cl@SubClause{\cl@SubClause
        \csname cl@#1SubClause\endcsname}%
      \@ifundefined{#1@Clause}{%
        \let\Clause\contract@paragraph
      }{%
        \expandafter\let\expandafter\Clause
        \csname #1@Clause\endcsname
      }%
      \@ifundefined{#1@SubClause}{%
        \let\SubClause\contract@subparagraph
      }{%
        \expandafter\let\expandafter\SubClause
        \csname #1@SubClause\endcsname
      }%
      \@ifundefined{#1@Sentence}{%
        \let\Sentence\contract@sentence
      }{%
        \expandafter\let\expandafter\Sentence\csname #1@Sentence\endcsname
      }%
      \@ifundefined{\scrjura@env@type @everypar}{%
        \expandafter\let
        \csname \scrjura@env@type @everypar\endcsname
        \contract@everypar
      }{}%
%    \end{macrocode}
% Font alias for \fnt{Clause}. If neither a font not an alias is defined for
% the new environment \fnt{contract.Clause} is used.
% \changes{v3.25}{2017/12/08}{Font alias fixed}
%    \begin{macrocode}
      \IfExistskomafont{#1.Clause}{%
        \IfIsAliaskomafont{#1.Clause}{%
          \aliaskomafont{Clause}{\csname scr@fnt@instead@#1.Clause\endcsname}%
        }{%
          \aliaskomafont{Clause}{#1.Clause}%
        }%
      }{%
        \aliaskomafont{Clause}{contract.Clause}%
      }%
      #3%
    \else
      \PackageError{scrjura}{nested scrjura environments detected}{%
        You must not use a `#1' environment inside\MessageBreak
        a `\scrjura@env@type' environment or after loading\MessageBreak
        package `scrjura' with option `\scrjura@env@type'!}%
    \fi
  }{%
    #4%
    \par
  }%
}
%</body>
%    \end{macrocode}
% \end{macro}%^^A \@dewjuraenvironment
% \end{command}%^^A \DeclareNewJuraEnvironment
%
% \begin{macro}{\contract@paragraph}
% This is the \cs{Clause} used by contracts. A contract consists (usually) of
% several clauses. Each clause has optional elements managed by
% \meta{key}=\meta{value} pairs handled by \pkg*{scrkbase} and last but not
% least by \pkg{keyval}.
% \begin{option}{title,head,nohead}
% \begin{option}{entry,noentry}
% \changes{v0.6}{2011/09/30}{deprecated}
% \begin{option}{tocentry,notocentry}
% \changes{v0.6}{2011/09/30}{new}
% Title, running head and toc entry of the clause. The title is the default
% for running head and toc entry. But you can also use an empty value for
% each of them or use the \opt{no\dots} options to switch them off.
%    \begin{macrocode}
%<*body>
\define@key{contract}{title}{%
  \def\contract@title{#1}%
  \ifx\contract@entry\relax\def\contract@entry{\contract@title}\fi
  \ifx\contract@head\relax\def\contract@head{\contract@title}\fi
}
\define@key{contract}{entry}{%
  \PackageWarning{scrjura}{deprecated option `entry'.\MessageBreak
    You should use option `tocentry' instead of\MessageBreak
    option `entry'%
  }%
  \def\contract@entry{#1}}
\define@key{contract}{tocentry}{\def\contract@entry{#1}}
\define@key{contract}{noentry}[]{%
  \PackageWarning{scrjura}{deprecated option `noentry'.\MessageBreak
    You should use option `notocentry' instead of\MessageBreak
    option `noentry'%
  }%
  \let\contract@entry\relax}
\define@key{contract}{notocentry}[]{\let\contract@entry\relax}
\define@key{contract}{head}{\def\contract@head{#1}}
\define@key{contract}{nohead}[]{\let\contract@head\relax}
%    \end{macrocode}
% \end{option}
% \end{option}
% \end{option}
% \begin{option}{number}
% The number can be changed manually. But clauses without numbers are not
% allowed. So if you use an empty value, the number is automatically set.
%    \begin{macrocode}
\define@key{contract}{number}{\def\contract@number{#1}}
%    \end{macrocode}
% \end{option}
% \begin{macro}{\contract@preskip,\contract@postskip}
% \begin{option}{preskip,postskip}
% The options are used to specify the distance before and after the
% clause. The preset value of these options are the global settings done by
% |\setkeys{contract}{…}|.
%    \begin{macrocode}
\newcommand*{\contract@preskip}{2\baselineskip}
\newcommand*{\contract@postskip}{\baselineskip}
\define@key{contract}{preskip}{\def\contract@preskip{#1}}
\define@key{contract}{postskip}{\def\contract@postskip{#1}}
%    \end{macrocode}
% \end{option}
% \end{macro}
% \begin{option}{dummy}
% The option switches the boolean \cs{ifcontract@dummy}.
% \begin{macro}{\ifcontract@dummy}
% If the boolean is \cs{iftrue} the clause will not be printed. But note: you
% cannot use this to remove the paragraphs or sentences of the clause. But you
% can use this option to generate holes in the numbering without manually
% manipulating the counters.
%    \begin{macrocode}
\newif\ifcontract@dummy
\define@key{contract}{dummy}[true]{\csname contract@dummy#1\endcsname}
%    \end{macrocode}
% \end{macro}
% \end{option}
% \begin{fontelement}{contract.Clause}
% \begin{macro}{\contract@paragraph@font}
% \changes{v3.25}{2017/12/08}{using element \fnt{Clause} instead of
%   \fnt{contract.Clause}}
% Correctly this macro should be named \cs{contract@paragraph@format}. But it
% is already used by some users for ugly tricks. So I will not rename it to
% avoid problems for existing documents. Additionally it would be better to
% use a new macro per environment. However the same reason not to change this.
%    \begin{macrocode}
\newkomafont{contract.Clause}{\sffamily\bfseries\large}
\newcommand*{\contract@paragraph@font}{\usekomafont{Clause}%
  \@hangfrom}
%    \end{macrocode}
% \end{macro}
% \end{fontelement}
% \begin{counter}{@AbsClause}
% \begin{macro}{\theH@AbsClause}
% \begin{command}{\theHClause,\theHSubClause}
%    \begin{macrocode}
% Here we have some not good tested code for \pkg{hyperref}.
\newcounter{@AbsClause}
\newcommand*{\theH@AbsClause}{P-\arabic{@AbsClause}}
\newcommand*{\theHClause}{\theH@AbsClause}
\newcommand*{\theHSubClause}{\theH@AbsClause}
%    \end{macrocode}
% \end{command}
% \end{macro}
% \end{counter}
% For the headings we use manual paragraph numbering, because we don't want
% any paragraph numbering inside the heading. After initializing the options
% they are processed.
% \changes{v0.7}{2013/04/18}{increase counter \cnt{contractAbsoluteClause}}
% \changes{v0.7b}{2014/11/03}{more flexible
%   \cnt{\meta{environment}AbsoluteClause}}
%    \begin{macrocode}
\newcommand*{\contract@paragraph}[1]{%
  \stepcounter{\scrjura@env@type AbsoluteClause}%
  \ManualPar\parnumbertrue
  \let\contract@title\relax
  \let\contract@entry\relax
  \let\contract@head\relax
  \let\contract@number\relax
  \contract@dummyfalse
  \ifx\relax#1\relax\else\setkeys{contract}{#1}\fi
%    \end{macrocode}
% Unless this is a dummy clause, the headings will be initialized and vertical
% skips will be done.
% \changes{v0.6a}{2012/10/08}{missing \cs{par} added}
%    \begin{macrocode}
  \ifcontract@dummy\else
    \par
    \@afterindentfalse
    \addvspace{\contract@preskip}%
  \fi
%    \end{macrocode}
% If there isn't a manual number, we use the next number. If there is a manual
% number, this number is printed and we take care that labels and
% \pkg{hyperref} also use the manual number.
% \changes{v0.6b}{2013/04/16}{using \cs{contract@Clauseformat} for manual
%   numbers too}
% \changes{v0.9c}{2015/05/13}{\cs{thecontractClause} replaced by
%   environment-dependent macro}
%    \begin{macrocode}
  \ifx\contract@number\relax
    \let\p@Clause\@empty
    \expandafter\let\expandafter\theClause
      \csname the\scrjura@env@type Clause\endcsname
    \refstepcounter{Clause}%
  \else
    \begingroup
      \let\@elt\@stpelt
      \cl@Clause
    \endgroup
%    \end{macrocode}
% \changes{v0.9f}{2016/02/24}{\cs{protect}\cs{\@nameuse} instead of
%   \cs{csname}\dots\cs{endcsname}}
%    \begin{macrocode}
    \protected@edef\theClause{%
      \protect\@nameuse{\scrjura@env@type @Clauseformat}{\contract@number}%
    }%
    \protected@edef\@currentlabel{\theClause}%
  \fi
  \stepcounter{@AbsClause}%
  \begingroup\expandafter\expandafter\expandafter\endgroup
  \expandafter\ifx\csname if@skiphyperref\endcsname\relax
  \else
    \expandafter\let\csname if@scrjura@skiphyperref\expandafter\endcsname
    \csname if@skiphyperref\endcsname
  \fi
  \if@scrjura@skiphyperref\else
    \hyper@refstepcounter{@AbsClause}%
    \typeout{absolute Nummer: \the@AbsClause^^JLabel: `\@currentHref'}%
  \fi
%    \end{macrocode}
% For simplification we use the code of clauses for sub-clauses.
%    \begin{macrocode}
  \let\theSubClause\theClause
%    \end{macrocode}
% Unless for dummy clauses, the heading is printed, the toc entry is done
% and also the running head.
% \changes{v0.7}{2013/04/28}{distance behind the number is part of the number}
% \changes{v0.9i}{2017/02/23}{usage of \cs{ext@toc}}
%    \begin{macrocode}
  \ifcontract@dummy\else
    \begingroup
      \if@juratitlepagebreak\else\interlinepenalty\@M\fi
      \contract@paragraph@font{\theClause
        \ifx\contract@title\relax\else\enskip\fi}%
      \contract@title
      \ifx\contract@entry\relax\else
        \expandafter\addxcontentsline\expandafter{\ext@toc}%
        {cpar}[\theClause]\contract@entry
        \addxcontentsline{cpa}{cpar}[\theClause]\contract@entry
      \fi
      \ifx\contract@head\relax\else
        \expandafter\Clausemark\expandafter{%
          \expandafter\theSubClause\expandafter\enskip\contract@head}%
      \fi
      \par
    \endgroup\nobreak\vskip\contract@postskip
%    \end{macrocode}
% Last but not least paragraph numbering is initialized.
%    \begin{macrocode}
    \scrjura@afterheading
  \fi
}
%</body>
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\contract@subparagraph}
% \changes{v0.6a}{2012/10/08}{fehlendes \cs{par} ergänzt}%^^A
% \changes{v0.7}{2013/04/18}{Zähler \texttt{contractAbsoluteClause} wird
%     erhöht}%^^A
% \changes{v0.7}{2013/04/28}{Abstand nach der Nummer als Bestandteil der
%     Nummer setzen}%^^A
% \changes{v0.9i}{2017/02/23}{Verwendung von \cs{ext@toc}}%^^A
% Das entspricht bis auf wenige Kleinigkeiten, die Unterparagraphen betreffen,
% |\contract@paragraph|
%    \begin{macrocode}
%<*body>
\newcommand*{\contract@subparagraph}[1]{%
  \stepcounter{\scrjura@env@type AbsoluteClause}%
  \ManualPar\parnumbertrue
  \let\contract@title\relax
  \let\contract@entry\relax
  \let\contract@head\relax
  \let\contract@number\relax
  \contract@dummyfalse
  \ifx\relax#1\relax\else\setkeys{contract}{#1}\fi
  \ifcontract@dummy\else
    \par
    \@afterindentfalse
    \vskip\contract@preskip
  \fi
  \ifx\contract@number\relax
    \let\p@SubClause\@empty
    \let\theSubClause\thecontractSubClause
    \refstepcounter{SubClause}%
  \else
    \begingroup
      \let\@elt\@stpelt
      \cl@SubClause
    \endgroup
    \protected@edef\theSubClause{\theClause\contract@number}%
    \protected@edef\@currentlabel{\theSubClause}%
  \fi
  \stepcounter{@AbsClause}%
  \begingroup\expandafter\expandafter\expandafter\endgroup
  \expandafter\ifx\csname if@skiphyperref\endcsname\relax
  \else
    \expandafter\let\csname if@scrjura@skiphyperref\expandafter\endcsname
    \csname if@skiphyperref\endcsname
  \fi
  \if@scrjura@skiphyperref\else
    \hyper@refstepcounter{@AbsClause}%
    \typeout{absolute Nummer: \the@AbsClause^^JLabel: `\@currentHref'}%
  \fi
  \ifcontract@dummy\else
    \begingroup
      \if@juratitlepagebreak\else\interlinepenalty\@M\fi
      \contract@paragraph@font{\theSubClause
        \ifx\contract@title\relax\else\enskip\fi}%
      \contract@title
      \ifx\contract@entry\relax\else
        \expandafter\addxcontentsline\expandafter{\ext@toc}%
        {cpar}[\theSubClause]\contract@entry
        \addxcontentsline{cpa}{cpar}[\theSubClause]\contract@entry
      \fi
      \ifx\contract@head\relax\else
        \expandafter\Clausemark\expandafter{%
          \expandafter\theSubClause\expandafter\enskip\contract@head}%
      \fi
      \par
    \endgroup
    \nobreak\vskip\contract@postskip
    \scrjura@afterheading
  \fi
}
%</body>
%    \end{macrocode}
% \end{macro}
%
% \begin{command}{\AutoPar,\ManualPar}
% Switching between automatic or manual paragraph numbers for all
% \pkg*{scrjura} environments.
%    \begin{macrocode}
%<*body>
\newcommand*{\AutoPar}{%
  \expandafter\let\expandafter\scrjura@everypar
  \csname \scrjura@env@type @everypar\endcsname
}
\newcommand*{\ManualPar}{%
  \let\scrjura@everypar\relax
}
%</body>
%    \end{macrocode}
% \end{command}
%
% \begin{macro}{\scrjura@afterheading,\jura@afterheading}
% \changes{v0.7b}{2014/11/03}{\cs{jura@afterheading} renamed}
% \changes{v0.7b}{2014/11/03}{no argument}
% \changes{v3.27}{2019/02/25}{\cs{CheckCommand} for \cs{@afterheading}}
% Similar to \cs{afterheading} but with automatic paragraph numbers.
% \begin{description}
% \item[ToDo:] Test if this can be done using \LaTeX{} hooks, depending on the
%   \LaTeX{} release.
% \end{description}
%    \begin{macrocode}
%<*body>
\CheckCommand*{\@afterheading}{%
  \@nobreaktrue
  \everypar{%
    \if@nobreak
      \@nobreakfalse
      \clubpenalty \@M
      \if@afterindent \else
        {\setbox\z@\lastbox}%
      \fi
    \else
      \clubpenalty \@clubpenalty
      \everypar{}%
    \fi}%
}
\newcommand*{\scrjura@afterheading}{%
  \@nobreaktrue
  \everypar{%
    \if@nobreak
      \@nobreakfalse
      \clubpenalty \@M
      \if@afterindent \else
        {\setbox\z@\lastbox}%
      \fi
    \else
      \clubpenalty \@clubpenalty
      \everypar{%
        \scrjura@everypar
      }%
    \fi
    \scrjura@everypar
  }%
  \AutoPar
}
%    \end{macrocode}
% \begin{macro}{\scrjura@everypar,\jura@everypar}
% \changes{v0.7b}{2014/11/03}{\cs{jura@everypar} renamed}
% The macro to be used at the very beginning of every paragraph to add the
% number. To be used only inside \pkg*{scrjura} environments, so empty outside.
%    \begin{macrocode}
\newcommand*{\scrjura@everypar}{}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\@doendpe}
% \LaTeX{} used this macro, to reset all paragraph actions at the end of
% environments. To avoid unwanted switching-off of the paragraph number it
% will be reinitialized.
% \begin{macro}{\scrjura@doendpe}
% \begin{macro}{\IncludeInRelease}
% \changes{v0.9e}{2015/11/03}{used temporary}
% \changes{v3.28}{2019/11/18}{\cs{ifstr} renamed into \cs{Ifstr}}
% \begin{macro}{\@gobble@IncludeInRelease}
% \changes{v0.9e}{2015/11/03}{used temporary}
% \begin{macro}{\EndIncludeInRelease}
% \changes{v0.9e}{2015/11/03}{used temporary}
% From \LaTeX{} 2015/01/01 a different definition of \cs{@doendpe} is used. So
% we also have to use different versions depending on the release. We do so
% with some tricks. Maybe this should be replaced by usage of
% \cs{IfLTXAtLeastTF} from already loaded \pkg*{scrbase}.
%    \begin{macrocode}
\providecommand*{\IncludeInRelease}[3]{%
  \PackageInfo{scrjura}{temporary definition of \string\IncludeInRelease}%
  \Ifstr{#1}{0000/00/00}{%
    \let\IncludeInRelease\@undefined
    \def\EndIncludeInRelease{\let\EndIncludeInRelease\@undefined}%
  }{%
    \let\EndIncludeInRelease\relax
    \long\def\@gobble@IncludeInRelease##1\EndIncludeInRelease{%
      \let\@gobble@IncludeInRelease\@undefined
    }%
    \expandafter\@gobble@IncludeInRelease
  }%
}
\IncludeInRelease{2015/01/01}{\@doendpe}{clubpenalty fix}
\CheckCommand*\@doendpe{\@endpetrue
     \def\par{\@restorepar
              \clubpenalty\@clubpenalty
              \everypar{}\par\@endpefalse}\everypar
               {{\setbox\z@\lastbox}%
                \everypar{}\@endpefalse}}
\newcommand*{\scrjura@doendpe}{%
  \@endpetrue
  \def\par{%
    \@restorepar
    \clubpenalty\@clubpenalty
    \everypar{%
      \csname scrjura@everypar\endcsname
    }%
    \par\@endpefalse
  }%
  \everypar{%
    {\setbox\z@\lastbox}\everypar{%
      \csname scrjura@everypar\endcsname
    }%
    \@endpefalse
  }%
}
\EndIncludeInRelease
\IncludeInRelease{0000/00/00}{\@doendpe}{clubpenalty fix}
\CheckCommand*\@doendpe{\@endpetrue
  \def\par{\@restorepar\everypar{}\par\@endpefalse}\everypar
  {{\setbox\z@\lastbox}\everypar{}\@endpefalse}}
\newcommand*{\scrjura@doendpe}{%
  \@endpetrue
  \def\par{%
    \@restorepar\everypar{%
      \csname scrjura@everypar\endcsname
    }%
    \par\@endpefalse
  }%
  \everypar{%
    {\setbox\z@\lastbox}\everypar{%
      \csname scrjura@everypar\endcsname
    }%
    \@endpefalse
  }%
}
\EndIncludeInRelease
%</body>
%    \end{macrocode}
% \end{macro}%^^A \EndIncludeInRelease
% \end{macro}%^^A \@gobble@IncludeInRelease
% \end{macro}%^^A \IncludeInRelease
% \end{macro}%^^A \scrjura@doendpe
% \end{macro}%^^A \@doendpe
% \end{macro}%^^A \scrjura@everypar
%
% \subsection{Entry to table of contents}
% \begin{macro}{\l@cpar}
% Toc entry of contract clauses.
% \changes{v3.27}{2019/02/25}{usage of \pkg*{tocbasic}}
% This is done using \pkg*{tocbasic}. The definition has to be part of the
% initialization of the package, otherwise package options wouldn't be able to
% change the setting.
%    \begin{macrocode}
%<*init>
\DeclareTOCStyleEntry[%
  indent=1.5em,
  numwidth=2em,
  level=\maxdimen
]{default}{cpar}
%</init>
%    \end{macrocode}
% \end{macro}
%
% \subsection{Numbering of paragraphs and sentences}
%
% \begin{macro}{\scrjura@separator,\jura@separator}
% \changes{v0.7b}{2014/11/03}{\cs{jura@separator} renamed}
% Used to make it possible to remove white spaces at the beginning or end.
%    \begin{macrocode}
%<*body>
\DeclareRobustCommand*{\scrjura@separator}[1]{#1}
%</body>
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\scrjura@usetype,\jura@usetype}
% \changes{v0.5d}{2010/04/28}{new}
% \changes{v0.7b}{2014/11/03}{\cs{jura@usetype} renamed}
% By default it is robust but does only call \cs{scrjura@@usetype} with the
% only argument.
% \begin{macro}{\scrjura@@usetype,\jura@@usetype}
% \changes{v0.5d}{2010/04/28}{new}
% \changes{v0.7b}{2014/11/03}{\cs{jura@@usetype} renamed}
% This second command is not robust and can easily be redefined. But by
% default it also does nothing but eating the argument.
%    \begin{macrocode}
%<*body>
\DeclareRobustCommand*{\scrjura@usetype}[1]{\scrjura@@usetype{#1}}
\newcommand*{\scrjura@@usetype}[1]{}
%</body>
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\contract@everypar}
% The \cs{scrjura@everpar} used by contracts.
% \begin{macro}{\ifparnumber,\parnumbertrue,\parnumberfalse}
% \changes{v0.6}{2011/09/29}{moved the definition into the definition of the
%   option}
% \begin{counter}{par}
% \begin{command}{\thepar,\theHpar}
% \begin{command}{\parformat}
% \changes{v0.7}{2013/06/07}{new font element \fnt{parnumber}}
% \begin{command}{\parformatseparation}
% \changes{v0.9f}{2016/02/06}{new}
% \begin{macro}{\p@par}
% \changes{v0.5d}{2010/04/28}{added \cs{jura@usetype} with argument
%   \cs{jura@env@type}}
% \begin{command}{\withoutparnumber}
% \changes{v3.25}{2017/12/19}{new}
% The boolean defines if paragraph numbers have to be used. If they are
% deactivated also manual paragraph numbers are deactivated and the paragraphs
% are not counted. Otherwise the paragraphs are numbered using \cs{thepar}. It
% is important to reset the paragraph counter with every clause and
% sub-clause. And for labels the parent object the clause has to be used.
%    \begin{macrocode}
%<*body>
\newcounter{par}
\renewcommand*{\thepar}{\arabic{par}}
\newcommand*{\theHpar}{\theH@AbsClause-\Roman{par}}
\newcommand*{\parformat}{(\thepar)}
\newcommand*{\parformatseparation}{\nobreakspace}
\newkomafont{parnumber}{}
\renewcommand*\p@par{{\scrjura@usetype{\scrjura@env@type}\theSubClause\scrjura@separator{\nobreakspace}}}
\@addtoreset{par}{Clause}
\@addtoreset{par}{SubClause}
\newcommand*{\withoutparnumber}{}
%</body>
%    \end{macrocode}
% \end{command}
% \end{macro}
% \end{command}
% \end{command}
% \end{command}
% \end{counter}
% \end{macro}
% \changes{v0.5c}{2010/04/26}{first argument of \cs{newmaxpar} and second
%   argument of \cs{getmaxpar} is \meta{contract} not \meta{contractpars}}
% \changes{v0.5c}{2010/04/26}{\cs{contract@Clauseformat} expands while writing
%   to its own argument}
% \changes{v0.7}{2013/04/18}{using counter \cnt{contractAbsoluteClause}}
% \changes{v0.7}{2013/05/23}{initializing sentence number for manually
%   numbered paragraphs to 0 instead of 1, because first action of
%   \cs{Sentence} is increasing the number}
% \changes{v0.7}{2013/05/23}{recognize paragraph number of \cs{thisparnumber}}
% \changes{v0.7}{2013/06/06}{if paragraph numbers are not completely numerical
%   always set the number}
% \changes{v0.7b}{2014/11/03}{more flexible replacement of
%   \cnt{contractAbsoluteClause}}
% \changes{v0.9f}{2016/02/06}{\cs{nobreakspace} replaced by
%     \cs{parformatseparation}}
% \changes{v0.9g}{2016/03/25}{writing to \file{aux}-file \cs{if@filesw}}
%    \begin{macrocode}
%<*body>
\newcommand*{\contract@everypar}{%
  \ifparnumber
    \ifx\scrjura@special@par\relax
      \ifx\scrjura@special@reset@par\relax\else
        \global\let\thepar\scrjura@special@reset@par
        \global\let\scrjura@special@reset@par\relax
      \fi
      \refstepcounter{par}%
      \refstepcounter{sentence}%
    \else
      \ifx\scrjura@special@reset@par\relax
        \global\let\scrjura@special@reset@par\thepar
      \fi
      \global\let\thepar\scrjura@special@par
      \global\let\scrjura@special@par\relax
      \setcounter{sentence}{0}\refstepcounter{sentence}%
    \fi
    \begingroup
      \if@filesw
        \protected@write\@auxout{%
          \expandafter\let\csname \scrjura@env@type @Clauseformat\endcsname
          \@firstofone
        }{%
          \string\newmaxpar{\scrjura@env@type}%
                           {\csname the\scrjura@env@type 
                             AbsoluteClause\endcsname}%
                           {\thepar}%
        }%
      \fi
      \getmaxpar\@tempa{\scrjura@env@type}%
                       {\csname the\scrjura@env@type AbsoluteClause\endcsname}%
      \typeout{Stored max is \@tempa}%
      \def\reserved@a##1\@nnil{\def\@tempa{##1}}%
      \afterassignment\reserved@a\@tempcnta=0\@tempa\relax\@nnil
      \ifnum \@tempcnta>\@ne
        {\usekomafont{parnumber}{\parformat\parformatseparation}}%
      \else
        \def\reserved@a{\relax}%
        \ifx\@tempa\reserved@a
          \withoutparnumber
        \else
          {\usekomafont{parnumber}{\parformat\parformatseparation}}%
        \fi
      \fi
    \endgroup
  \else
    \begingroup\withoutparnumber\endgroup
    \setcounter{sentence}{-1}\refstepcounter{sentence}%
  \fi
}
%</body>
%    \end{macrocode}
% \end{macro}
%
% \begin{command}{\thisparnumber}
% \changes{v0.7}{2013/05/23}{new}
% \begin{macro}{\scrjura@special@par,\scrjura@special@reset@par}
% \changes{v0.7}{2013/05/23}{new}
% You can use this for manual paragraph numbering. But the number has to be
% fully expandable!
%    \begin{macrocode}
%<*body>
\newcommand*{\thisparnumber}[1]{%
  \def\scrjura@special@par{#1}%
}
\newcommand*{\scrjura@special@par}{}
\let\scrjura@special@par\relax
\newcommand*{\scrjura@special@reset@par}{}
\let\scrjura@special@reset@par\relax
%</body>
%    \end{macrocode}
% \end{macro}%^^A \scrjura@special@par
% \end{command}%^^A\thisparnumber
%
%
% \subsection{Referencing}
%
% \begin{command}{\refL}
% \changes{v0.9h}{2016/04/12}{\cs{@ifstar} replaced by \cs{kernel@ifstar}}
% \begin{macro}{\ref@L}
% Similar to \cs{ref} but always the long form.
%    \begin{macrocode}
%<*body>
\newcommand*{\refL}{\kernel@ifstar {\ref@L*}{\ref@L{}}}
\newcommand*{\ref@L}[2]{%
  \begingroup
    \def\parcite@format{0}%
    \let\sentencecite@format\parcite@format
    \ref#1{#2}%
  \endgroup
}
%    \end{macrocode}
% \end{macro}
% \end{command}
%
% \begin{command}{\refS}
% \changes{v0.9h}{2016/04/12}{\cs{@ifstar} replaced by \cs{kernel@ifstar}}
% \begin{macro}{\ref@S}
% Similar to \cs{ref} but always the short form.
%    \begin{macrocode}
\newcommand*{\refS}{\kernel@ifstar {\ref@S*}{\ref@S{}}}
\newcommand*{\ref@S}[2]{%
  \begingroup
    \def\parcite@format{1}%
    \let\sentencecite@format\parcite@format
    \ref#1{#2}%
  \endgroup
}
%    \end{macrocode}
% \end{macro}
% \end{command}
%
% \begin{command}{\refN}
% \changes{v0.9h}{2016/04/12}{\cs{@ifstar} replaced by \cs{kernel@ifstar}}
% \begin{macro}{\ref@N}
% Similar to \cs{ref} but always the numerical form.
%    \begin{macrocode}
\newcommand*{\refN}{\kernel@ifstar {\ref@N*}{\ref@N{}}}
\newcommand*{\ref@N}[2]{%
  \begingroup
    \def\parcite@format{2}%
    \let\sentencecite@format\parcite@format
    \ref#1{#2}%
  \endgroup
}
%    \end{macrocode}
% \end{macro}
% \end{command}
%
% \begin{command}{\refClause}
% \changes{v0.9h}{2016/04/12}{\cs{@ifstar} replaced by \cs{kernel@ifstar}}
% \begin{macro}{\ref@Clause}
% Reference only the clause of a clause, paragraph or sentence. For better
% compatibility with \pkg{hyperref} there is also a star version if
% \pkg{hyperref} is used. Without \pkg{hyperref} the star version is nonsense.
%    \begin{macrocode}
\newcommand*{\refClause}{%
  \kernel@ifstar {\ref@Clause*}{\ref@Clause{}}
}
\newcommand*{\ref@Clause}[2]{%
  \expandafter\ifx\csname r@#2\endcsname\relax
    \ref#1{#2}%
  \else
    \begingroup
%    \end{macrocode}
% Copy all parts of the reference but the first one to \cs{@tempb}.
%    \begin{macrocode}
      \expandafter\expandafter\expandafter\expandafter
      \expandafter\expandafter\expandafter\def
      \expandafter\expandafter\expandafter\expandafter
      \expandafter\expandafter\expandafter\@tempb
      \expandafter\expandafter\expandafter\expandafter
      \expandafter\expandafter\expandafter{%
        \expandafter\expandafter\expandafter\@gobble\csname r@#2\endcsname}%
%    \end{macrocode}
% Copy the first part of the reference to \cs{@tempa}.
%    \begin{macrocode}
      \def\@tempc##1##2\@nil{##1}%
      \let\scrjura@separator\@gobble
      \protected@edef\@tempa{\expandafter\expandafter\expandafter\@tempc
        \csname r@#2\endcsname\noexpand\@nil}%
%    \end{macrocode}
% Copy the first part of \cs{@tempa} to \cs{@tempb}.
%    \begin{macrocode}
      \protected@edef\@tempa{\expandafter\expandafter\expandafter\@tempc
        \@tempa\@nil}%
      \let\@@protect\protect
      \let\protect\noexpand
      \expandafter\edef\csname r@#2\endcsname{{\@tempa}\@tempb}%
      \let\protect\@@protect
      \ref#1{#2}%
    \endgroup
  \fi
}
%    \end{macrocode}
% \end{macro}
% \end{command}
%
% \begin{command}{\refClauseN}
% \changes{v0.9h}{2016/04/12}{\cs{@ifstar} replaced by \cs{kernel@ifstar}}
% \begin{macro}{\ref@ClauseN}
% Reference only the clause number of a clause, a paragraph or a sentence.
% For improved compatibility with \pkg{hyperref} there is also a star version
% if \pkg{hyperref} is used. Without \pkg{hyperref} the star version is
% nonsense.
%    \begin{macrocode} 
\newcommand*{\refClauseN}{%
  \kernel@ifstar {\ref@ClauseN*}{\ref@ClauseN{}}
}
\newcommand*{\ref@ClauseN}[2]{%
  \begingroup
    \let\Clauseformat\relax
    \ref@Clause{#1}{#2}%
  \endgroup
}
%    \end{macrocode}
% \end{macro}
% \end{command}
%
% \begin{command}{\refPar}
% \changes{v0.9h}{2016/04/12}{\cs{@ifstar} replaced by \cs{kernel@ifstar}}
% \begin{macro}{\ref@Par}
% References only the paragraph of a paragraph or sentence.
% For improved compatibility with \pkg{hyperref} there is also a star version
% if \pkg{hyperref} is used. Without \pkg{hyperref} the star version is
% nonsense.
%    \begin{macrocode}
\newcommand*{\refPar}{%
  \kernel@ifstar {\ref@Par*}{\ref@Par{}}
}
\newcommand*{\ref@Par}[2]{%
  \expandafter\ifx\csname r@#2\endcsname\relax
    \ref#1{#2}%
  \else
    \begingroup
%    \end{macrocode}
% Copy all parts of the reference but the first one to \cs{@tempb}.
%    \begin{macrocode}
      \expandafter\expandafter\expandafter\expandafter
      \expandafter\expandafter\expandafter\def
      \expandafter\expandafter\expandafter\expandafter
      \expandafter\expandafter\expandafter\@tempb
      \expandafter\expandafter\expandafter\expandafter
      \expandafter\expandafter\expandafter{%
        \expandafter\expandafter\expandafter\@gobble\csname r@#2\endcsname}%
%    \end{macrocode}
% Copy the first part of the reference to \cs{@tempa}.
%    \begin{macrocode}
      \def\@tempc##1##2\@nil{##1}%
      \let\scrjura@separator\@gobble
      \protected@edef\@tempa{\expandafter\expandafter\expandafter\@tempc
        \csname r@#2\endcsname\noexpand\@nil}%
%    \end{macrocode}
% Copy the second part of \cs{@tempa} to \cs{@tempa} ablegen.
%    \begin{macrocode}
      \def\@tempc##1##2##3\@nil{##2}%
      \protected@edef\@tempa{\expandafter\expandafter\expandafter\@tempc
        \@tempa{%
          \protect\G@refundefinedtrue
          \nfss@text{\reset@font\bfseries ??}%
          \@latex@warning{Reference `#2' on page \thepage \space
            with undefined par number}%
        }\noexpand\@nil}%
      \let\@@protect\protect
      \let\protect\noexpand
      \expandafter\edef\csname r@#2\endcsname{{\@tempa}\@tempb}%
      \let\protect\@@protect
      \ref#1{#2}%
    \endgroup
  \fi
}
%    \end{macrocode}
% \end{macro}
% \end{command}
%
% \begin{command}{\refParL}
% \changes{v0.9h}{2016/04/12}{\cs{@ifstar} replaced by \cs{kernel@ifstar}}
% \begin{macro}{\ref@ParX}
% The same but long.
%    \begin{macrocode}
\newcommand*{\refParL}{%
  \kernel@ifstar {\ref@ParX0*}{\ref@ParX0{}}
}
\newcommand*{\ref@ParX}[3]{%
  \begingroup
    \def\parcite@format{#1}%
    \let\sentencecite@format\parcite@format
    \ref@Par{#2}{#3}%
  \endgroup
}
%    \end{macrocode}
% \end{macro}
% \end{command}
%
% \begin{command}{\refParS}
% \changes{v0.9h}{2016/04/12}{\cs{@ifstar} replaced by \cs{kernel@ifstar}}
% The same but short.
%    \begin{macrocode}
\newcommand*{\refParS}{%
  \kernel@ifstar {\ref@ParX1*}{\ref@ParX1{}}
}
%    \end{macrocode}
% \end{command}
%
% \begin{command}{\refParN}
% \begin{macro}{\ref@ParN}
% \changes{v0.9h}{2016/04/12}{\cs{@ifnextchar} replaced by
%   \cs{kernel@ifnextchar}}
% \changes{v0.9h}{2016/04/12}{\cs{@ifstar} replaced by \cs{kernel@ifstar}}
% \begin{macro}{\ref@@ParN}
% The same but numerical.
%    \begin{macrocode}
\newcommand*{\refParN}{%
  \kernel@ifstar {\ref@ParN2*}{\ref@ParN2{}}
}
\newcommand*{\ref@ParN}[2]{%
  \kernel@ifnextchar [%]
    {\ref@@ParN{#1}{#2}}%
    {\ref@ParX{#1}{#2}}%
}
\newcommand*{\ref@@ParN}{}
\def\ref@@ParN#1#2[#3]#4{%
  \begingroup
    \renewcommand*{\parnumericformat}[1]{%
      \csname @#3\endcsname{\number ##1\relax}%
    }%
    \ref@ParX{#1}{#2}{#4}%
  \endgroup
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{command}
%
% \begin{command}{\refSentence}
% \changes{v0.9h}{2016/04/12}{\cs{@ifstar} replaced by \cs{kernel@ifstar}}
% \begin{macro}{\ref@Sentence}
% Reference only the sentence of a sentence.
% For improved compatibility with \pkg{hyperref} there is also a star version
% if \pkg{hyperref} is used. Without \pkg{hyperref} the star version is
% nonsense.
%    \begin{macrocode}
\newcommand*{\refSentence}{%
  \kernel@ifstar {\ref@Sentence*}{\ref@Sentence{}}
}
\newcommand*{\ref@Sentence}[2]{%
  \expandafter\ifx\csname r@#2\endcsname\relax
    \ref#1{#2}%
  \else
    \begingroup
%    \end{macrocode}
% Copy all parts of the reference to \cs{@tempb}.
%    \begin{macrocode}
      \expandafter\expandafter\expandafter\expandafter
      \expandafter\expandafter\expandafter\def
      \expandafter\expandafter\expandafter\expandafter
      \expandafter\expandafter\expandafter\@tempb
      \expandafter\expandafter\expandafter\expandafter
      \expandafter\expandafter\expandafter{%
        \expandafter\expandafter\expandafter\@gobble\csname r@#2\endcsname}%
%    \end{macrocode}
% Copy the first part of the reference to \cs{@tempa}.
%    \begin{macrocode}
      \def\@tempc##1##2\@nil{##1}%
      \let\scrjura@separator\@gobble
      \protected@edef\@tempa{\expandafter\expandafter\expandafter\@tempc
        \csname r@#2\endcsname\noexpand\@nil}%
%    \end{macrocode}
% Copy the third part of \cs{@tempa} to \cs{@tempa}.
%    \begin{macrocode}
      \def\@tempc##1##2##3##4\@nil{##3}%
      \protected@edef\@tempa{\expandafter\expandafter\expandafter\@tempc
        \@tempa{}{%
          \protect\G@refundefinedtrue
          \nfss@text{\reset@font\bfseries ??}%
          \@latex@warning{Reference `#2' on page \thepage \space
            with undefined sentence number}%
        }\noexpand\@nil}%
      \let\@@protect\protect
      \let\protect\noexpand
      \expandafter\edef\csname r@#2\endcsname{{\@tempa}\@tempb}%
      \let\protect\@@protect
      \ref#1{#2}%
    \endgroup
  \fi
}
%    \end{macrocode}
% \end{macro}
% \end{command}
%
% \begin{command}{\refSentenceL}
% \changes{v0.9h}{2016/04/12}{\cs{@ifstar} replaced by \cs{kernel@ifstar}}
% \begin{macro}{\ref@SentenceX}
% The same but long.
%    \begin{macrocode}
\newcommand*{\refSentenceL}{%
  \kernel@ifstar {\ref@SentenceX0*}{\ref@SentenceX0{}}
}
\newcommand*{\ref@SentenceX}[3]{%
  \begingroup
    \def\parcite@format{#1}%
    \let\sentencecite@format\parcite@format
    \ref@Sentence{#2}{#3}%
  \endgroup
}
%    \end{macrocode}
% \end{macro}
% \end{command}
%
% \begin{command}{\refSentenceS}
% \changes{v0.9h}{2016/04/12}{\cs{@ifstar} replaced by \cs{kernel@ifstar}}
% The same but short.
%    \begin{macrocode}
\newcommand*{\refSentenceS}{%
  \kernel@ifstar {\ref@SentenceX1*}{\ref@SentenceX1{}}
}
%    \end{macrocode}
% \end{command}
%
% \begin{command}{\refSentenceN}
% \changes{v0.9h}{2016/04/12}{\cs{@ifstar} replaced by \cs{kernel@ifstar}}
% The same but numeric.
%    \begin{macrocode}
\newcommand*{\refSentenceN}{%
  \kernel@ifstar {\ref@SentenceX2*}{\ref@SentenceX2{}}
}
%</body>
%    \end{macrocode}
% \end{command}
%
% \begin{macro}{\contract@sentence}
% \changes{v0.7a}{2014/01/28}{using \cs{textsuperscript}}
% \changes{v0.7a}{2014/01/28}{\cs{nobreak}\cs{hskip}\cs{z@} added to allow
%   hyphenation of the first word after the sentence mark}
% Numbering of sentences.
% \begin{counter}{sentence}
% \begin{command}{\thesentence,\theHsentence}
% \begin{macro}{\p@sentence}
% \changes{v3.27}{2019/10/09}{adaption for \LaTeX{} 2019-10-01}
% The counter is used for numbering the sentences. It is important to add the
% paragraph as parent object to labels. The original method to make it
% possible to use \cs{thesentence} as an argument of \cs{p@sentence} does not
% work any longer using \LaTeX{} 2019-10-01 or newer. It would result in an
% error message. So the code has to be adapted to the new definition of
% \cs{refstepcounter} in \LaTeX{} 2019-10-01. From this version it uses
% \cs{labelformat}. Don't ask me, what I think about the fact, that every new
% versions of \LaTeX{} can break existing packages and package authors have to
% find out such incompatibilities on their own.
%    \begin{macrocode}
%<*body>
\newcounter{sentence}[par]
\renewcommand*{\thesentence}{\arabic{sentence}}
\newcommand*{\theHsentence}{\theHpar-\arabic{sentence}}
\scr@ifundefinedorrelax{labelformat}{%
  \renewcommand*{\p@sentence}{\expandafter\p@@sentence}
  \newcommand*{\p@@sentence}[1]{\p@par{{\par@cite{\thepar}}%
      \scrjura@separator{\nobreakspace}}{\sentence@cite{#1}}}%
}{%
  \labelformat{sentence}{\p@par{{\par@cite{\thepar}}%
      \scrjura@separator{\nobreakspace}}{\sentence@cite{#1}}}%
}
\newcommand*{\contract@sentence}{%
%    \end{macrocode}
% \changes{v0.9e}{2015/11/04}{first start the paragraph then print the number}
% \changes{v3.26}{2018/07/20}{new font element \fnt{sentencenumber}}
% \changes{v3.26}{2018/07/20}{new formatting \cs{sentencenumberformat}}
% For the numbering it is important not to increase the paragraph number at
% the very beginning, because the paragraph already does so. To make this
% work, the paragraph has to start before we print the number. But immediately
% after a \env{minipage}, a list or a \cs{parbox} we should behave as not
% being at the beginning of a paragraph.
%    \begin{macrocode}
  \ifvmode
    \if@endpe
      \refstepcounter{sentence}%
    \else
      \leavevmode
    \fi
  \else
    \refstepcounter{sentence}%
  \fi
  {\usekomafont{sentencenumber}{\sentencenumberformat}}%
  \nobreak\hskip\z@
}
%    \end{macrocode}
% \begin{fontelement}{sentencenumber}
% \begin{command}{\sentencenumberformat}
% \changes{v3.26}{2018/07/20}{new}
% Formatting an font can be changed using font element \fnt{sentencenumber}
% and command \cs{sentencenumberformat}. The last has the preset
% \cs{textsuperscript}.
%    \begin{macrocode}
\newkomafont{sentencenumber}{}
\newcommand*{\sentencenumberformat}{\textsuperscript{\thesentence}}
%</body>
%    \end{macrocode}
% \end{command}
% \end{fontelement}
% \end{macro}
% \end{command}
% \end{counter}
% \end{macro}
%
% \begin{macro}{\par@cite}
% \begin{command}{\parciteformat}
% \changes{v0.5d}{2010/04/28}{argument moved}
% Reference style for paragraphs.
%    \begin{macrocode}
%<*body>
\DeclareRobustCommand*{\par@cite}[1]{\parciteformat{#1}}
\newcommand*{\parciteformat}[1]{%
  \ifcase \parcite@format
    \expandafter\parlongformat
  \or
    \expandafter\parshortformat
  \or
    \expandafter\parnumericformat
  \else
    \unskip\expandafter\@gobble
  \fi
  {#1}%
}
%    \end{macrocode}
% \end{command}
% \end{macro}
%
% \begin{macro}{\sentence@cite}
% \begin{command}{\sentenceciteformat}
% \changes{v0.5d}{2010/04/28}{argument moved}
% Reference style for sentences. Preset is \cs{@arabic}.
%    \begin{macrocode}
\DeclareRobustCommand*{\sentence@cite}[1]{\sentenceciteformat{#1}}
\newcommand*{\sentenceciteformat}[1]{%
  \ifcase \sentencecite@format
    \expandafter\sentencelongformat
  \or
    \expandafter\sentenceshortformat
  \or
    \expandafter\sentencenumericformat
  \else
    \unskip\expandafter\@gobble
  \fi
  {#1}%
}
%    \end{macrocode}
% \end{command}
% \end{macro}
%
% \begin{command}{\parlongformat,\parshortformat,\parnumericformat,
%                 \sentencelongformat,\sentenceshortformat,
%                 \sentencenumericformat}
% The six formattings.
%    \begin{macrocode}
\newcommand*{\parlongformat}[1]{\parname~#1}
\newcommand*{\parshortformat}[1]{\parshortname~#1}
\newcommand*{\parnumericformat}[1]{\@Roman{\number #1\relax}}
\newcommand*{\sentencelongformat}[1]{\sentencename~#1}
\newcommand*{\sentenceshortformat}[1]{\sentenceshortname~#1}
\newcommand*{\sentencenumericformat}[1]{\@arabic{\number #1\relax}.}
%</body>
%    \end{macrocode}
% \end{command}
%
% \subsection{Language dependent names}
%
% \begin{command}{\parname,\parshortname,\sentencename,\sentenceshortname}
% \begin{macro}{\scrjura@lang@error}
% \changes{v0.7}{2013/09/19}{Usage of \cs{PackageError} instead of
%   \cs{PackageErrorNoLine}}
% \changes{v3.24}{2017/05/29}{adaption for language name bug in
%   \pkg{babel}~3.10}
% The names of paragraphs and sentences and their short versions. The English
% names are donated by ``m.eik''.
%    \begin{macrocode}
%<*body>
\newcommand*{\parname}{Paragraph}
\AtBeginDocument{%
  \providecaptionname{german,ngerman,austrian,naustrian}\parname{Absatz}%
  \providecaptionname{german,ngerman,austrian,naustrian}\parshortname{Abs.}%
  \providecaptionname{german,ngerman,austrian,naustrian}\sentencename{Satz}%
  \providecaptionname{german,ngerman,austrian,naustrian}\sentenceshortname{S.}%
  \providecaptionname{english,american,british,canadian,%
    USenglish,UKenglish,usenglish,ukenglish}\parname{paragraph}%
  \providecaptionname{english,american,british,canadian,%
    USenglish,UKenglish,usenglish,ukenglish}\parshortname{par.}%
  \providecaptionname{english,american,british,canadian,%
    USenglish,UKenglish,usenglish,ukenglish}\sentencename{sentence}%
  \providecaptionname{english,american,british,canadian,%
    USenglish,UKenglish,usenglish,ukenglish}\sentenceshortname{sent.}%
}
\providecommand*{\parname}{\scrjura@lang@error{\parname}}
\providecommand*{\parshortname}{\scrjura@lang@error{\parshortname}}
\providecommand*{\sentencename}{\scrjura@lang@error{\sentencename}}
\providecommand*{\sentenceshortname}{\scrjura@lang@error{\sentenceshortname}}
\newcommand*{\scrjura@lang@error}[1]{%
  \PackageError{scrjura}{%
    current language not supported%
  }{%
    Currently scrjura only supports languages `german', `ngerman',
    `austrian',\MessageBreak
    `naustrian', `english', `american', `british', `canadian',
    `USenglish',\MessageBreak
    `UKenglish', `usenglish`, and `ukenglish'.\MessageBreak
    It seems, that you are using another language (maybe `\languagename') or
    that\MessageBreak
    your language selection isn't compatible to package `babel'.\MessageBreak
    Because of this you have to define `\string#1' by yourself!\MessageBreak
    It would be nice if you'll send your definitions to the author.%
  }%
  \textbf{??}%
}
%</body>
%    \end{macrocode}
% \end{macro}
% \end{command}
%
% \subsection{Using values from last \LaTeX{} run}
%
% \begin{command}{\newmaxpar}
% \changes{v0.6b}{2013/04/16}{\cs{\#1@Clauseformat} expands to its argument}
% \begin{command}{\getmaxpar}
% \changes{v0.6}{2011/09/30}{argument no 3 is expanded using
%   \cs{protected@edef}}
% \changes{v0.5c}{2010/04/26}{\cs{protected@edef} replaced by \cs{edef}}
% \changes{v0.5c}{2010/04/26}{\cs{\#2@Clauseformat} expands to its argument}
% Two helper macros, to save a counter in a \file{aux}-file and get the value
% back or another value of it is not in the \file{aux}-file.
%    \begin{macrocode}
%<*body>
\newcommand*{\newmaxpar}[3]{%
  \begingroup
    \expandafter\let\csname #1@Clauseformat\endcsname\@firstofone
    \protected@edef\@tempa{#2}\@onelevel@sanitize\@tempa
    \expandafter\xdef\csname max@#1@\@tempa\endcsname{#3}%
  \endgroup
}
\newcommand*{\getmaxpar}[3]{%
  \begingroup
    \expandafter\let\csname #2@Clauseformat\endcsname\@firstofone
    \protected@edef\@tempa{#3}%
    \@onelevel@sanitize\@tempa
    \expandafter\ifx \csname max@#2@\@tempa\endcsname\relax
      \edef\@tempa{\endgroup\edef\noexpand#1{\expandafter\the\value{par}}}%
    \else
      \edef\@tempa{\endgroup
        \edef\noexpand#1{\csname max@#2@\@tempa\endcsname}}%
    \fi
  \@tempa
}
%    \end{macrocode}
% \changes{v0.7b}{2014/11/10}{added fallback code to \file{aux}-file}
% \changes{v0.9g}{2015/03/25}{write to \file{aux}-file \cs{if@filesw}}
% Because some users remove \pkg*{scrjura} from their documents without
% deleting the \file{aux}-file, we add a fallback definition of \cs{newmaxpar}
% to the \file{aux}-file. This avoids error messages because of undefined
% \cs{newmaxpar}.
%    \begin{macrocode}
\AtBeginDocument{%
  \if@filesw
    \immediate\write\@auxout{%
      \string\providecommand*\string\newmaxpar[3]{}
    }%
  \fi
}
%</body>
%    \end{macrocode}
% \end{command}
% \end{command}
%
% \iffalse
%</package>
% \fi
%
% \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:
