%% %% This is file `secnum.sty', %% generated with the docstrip utility. %% %% The original source files were: %% %% secnum.dtx (with options: `package') %% %% Copyright (C) 2019-- %% Gau, Syu ( GauSyu@Gmail.com ) %% %% ---------------------------------------------------------------------- %% %% This work may be distributed and/or modified under the %% conditions of the LaTeX Project Public License, either %% version 1.3c of this license or (at your option) any later %% version. This version of this license is in %% http://www.latex-project.org/lppl/lppl-1-3c.txt %% and the latest version of this license is in %% http://www.latex-project.org/lppl.txt %% and version 1.3 or later is part of all distributions of %% LaTeX version 2005/12/01 or later. %% %% This work has the LPPL maintenance status `maintained'. %% %% The Current Maintainer of this work is %% Gau, Syu ( GauSyu@Gmail.com ). %% %% ---------------------------------------------------------------------- %% \NeedsTeXFormat{LaTeX2e} \RequirePackage{expl3} \ProvidesExplPackage{secnum}{2020/02/02}{} { An intuitive way to format section numbering } \RequirePackage{xparse} \tl_new:N \l__syu_secnum_tl \seq_new:N \l__syu_secnum_seq \tl_new:N \g__syu_chapter_tl \tl_new:N \g__syu_section_tl \tl_new:N \g__syu_subsection_tl \tl_new:N \g__syu_subsubsection_tl \tl_new:N \g__syu_paragraph_tl \tl_new:N \g__syu_subparagraph_tl \int_new:N \g__syu_if_thechapter_int \if_cs_exist:N \thechapter \int_gset:Nn \g__syu_if_thechapter_int 1 \else: \int_gset:Nn \g__syu_if_thechapter_int 0 \fi: \DeclareDocumentCommand{\setsecnum}{m} { \tl_set:Nn \l__syu_secnum_tl {#1} \__syu_secnum_unabbr:N \l__syu_secnum_tl \__syu_split_by_macros:NN \l__syu_secnum_tl \l__syu_secnum_seq \__syu_secnum_from_seq:N \l__syu_secnum_seq \setcounter{secnumdepth}{ \seq_count:N \l__syu_secnum_seq } \setcounter{tocdepth}{ \seq_count:N \l__syu_secnum_seq } \__syu_secnum: } \cs_new_protected:Npn \__syu_secnum_unabbr:N #1 { \regex_replace_all:nnN {A} {\c{Alph}} #1 \regex_replace_all:nnN {a} {\c{alph}} #1 \regex_replace_all:nnN {I} {\c{Roman}} #1 \regex_replace_all:nnN {i} {\c{roman}} #1 \regex_replace_all:nnN {1} {\c{arabic}} #1 } \cs_new_protected:Npn \__syu_split_by_macros:NN #1 #2 { \tl_clear:N \l_tmpa_tl \seq_clear:N #2 \tl_map_inline:Nn #1 { \tl_put_right:Nn \l_tmpa_tl ##1 \__syu_if_macro:nT ##1 { \seq_put_right:NV #2 \l_tmpa_tl \tl_clear:N \l_tmpa_tl } } } \tl_new:N \g__syu_macro_tl \tl_set:Nx \g__syu_macro_tl { \meaning \g__syu_macro_tl } \tl_gset:Nx \g__syu_macro_tl { \tl_range:Nnn \g__syu_macro_tl {1}{5} } \prg_new_protected_conditional:Npnn \__syu_if_macro:n #1 { T , F , TF } { \group_begin: \tl_set:Nx \l_tmpa_tl {\meaning #1} \tl_set:Nx \l_tmpa_tl {\tl_range:Nnn \l_tmpa_tl {1} {5}} \exp_after:wN \group_end: \if_meaning:w \l_tmpa_tl \g__syu_macro_tl \prg_return_true: \else: \prg_return_false: \fi: } \cs_new_protected:Npn \__syu_secnum_from_seq:N #1 { \tl_gset:Nx \g__syu_chapter_tl { \seq_item:Nn #1 { \g__syu_if_thechapter_int } } \tl_gset:Nx \g__syu_section_tl { \seq_item:Nn #1 { 1 + \g__syu_if_thechapter_int } } \tl_gset:Nx \g__syu_subsection_tl { \seq_item:Nn #1 { 2 + \g__syu_if_thechapter_int } } \tl_gset:Nx \g__syu_subsubsection_tl { \seq_item:Nn #1 { 3 + \g__syu_if_thechapter_int } } \tl_gset:Nx \g__syu_paragraph_tl { \seq_item:Nn #1 { 4 + \g__syu_if_thechapter_int } } \tl_gset:Nx \g__syu_subparagraph_tl { \seq_item:Nn #1 { 5 + \g__syu_if_thechapter_int } } } \cs_new:Nn \__syu_secnum: { \if_cs_exist:N \thechapter \renewcommand*{\thechapter} { \g__syu_chapter_tl {chapter} } \renewcommand*{\thesection} { \thechapter \g__syu_section_tl {section} } \else: \renewcommand*{\thesection} { \g__syu_section_tl {section} } \fi: \renewcommand*{\thesubsection} { \thesection \g__syu_subsection_tl {subsection} } \renewcommand*{\thesubsubsection} { \thesubsection \g__syu_subsubsection_tl {subsubsection} } \renewcommand*{\theparagraph} { \thesubsubsection \g__syu_paragraph_tl {paragraph} } \renewcommand*{\thesubparagraph} { \theparagraph \g__syu_subparagraph_tl {subparagraph} } } \endinput %% %% End of file `secnum.sty'.