% Maintained by Matthew Bertucci, 2024-present
% Please report all issues and feature requests at https://github.com/mbertucci47/keytheorems
% This work is licensed under the LPPL version 1.3c or later: https://www.latex-project.org/lppl.txt
\ProvidesExplFile{keythms-memoir-support}{\@keythms@date}{\@keythms@version}
  {keytheorems~support~for~the~memoir~class}

\bool_new:N \l__keythms_support_titlecode_bool

\keys_define:nn { keytheorems/listof }
  {
    indent     .initial:n = 0pt,
    title-code .code:n    =
      {
        \bool_set_true:N \l__keythms_support_titlecode_bool
        \cs_set:Npn \__keythms_listof_titlecmd:n ##1 { #1 }
      },
  }

% use memoir's list function; not using \newlistentry, though
\newlistof{ keythms_support_memoir_listof:w }{ thlist }
  { \l__keythms_listof_title_tl }

% small hack to use the same marks as \listoffigures
\cs_set:Npn \thlistmark
  {
    \group_begin:
    \cs_set_eq:NN \listfigurename \l__keythms_listof_title_tl
    \lofmark
    \group_end:
  }

\RenewDocumentCommand \listofkeytheorems { +O{} }
  {
    \bool_gset_true:N \g__keythms_listof_writefile_bool
    \group_begin:
    \keys_set:nn { keytheorems/listof } { #1 }
    \cs_set_protected:Npn \KeyThmsContentsLine ##1 { ##1 }
    \bool_if:NF \l__keythms_listof_nochapskip_bool
      {
        \cs_set_eq:NN \KeyThmsAddvspace \addvspace
      }
    \bool_if:NTF \l__keythms_listof_onecol_bool
      { \onecoltocetc }
      { \doccoltocetc } % I guess this is what we want?
    \bool_if:NT \l__keythms_listof_swapnumber_bool
      {
        \cs_set:Npn \__keythms_listof_misdirect:nnn ##1##2##3
          { ##1 ~ ##2##3 }
      }
    \bool_if:NTF \l__keythms_listof_notitle_bool
      {
        \cs_set:Npn \@thlistmaketitle {}
        \keythms_support_memoir_listof:w*
      }
      {
        \bool_if:NT \l__keythms_support_titlecode_bool
          {
            \cs_set:Npn \@thlistmaketitle
              { \__keythms_listof_titlecmd:n { \l__keythms_listof_title_tl } }
          }
        \bool_if:NTF \l__keythms_listof_notoc_bool
          { \keythms_support_memoir_listof:w* }
          { \keythms_support_memoir_listof:w }
      }
    \group_end:
  }

\file_input_stop: