diff options
Diffstat (limited to 'macros/latex/contrib/updatemarks/tex/updatemarks.sty')
-rw-r--r-- | macros/latex/contrib/updatemarks/tex/updatemarks.sty | 225 |
1 files changed, 172 insertions, 53 deletions
diff --git a/macros/latex/contrib/updatemarks/tex/updatemarks.sty b/macros/latex/contrib/updatemarks/tex/updatemarks.sty index ab5acb8aa3..244ce20b5f 100644 --- a/macros/latex/contrib/updatemarks/tex/updatemarks.sty +++ b/macros/latex/contrib/updatemarks/tex/updatemarks.sty @@ -1,12 +1,12 @@ % updatemarks.sty -% Copyright 2023 Wenjian Chern. +% Copyright 2023, 2024 Wenjian Chern. % % This work may be distributed and/or modified under the -% conditions of the LaTeX Project Public License, either version 1.3 +% conditions of the LaTeX Project Public License, either version 1.3c % of this license or any later version. % 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 +% and version 1.3c or later is part of all distributions of LaTeX % version 2005/12/01 or later. % % This work has the LPPL maintenance status `maintained'. @@ -16,27 +16,38 @@ % This work consists of the files updatemarks.sty and updatemarks.tex % \NeedsTeXFormat{LaTeX2e} -\@ifundefined{ProvidesExplPackage}{\RequirePackage{expl3}}{} \@ifundefined{NewDocumentCommand}{\RequirePackage{xparse}}{} -\ProvidesExplPackage{updatemarks}{2023/09/03}{0.2b}{extract and update marks from box} +\ProvidesExplPackage{updatemarks}{2024/02/19}{0.2e}{extract and update marks from box} \RequirePackage{etoolbox} +\RequirePackage{updatemarks-nums} \seq_new:N \g__updatemarks_seq \box_new:N \l__updatemarks_r_box \cs_new_eq:NN \l__updatemarks_s_box \l_tmpa_box % this box is used for locally split \tex_countdef:D \g_updatemarks_max_int 256 \exp_stop_f: \tl_new:N \l__updatemarks_tl +\tl_new:N \g__updatemarks_saved_tl - -%% basicly copy from \__mark_update_structure:nn of LaTeX kernel -\cs_new_protected:Npn \__updatemarks_extract:nnn #1#2#3 % box, map of number, code +%% basicly copy from \__mark_extract_and_handle_marks:nn of LaTeX kernel +\cs_new_protected:Npn \__updatemarks_extract:nnn #1#2#3 % material, map of number, code + { + \__updatemarks_extract:nn {#1} + { \__updatemarks_extract_split:nn {#2} {#3} } + } +\cs_new_protected:Npn \__updatemarks_extract:nn #1#2 % material, code { \group_begin: \dim_set_eq:NN \tex_splitmaxdepth:D \c_max_dim \int_set_eq:NN \tex_vbadness:D \c_max_int \dim_set_eq:NN \tex_vfuzz:D \c_max_dim + \__updatemarks_prepare_and_extract:nn {#2} {#1} + \group_end: + } +% old mechanism +\cs_new_protected:Npn \__updatemarks_prepare_and_extract:nn #1#2 % code, material + { \vbox_set_to_ht:Nnw \l__updatemarks_r_box { -.5 \c_max_dim } - #1 \tex_unskip:D + #2 \tex_unskip:D \box_set_to_last:N \l__updatemarks_r_box \int_compare:nNnT { \tex_lastnodetype:D } < { 0 } { @@ -53,18 +64,15 @@ \int_compare:nNnTF { \tex_badness:D } > { 0 } { \vbox_set_split_to_ht:NNn \l__updatemarks_s_box \l__updatemarks_r_box \c_max_dim - \__updatemarks_extract_split:nn {#2} {#3} + #1 } - { - \msg_error:nn { updatemarks } { infinite-shrinkage } - #2 - { - \cs_undefine:N \l_updatemarks_first_tl - \cs_undefine:N \l_updatemarks_last_tl - #3 - } - } - \group_end: + { \msg_error:nn { updatemarks } { infinite-shrinkage } } + } +% new mechanism, copy a LaTeX kernel command +\cs_if_exist:NT \__mark_prepare_and_extract:nn + { + \cs_gset_eq:NN \__updatemarks_prepare_and_extract:nn + \__mark_prepare_and_extract:nn } \cs_new_protected:Npn \__updatemarks_extract_split:nn #1#2 % map of number, code { @@ -76,7 +84,11 @@ \cs_undefine:N \l_updatemarks_first_tl \cs_undefine:N \l_updatemarks_last_tl } - { \tl_set:No \l_updatemarks_first_tl { \tex_splitfirstmarks:D ##1 } } + { + \tl_set:No \l_updatemarks_first_tl { \tex_splitfirstmarks:D ##1 } + \tl_if_empty:NT \l_updatemarks_first_tl + { \cs_undefine:N \l_updatemarks_first_tl } + } #2 } } @@ -89,6 +101,32 @@ \tl_gset_eq:cN { g__updatemarks_last-#1_tl } \l_updatemarks_last_tl } } +\cs_new_protected:Npn \__updatemarks_extract_for_reinsertion:nn #1#2 % material, map + { + \__updatemarks_extract:nn {#1} + { + #2 + { + \tl_if_empty:oF { \tex_splitbotmarks:D ##1 } + { + \tl_if_empty:oF { \tex_splitfirstmarks:D ##1 } + { + \tl_gput_right:Nx \g__updatemarks_saved_tl + { + \tex_marks:D ##1 + { \exp_not:N \exp_not:n { \tex_splitfirstmarks:D ##1 } } + } + } + \tl_gput_right:Nx \g__updatemarks_saved_tl + { + \tex_marks:D ##1 + { \exp_not:N \exp_not:n { \tex_splitbotmarks:D ##1 } } + } + } + } + } + } + \cs_new_protected:Npn \updatemarks_extract:nN #1#2 % box material, seq { \__updatemarks_extract:nnn {#1} @@ -101,22 +139,77 @@ { \seq_map_inline:Nn #1 } { \__updatemarks_extract_num:n {##1} } } +\cs_new_protected:Npn \updatemarks_extract:nNN #1#2#3 + { + \tl_clear:N \g__updatemarks_saved_tl + \__updatemarks_extract_for_reinsertion:nn {#1} + { \seq_map_inline:Nn #2 } + \tl_set_eq:NN #3 \g__updatemarks_saved_tl + } +\cs_new_eq:NN \__updatemarks_extract_act:n ? +\cs_new_protected:Npn \updatemarks_extract_act:nNn #1#2#3 % material, seq, code + { + \cs_set_protected:Npn \__updatemarks_extract_act:n ##1 {#3} + \__updatemarks_extract:nnn {#1} + { \seq_map_inline:Nn #2 } + { \__updatemarks_extract_act:n {##1} } + } +\bool_new:N \l_updatemarks_nonempty_bool +\tl_new:N \l__updatemarks_saved_tl \cs_new_protected:Npn \updatemarks_save:Nnn #1#2#3 % seq, pos, value { - \seq_map_inline:Nn #1 - { \tl_gset:co { g__updatemarks_#2-##1_tl } { #3 {##1} } } + \bool_if:NTF \l_updatemarks_nonempty_bool + { + \seq_map_inline:Nn #1 + { + \tl_set:No \l__updatemarks_saved_tl { #3 {##1} } + \tl_if_empty:NF \l__updatemarks_saved_tl + { \tl_gset_eq:cN { g__updatemarks_#2-##1_tl } \l__updatemarks_saved_tl } + } + } + { + \seq_map_inline:Nn #1 + { + \tl_gset:co { g__updatemarks_#2-##1_tl } { #3 {##1} } + } + } } -\cs_new_protected:Npn \updatemarks_save_x:Nnn #1#2#3 % seq, pos, value +\cs_new_protected:Npn \updatemarks_save_e:Nnn #1#2#3 % seq, pos, value { - \seq_map_inline:Nn #1 - { \tl_gset:cx { g__updatemarks_#2-##1_tl } { #3 {##1} } } + \bool_if:NTF \l_updatemarks_nonempty_bool + { + \seq_map_inline:Nn #1 + { + \tl_set:Nx \l__updatemarks_saved_tl { #3 {##1} } + \tl_if_empty:NF \l__updatemarks_saved_tl + { \tl_gset_eq:cN { g__updatemarks_#2-##1_tl } \l__updatemarks_saved_tl } + } + } + { + \seq_map_inline:Nn #1 + { + \tl_gset:cx { g__updatemarks_#2-##1_tl } { #3 {##1} } + } + } } +\cs_new_eq:NN \updatemarks_save_x:Nnn \updatemarks_save_e:Nnn \cs_new_protected:Npn \updatemarks_alias:Nnn #1#2#3 % seq, pos1, pos2 { - \seq_map_inline:Nn #1 - { \tl_gset_eq:cc { g__updatemarks_#2-##1_tl } { g__updatemarks_#3-##1_tl } } + \bool_if:NTF \l_updatemarks_nonempty_bool + { + \seq_map_inline:Nn #1 + { + \tl_set_eq:Nc \l__updatemarks_saved_tl { g__updatemarks_#3-##1_tl } + \tl_if_empty:NF \l__updatemarks_saved_tl + { \tl_gset_eq:cN { g__updatemarks_#2-##1_tl } \l__updatemarks_saved_tl } + } + } + { + \seq_map_inline:Nn #1 + { \tl_gset_eq:cc { g__updatemarks_#2-##1_tl } { g__updatemarks_#3-##1_tl } } + } } \cs_new_protected:Npn \updatemarks_remove:Nn #1#2 % seq, pos { \seq_map_inline:Nn #1 { \cs_undefine:c { g__updatemarks_#2-##1_tl } } } @@ -145,30 +238,32 @@ \if@nobreak\ifvmode\nobreak\fi\fi } } -% do not check if it is <= \g_updatemarks_max_int \cs_new_protected:Npn \__updatemarks_gput:Nn #1#2 { \group_begin: \cs_set_eq:NN \MarkClass \__updatemarks_class_num:n \cs_set_eq:NN \MaxClass \g_updatemarks_max_int - \clist_map_inline:nn {#2} - { \seq_gput_right:Nx #1 { \int_eval:n { \__updatemarks_maybe_class:n {##1} } } } + \parserange_use_delimiter:n { -> } + \parserange_check: + \parserange_set_to_int:n { \__updatemarks_maybe_class:n {##1} } + \parserange:nnnN { 0 } { \g_updatemarks_max_int } {#2} \g__updatemarks_seq + \seq_gset_eq:NN #1 \g__updatemarks_seq \seq_gremove_duplicates:N #1 \group_end: } +\cs_new_protected:Npn \updatemarks_parse_classes:Nn { \__updatemarks_gput:Nn } -\cs_new:Npn \__updatemarks_class_num:n #1 { \cs:w c__mark_class_ #1 _mark \cs_end: } +\cs_new:Npn \__updatemarks_class_num:n #1 + { + \cs_if_exist_use:cF { c__mark_class_ #1 _mark } + { -1 \msg_expandable_error:nnn { updatemarks } { unknown-class } {#1} } + } \cs_new:Npn \__updatemarks_maybe_class:n #1 { \tl_if_head_eq_meaning:nNTF {#1} [ % ] { \__updatemarks_maybe_class_aux:w #1 } {#1} } -\cs_new:Npn \__updatemarks_maybe_class_aux:w [#1] - { - \cs_if_exist_use:cF { c__mark_class_ #1 _mark } - { 0 \msg_expandable_error:nnn { updatemarks } { unknown-class } {#1} } - } - +\cs_new:Npn \__updatemarks_maybe_class_aux:w [#1] { \__updatemarks_class_num:n {#1} } \seq_new:N \g_updatemarks_seq @@ -200,6 +295,34 @@ \g__updatemarks_seq } } +\NewDocumentCommand \ExtractMarksTo { s o +m m } + { + \tl_if_novalue:nTF {#2} + { + \updatemarks_extract:nNN + { + \bool_if:nTF {#1} { #3 } + { + \if_hbox:N #3 \hbox_unpack:N #3 \scan_stop: \fi: + \if_vbox:N #3 \vbox_unpack:N #3 \scan_stop: \fi: + } + } + \g_updatemarks_seq #4 + } + { + \seq_gclear:N \g__updatemarks_seq + \__updatemarks_gput:Nn \g__updatemarks_seq {#2} + \updatemarks_extract:nNN + { + \bool_if:nTF {#1} { #3 } + { + \if_hbox:N #3 \hbox_unpack:N #3 \scan_stop: \fi: + \if_vbox:N #3 \vbox_unpack:N #3 \scan_stop: \fi: + } + } + \g__updatemarks_seq #4 + } + } \NewDocumentCommand \ExtractSplitMarks { o } { \tl_if_novalue:nTF {#1} @@ -259,11 +382,7 @@ } } { - \AtBeginDocument - { - \int_step_inline:nnn { 0 } { \g_updatemarks_max_int } - { \seq_gput_right:Nn \g_updatemarks_seq {#1} } - } + \AtBeginDocument { \AddAllocatedToUpdateMarksList } } \msg_new:nnn { updatemarks } { unknown-class } { Unknown~mark~class~`#1'. } @@ -316,7 +435,8 @@ \apptocmd \endminipage { \updatemarks@of{minipage} } { } { \ERROR } } % tcolorbox -\providecommand \updatemarks@tcolorbox@patch +\cs_if_exist:NTF \updatemarks@tcolorbox@patch { \use_none:n } + { \tl_const:Nn \updatemarks@tcolorbox@patch } { \tcbset{updatemarks/.is~choice, updatemarks/true/.code=\bool_set_true:N \l__updatemarks_tcolorbox_bool, @@ -363,7 +483,8 @@ \fi } % multicol -\providecommand \updatemarks@multicol@patch +\cs_if_exist:NTF \updatemarks@multicol@patch { \use_none:n } + { \tl_const:Nn \updatemarks@multicol@patch } { %% the patch is used to extract marks \tl_set:No \set@keptmarks @@ -402,14 +523,16 @@ % patches of new mark mechanism \updatemarks@multicolnewmark@patch } -\providecommand \updatemarks@adjmulticol@patch +\cs_if_exist:NTF \updatemarks@adjmulticol@patch { \use_none:n } + { \tl_const:Nn \updatemarks@adjmulticol@patch } { \patchcmd \adjmc@process@ne@column { \unvbox } { \extractmarks@of{multicol}{\unvcopy\mult@box}\unvbox } { } { \ERROR } \updatemarks@adjmulticolnewmark@patch } -\providecommand \updatemarks@paracol@patch +\cs_if_exist:NTF \updatemarks@paracol@patch { \use_none:n } + { \tl_const:Nn \updatemarks@paracol@patch } { \updatemarks@paracolnewmark@patch } @@ -451,12 +574,8 @@ { \bool_if:NT \l__updatemarks_multicol_bool { - \seq_map_inline:Nn \g_updatemarks_seq - { - \tl_set:Nx \l__updatemarks_tl { \updatemarks_value:nn { top } {#1} } - \tl_if_empty:NT \l__updatemarks_tl - { \tl_gset:co { g__updatemarks_top-#1_tl } { \tex_topmarks:D #1 } } - } + \bool_set_false:N \l_updatemarks_nonempty_bool + \updatemarks_save:Nnn \g_updatemarks_seq { top } { \tex_topmarks:D \use:n } } } \tl_const:Nn \updatemarks@multicol@middlepage |