implement counters and option parsing

This commit is contained in:
Maximilian Keßler 2022-01-23 15:21:29 +01:00
parent 02356e81d7
commit beb4b7af0a

View file

@ -52,6 +52,20 @@
% \end{macrocode} % \end{macrocode}
% %
% %
% \subsection{Dependencies}
% \begin{macrocode}
\RequirePackage{l3keys2e}
% \end{macrocode}
%
% \subsection{Counter management}
%
%
% Wrappers for \LaTeX2e counter manipulation
%
%
% \begin{macro}{\arabic:n, \counter_new:n, \counter_within:nn,\counter_new:nn}
%
% Obvious meanings.
% %
% \begin{macrocode} % \begin{macrocode}
\cs_set_eq:NN \arabic:n \arabic \cs_set_eq:NN \arabic:n \arabic
@ -62,9 +76,23 @@
\counter_new:n { #1 } \counter_new:n { #1 }
\counter_within:nn { #1 } { #2 } \counter_within:nn { #1 } { #2 }
} }
\cs_set_eq:Nc \counter_alias:nn { @counteralias } % this is from thmtools % \end{macrocode}
\cs_set_eq:Nc \counter_undefined_error:n { @nocounterr } % \end{macro}
%
%
%
%
% \begin{macro}
% {
% \counter_if_exist_p:n,
% \counter_if_exist:nT,
% \counter_if_exist:F,
% \counter_if_exist:nTF,
% }
%
%
%
% \begin{macrocode}
\cs_new:Npn \counter_if_exist_p:n #1 \cs_new:Npn \counter_if_exist_p:n #1
{ {
\cs_if_exist_p:c { c@ #1 } \cs_if_exist_p:c { c@ #1 }
@ -81,7 +109,28 @@
{ {
\cs_if_exist:cTF { c@ #1 } \cs_if_exist:cTF { c@ #1 }
} }
% \end{macrocode}
% \end{macro}
%
%
%
% \begin{macro}{\counter_undefined_error:n}
%
% Standard counter error message.
%
% \begin{macrocode}
\cs_set_eq:Nc \counter_undefined_error:n { @nocounterr }
% \end{macrocode}
% \end{macro}
%
%
%
%
% \begin{macro}{\counter_ensure_exist:n}
%
%
%
% \begin{macrocode}
\cs_new:Npn \counter_ensure_exist:n #1 \cs_new:Npn \counter_ensure_exist:n #1
{ {
\counter_if_exist:nF { #1 } \counter_if_exist:nF { #1 }
@ -89,6 +138,17 @@
\counter_undefined_error:n { #1 } \counter_undefined_error:n { #1 }
} }
} }
% \end{macrocode}
% \end{macro}
%
%
%
%
%
% \begin{macro}{\counter_the:n, \counter_set_the:nn}
%
%
% \begin{macrocode}
\cs_new:Npn \counter_the:n #1 \cs_new:Npn \counter_the:n #1
{ {
\use:c { the #1 } \use:c { the #1 }
@ -98,6 +158,20 @@
\counter_ensure_exist:n { #1 } \counter_ensure_exist:n { #1 }
\exp_args:Nc \renewcommand { the #1 } { #2 } \exp_args:Nc \renewcommand { the #1 } { #2 }
} }
% \end{macrocode}
% \end{macro}
%
%
%
%
% \begin{macro}{\counter_sub:nn}
% \begin{syntax}
% \cs{counter_sub:nn}\marg{counter_1}\marg{counter_2}
% \end{syntax}
%
%
%
% \begin{macrocode}
\cs_new:Npn \counter_sub:nn #1 #2 \cs_new:Npn \counter_sub:nn #1 #2
{ {
\counter_within:nn { #1 } { #2 } \counter_within:nn { #1 } { #2 }
@ -106,13 +180,160 @@
\counter_the:n { #2 } . \arabic:n { #1 } \counter_the:n { #2 } . \arabic:n { #1 }
} }
} }
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\counter_new_sub:nn #1 #2}
%
%
%
% \begin{macrocode}
\cs_new:Npn \counter_new_sub:nn #1 #2
{
\counter_new:n { #1 }
\counter_sub:nn { #1 } { #2 }
}
% \end{macrocode}
% \end{macro}
%
% \subsection{Counter management}
%
%
%
% \begin{macro}{\@@_counter_sub_if_exist:n}
%
%
%
% \begin{macrocode}
\cs_new:Npn \@@_counter_sub_if_exist:n #1 \cs_new:Npn \@@_counter_sub_if_exist:n #1
{ {
\counter_if_exist:nT { #1 } \counter_if_exist:nT { #1 }
{ {
\counter_sub:nn { in #1 } { #1 } \counter_new_sub:nn { in #1 } { #1 }
} }
} }
% \end{macrocode}
% \end{macro}
%
%
%
%
%
%
% \begin{macro}{\counter_alias:nn, \counter_alias:nx}
% \begin{syntax}
% \cs{counter_alias:nn}\marg{counter_1}\marg{counter_2}
% \end{syntax}
%
%
%
% \begin{macrocode}
\cs_set_eq:Nc \counter_alias:nn { @counteralias }
\cs_generate_variant:Nn \counter_alias:nn { n x }
% \end{macrocode}
% \end{macro}
%
%
%
%
%
%
% \subsection{Initialization}
%
%
%
% \begin{variable}{indocument, insection, insubsection, inchapter, inpart}
%
%
%
% \begin{macrocode}
\counter_new:n { indocument }
\@@_counter_sub_if_exist:n { section }
\@@_counter_sub_if_exist:n { subsection }
\@@_counter_sub_if_exist:n { chapter }
\@@_counter_sub_if_exist:n { part }
% \end{macrocode}
% \end{variable}
%
% \begin{variable}{toplevel, sublevel, subsublevel, subsubsublevel}
%
% Note that the \texttt{toplevel} counter will be potentially redefined
% by the given package options.
%
% \begin{macrocode}
\counter_alias:nn { toplevel } { indocument }
\counter_new_sub:nn { sublevel } { toplevel }
\counter_new_sub:nn { subsublevel } { sublevel }
\counter_new_sub:nn { subsubsublevel } { subsublevel }
% \end{macrocode}
% \end{variable}
%
%
% \begin{variable}{\g_@@_style_str}
%
% This will hold the style information of the package.
%
% \begin{macrocode}
\str_new:N \g_@@_style_str
% \end{macrocode}
% \end{variable}
%
% \begin{variable}{\g_@@_translator_bool}
%
%
%
% \begin{macrocode}
\bool_new:N \g_@@_translator_bool
% \end{macrocode}
% \end{variable}
%
%
% \begin{variable}{\g_@@_generate_defaults_bool}
%
%
%
% \begin{macrocode}
\bool_new:N \g_@@_generate_defaults_bool
% \end{macrocode}
% \end{variable}
%
% \subsection{Key interface}
%
% \begin{macrocode}
\keys_define:nn { fancythm }
{
translator .bool_set:N = \g_@@_translator_bool ,
translator .default:n = { true } ,
generate ~ defaults .bool_set:N = \g_@@_generate_defaults_bool ,
generate ~ defaults .default:n = { true } ,
number in .choices:nn =
{ document, section, subsection, chapter, part }
{
\counter_alias:nx { toplevel } { in \tl_use:N \l_keys_choice_tl }
} ,
number in .default:n = { document } ,
style .choices:nn =
{ fancy, plain, classic }
{
\str_set:Nn \g_@@_style_str { \tl_use:N \l_keys_choice_tl }
} ,
style .default:n = { fancy }
}
% \end{macrocode}
%
%
%
% \begin{macrocode}
\ProcessKeysOptions{ fancythm }
% \end{macrocode}
%
%
% \begin{macrocode}
%
% \end{macrocode} % \end{macrocode}
% %
% %