%% ALPHANUMERIC LIST ITEMS
%
% change this info string if making any custom modification
\ProvidesFile{sphinxlatexlists.sty}[2021/01/27 lists]

% Provides support for this output mark-up from Sphinx latex writer:
% - \sphinxsetlistlabels

% Dependencies: the \spx@opt@maxlistdepth from sphinx.sty

\newcommand\sphinxsetlistlabels[5]
{% #1 = style, #2 = enum, #3 = enumnext, #4 = prefix, #5 = suffix
 % #2 and #3 are counters used by enumerate environement e.g. enumi, enumii.
 % #1 is a macro such as \arabic or \alph
 % prefix and suffix are strings (by default empty and a dot).
 \@namedef{the#2}{#1{#2}}%
 \@namedef{label#2}{#4\@nameuse{the#2}#5}%
 \@namedef{p@#3}{\@nameuse{p@#2}#4\@nameuse{the#2}#5}%
}%


%% MAXLISTDEPTH
%
% remove LaTeX's cap on nesting depth if 'maxlistdepth' key used.
% This is a hack, which works with the standard classes: it assumes \@toodeep
% is always used in "true" branches: "\if ... \@toodeep \else .. \fi."

% will force use the "false" branch (if there is one)
\def\spx@toodeep@hack{\fi\iffalse}

% do nothing if 'maxlistdepth' key not used or if package enumitem loaded.
\ifnum\spx@opt@maxlistdepth=\z@\expandafter\@gobbletwo\fi
\AtBeginDocument{%
\@ifpackageloaded{enumitem}{\remove@to@nnil}{}%
  \let\spx@toodeepORI\@toodeep
  \def\@toodeep{%
    \ifnum\@listdepth<\spx@opt@maxlistdepth\relax
      \expandafter\spx@toodeep@hack
    \else
      \expandafter\spx@toodeepORI
    \fi}%
% define all missing \@list... macros
  \count@\@ne
  \loop
     \ltx@ifundefined{@list\romannumeral\the\count@}
       {\iffalse}{\iftrue\advance\count@\@ne}%
  \repeat
  \loop
     \ifnum\count@>\spx@opt@maxlistdepth\relax\else
       \expandafter\let
         \csname @list\romannumeral\the\count@\expandafter\endcsname
         \csname @list\romannumeral\the\numexpr\count@-\@ne\endcsname
       % workaround 2.6--3.2d babel-french issue (fixed in 3.2e; no change needed)
       \ltx@ifundefined{leftmargin\romannumeral\the\count@}
       {\expandafter\let
         \csname leftmargin\romannumeral\the\count@\expandafter\endcsname
         \csname leftmargin\romannumeral\the\numexpr\count@-\@ne\endcsname}{}%
     \advance\count@\@ne
  \repeat
% define all missing enum... counters and \labelenum... macros and \p@enum..
  \count@\@ne
  \loop
     \ltx@ifundefined{c@enum\romannumeral\the\count@}
       {\iffalse}{\iftrue\advance\count@\@ne}%
  \repeat
  \loop
     \ifnum\count@>\spx@opt@maxlistdepth\relax\else
       \newcounter{enum\romannumeral\the\count@}%
       \expandafter\def
         \csname labelenum\romannumeral\the\count@\expandafter\endcsname
         \expandafter
         {\csname theenum\romannumeral\the\numexpr\count@\endcsname.}%
       \expandafter\def
         \csname p@enum\romannumeral\the\count@\expandafter\endcsname
         \expandafter
         {\csname p@enum\romannumeral\the\numexpr\count@-\@ne\expandafter
          \endcsname\csname theenum\romannumeral\the\numexpr\count@-\@ne\endcsname.}%
     \advance\count@\@ne
  \repeat
% define all missing labelitem... macros
  \count@\@ne
  \loop
     \ltx@ifundefined{labelitem\romannumeral\the\count@}
     {\iffalse}{\iftrue\advance\count@\@ne}%
  \repeat
  \loop
     \ifnum\count@>\spx@opt@maxlistdepth\relax\else
       \expandafter\let
         \csname labelitem\romannumeral\the\count@\expandafter\endcsname
         \csname labelitem\romannumeral\the\numexpr\count@-\@ne\endcsname
     \advance\count@\@ne
  \repeat
  \PackageInfo{sphinx}{maximal list depth extended to \spx@opt@maxlistdepth}%
\@gobble\@nnil
}

\endinput
