1%% NUMBERING OF FIGURES, TABLES, AND LITERAL BLOCKS
2%
3% change this info string if making any custom modification
4\ProvidesFile{sphinxlatexnumfig.sty}[2021/01/27 numbering]
5
6% Requires: remreset (old LaTeX only)
7% relates to numfig and numfig_secnum_depth configuration variables
8
9% LaTeX 2018-04-01 and later provides \@removefromreset
10\ltx@ifundefined{@removefromreset}
11    {\RequirePackage{remreset}}
12    {}% avoid warning
13% Everything is delayed to \begin{document} to allow hyperref patches into
14%   \newcounter to solve duplicate label problems for internal hyperlinks to
15%   code listings (literalblock counter).  User or extension re-definitions of
16%   \theliteralblock, et al., thus have also to be delayed. (changed at 3.5.0)
17\AtBeginDocument{%
18\ltx@ifundefined{c@chapter}
19   {\newcounter{literalblock}}%
20   {\newcounter{literalblock}[chapter]%
21    \def\theliteralblock{\ifnum\c@chapter>\z@\arabic{chapter}.\fi
22                         \arabic{literalblock}}%
23    }%
24\ifspx@opt@nonumfigreset
25    \ltx@ifundefined{c@chapter}{}{%
26      \@removefromreset{figure}{chapter}%
27      \@removefromreset{table}{chapter}%
28      \@removefromreset{literalblock}{chapter}%
29      \ifspx@opt@mathnumfig
30        \@removefromreset{equation}{chapter}%
31      \fi
32    }%
33    \def\thefigure{\arabic{figure}}%
34    \def\thetable {\arabic{table}}%
35    \def\theliteralblock{\arabic{literalblock}}%
36    \ifspx@opt@mathnumfig
37      \def\theequation{\arabic{equation}}%
38    \fi
39\else
40\let\spx@preAthefigure\@empty
41\let\spx@preBthefigure\@empty
42% \ifspx@opt@usespart  % <-- LaTeX writer could pass such a 'usespart' boolean
43%                      %     as sphinx.sty package option
44% If document uses \part, (triggered in Sphinx by latex_toplevel_sectioning)
45% LaTeX core per default does not reset chapter or section
46% counters at each part.
47% But if we modify this, we need to redefine \thechapter, \thesection to
48% include the part number and this will cause problems in table of contents
49% because of too wide numbering. Simplest is to do nothing.
50% \fi
51\ifnum\spx@opt@numfigreset>0
52    \ltx@ifundefined{c@chapter}
53      {}
54      {\g@addto@macro\spx@preAthefigure{\ifnum\c@chapter>\z@\arabic{chapter}.}%
55       \g@addto@macro\spx@preBthefigure{\fi}}%
56\fi
57\ifnum\spx@opt@numfigreset>1
58    \@addtoreset{figure}{section}%
59    \@addtoreset{table}{section}%
60    \@addtoreset{literalblock}{section}%
61    \ifspx@opt@mathnumfig
62      \@addtoreset{equation}{section}%
63    \fi%
64    \g@addto@macro\spx@preAthefigure{\ifnum\c@section>\z@\arabic{section}.}%
65    \g@addto@macro\spx@preBthefigure{\fi}%
66\fi
67\ifnum\spx@opt@numfigreset>2
68    \@addtoreset{figure}{subsection}%
69    \@addtoreset{table}{subsection}%
70    \@addtoreset{literalblock}{subsection}%
71    \ifspx@opt@mathnumfig
72      \@addtoreset{equation}{subsection}%
73    \fi%
74    \g@addto@macro\spx@preAthefigure{\ifnum\c@subsection>\z@\arabic{subsection}.}%
75    \g@addto@macro\spx@preBthefigure{\fi}%
76\fi
77\ifnum\spx@opt@numfigreset>3
78    \@addtoreset{figure}{subsubsection}%
79    \@addtoreset{table}{subsubsection}%
80    \@addtoreset{literalblock}{subsubsection}%
81    \ifspx@opt@mathnumfig
82      \@addtoreset{equation}{subsubsection}%
83    \fi%
84    \g@addto@macro\spx@preAthefigure{\ifnum\c@subsubsection>\z@\arabic{subsubsection}.}%
85    \g@addto@macro\spx@preBthefigure{\fi}%
86\fi
87\ifnum\spx@opt@numfigreset>4
88    \@addtoreset{figure}{paragraph}%
89    \@addtoreset{table}{paragraph}%
90    \@addtoreset{literalblock}{paragraph}%
91    \ifspx@opt@mathnumfig
92      \@addtoreset{equation}{paragraph}%
93    \fi%
94    \g@addto@macro\spx@preAthefigure{\ifnum\c@subparagraph>\z@\arabic{subparagraph}.}%
95    \g@addto@macro\spx@preBthefigure{\fi}%
96\fi
97\ifnum\spx@opt@numfigreset>5
98    \@addtoreset{figure}{subparagraph}%
99    \@addtoreset{table}{subparagraph}%
100    \@addtoreset{literalblock}{subparagraph}%
101    \ifspx@opt@mathnumfig
102      \@addtoreset{equation}{subparagraph}%
103    \fi%
104    \g@addto@macro\spx@preAthefigure{\ifnum\c@subsubparagraph>\z@\arabic{subsubparagraph}.}%
105    \g@addto@macro\spx@preBthefigure{\fi}%
106\fi
107\expandafter\g@addto@macro
108\expandafter\spx@preAthefigure\expandafter{\spx@preBthefigure}%
109\let\thefigure\spx@preAthefigure
110\let\thetable\spx@preAthefigure
111\let\theliteralblock\spx@preAthefigure
112\g@addto@macro\thefigure{\arabic{figure}}%
113\g@addto@macro\thetable{\arabic{table}}%
114\g@addto@macro\theliteralblock{\arabic{literalblock}}%
115  \ifspx@opt@mathnumfig
116    \let\theequation\spx@preAthefigure
117    \g@addto@macro\theequation{\arabic{equation}}%
118  \fi
119\fi
120}% end of big \AtBeginDocument
121
122\endinput
123