summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/stex/document-structure.sty
blob: b747cf4d05206b91f3ee8d2457ab5d55e88be190 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
%%
%% This is file `document-structure.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% document-structure.dtx  (with options: `package')
%% 
\ProvidesExplPackage{document-structure}{2022/05/24}{3.1.0}{Modular Document Structure}
\RequirePackage{l3keys2e}

\keys_define:nn{ document-structure }{
  class       .str_set_x:N  = \c_document_structure_class_str,
  topsect     .str_set_x:N  = \c_document_structure_topsect_str,,
  unknown     .code:n       = {
    \PassOptionsToClass{\CurrentOption}{stex}
    \PassOptionsToClass{\CurrentOption}{tikzinput}
  }
}
\ProcessKeysOptions{ document-structure }
\str_if_empty:NT \c_document_structure_class_str {
  \str_set:Nn \c_document_structure_class_str {article}
}
\str_if_empty:NT \c_document_structure_topsect_str {
  \str_set:Nn \c_document_structure_topsect_str {section}
}
\RequirePackage{xspace}
\RequirePackage{comment}
\RequirePackage{stex}
\AddToHook{begindocument}{
\ltx@ifpackageloaded{babel}{
    \clist_set:Nx \l_tmpa_clist {\bbl@loaded}
    \clist_if_in:NnT \l_tmpa_clist {ngerman}{
      \makeatletter\input{document-structure-ngerman.ldf}\makeatother
    }
  }{}
}
\int_new:N \l_document_structure_section_level_int
\str_case:VnF \c_document_structure_topsect_str {
  {part}{
    \int_set:Nn \l_document_structure_section_level_int {0}
  }
  {chapter}{
    \int_set:Nn \l_document_structure_section_level_int {1}
  }
}{
  \str_case:VnF \c_document_structure_class_str {
    {book}{
      \int_set:Nn \l_document_structure_section_level_int {0}
    }
    {report}{
      \int_set:Nn \l_document_structure_section_level_int {0}
    }
  }{
    \int_set:Nn \l_document_structure_section_level_int {2}
  }
}
\def\current@section@level{document}%
\newcommand\currentsectionlevel{\lowercase\expandafter{\current@section@level}\xspace}%
\newcommand\Currentsectionlevel{\expandafter\MakeUppercase\current@section@level\xspace}%
\cs_new_protected:Npn \skipfragment {
  \ifcase\l_document_structure_section_level_int
  \or\stepcounter{part}
  \or\stepcounter{chapter}
  \or\stepcounter{section}
  \or\stepcounter{subsection}
  \or\stepcounter{subsubsection}
  \or\stepcounter{paragraph}
  \or\stepcounter{subparagraph}
  \fi
}
\newcommand\at@begin@blindsfragment[1]{}
\newenvironment{blindfragment}
{
  \int_incr:N\l_document_structure_section_level_int
  \at@begin@blindsfragment\l_document_structure_section_level_int
}{}
\newcommand\sfragment@nonum[2]{
  \ifx\hyper@anchor\@undefined\else\phantomsection\fi
  \addcontentsline{toc}{#1}{#2}\@nameuse{#1}*{#2}
}
\newcommand\sfragment@num[2]{
  \tl_if_empty:NTF \l__document_structure_sfragment_short_tl {
    \@nameuse{#1}{#2}
  }{
    \cs_if_exist:NTF\rdfmeta@sectioning{
      \@nameuse{rdfmeta@#1@old}[\l__document_structure_sfragment_short_tl]{#2}
    }{
      \@nameuse{#1}[\l__document_structure_sfragment_short_tl]{#2}
    }
  }
}
\keys_define:nn { document-structure / sfragment }{
  id            .str_set_x:N = \l__document_structure_sfragment_id_str,
  date          .str_set_x:N = \l__document_structure_sfragment_date_str,
  creators      .clist_set:N = \l__document_structure_sfragment_creators_clist,
  contributors  .clist_set:N = \l__document_structure_sfragment_contributors_clist,
  srccite       .tl_set:N    = \l__document_structure_sfragment_srccite_tl,
  type          .tl_set:N    = \l__document_structure_sfragment_type_tl,
  short         .tl_set:N    = \l__document_structure_sfragment_short_tl,
  display       .tl_set:N    = \l__document_structure_sfragment_display_tl,
  intro         .tl_set:N    = \l__document_structure_sfragment_intro_tl,
  imports       .tl_set:N    = \l__document_structure_sfragment_imports_tl,
  loadmodules   .bool_set:N  = \l__document_structure_sfragment_loadmodules_bool
}
\cs_new_protected:Nn \__document_structure_sfragment_args:n {
  \str_clear:N \l__document_structure_sfragment_id_str
  \str_clear:N \l__document_structure_sfragment_date_str
  \clist_clear:N \l__document_structure_sfragment_creators_clist
  \clist_clear:N \l__document_structure_sfragment_contributors_clist
  \tl_clear:N \l__document_structure_sfragment_srccite_tl
  \tl_clear:N \l__document_structure_sfragment_type_tl
  \tl_clear:N \l__document_structure_sfragment_short_tl
  \tl_clear:N \l__document_structure_sfragment_display_tl
  \tl_clear:N \l__document_structure_sfragment_imports_tl
  \tl_clear:N \l__document_structure_sfragment_intro_tl
  \bool_set_false:N \l__document_structure_sfragment_loadmodules_bool
  \keys_set:nn { document-structure / sfragment } { #1 }
}
\newif\if@mainmatter\@mainmattertrue
\newcommand\at@begin@sfragment[3][]{}
\keys_define:nn { document-structure / sectioning }{
  name    .str_set_x:N  = \l__document_structure_sect_name_str   ,
  ref     .str_set_x:N  = \l__document_structure_sect_ref_str    ,
  clear   .bool_set:N   = \l__document_structure_sect_clear_bool ,
  clear   .default:n    = {true}                ,
  num     .bool_set:N   = \l__document_structure_sect_num_bool   ,
  num     .default:n    = {true}
}
\cs_new_protected:Nn \__document_structure_sect_args:n {
  \str_clear:N \l__document_structure_sect_name_str
  \str_clear:N \l__document_structure_sect_ref_str
  \bool_set_false:N \l__document_structure_sect_clear_bool
  \bool_set_false:N \l__document_structure_sect_num_bool
  \keys_set:nn { document-structure / sectioning } { #1 }
}
\newcommand\omdoc@sectioning[3][]{
  \__document_structure_sect_args:n {#1 }
  \let\omdoc@sect@name\l__document_structure_sect_name_str
  \bool_if:NT \l__document_structure_sect_clear_bool { \cleardoublepage }
  \if@mainmatter% numbering not overridden by frontmatter, etc.
    \bool_if:NTF \l__document_structure_sect_num_bool {
      \sfragment@num{#2}{#3}
    }{
      \sfragment@nonum{#2}{#3}
    }
    \def\current@section@level{\omdoc@sect@name}
  \else
    \sfragment@nonum{#2}{#3}
  \fi
}% if@mainmatter
\newcommand\sfragment@redefine@addtocontents[1]{%
}% hypreref.sty loaded?
\newenvironment{sfragment}[2][]% keys, title
{
  \__document_structure_sfragment_args:n { #1 }%\sref@target%
  \stex_csl_to_imports:No \usemodule \l__document_structure_sfragment_imports_tl

  \bool_if:NT \l__document_structure_sfragment_loadmodules_bool {
    \sfragment@redefine@addtocontents{
      %\@ifundefined{module@id}\used@modules%
      %{\@ifundefined{module@\module@id @path}{\used@modules}\module@id}
    }
  }

  \stex_document_title:n { #2 }

  \int_incr:N\l_document_structure_section_level_int
  \ifcase\l_document_structure_section_level_int
    \or\omdoc@sectioning[name=\omdoc@part@kw,clear,num]{part}{#2}
    \or\omdoc@sectioning[name=\omdoc@chapter@kw,clear,num]{chapter}{#2}
    \or\omdoc@sectioning[name=\omdoc@section@kw,num]{section}{#2}
    \or\omdoc@sectioning[name=\omdoc@subsection@kw,num]{subsection}{#2}
    \or\omdoc@sectioning[name=\omdoc@subsubsection@kw,num]{subsubsection}{#2}
    \or\omdoc@sectioning[name=\omdoc@paragraph@kw,ref=this \omdoc@paragraph@kw]{paragraph}{#2}
    \or\omdoc@sectioning[name=\omdoc@subparagraph@kw,ref=this \omdoc@subparagraph@kw]{paragraph}{#2}
  \fi
  \at@begin@sfragment[#1]\l_document_structure_section_level_int{#2}
  \str_if_empty:NF \l__document_structure_sfragment_id_str {
    \stex_ref_new_doc_target:n\l__document_structure_sfragment_id_str
  }
}% for customization
{}
\newcommand\omdoc@part@kw{Part}
\newcommand\omdoc@chapter@kw{Chapter}
\newcommand\omdoc@section@kw{Section}
\newcommand\omdoc@subsection@kw{Subsection}
\newcommand\omdoc@subsubsection@kw{Subsubsection}
\newcommand\omdoc@paragraph@kw{paragraph}
\newcommand\omdoc@subparagraph@kw{subparagraph}
\providecommand\printindex{\IfFileExists{\jobname.ind}{\input{\jobname.ind}}{}}
\cs_if_exist:NTF\frontmatter{
  \let\__document_structure_orig_frontmatter\frontmatter
  \let\frontmatter\relax
}{
  \tl_set:Nn\__document_structure_orig_frontmatter{
    \clearpage
    \@mainmatterfalse
    \pagenumbering{roman}
  }
}
\cs_if_exist:NTF\backmatter{
  \let\__document_structure_orig_backmatter\backmatter
  \let\backmatter\relax
}{
  \tl_set:Nn\__document_structure_orig_backmatter{
    \clearpage
    \@mainmatterfalse
    \pagenumbering{roman}
  }
}
\newenvironment{frontmatter}{
  \__document_structure_orig_frontmatter
}{
  \cs_if_exist:NTF\mainmatter{
    \mainmatter
  }{
    \clearpage
    \@mainmattertrue
    \pagenumbering{arabic}
  }
}
\newenvironment{backmatter}{
  \__document_structure_orig_backmatter
}{
  \cs_if_exist:NTF\mainmatter{
    \mainmatter
  }{
    \clearpage
    \@mainmattertrue
    \pagenumbering{arabic}
  }
}
\@mainmattertrue\pagenumbering{arabic}
\def \c__document_structure_document_str{document}
\newcommand\afterprematurestop{}
\def\prematurestop@endsfragment{
  \unless\ifx\@currenvir\c__document_structure_document_str
    \expandafter\expandafter\expandafter\end\expandafter\expandafter\expandafter{\expandafter\@currenvir\expandafter}
    \expandafter\prematurestop@endsfragment
  \fi
}
\providecommand\prematurestop{
  \message{Stopping~sTeX~processing~prematurely}
  \prematurestop@endsfragment
  \afterprematurestop
  \end{document}
}
\RequirePackage{etoolbox}
\newcommand\setSGvar[1]{\@namedef{sTeX@Gvar@#1}}
\newrobustcmd\useSGvar[1]{%
  \@ifundefined{sTeX@Gvar@#1}
  {\PackageError{document-structure}
    {The sTeX Global variable #1 is undefined}
    {set it with \protect\setSGvar}}
\@nameuse{sTeX@Gvar@#1}}
\newrobustcmd\ifSGvar[3]{\def\@test{#2}%
  \@ifundefined{sTeX@Gvar@#1}
  {\PackageError{document-structure}
    {The sTeX Global variable #1 is undefined}
    {set it with \protect\setSGvar}}
  {\expandafter\ifx\csname sTeX@Gvar@#1\endcsname\@test #3\fi}}
\endinput
%%
%% End of file `document-structure.sty'.