diff options
Diffstat (limited to 'Master/texmf-dist/tex/latex/l3experimental/l3sort/l3sort.sty')
-rw-r--r-- | Master/texmf-dist/tex/latex/l3experimental/l3sort/l3sort.sty | 283 |
1 files changed, 198 insertions, 85 deletions
diff --git a/Master/texmf-dist/tex/latex/l3experimental/l3sort/l3sort.sty b/Master/texmf-dist/tex/latex/l3experimental/l3sort/l3sort.sty index bc2c7375122..bc01c1d4039 100644 --- a/Master/texmf-dist/tex/latex/l3experimental/l3sort/l3sort.sty +++ b/Master/texmf-dist/tex/latex/l3experimental/l3sort/l3sort.sty @@ -6,48 +6,21 @@ %% %% l3sort.dtx (with options: `package') %% -%% EXPERIMENTAL CODE +%% Copyright (C) 2012-2016 The LaTeX3 Project %% -%% Do not distribute this file without also distributing the -%% source files specified above. +%% It may be distributed and/or modified under the conditions of +%% the LaTeX Project Public License (LPPL), either version 1.3c of +%% this license or (at your option) any later version. The latest +%% version of this license is in the file: %% -%% Do not distribute a modified version of this file. -%% -%% File l3sort.dtx (C) Copyright 2012,2014-2016 The LaTeX3 Project -%% -%% It may be distributed and/or modified under the conditions of the -%% LaTeX Project Public License (LPPL), either version 1.3c of this -%% license or (at your option) any later version. The latest version -%% of this license is in the file -%% %% http://www.latex-project.org/lppl.txt -%% +%% %% This file is part of the "l3experimental bundle" (The Work in LPPL) %% and all files in that bundle must be distributed together. -%% -%% The released version of this bundle is available from CTAN. -%% -%% ----------------------------------------------------------------------- -%% -%% The development version of the bundle can be found at -%% -%% http://www.latex-project.org/svnroot/experimental/trunk/ -%% -%% for those people who are interested. -%% -%%%%%%%%%%% -%% NOTE: %% -%%%%%%%%%%% -%% -%% Snapshots taken from the repository represent work in progress and may -%% not work or may contain conflicting material! We therefore ask -%% people _not_ to put them into distributions, archives, etc. without -%% prior consultation with the LaTeX Project Team. -%% -%% ----------------------------------------------------------------------- -%% -\RequirePackage{expl3}[2016/11/21] -\@ifpackagelater{expl3}{2016/11/21} +%% +%% File l3sort.dtx (C) Copyright 2012,2014-2016 The LaTeX3 Project +\RequirePackage{expl3}[2017/01/28] +\@ifpackagelater{expl3}{2017/01/28} {} {% \PackageError{l3sort}{Support package l3kernel too old} @@ -59,33 +32,110 @@ }% \endinput } -\GetIdInfo$Id: l3sort.dtx 6760 2016-11-21 20:35:31Z joseph $ +\GetIdInfo$Id: l3sort.dtx 6829 2017-01-28 08:52:51Z joseph $ {L3 Experimental sorting functions} \ProvidesExplPackage {\ExplFileName}{\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription} -\int_const:Nn \c__sort_max_length_int - { \sys_if_engine_luatex:TF { 49152 } { 24576 } } \int_new:N \l__sort_length_int +\int_new:N \l__sort_min_int +\int_new:N \l__sort_top_int +\int_new:N \l__sort_max_int +\int_new:N \l__sort_true_max_int \int_new:N \l__sort_block_int \int_new:N \l__sort_begin_int \int_new:N \l__sort_end_int \int_new:N \l__sort_A_int \int_new:N \l__sort_B_int \int_new:N \l__sort_C_int +\cs_new_protected:Npn \__sort_shrink_range: + { + \int_set:Nn \l__sort_A_int + { \l__sort_true_max_int - \l__sort_min_int + \c_one } + \int_set:Nn \l__sort_block_int { \c_max_register_int / \c_two } + \__sort_shrink_range_loop: + \int_set:Nn \l__sort_max_int + { + \int_compare:nNnTF + { \l__sort_block_int * \c_three / \c_two } > \l__sort_A_int + { + \l__sort_min_int + + ( \l__sort_A_int - \c_one ) / \c_two + + \l__sort_block_int / \c_four + - \c_one + } + { \l__sort_true_max_int - \l__sort_block_int / \c_two } + } + } +\cs_new_protected:Npn \__sort_shrink_range_loop: + { + \if_int_compare:w \l__sort_A_int < \l__sort_block_int + \tex_divide:D \l__sort_block_int \c_two + \exp_after:wN \__sort_shrink_range_loop: + \fi: + } +\cs_new_protected:Npn \__sort_compute_range: + { + \int_set:Nn \l__sort_min_int { \tex_count:D 15 + \c_one } + \int_set:Nn \l__sort_true_max_int { \c_max_register_int + \c_one } + \__sort_shrink_range: + \if_meaning:w \loctoks \tex_undefined:D \else: + \if_meaning:w \loctoks \scan_stop: \else: + \__sort_redefine_compute_range: + \__sort_compute_range: + \fi: + \fi: + } +\cs_new_protected:Npn \__sort_redefine_compute_range: + { + \cs_if_exist:cTF { ver@elocalloc.sty } + { + \cs_gset_protected:Npn \__sort_compute_range: + { + \int_set:Nn \l__sort_min_int { \tex_count:D 265 } + \int_set_eq:NN \l__sort_true_max_int \e@alloc@top + \__sort_shrink_range: + } + } + { + \cs_gset_protected:Npn \__sort_compute_range: + { + \int_set:Nn \l__sort_min_int { \tex_count:D 265 } + \int_set:Nn \l__sort_true_max_int { \tex_count:D 275 } + \__sort_shrink_range: + } + } + } +\cs_if_exist:NT \loctoks { \__sort_redefine_compute_range: } +\tl_map_inline:nn { \lastallocatedtoks \c_syst_last_allocated_toks } + { + \cs_if_exist:NT #1 + { + \cs_gset_protected:Npn \__sort_compute_range: + { + \int_set:Nn \l__sort_min_int { #1 + \c_one } + \int_set:Nn \l__sort_true_max_int { \c_max_register_int + \c_one } + \__sort_shrink_range: + } + } + } \cs_new_protected:Npn \__sort_main:NNNnNn #1#2#3#4#5#6 { \group_begin: - \l__sort_length_int \c_zero + \__sort_disable_toksdef: + \__sort_compute_range: + \int_set_eq:NN \l__sort_top_int \l__sort_min_int #2 #5 { - \if_int_compare:w \l__sort_length_int = \c__sort_max_length_int + \if_int_compare:w \l__sort_top_int = \l__sort_max_int \__sort_too_long_error:NNw #3 #5 \fi: - \tex_toks:D \l__sort_length_int {##1} - \tex_advance:D \l__sort_length_int \c_one + \tex_toks:D \l__sort_top_int {##1} + \tex_advance:D \l__sort_top_int \c_one } - \cs_set:Npn \sort_compare:nn ##1 ##2 { #6 } - \l__sort_block_int \c_one + \int_set:Nn \l__sort_length_int + { \l__sort_top_int - \l__sort_min_int } + \cs_set:Npn \__sort_compare:nn ##1 ##2 { #6 } + \int_set_eq:NN \l__sort_block_int \c_one \__sort_level: \use:x { @@ -96,26 +146,26 @@ \cs_new_protected:Npn \seq_sort:Nn { \__sort_main:NNNnNn \tl_set:Nn - \seq_map_inline:Nn \seq_map_break: - { \s__seq \__sort_toks:NNw \exp_not:N \__seq_item:n 0 ; } + \seq_map_inline:Nn \seq_map_break:n + { \s__seq \__sort_toks:NN \exp_not:N \__seq_item:n } } \cs_new_protected:Npn \seq_gsort:Nn { \__sort_main:NNNnNn \tl_gset:Nn - \seq_map_inline:Nn \seq_map_break: - { \s__seq \__sort_toks:NNw \exp_not:N \__seq_item:n 0 ; } + \seq_map_inline:Nn \seq_map_break:n + { \s__seq \__sort_toks:NN \exp_not:N \__seq_item:n } } \cs_new_protected:Npn \tl_sort:Nn { \__sort_main:NNNnNn \tl_set:Nn - \tl_map_inline:Nn \tl_map_break: - { \__sort_toks:NNw \prg_do_nothing: \prg_do_nothing: 0 ; } + \tl_map_inline:Nn \tl_map_break:n + { \__sort_toks:NN \prg_do_nothing: \prg_do_nothing: } } \cs_new_protected:Npn \tl_gsort:Nn { \__sort_main:NNNnNn \tl_gset:Nn - \tl_map_inline:Nn \tl_map_break: - { \__sort_toks:NNw \prg_do_nothing: \prg_do_nothing: 0 ; } + \tl_map_inline:Nn \tl_map_break:n + { \__sort_toks:NN \prg_do_nothing: \prg_do_nothing: } } \cs_new_protected:Npn \clist_sort:Nn { \__sort_clist:NNn \tl_set:Nn } @@ -126,17 +176,19 @@ \clist_if_empty:NF #2 { \__sort_main:NNNnNn #1 - \clist_map_inline:Nn \clist_map_break: + \clist_map_inline:Nn \clist_map_break:n { \exp_last_unbraced:Nf \use_none:n - { \__sort_toks:NNw \exp_args:No \__clist_wrap_item:n 0 ; } + { \__sort_toks:NN \exp_args:No \__clist_wrap_item:n } } #2 {#3} } } +\cs_new:Npn \__sort_toks:NN #1#2 + { \__sort_toks:NNw #1 #2 \l__sort_min_int ; } \cs_new:Npn \__sort_toks:NNw #1#2#3 ; { - \if_int_compare:w #3 < \l__sort_length_int + \if_int_compare:w #3 < \l__sort_top_int #1 #2 { \tex_the:D \tex_toks:D #3 } \exp_after:wN \__sort_toks:NNw \exp_after:wN #1 \exp_after:wN #2 \__int_value:w \__int_eval:w #3 + \c_one \exp_after:wN ; @@ -145,9 +197,9 @@ \cs_new_protected:Npn \__sort_level: { \if_int_compare:w \l__sort_block_int < \l__sort_length_int - \l__sort_end_int \c_zero + \l__sort_end_int \l__sort_min_int \__sort_merge_blocks: - \tex_multiply:D \l__sort_block_int \c_two + \tex_advance:D \l__sort_block_int \l__sort_block_int \exp_after:wN \__sort_level: \fi: } @@ -155,23 +207,23 @@ { \l__sort_begin_int \l__sort_end_int \tex_advance:D \l__sort_end_int \l__sort_block_int - \if_int_compare:w \__int_eval:w \l__sort_end_int < \l__sort_length_int + \if_int_compare:w \l__sort_end_int < \l__sort_top_int \l__sort_A_int \l__sort_end_int \tex_advance:D \l__sort_end_int \l__sort_block_int - \if_int_compare:w \l__sort_end_int > \l__sort_length_int - \l__sort_end_int \l__sort_length_int + \if_int_compare:w \l__sort_end_int > \l__sort_top_int + \l__sort_end_int \l__sort_top_int \fi: \l__sort_B_int \l__sort_A_int - \l__sort_C_int \l__sort_length_int - \sort_copy_block: - \tex_advance:D \l__sort_A_int \c_minus_one - \tex_advance:D \l__sort_B_int \c_minus_one - \tex_advance:D \l__sort_C_int \c_minus_one - \__sort_merge_blocks_aux: + \l__sort_C_int \l__sort_top_int + \__sort_copy_block: + \tex_advance:D \l__sort_A_int - \c_one + \tex_advance:D \l__sort_B_int - \c_one + \tex_advance:D \l__sort_C_int - \c_one + \exp_after:wN \__sort_merge_blocks_aux: \exp_after:wN \__sort_merge_blocks: \fi: } -\cs_new_protected:Npn \sort_copy_block: +\cs_new_protected:Npn \__sort_copy_block: { \tex_toks:D \l__sort_C_int \tex_toks:D \l__sort_B_int \tex_advance:D \l__sort_C_int \c_one @@ -179,29 +231,48 @@ \if_int_compare:w \l__sort_B_int = \l__sort_end_int \use_i:nn \fi: - \sort_copy_block: + \__sort_copy_block: } \cs_new_protected:Npn \__sort_merge_blocks_aux: { - \exp_after:wN \sort_compare:nn \exp_after:wN + \exp_after:wN \__sort_compare:nn \exp_after:wN { \tex_the:D \tex_toks:D \exp_after:wN \l__sort_A_int \exp_after:wN } \exp_after:wN { \tex_the:D \tex_toks:D \l__sort_C_int } + \prg_do_nothing: + \__sort_return_mark:N + \__sort_return_mark:N + \__sort_return_none_error: + } +\cs_new_protected:Npn \sort_ordered: #1 \__sort_return_mark:N + { #1 \__sort_return_mark:N \__sort_return_two_error:w \__sort_ordered: } +\cs_new_protected:Npn \sort_reversed: #1 \__sort_return_mark:N + { #1 \__sort_return_mark:N \__sort_return_two_error:w \__sort_return_reversed: } +\cs_new_protected:Npn \__sort_return_mark:N #1 { } +\cs_new_protected:Npn \__sort_return_none_error: + { + \__msg_kernel_error:nnxx { sort } { return-none } + { \tex_the:D \tex_toks:D \l__sort_A_int } + { \tex_the:D \tex_toks:D \l__sort_C_int } + \__sort_ordered: } -\cs_new_protected:Npn \sort_ordered: +\cs_new_protected:Npn \__sort_return_two_error:w + #1 \__sort_return_none_error: + { \__msg_kernel_error:nn { sort } { return-two } } +\cs_new_protected:Npn \__sort_ordered: { \tex_toks:D \l__sort_B_int \tex_toks:D \l__sort_C_int - \tex_advance:D \l__sort_B_int \c_minus_one - \tex_advance:D \l__sort_C_int \c_minus_one - \if_int_compare:w \l__sort_C_int < \l__sort_length_int + \tex_advance:D \l__sort_B_int - \c_one + \tex_advance:D \l__sort_C_int - \c_one + \if_int_compare:w \l__sort_C_int < \l__sort_top_int \use_i:nn \fi: \__sort_merge_blocks_aux: } -\cs_new_protected:Npn \sort_reversed: +\cs_new_protected:Npn \__sort_return_reversed: { \tex_toks:D \l__sort_B_int \tex_toks:D \l__sort_A_int - \tex_advance:D \l__sort_B_int \c_minus_one - \tex_advance:D \l__sort_A_int \c_minus_one + \tex_advance:D \l__sort_B_int - \c_one + \tex_advance:D \l__sort_A_int - \c_one \if_int_compare:w \l__sort_A_int < \l__sort_begin_int \__sort_merge_blocks_end: \use_i:nn \fi: @@ -210,8 +281,8 @@ \cs_new_protected:Npn \__sort_merge_blocks_end: { \tex_toks:D \l__sort_B_int \tex_toks:D \l__sort_C_int - \tex_advance:D \l__sort_B_int \c_minus_one - \tex_advance:D \l__sort_C_int \c_minus_one + \tex_advance:D \l__sort_B_int - \c_one + \tex_advance:D \l__sort_C_int - \c_one \if_int_compare:w \l__sort_B_int < \l__sort_begin_int \use_i:nn \fi: @@ -298,18 +369,60 @@ } #6 \q_stop } +\cs_new_protected:Npn \__sort_error: + { + \cs_set_eq:NN \__sort_merge_blocks_aux: \prg_do_nothing: + \cs_set_eq:NN \__sort_merge_blocks: \prg_do_nothing: + \cs_set_protected:Npn \__sort_level: \use:x ##1 { \group_end: } + } +\cs_new_protected:Npn \__sort_disable_toksdef: + { \cs_set_eq:NN \toksdef \__sort_disabled_toksdef:n } +\cs_new_protected:Npn \__sort_disabled_toksdef:n #1 + { + \__msg_kernel_error:nnx { sort } { toksdef } + { \token_to_str:N #1 } + \__sort_error: + \tex_toksdef:D #1 + } +\__msg_kernel_new:nnnn { sort } { toksdef } + { Allocation~of~\iow_char:N\\toks~registers~impossible~while~sorting. } + { + The~comparison~code~used~for~sorting~a~list~has~attempted~to~ + define~#1~as~a~new~\iow_char:N\\toks~register~using~\iow_char:N\\newtoks~ + or~a~similar~command.~The~list~will~not~be~sorted. + } \cs_new_protected:Npn \__sort_too_long_error:NNw #1#2 \fi: { \fi: - \__msg_kernel_error:nnx { sort } { too-large } { \token_to_str:N #2 } - #1 + \__msg_kernel_error:nnxxx { sort } { too-large } + { \token_to_str:N #2 } + { \int_eval:n { \l__sort_true_max_int - \l__sort_min_int } } + { \int_eval:n { \l__sort_top_int - \l__sort_min_int } } + #1 \__sort_error: } \__msg_kernel_new:nnnn { sort } { too-large } { The~list~#1~is~too~long~to~be~sorted~by~TeX. } { - TeX~has~\int_eval:n { \c_max_register_int + 1 }~registers~available:~ - this~only~allows~to~sorts~with~up~to~\int_use:N \c__sort_max_length_int - \ items.~All~extra~items~will~be~ignored. + TeX~has~#2~toks~registers~still~available:~ + this~only~allows~to~sort~with~up~to~#3~ + items.~All~extra~items~will~be~deleted. + } +\__msg_kernel_new:nnnn { sort } { return-none } + { The~comparison~code~did~not~return. } + { + When~sorting~a~list,~the~code~to~compare~items~#1~and~#2~ + did~not~call~ + \iow_char:N\\sort_ordered: ~nor~ + \iow_char:N\\sort_reversed: .~ + Exactly~one~of~these~should~be~called. + } +\__msg_kernel_new:nnnn { sort } { return-two } + { The~comparison~code~returned~multiple~times. } + { + When~sorting~a~list,~the~code~to~compare~items~called~ + \iow_char:N\\sort_ordered: ~or~ + \iow_char:N\\sort_reversed: ~multiple~times.~ + Exactly~one~of~these~should~be~called. } %% %% |