| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
% Copyright (C) 2019-- |
| 4 |
% Gau, Syu ( [email protected] ) |
| 5 |
% |
| 6 |
% ---------------------------------------------------------------------- |
| 7 |
% |
| 8 |
% This work may be distributed and/or modified under the |
| 9 |
% conditions of the LaTeX Project Public License, either |
| 10 |
% version 1.3c of this license or (at your option) any later |
| 11 |
% version. This version of this license is in |
| 12 |
% http://www.latex-project.org/lppl/lppl-1-3c.txt |
| 13 |
% and the latest version of this license is in |
| 14 |
% http://www.latex-project.org/lppl.txt |
| 15 |
% and version 1.3 or later is part of all distributions of |
| 16 |
% LaTeX version 2005/12/01 or later. |
| 17 |
% |
| 18 |
% This work has the LPPL maintenance status `maintained'. |
| 19 |
% |
| 20 |
% The Current Maintainer of this work is |
| 21 |
% Gau, Syu ( [email protected] ). |
| 22 |
% |
| 23 |
% ---------------------------------------------------------------------- |
| 24 |
% |
| 25 |
%<*internal> |
| 26 |
\iffalse |
| 27 |
%</internal> |
| 28 |
%<*readme> |
| 29 |
|
| 30 |
# secnum |
| 31 |
|
| 32 |
This package provides a macro `\setsecnum` to format section numbering intuitively. |
| 33 |
|
| 34 |
## Usage |
| 35 |
|
| 36 |
One can simply use `\setsecnum{A,:1.i}` to set the section numbering |
| 37 |
format as `Alph` for the sections, `arabic` for the subsections and |
| 38 |
`arabic.roman` for the subsubsections and |
| 39 |
the `secnumdepth` and `tocdepth` will be 3. |
| 40 |
|
| 41 |
If one want to set the tocdepth manually, |
| 42 |
there is an option `tocdep` for it. |
| 43 |
|
| 44 |
One may notice that the comma `,` plays a special role in the numbering format: |
| 45 |
the shallower section levels will not be shown in titles of deeper levels, |
| 46 |
but it will appear in reference labels. |
| 47 |
|
| 48 |
## Installation |
| 49 |
|
| 50 |
The installation is the same as usual Tex packages. |
| 51 |
|
| 52 |
0. Put the source file `secnum.dtx` in a empty folder and go to there. |
| 53 |
|
| 54 |
1. Run the following to create the package file `secnum.sty` (as well as this file `README.md`) |
| 55 |
|
| 56 |
pdfTeX secnum.dtx |
| 57 |
|
| 58 |
2. Move the following file into proper directories searched by TeX. |
| 59 |
The recommended directory is |
| 60 |
|
| 61 |
tex/latex/secnum |
| 62 |
|
| 63 |
3. To produce the documentation run the following |
| 64 |
|
| 65 |
pdfLaTeX secnum.dtx |
| 66 |
|
| 67 |
4. The recommended directory for the documentation is |
| 68 |
|
| 69 |
doc/latex/secnum |
| 70 |
|
| 71 |
## Download |
| 72 |
|
| 73 |
One can also download the generated files from the [github release](https://github.com/GauSyu/secnum/releases). |
| 74 |
|
| 75 |
%</readme> |
| 76 |
%<*internal> |
| 77 |
\fi |
| 78 |
\begingroup |
| 79 |
\def\nameoflatexe{LaTeX2e} |
| 80 |
\expandafter\endgroup\ifx\nameoflatexe\fmtname\else |
| 81 |
\csname fi\endcsname |
| 82 |
%</internal> |
| 83 |
%<*install> |
| 84 |
|
| 85 |
\input docstrip.tex |
| 86 |
|
| 87 |
\preamble |
| 88 |
|
| 89 |
Copyright (C) 2019-- |
| 90 |
Gau, Syu ( [email protected] ) |
| 91 |
|
| 92 |
---------------------------------------------------------------------- |
| 93 |
|
| 94 |
This work may be distributed and/or modified under the |
| 95 |
conditions of the LaTeX Project Public License, either |
| 96 |
version 1.3c of this license or (at your option) any later |
| 97 |
version. This version of this license is in |
| 98 |
http://www.latex-project.org/lppl/lppl-1-3c.txt |
| 99 |
and the latest version of this license is in |
| 100 |
http://www.latex-project.org/lppl.txt |
| 101 |
and version 1.3 or later is part of all distributions of |
| 102 |
LaTeX version 2005/12/01 or later. |
| 103 |
|
| 104 |
This work has the LPPL maintenance status `maintained'. |
| 105 |
|
| 106 |
The Current Maintainer of this work is |
| 107 |
Gau, Syu ( [email protected] ). |
| 108 |
|
| 109 |
---------------------------------------------------------------------- |
| 110 |
|
| 111 |
\endpreamble |
| 112 |
|
| 113 |
\keepsilent |
| 114 |
|
| 115 |
\generate{ |
| 116 |
\usedir{tex/latex/secnum} |
| 117 |
\file{\jobname.sty}{\from{\jobname.dtx}{package}} |
| 118 |
\nopreamble\nopostamble |
| 119 |
\file{README.md}{\from{\jobname.dtx}{readme}} |
| 120 |
} |
| 121 |
\Msg{*************************************************************} |
| 122 |
\Msg{* *} |
| 123 |
\Msg{* To finish the installation you have to move the following *} |
| 124 |
\Msg{* file into proper directories searched by TeX: *} |
| 125 |
\Msg{* *} |
| 126 |
\Msg{* The recommended directory is TDS:tex/latex/secnum *} |
| 127 |
\Msg{* *} |
| 128 |
\Msg{* secnum.sty *} |
| 129 |
\Msg{* *} |
| 130 |
\Msg{* To produce the documentation run the file secnum.dtx *} |
| 131 |
\Msg{* through XeLaTeX. *} |
| 132 |
\Msg{* *} |
| 133 |
\Msg{* Happy TeXing! *} |
| 134 |
\Msg{* *} |
| 135 |
\Msg{*************************************************************} |
| 136 |
\endbatchfile |
| 137 |
%</install> |
| 138 |
%<*internal> |
| 139 |
\fi |
| 140 |
%</internal> |
| 141 |
%<*driver> |
| 142 |
\ProvidesFile{secnum.dtx} |
| 143 |
\documentclass{l3doc} |
| 144 |
\usepackage{indentfirst} |
| 145 |
\usepackage{booktabs} |
| 146 |
\usepackage{xcolor} |
| 147 |
\usepackage[tocdep=2]{secnum} |
| 148 |
\setsecnum{A,:1.i} |
| 149 |
\ExplSyntaxOn |
| 150 |
\cs_set_eq:NN \__codedoc_macro_end_style:n \use_none:n |
| 151 |
\ExplSyntaxOff |
| 152 |
\DeclareRobustCommand \opt {\texttt} |
| 153 |
\def\glossaryname{Changes History} |
| 154 |
\GlossaryPrologue{\section{\glossaryname}} |
| 155 |
\EnableCrossrefs |
| 156 |
\CodelineIndex |
| 157 |
\RecordChanges |
| 158 |
\begin{document} |
| 159 |
\DocInput{\jobname.dtx} |
| 160 |
\PrintChanges |
| 161 |
\end{document} |
| 162 |
%</driver> |
| 163 |
% \fi |
| 164 |
% \GetFileInfo{\jobname.sty} |
| 165 |
% \DoNotIndex{\cs} |
| 166 |
% |
| 167 |
% \title{ The \pkg{\jobname} package } |
| 168 |
% \author{ Gau, Syu } |
| 169 |
% \date{ \textit{Last Update:} \filedate } |
| 170 |
% |
| 171 |
% \maketitle |
| 172 |
% |
| 173 |
% \begin{abstract} |
| 174 |
% The package \pkg{\jobname} provides a marco \cs{setsecnum} |
| 175 |
% which allows user to format section numbering intuitively. |
| 176 |
% \end{abstract} |
| 177 |
% |
| 178 |
% \tableofcontents |
| 179 |
% \begin{documentation} |
| 180 |
% |
| 181 |
% \section{Example} |
| 182 |
% This document uses the following setting of section numbering format. |
| 183 |
% \begin{verbatim} |
| 184 |
% \usepackage[tocdep=2]{secnum} |
| 185 |
% \setsecnum{A,:1.i} |
| 186 |
% \end{verbatim} |
| 187 |
% |
| 188 |
% \section{Usage} |
| 189 |
% Before using the macro, load the package in preamble. |
| 190 |
% \begin{verbatim} |
| 191 |
% \usepackage{secnum} |
| 192 |
% \end{verbatim} |
| 193 |
% |
| 194 |
% \subsection{Set numbering format} |
| 195 |
% One can format the section numbering by using the |
| 196 |
% marco \cs{setsecnum} in preamble. |
| 197 |
% \begin{function}{\setsecnum} |
| 198 |
% \begin{syntax} |
| 199 |
% \cs{setsecnum}\marg{num format} |
| 200 |
% \end{syntax} |
| 201 |
% |
| 202 |
% A typical \meta{num format} is like this: |
| 203 |
% \begin{center} |
| 204 |
% \verb|A,:1.i| |
| 205 |
% \end{center} |
| 206 |
% It consists of some syntax abbrs of numbering formats, |
| 207 |
% reffering the follows, |
| 208 |
% \begin{center} |
| 209 |
% \begin{tabular}{ccccc} |
| 210 |
% \toprule |
| 211 |
% A & a & I & i & 1 \\ |
| 212 |
% \midrule |
| 213 |
% \cs{Alph} & \cs{alph} & \cs{Roman} & \cs{roman} & \cs{arabic} \\ |
| 214 |
% \bottomrule |
| 215 |
% \end{tabular} |
| 216 |
% \end{center} |
| 217 |
% and some separators delimiting them. |
| 218 |
% |
| 219 |
% A separator can contain any character except above abbrs, |
| 220 |
% the tokens ``\verb|{|'', ``\verb|}|'' and ``\verb|#|'' |
| 221 |
% (more precisely, explicit character tokens with category code |
| 222 |
% 1 (begin-group) or 2 (end-group), and tokens with category code 6) and the space ``\verb*| |''. |
| 223 |
% |
| 224 |
% Note that \meta{num format} must end with an abbr. |
| 225 |
% |
| 226 |
% \begin{texnote} |
| 227 |
% This command will overwrite |
| 228 |
% \opt{secnumdepth} and \opt{tocdepth} |
| 229 |
% \end{texnote} |
| 230 |
% \end{function} |
| 231 |
% |
| 232 |
% \subsection{Breaking the numbering} |
| 233 |
% The comma ``\verb|,|'' in above example is used as the breaking mark. |
| 234 |
% When a separator contains a comma |
| 235 |
% (in our example, \verb|,:| between \verb|A| and \verb|1|), |
| 236 |
% the shallower section levels (in our example, \cs{thesection}) |
| 237 |
% will not be shown in titles of deeper levels |
| 238 |
% (in our example, \cs{thesubsection} and \cs{thesubsubsection}). |
| 239 |
% However, the numbering will appear in the reference labels with the given separator removing the comma. |
| 240 |
% For instance, the next subsection is refered as \ref{Options}. |
| 241 |
% |
| 242 |
% \subsection{Package options}\label{Options} |
| 243 |
% \subsubsection{tocdep} |
| 244 |
% There is an option setting \opt{tocdepth}, the table-of-contents depth manually. |
| 245 |
% \begin{function}{ tocdep } |
| 246 |
% \begin{syntax} |
| 247 |
% \opt{tocdep} = \meta{integer} |
| 248 |
% \end{syntax} |
| 249 |
% |
| 250 |
% The \meta{integer} refers to the table-of-contents depth, |
| 251 |
% which should between $1$ and $5$. |
| 252 |
% |
| 253 |
% \begin{texnote} |
| 254 |
% If this option is used, then \cs{setsecnum} will not overwrite \opt{tocdepth}. |
| 255 |
% \end{texnote} |
| 256 |
% \end{function} |
| 257 |
% |
| 258 |
% \subsubsection{breaking} |
| 259 |
% Another option is used to change the breaking mark. |
| 260 |
% \begin{function}{ breaking } |
| 261 |
% \begin{syntax} |
| 262 |
% \opt{breaking} = \meta{token} |
| 263 |
% \end{syntax} |
| 264 |
% |
| 265 |
% The \meta{token} will be the breaking mark |
| 266 |
% (the default is the comma ``\verb|,|''). |
| 267 |
% It can be any character except above abbrs, |
| 268 |
% the tokens ``\verb|{|'', ``\verb|}|'' and ``\verb|#|'' |
| 269 |
% (more precisely, explicit character tokens with category code |
| 270 |
% 1 (begin-group) or 2 (end-group), and tokens with category code 6) and the space ``\verb*| |''. |
| 271 |
% \end{function} |
| 272 |
% |
| 273 |
% \section{Process} |
| 274 |
% The process of the macro \cs{setsecnum} can be |
| 275 |
% explained as follows. |
| 276 |
% \begin{enumerate}[label=Step \arabic*.] |
| 277 |
% \item The main function eats the input, saying \opt{A,:1.i}, |
| 278 |
% and stores it in a token list. |
| 279 |
% \item Replace abbrs by macros. |
| 280 |
% In our example, it results |
| 281 |
% ``\cs{Alph}\opt{,:}\cs{arabic}\opt{.}\cs{roman}'' |
| 282 |
% \item Split this token list into a sequence by macros. |
| 283 |
% In our example, it results ``\cs{Alph}'', |
| 284 |
% ``\opt{,:}'', ``\cs{arabic}'', ``\opt{.}'', |
| 285 |
% and ``\cs{roman}''. |
| 286 |
% \item Store those codes in indivial containers. |
| 287 |
% \item Detect if there is \cs{thechapter}. |
| 288 |
% Skip the chapter level if not. |
| 289 |
% In our example, this is the case. |
| 290 |
% \item Use the containers to redefine |
| 291 |
% \cs{thesection}, \cs{thesubsection}, |
| 292 |
% \cs{thesubsubsection} etc. |
| 293 |
% In each step, detect if such level needs numbering and |
| 294 |
% if there is a breaking mark in the container. |
| 295 |
% In our example, the numbering formats will be redefined as |
| 296 |
% \end{enumerate} |
| 297 |
% \begin{verbatim} |
| 298 |
% \renewcommand*{\thesection}{\Alph{section}} |
| 299 |
% \renewcommand*{\thesubsection}{\arabic{subsection}} |
| 300 |
% \renewcommand*{\thesubsubsection}{thesubsection.\roman{subsubsection}} |
| 301 |
% \makeatletter |
| 302 |
% \renewcommand*{\p@subsection}{\Alph{section}:} |
| 303 |
% \renewcommand*{\p@subsubsection}{\Alph{section}:} |
| 304 |
% \makeatother |
| 305 |
% \end{verbatim} |
| 306 |
% |
| 307 |
% \end{documentation} |
| 308 |
% |
| 309 |
% \StopEventually{} |
| 310 |
% |
| 311 |
% \begin{implementation} |
| 312 |
% \section{Implementation} |
| 313 |
% The following is the implementation. |
| 314 |
% Users can ignore. |
| 315 |
% \subsection{Preparations} |
| 316 |
% This package uses \LaTeX3. |
| 317 |
% Therefore, the packages \pkg{expl3}, \pkg{xparse} and \pkg{l3keys2e} |
| 318 |
% are needed and should use |
| 319 |
% \cs{ProvidesExplPackage} rather than \cs{ProvidesPackage}. |
| 320 |
% |
| 321 |
% \begin{macrocode} |
| 322 |
%<*package> |
| 323 |
%<@@=syu> |
| 324 |
\NeedsTeXFormat{LaTeX2e} |
| 325 |
\RequirePackage{expl3,xparse,l3keys2e} |
| 326 |
\ProvidesExplPackage{secnum}{2022/01/30}{} |
| 327 |
{ An intuitive way to format section numbering } |
| 328 |
% \end{macrocode} |
| 329 |
% |
| 330 |
% \begin{variable}{ \g__syu_secnum_depth } |
| 331 |
% This \meta{integer} counts the depth of section levels. |
| 332 |
% \begin{macrocode} |
| 333 |
\int_new:N \g__syu_secnum_depth |
| 334 |
% \end{macrocode} |
| 335 |
% \end{variable} |
| 336 |
% |
| 337 |
% \begin{variable}{ \g__syu_ifchapter_int } |
| 338 |
% This \meta{integer} encodes if \cs{thechapter} is defined. |
| 339 |
% \begin{macrocode} |
| 340 |
\int_new:N \g__syu_ifchapter_int |
| 341 |
% \end{macrocode} |
| 342 |
% If \cs{thechapter} is defined, it is $1$. |
| 343 |
% \begin{macrocode} |
| 344 |
\if_cs_exist:N \thechapter |
| 345 |
\int_gset:Nn \g__syu_ifchapter_int 1 |
| 346 |
% \end{macrocode} |
| 347 |
% Otherwise, it is $0$. |
| 348 |
% \begin{macrocode} |
| 349 |
\else: |
| 350 |
\int_gset:Nn \g__syu_ifchapter_int 0 |
| 351 |
\fi: |
| 352 |
% \end{macrocode} |
| 353 |
% \end{variable} |
| 354 |
% |
| 355 |
% \begin{variable}{ \g__syu_secnum_bkm } |
| 356 |
% This variable is used to store the breaking mark. |
| 357 |
% \begin{macrocode} |
| 358 |
\tl_gset:Nx \g__syu_secnum_bkmr {,} |
| 359 |
% \end{macrocode} |
| 360 |
% We need the following variants |
| 361 |
% \begin{macrocode} |
| 362 |
\cs_generate_variant:Nn \tl_if_in:NnTF { NV } |
| 363 |
\cs_generate_variant:Nn \tl_remove_all:Nn { NV } |
| 364 |
% \end{macrocode} |
| 365 |
% \end{variable} |
| 366 |
% |
| 367 |
% \begin{variable}{ |
| 368 |
% \g__syu_chapter_tl, |
| 369 |
% \g__syu_chapter_section_tl, |
| 370 |
% \g__syu_section_tl, |
| 371 |
% \g__syu_section_subsection_tl, |
| 372 |
% \g__syu_subsection_tl, |
| 373 |
% \g__syu_subsection_subsubsection_tl, |
| 374 |
% \g__syu_subsubsection_tl, |
| 375 |
% \g__syu_subsubsection_paragraph_tl, |
| 376 |
% \g__syu_paragraph_tl, |
| 377 |
% \g__syu_paragraph_subparagraph_tl, |
| 378 |
% \g__syu_subparagraph_tl |
| 379 |
% } |
| 380 |
% The following variables are used to store |
| 381 |
% the individal formatting codes. |
| 382 |
% \begin{macrocode} |
| 383 |
\tl_new:N \g__syu_chapter_tl |
| 384 |
\tl_new:N \g__syu_chapter_section_tl |
| 385 |
\tl_new:N \g__syu_section_tl |
| 386 |
\tl_new:N \g__syu_section_subsection_tl |
| 387 |
\tl_new:N \g__syu_subsection_tl |
| 388 |
\tl_new:N \g__syu_subsection_subsubsection_tl |
| 389 |
\tl_new:N \g__syu_subsubsection_tl |
| 390 |
\tl_new:N \g__syu_subsubsection_paragraph_tl |
| 391 |
\tl_new:N \g__syu_paragraph_tl |
| 392 |
\tl_new:N \g__syu_paragraph_subparagraph_tl |
| 393 |
\tl_new:N \g__syu_subparagraph_tl |
| 394 |
% \end{macrocode} |
| 395 |
% \end{variable} |
| 396 |
% |
| 397 |
% \changes{2020/01/12}{2020/01/12}{Add package option to set \opt{tocdepth}.} |
| 398 |
% \subsection{Package option} |
| 399 |
% \begin{macrocode} |
| 400 |
\keys_define:nn { syu / options }{ |
| 401 |
% \end{macrocode} |
| 402 |
% |
| 403 |
% \begin{macro}{ tocdep } |
| 404 |
% Set the table-of-contents depth. |
| 405 |
% \begin{macrocode} |
| 406 |
tocdep .code:n = { |
| 407 |
\int_const:Nn \g__syu_tocdep {#1} |
| 408 |
\setcounter{tocdepth}{ \g__syu_tocdep } |
| 409 |
}, |
| 410 |
% \end{macrocode} |
| 411 |
% \end{macro} |
| 412 |
% |
| 413 |
% \begin{macro}{ breaking } |
| 414 |
% Set the breaking mark used in \meta{num format}. |
| 415 |
% \begin{macrocode} |
| 416 |
breaking .code:n = { |
| 417 |
\tl_gset:Nx \g__syu_secnum_bkmr {#1} |
| 418 |
}, |
| 419 |
% \end{macrocode} |
| 420 |
% \end{macro} |
| 421 |
% |
| 422 |
% \begin{macrocode} |
| 423 |
} |
| 424 |
% \end{macrocode} |
| 425 |
% |
| 426 |
% Passing keys to options. |
| 427 |
% \begin{macrocode} |
| 428 |
\ProcessKeysOptions{ syu / options } |
| 429 |
% \end{macrocode} |
| 430 |
% |
| 431 |
% \subsection{Main function} |
| 432 |
% \begin{macro}{\setsecnum} |
| 433 |
% Here is the definition of the main function \cs{setsecnum}. |
| 434 |
% \begin{macrocode} |
| 435 |
\DeclareDocumentCommand{\setsecnum}{m}{ |
| 436 |
% \end{macrocode} |
| 437 |
% Store the input in. |
| 438 |
% \begin{macrocode} |
| 439 |
\tl_set:Nn \l__syu_secnum_tl {#1} |
| 440 |
% \end{macrocode} |
| 441 |
% Replace syntax abbrs by corresponding macros. |
| 442 |
% \begin{macrocode} |
| 443 |
\__syu_secnum_unabbr:N \l__syu_secnum_tl |
| 444 |
% \end{macrocode} |
| 445 |
% Split into a sequence by macros. |
| 446 |
% \begin{macrocode} |
| 447 |
\__syu_split_by_macros:NNN |
| 448 |
\l__syu_secnum_tl \l__syu_secnum_seq \g__syu_secnum_depth |
| 449 |
% \end{macrocode} |
| 450 |
% Read formatting information. |
| 451 |
% \begin{macrocode} |
| 452 |
\__syu_secnum_from_seq:N \l__syu_secnum_seq |
| 453 |
% \end{macrocode} |
| 454 |
% Set the \opt{secnumdepth} and \opt{tocdepth}. |
| 455 |
% \changes{2020/01/12}{2020/01/12}{Add codes to set \opt{tocdepth}.} |
| 456 |
% \begin{macrocode} |
| 457 |
\setcounter{secnumdepth}{ |
| 458 |
\int_eval:n { \g__syu_secnum_depth - \g__syu_ifchapter_int } |
| 459 |
} |
| 460 |
\int_if_exist:NTF \g__syu_tocdep { |
| 461 |
\setcounter{tocdepth}{ \g__syu_tocdep } |
| 462 |
}{ |
| 463 |
\setcounter{tocdepth}{ |
| 464 |
\int_eval:n { \g__syu_secnum_depth - \g__syu_ifchapter_int } |
| 465 |
} |
| 466 |
} |
| 467 |
% \end{macrocode} |
| 468 |
% Format numberings. |
| 469 |
% \begin{macrocode} |
| 470 |
\__syu_secnum: |
| 471 |
} |
| 472 |
% \end{macrocode} |
| 473 |
% \end{macro} |
| 474 |
% |
| 475 |
% \subsection{Unabbravation} |
| 476 |
% \begin{variable}{ \__syu_secnum_unabbr:N } |
| 477 |
% This function replace the abbrs in a \meta{tl var} |
| 478 |
% by expansions. |
| 479 |
% \begin{macrocode} |
| 480 |
\cs_new_protected:Npn \__syu_secnum_unabbr:N #1 { |
| 481 |
\regex_replace_all:nnN {A} {\c{Alph}} #1 |
| 482 |
\regex_replace_all:nnN {a} {\c{alph}} #1 |
| 483 |
\regex_replace_all:nnN {I} {\c{Roman}} #1 |
| 484 |
\regex_replace_all:nnN {i} {\c{roman}} #1 |
| 485 |
\regex_replace_all:nnN {1} {\c{arabic}} #1 |
| 486 |
} |
| 487 |
% \end{macrocode} |
| 488 |
% \end{variable} |
| 489 |
% |
| 490 |
% \subsection{Split to sequence} |
| 491 |
% \changes{2022/01/29}{2022/01/29}{Rewrite the split functions.} |
| 492 |
% \begin{variable}{ \__syu_split_by_macros:NNN } |
| 493 |
% This function splits a \meta{tl var} into a \meta{sequence} |
| 494 |
% by macros and provides the number of macros it contains. |
| 495 |
% \begin{macrocode} |
| 496 |
\cs_new_protected:Npn \__syu_split_by_macros:NNN #1 #2 #3 { |
| 497 |
\tl_set:Nn \l_tmpa_tl {S} |
| 498 |
\seq_clear:N #2 |
| 499 |
\int_set:Nn #3 {0} |
| 500 |
\tl_map_inline:Nn #1 { |
| 501 |
\__syu_if_macro:nTF ##1 { |
| 502 |
\seq_put_right:NV #2 \l_tmpa_tl |
| 503 |
\tl_clear:N \l_tmpa_tl |
| 504 |
\tl_put_right:Nn \l_tmpa_tl ##1 |
| 505 |
\seq_put_right:NV #2 \l_tmpa_tl |
| 506 |
\tl_clear:N \l_tmpa_tl |
| 507 |
\int_incr:N #3 |
| 508 |
}{ |
| 509 |
\tl_put_right:Nn \l_tmpa_tl ##1 |
| 510 |
} |
| 511 |
} |
| 512 |
} |
| 513 |
% \end{macrocode} |
| 514 |
% \end{variable} |
| 515 |
% But how to see if an \meta{item} in the token list is a macro? |
| 516 |
% \begin{variable}{ \g__syu_macro_tl } |
| 517 |
% This \meta{tl var} stores the first five characters |
| 518 |
% of the meaning of any macro, |
| 519 |
% i.e. \opt{macro} (watch out its catcode). |
| 520 |
% The idea is to creat a \meta{tl var} and then set |
| 521 |
% its value to be the first five characters of its meaning. |
| 522 |
% \begin{macrocode} |
| 523 |
\tl_new:N \g__syu_macro_tl |
| 524 |
\tl_set:Nx \g__syu_macro_tl { \meaning \g__syu_macro_tl } |
| 525 |
\tl_gset:Nx \g__syu_macro_tl { \tl_range:Nnn \g__syu_macro_tl {1}{5} } |
| 526 |
% \end{macrocode} |
| 527 |
% \end{variable} |
| 528 |
% \begin{variable}{ \__syu_if_macro:nT, |
| 529 |
% \__syu_if_macro:nF, \__syu_if_macro:nTF, } |
| 530 |
% Then, define a conditional testing if the input is a macro. |
| 531 |
% Note that I use \cs{if_meaning} rather than \cs{tl_if_eq:NNTF}. |
| 532 |
% \begin{macrocode} |
| 533 |
\prg_new_protected_conditional:Npnn \__syu_if_macro:n #1 { T , F , TF }{ |
| 534 |
\group_begin: |
| 535 |
\tl_set:Nx \l_tmpa_tl {\meaning #1} |
| 536 |
\tl_set:Nx \l_tmpa_tl {\tl_range:Nnn \l_tmpa_tl {1} {5}} |
| 537 |
% \end{macrocode} |
| 538 |
% This is a trick to keep \cs{l_tmpa_tl} in the current local group |
| 539 |
% \begin{macrocode} |
| 540 |
\exp_after:wN |
| 541 |
\group_end: |
| 542 |
% \end{macrocode} |
| 543 |
% while throwing the comparison result out. |
| 544 |
% \begin{macrocode} |
| 545 |
\if_meaning:w \l_tmpa_tl \g__syu_macro_tl |
| 546 |
\prg_return_true: |
| 547 |
\else: |
| 548 |
\prg_return_false: |
| 549 |
\fi: |
| 550 |
} |
| 551 |
% \end{macrocode} |
| 552 |
% \end{variable} |
| 553 |
% |
| 554 |
% \subsection{Read formatting info} |
| 555 |
% \changes{2022/01/29}{2022/01/29}{Write them separately.} |
| 556 |
% \begin{variable}{ \__syu_secnum_from_seq:N } |
| 557 |
% Read the formatting info from given \meta{sequence}. |
| 558 |
% \begin{macrocode} |
| 559 |
\cs_new_protected:Npn \__syu_secnum_from_seq:N #1 { |
| 560 |
% \end{macrocode} |
| 561 |
% Use \cs{tl_gset:Nx} since: 1, these data are global and |
| 562 |
% 2: I need them eating the fully expanded results. |
| 563 |
% \begin{macrocode} |
| 564 |
\int_if_odd:nTF \g__syu_ifchapter_int { |
| 565 |
\tl_gset:Nx \g__syu_chapter_tl |
| 566 |
{ \seq_item:Nn #1 { 2 } } |
| 567 |
\tl_gset:Nx \g__syu_chapter_section_tl |
| 568 |
{ \seq_item:Nn #1 { 3 } } |
| 569 |
\tl_gset:Nx \g__syu_section_tl |
| 570 |
{ \seq_item:Nn #1 { 4 } } |
| 571 |
\tl_gset:Nx \g__syu_section_subsection_tl |
| 572 |
{ \seq_item:Nn #1 { 5 } } |
| 573 |
\tl_gset:Nx \g__syu_subsection_tl |
| 574 |
{ \seq_item:Nn #1 { 6 } } |
| 575 |
\tl_gset:Nx \g__syu_subsection_subsubsection_tl |
| 576 |
{ \seq_item:Nn #1 { 7 } } |
| 577 |
\tl_gset:Nx \g__syu_subsubsection_tl |
| 578 |
{ \seq_item:Nn #1 { 8 } } |
| 579 |
\tl_gset:Nx \g__syu_subsubsection_paragraph_tl |
| 580 |
{ \seq_item:Nn #1 { 9 } } |
| 581 |
\tl_gset:Nx \g__syu_paragraph_tl |
| 582 |
{ \seq_item:Nn #1 { 10 } } |
| 583 |
\tl_gset:Nx \g__syu_paragraph_subparagrah_tl |
| 584 |
{ \seq_item:Nn #1 { 11 } } |
| 585 |
\tl_gset:Nx \g__syu_subparagraph_tl |
| 586 |
{ \seq_item:Nn #1 { 12 } } |
| 587 |
}{ |
| 588 |
\tl_gset:Nx \g__syu_section_tl |
| 589 |
{ \seq_item:Nn #1 { 2 } } |
| 590 |
\tl_gset:Nx \g__syu_section_subsection_tl |
| 591 |
{ \seq_item:Nn #1 { 3 } } |
| 592 |
\tl_gset:Nx \g__syu_subsection_tl |
| 593 |
{ \seq_item:Nn #1 { 4 } } |
| 594 |
\tl_gset:Nx \g__syu_subsection_subsubsection_tl |
| 595 |
{ \seq_item:Nn #1 { 5 } } |
| 596 |
\tl_gset:Nx \g__syu_subsubsection_tl |
| 597 |
{ \seq_item:Nn #1 { 6 } } |
| 598 |
\tl_gset:Nx \g__syu_subsubsection_paragraph_tl |
| 599 |
{ \seq_item:Nn #1 { 7 } } |
| 600 |
\tl_gset:Nx \g__syu_paragraph_tl |
| 601 |
{ \seq_item:Nn #1 { 8 } } |
| 602 |
\tl_gset:Nx \g__syu_paragraph_subparagrah_tl |
| 603 |
{ \seq_item:Nn #1 { 9 } } |
| 604 |
\tl_gset:Nx \g__syu_subparagraph_tl |
| 605 |
{ \seq_item:Nn #1 { 10 } } |
| 606 |
} |
| 607 |
} |
| 608 |
% \end{macrocode} |
| 609 |
% \end{variable} |
| 610 |
% |
| 611 |
% \subsection{Formatting} |
| 612 |
% \changes{2022/01/29}{2022/01/29}{The whole function \cs{__syu_secnum:} is rewritten.} |
| 613 |
% \begin{variable}{ \__syu_secnum: } |
| 614 |
% Formatting section numbering. |
| 615 |
% \begin{macrocode} |
| 616 |
\cs_new:Nn \__syu_secnum: { |
| 617 |
% \end{macrocode} |
| 618 |
% \subsubsection{Detect if there is \cs{thechapter}}\noindent |
| 619 |
% When \cs{thechapter} is defined, start from it. |
| 620 |
% \begin{macrocode} |
| 621 |
\if_cs_exist:N \thechapter |
| 622 |
\renewcommand*{\thechapter}{ \g__syu_chapter_tl {chapter} } |
| 623 |
% \end{macrocode} |
| 624 |
% Test if the numbering breaks before section. |
| 625 |
% \begin{macrocode} |
| 626 |
\tl_if_in:NVTF \g__syu_chapter_section_tl \g__syu_secnum_bkmr { |
| 627 |
% \end{macrocode} |
| 628 |
% Remove the breaking marker. |
| 629 |
% \begin{macrocode} |
| 630 |
\tl_remove_all:NV |
| 631 |
\g__syu_chapter_section_tl \g__syu_secnum_bkmr |
| 632 |
% \end{macrocode} |
| 633 |
% Format \cs{thesection}. |
| 634 |
% \begin{macrocode} |
| 635 |
\renewcommand*{\thesection}{ \g__syu_section_tl {section} } |
| 636 |
% \end{macrocode} |
| 637 |
% Restore the \cs{p@}s. |
| 638 |
% \begin{macrocode} |
| 639 |
\makeatletter |
| 640 |
\renewcommand*{\p@section}{ |
| 641 |
\thechapter\g__syu_chapter_section_tl |
| 642 |
} |
| 643 |
\renewcommand*{\p@subsection}{ \p@section} |
| 644 |
\renewcommand*{\p@subsubsection}{ \p@section } |
| 645 |
\renewcommand*{\p@paragraph}{ \p@section} |
| 646 |
\renewcommand*{\p@subparagraph}{ \p@section } |
| 647 |
\makeatother |
| 648 |
}{ |
| 649 |
% \end{macrocode} |
| 650 |
% Format \cs{thesection}. |
| 651 |
% \begin{macrocode} |
| 652 |
\renewcommand*{\thesection}{ |
| 653 |
\thechapter\g__syu_chapter_section_tl |
| 654 |
\g__syu_section_tl {section} |
| 655 |
} |
| 656 |
} |
| 657 |
% \end{macrocode} |
| 658 |
% Otherwise start from \cs{thesection}. |
| 659 |
% \begin{macrocode} |
| 660 |
\else: |
| 661 |
\renewcommand*{\thesection}{ \g__syu_section_tl {section} } |
| 662 |
\fi: |
| 663 |
% \end{macrocode} |
| 664 |
% |
| 665 |
% \changes{2021/08/28}{2021/08/28}{The usage of breaking commas.} |
| 666 |
% \subsubsection{Subsections}\noindent |
| 667 |
% Test if the subsections are needed to be numbered. |
| 668 |
% \begin{macrocode} |
| 669 |
\tl_if_empty:NF \g__syu_subsection_tl { |
| 670 |
% \end{macrocode} |
| 671 |
% Test if the numbering breaks before subsection. |
| 672 |
% \begin{macrocode} |
| 673 |
\tl_if_in:NVTF \g__syu_section_subsection_tl \g__syu_secnum_bkmr { |
| 674 |
% \end{macrocode} |
| 675 |
% Remove the breaking marker. |
| 676 |
% \begin{macrocode} |
| 677 |
\tl_remove_all:NV |
| 678 |
\g__syu_section_subsection_tl \g__syu_secnum_bkmr |
| 679 |
% \end{macrocode} |
| 680 |
% Format \cs{thesubsection}. |
| 681 |
% \begin{macrocode} |
| 682 |
\renewcommand*{\thesubsection}{ \g__syu_subsection_tl {subsection} } |
| 683 |
% \end{macrocode} |
| 684 |
% Restore the \cs{p@}s. |
| 685 |
% \begin{macrocode} |
| 686 |
\makeatletter |
| 687 |
\renewcommand*{\p@subsection}{ |
| 688 |
\p@section\g__syu_section_tl{section} |
| 689 |
\g__syu_section_subsection_tl |
| 690 |
} |
| 691 |
\renewcommand*{\p@subsubsection}{ \p@subsection } |
| 692 |
\renewcommand*{\p@paragraph}{ \p@subsection} |
| 693 |
\renewcommand*{\p@subparagraph}{ \p@subsection } |
| 694 |
\makeatother |
| 695 |
}{ |
| 696 |
% \end{macrocode} |
| 697 |
% Format \cs{thesubsection}. |
| 698 |
% \begin{macrocode} |
| 699 |
\renewcommand*{\thesubsection}{ |
| 700 |
\thesection\g__syu_section_subsection_tl |
| 701 |
\g__syu_subsection_tl {subsection} |
| 702 |
} |
| 703 |
} |
| 704 |
} |
| 705 |
% \end{macrocode} |
| 706 |
% |
| 707 |
% \subsubsection{Subsubsections}\noindent |
| 708 |
% Test if the subsubsections are needed to be numbered. |
| 709 |
% \begin{macrocode} |
| 710 |
\tl_if_empty:NF \g__syu_subsubsection_tl { |
| 711 |
% \end{macrocode} |
| 712 |
% Test if the numbering breaks before subsubsection. |
| 713 |
% \begin{macrocode} |
| 714 |
\tl_if_in:NVTF \g__syu_subsection_subsubsection_tl \g__syu_secnum_bkmr { |
| 715 |
% \end{macrocode} |
| 716 |
% Remove the breaking marker. |
| 717 |
% \begin{macrocode} |
| 718 |
\tl_remove_all:NV |
| 719 |
\g__syu_subsection_subsubsection_tl \g__syu_secnum_bkmr |
| 720 |
% \end{macrocode} |
| 721 |
% Format \cs{thesubsubsection}. |
| 722 |
% \begin{macrocode} |
| 723 |
\renewcommand*{\thesubsubsection} |
| 724 |
{ \g__syu_subsubsection_tl {subsubsection} } |
| 725 |
% \end{macrocode} |
| 726 |
% Restore the \cs{p@}s. |
| 727 |
% \begin{macrocode} |
| 728 |
\makeatletter |
| 729 |
\renewcommand*{\p@subsubsection}{ |
| 730 |
\p@subsection\g__syu_subsection_tl {subsection} |
| 731 |
\g__syu_subsection_subsubsection_tl |
| 732 |
} |
| 733 |
\renewcommand*{\p@paragraph}{ \p@subsubsection} |
| 734 |
\renewcommand*{\p@subparagraph}{ \p@subsubsection } |
| 735 |
\makeatother |
| 736 |
}{ |
| 737 |
% \end{macrocode} |
| 738 |
% Format \cs{thesubsubsection}. |
| 739 |
% \begin{macrocode} |
| 740 |
\renewcommand*{\thesubsubsection}{ |
| 741 |
\thesubsection\g__syu_subsection_subsubsection_tl |
| 742 |
\g__syu_subsubsection_tl {subsubsection} |
| 743 |
} |
| 744 |
} |
| 745 |
} |
| 746 |
% \end{macrocode} |
| 747 |
% |
| 748 |
% \subsubsection{Paragraphs}\noindent |
| 749 |
% Test if the paragraphs are needed to be numbered. |
| 750 |
% \begin{macrocode} |
| 751 |
\tl_if_empty:NF \g__syu_paragraph_tl { |
| 752 |
% \end{macrocode} |
| 753 |
% Test if the numbering breaks before paragraph. |
| 754 |
% \begin{macrocode} |
| 755 |
\tl_if_in:NVTF \g__syu_subsubsection_paragraph_tl \g__syu_secnum_bkmr { |
| 756 |
% \end{macrocode} |
| 757 |
% Remove the breaking marker. |
| 758 |
% \begin{macrocode} |
| 759 |
\tl_remove_all:NV |
| 760 |
\g__syu_subsubsection_paragraph_tl \g__syu_secnum_bkmr |
| 761 |
% \end{macrocode} |
| 762 |
% Format \cs{theparagraph}. |
| 763 |
% \begin{macrocode} |
| 764 |
\renewcommand*{\theparagraph}{ \g__syu_paragraph_tl {paragraph} } |
| 765 |
% \end{macrocode} |
| 766 |
% Restore the \cs{p@}s. |
| 767 |
% \begin{macrocode} |
| 768 |
\makeatletter |
| 769 |
\renewcommand*{\p@paragraph}{ |
| 770 |
\p@subsubsection\g__syu_subsubsection_tl {subsubsection} |
| 771 |
\g__syu_subsubsection_paragraph_tl |
| 772 |
} |
| 773 |
\renewcommand*{\p@subparagraph}{ \p@paragraph } |
| 774 |
\makeatother |
| 775 |
}{ |
| 776 |
% \end{macrocode} |
| 777 |
% Format \cs{theparagraph}. |
| 778 |
% \begin{macrocode} |
| 779 |
\renewcommand*{\theparagraph}{ |
| 780 |
\thesubsubsection\g__syu_subsubsection_paragraph_tl |
| 781 |
\g__syu_paragraph_tl {paragraph} |
| 782 |
} |
| 783 |
} |
| 784 |
} |
| 785 |
% \end{macrocode} |
| 786 |
% |
| 787 |
% \subsubsection{Subparagraphs}\noindent |
| 788 |
% Test if the subparagraphs are needed to be numbered. |
| 789 |
% \begin{macrocode} |
| 790 |
\tl_if_empty:NF \g__syu_subparagraph_tl { |
| 791 |
% \end{macrocode} |
| 792 |
% Test if the numbering breaks before paragraph. |
| 793 |
% \begin{macrocode} |
| 794 |
\tl_if_in:NVTF \g__syu_paragraph_subparagrah_tl \g__syu_secnum_bkmr { |
| 795 |
% \end{macrocode} |
| 796 |
% Remove the breaking marker. |
| 797 |
% \begin{macrocode} |
| 798 |
\tl_remove_all:NV |
| 799 |
\g__syu_paragraph_subparagrah_tl \g__syu_secnum_bkmr |
| 800 |
% \end{macrocode} |
| 801 |
% Format \cs{thesubparagraph}. |
| 802 |
% \begin{macrocode} |
| 803 |
\renewcommand*{\thesubparagraph}{ \g__syu_subparagraph_tl {subparagraph} } |
| 804 |
% \end{macrocode} |
| 805 |
% Restore the \cs{p@}s. |
| 806 |
% \begin{macrocode} |
| 807 |
\makeatletter |
| 808 |
\renewcommand*{\p@subparagraph}{ |
| 809 |
\p@paragraph\g__syu_paragraph_tl {paragraph} |
| 810 |
\g__syu_paragraph_subparagrah_tl |
| 811 |
} |
| 812 |
\makeatother |
| 813 |
}{ |
| 814 |
% \end{macrocode} |
| 815 |
% Format \cs{thesubparagraph}. |
| 816 |
% \begin{macrocode} |
| 817 |
\renewcommand*{\thesubparagraph}{ |
| 818 |
\theparagraph\g__syu_paragraph_subparagrah_tl |
| 819 |
\g__syu_subparagraph_tl {subparagraph} |
| 820 |
} |
| 821 |
} |
| 822 |
} |
| 823 |
} |
| 824 |
% \end{macrocode} |
| 825 |
% \end{variable} |
| 826 |
% |
| 827 |
% \begin{macrocode} |
| 828 |
%</package> |
| 829 |
% \end{macrocode} |
| 830 |
%\end{implementation} |
| 831 |
% |
| 832 |
% |
| 833 |
% \changes{2020/01/01}{2020/01/01}{Correct the package name.} |
| 834 |
% |
| 835 |
% \Finale |
| 836 |
\endinput |