summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex')
-rw-r--r--Master/texmf-dist/tex/latex/l3experimental/l3str/l3regex-trace.sty1637
-rw-r--r--Master/texmf-dist/tex/latex/l3experimental/l3str/l3regex.sty1637
-rw-r--r--Master/texmf-dist/tex/latex/l3experimental/l3str/l3str.sty970
-rw-r--r--Master/texmf-dist/tex/latex/l3experimental/xcoffins/xcoffins.sty2
-rw-r--r--Master/texmf-dist/tex/latex/l3experimental/xgalley/l3galley.sty764
-rw-r--r--Master/texmf-dist/tex/latex/l3experimental/xgalley/xgalley.sty616
6 files changed, 5625 insertions, 1 deletions
diff --git a/Master/texmf-dist/tex/latex/l3experimental/l3str/l3regex-trace.sty b/Master/texmf-dist/tex/latex/l3experimental/l3str/l3regex-trace.sty
new file mode 100644
index 00000000000..29045fcdea9
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/l3experimental/l3str/l3regex-trace.sty
@@ -0,0 +1,1637 @@
+%%
+%% This is file `l3regex-trace.sty',
+%% generated with the docstrip utility.
+%%
+%% The original source files were:
+%%
+%% l3regex.dtx (with options: `package,trace')
+%%
+%% EXPERIMENTAL CODE
+%%
+%% Do not distribute this file without also distributing the
+%% source files specified above.
+%%
+%% Do not distribute a modified version of this file.
+%%
+%% File: l3regex.dtx Copyright (C) 2011 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 LaTeX3 Project.
+%%
+%% -----------------------------------------------------------------------
+\RequirePackage{expl3}
+\GetIdInfo$Id: l3regex.dtx 2895 2011-10-09 15:58:19Z joseph $
+ {L3 Experimental Regular Expressions}
+\ProvidesExplPackage
+ {\ExplFileName}{\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription}
+\RequirePackage{l3str}
+\cs_new:Npn \regex_tmp:w { }
+\tl_new:N \g_regex_tmpa_tl
+\tl_new:N \l_regex_tmpa_tl
+\tl_new:N \l_regex_tmpb_tl
+\int_new:N \l_regex_tmpa_int
+\tl_new:N \l_regex_pattern_str
+\int_new:N \l_regex_max_state_int
+\int_new:N \l_regex_left_state_int
+\int_new:N \l_regex_right_state_int
+\seq_new:N \l_regex_left_state_seq
+\seq_new:N \l_regex_right_state_seq
+\int_new:N \l_regex_capturing_group_int
+\seq_new:N \l_regex_capturing_group_seq
+\tl_new:N \l_regex_one_or_group_tl
+\int_new:N \l_regex_repetition_int
+\bool_new:N \l_regex_look_behind_bool
+\tl_new:N \l_regex_look_behind_str
+\cs_new_eq:NN \regex_build_tmp_class:n \use_none:n
+\bool_new:N \l_regex_class_bool
+\tl_new:N \l_regex_class_tl
+\tl_const:Nn \c_regex_d_tl
+ {
+ \regex_item_range:nn {48} {57} % 0--9
+ }
+\tl_const:Nn \c_regex_D_tl
+ {
+ \regex_item_more:n {57} % 9
+ \regex_item_range:nn {0} {47} % 0
+ }
+\tl_const:Nn \c_regex_h_tl
+ {
+ \regex_item_equal:n {32} % space
+ \regex_item_equal:n {9} % tab
+ }
+\tl_const:Nn \c_regex_H_tl
+ {
+ \regex_item_neq:n {32} % space
+ \regex_item_neq:n {9} % tab
+ \regex_break_true:w
+ }
+\tl_const:Nn \c_regex_s_tl
+ {
+ \regex_item_equal:n {32} % space
+ \regex_item_neq:n {11} % vtab
+ \regex_item_range:nn {9} {13} % tab, lf, vtab, ff, cr
+ }
+\tl_const:Nn \c_regex_S_tl
+ {
+ \regex_item_more:n {32} % > space
+ \regex_item_range:nn {14} {31} % tab < ... < space
+ \regex_item_range:nn {0} {8} % < tab
+ \regex_item_equal:n {11} % vtab
+ }
+\tl_const:Nn \c_regex_v_tl
+ {
+ \regex_item_range:nn {10} {13} % lf, vtab, ff, cr
+ }
+\tl_const:Nn \c_regex_V_tl
+ {
+ \regex_item_more:n {13} % cr
+ \regex_item_range:nn {0} {9} % < lf
+ }
+\tl_const:Nn \c_regex_w_tl
+ {
+ \regex_item_range:nn {97} {122} % a--z
+ \regex_item_range:nn {65} {90} % A--Z
+ \regex_item_range:nn {48} {57} % 0--9
+ \regex_item_equal:n {95} % _
+ }
+\tl_const:Nn \c_regex_W_tl
+ {
+ \regex_item_range:nn {0} {47} % <`0
+ \regex_item_range:nn {58} {64} % (`9+1)--(`A-1)
+ \regex_item_range:nn {91} {94} % (`Z+1)--(`_-1)
+ \regex_item_equal:n {96} % `
+ \regex_item_more:n {122} % z
+ }
+\tl_const:Nn \c_regex_N_tl
+ {
+ \regex_item_neq:n {10} % lf
+ \regex_break_true:w
+ }
+\tl_new:N \l_regex_query_str
+\int_new:N \l_regex_start_step_int
+\int_new:N \l_regex_current_char_int
+\int_new:N \l_regex_current_step_int
+\int_new:N \l_regex_unique_step_int
+\int_new:N \l_regex_current_state_int
+\prop_new:N \l_regex_current_submatches_prop
+\int_new:N \l_regex_max_index_int
+\tl_new:N \l_regex_every_match_tl
+\cs_new_protected:Npn \regex_last_match_empty_no:F #1 {#1}
+\cs_new_protected:Npn \regex_last_match_empty_yes:F
+ { \int_compare:nNnF \l_regex_start_step_int = \l_regex_current_step_int }
+\cs_new_eq:NN \regex_last_match_empty:F \regex_last_match_empty_no:F
+\bool_new:N \l_regex_success_bool
+\bool_new:N \l_regex_success_empty_bool
+\int_new:N \l_regex_success_step_int
+\prop_new:N \l_regex_success_submatches_prop
+\bool_new:N \l_regex_fresh_thread_bool
+\seq_new:N \g_regex_submatches_seq
+\int_new:N \g_regex_match_count_int
+\seq_new:N \g_regex_split_seq
+\tl_new:N \l_regex_replacement_tl
+\tl_new:N \g_regex_replaced_str
+\cs_new_eq:NN \s_regex_toks \scan_stop:
+\cs_new_protected:Npn \regex_toks_put_left:Nx #1#2
+ {
+ \cs_set_nopar:Npx \regex_tmp:w \s_regex_toks { \s_regex_toks #2 }
+ \tex_toks:D #1 \exp_after:wN \exp_after:wN \exp_after:wN
+ { \exp_after:wN \regex_tmp:w \tex_the:D \tex_toks:D #1 }
+ }
+\cs_new_protected:Npn \regex_toks_put_right:Nx #1#2
+ {
+ \cs_set_nopar:Npx \regex_tmp:w {#2}
+ \tex_toks:D #1 \exp_after:wN
+ { \tex_the:D \tex_toks:D \exp_after:wN #1 \regex_tmp:w }
+ }
+\cs_new_eq:NN \regex_if_tail_stop:N \quark_if_recursion_tail_stop:N
+\cs_new_protected_nopar:Npn \regex_if_tail_error:Nn #1#2
+ { \quark_if_recursion_tail_stop_do:Nn #1 { \regex_build_error:n {#2} } }
+\cs_new_protected_nopar:Npn \regex_build_error:n #1
+ {
+ \msg_error:nnxx { regex } { build-error } {\int_eval:n{#1}}
+ {
+ \prg_case_int:nnn {#1}
+ {
+ {-999} {File~not~found}
+ {-998} {Unsupported~construct}
+ {-997} {The~regular~expression~is~too~large~(32768~states).}
+ {1} {\iow_char:N\\~at~end~of~pattern }
+ {4} {Numbers~out~of~order~in~\iow_char:N\{\iow_char\}~quantifier.}
+ {6} {Missing~terminating~\iow_char:N\]~for~character~class }
+ {7} {Invalid~escape~sequence~in~character~class}
+ {8} {Range~out~of~order~in~character~class}
+ {22} {Mismatched~parentheses}
+ {34} {Character~value~in~\iow_char:N\\x{...}~sequence~is~too~large}
+ }
+ { Internal~bug. }
+ }
+ }
+\msg_new:nnn { regex } { build-error } { (error~#1): ~ #2 }
+\cs_new_nopar:Npn \regex_break_true:w #1 \regex_break_point:TF #2 #3 {#2}
+\cs_new_nopar:Npn \regex_break_false:w #1 \regex_break_point:TF #2 #3 {#3}
+\cs_new_eq:NN \regex_break_point:TF \use_ii:nn
+\cs_new_nopar:Npn \regex_item_equal:n #1
+ {
+ \if_num:w #1 = \l_regex_current_char_int
+ \exp_after:wN \regex_break_true:w
+ \fi:
+ }
+\cs_new_nopar:Npn \regex_item_range:nn #1 #2
+ {
+ \reverse_if:N \if_num:w #1 > \l_regex_current_char_int
+ \reverse_if:N \if_num:w #2 < \l_regex_current_char_int
+ \exp_after:wN \exp_after:wN \exp_after:wN \regex_break_true:w
+ \fi:
+ \fi:
+ }
+\cs_new_nopar:Npn \regex_item_less:n #1
+ {
+ \if_num:w #1 > \l_regex_current_char_int
+ \exp_after:wN \regex_break_true:w
+ \fi:
+ }
+\cs_new_nopar:Npn \regex_item_more:n #1
+ {
+ \if_num:w #1 < \l_regex_current_char_int
+ \exp_after:wN \regex_break_true:w
+ \fi:
+ }
+\cs_new_nopar:Npn \regex_item_neq:n #1
+ {
+ \if_num:w #1 = \l_regex_current_char_int
+ \exp_after:wN \regex_break_false:w
+ \fi:
+ }
+\cs_new_protected:Npn \regex_get_digits:nw #1
+ {
+ \tex_afterassignment:D \regex_tmp:w
+ \cs_set_nopar:Npx \regex_tmp:w
+ {
+ \exp_not:n {#1}
+ { \if_false: } } \fi:
+ \regex_get_digits_aux:N
+ }
+\cs_new_nopar:Npn \regex_get_digits_aux:N #1
+ {
+ \if_num:w 9 < 1 \exp_not:N #1 \exp_stop_f:
+ \else:
+ \if_charcode:w \c_space_token \exp_not:N #1
+ \else:
+ \regex_get_digits_end:w
+ \fi:
+ \fi:
+ #1 \regex_get_digits_aux:N
+ }
+\cs_new_nopar:Npn \regex_get_digits_end:w
+ \fi: \fi: #1 \regex_get_digits_aux:N
+ {
+ \fi: \fi:
+ \if_false: { { \fi: } }
+ #1
+ }
+\prg_new_conditional:Npnn \regex_aux_char_if_special:N #1 { TF }
+ {
+ \if_num:w `#1 < 97 \exp_stop_f:
+ \if_num:w `#1 < 58 \exp_stop_f:
+ \if_num:w \int_eval:w (`#1 - \c_eight)/\c_sixteen = \c_two
+ \prg_return_true:
+ \else:
+ \prg_return_false:
+ \fi:
+ \else:
+ \if_num:w \int_eval:w `#1 / 26 = \c_three
+ \prg_return_false:
+ \else:
+ \prg_return_true:
+ \fi:
+ \fi:
+ \else:
+ \if_num:w \int_eval:w `#1 / \c_five = 25 \exp_stop_f:
+ \prg_return_true:
+ \else:
+ \prg_return_false:
+ \fi:
+ \fi:
+ }
+\prg_new_conditional:Npnn \regex_aux_char_if_alphanumeric:N #1 { TF }
+ {
+ \if_num:w `#1 < 91 \exp_stop_f:
+ \if_num:w `#1 < 65 \exp_stop_f:
+ \if_num:w \c_nine < 1 #1 \exp_stop_f:
+ \prg_return_true:
+ \else:
+ \prg_return_false:
+ \fi:
+ \else:
+ \prg_return_true:
+ \fi:
+ \else:
+ \if_num:w \int_eval:w (`#1-\c_six)/26 = \c_four
+ \prg_return_true:
+ \else:
+ \prg_return_false:
+ \fi:
+ \fi:
+ }
+\cs_new_protected_nopar:Npn \regex_build_new_state:
+ {
+ \int_compare:nNnTF \l_regex_max_state_int > {32766}
+ { \regex_build_error:n {-997} }
+ {
+ \int_incr:N \l_regex_max_state_int
+ \tex_toks:D \l_regex_max_state_int { \s_regex_toks }
+ }
+ \int_set_eq:NN \l_regex_left_state_int \l_regex_right_state_int
+ \int_set_eq:NN \l_regex_right_state_int \l_regex_max_state_int
+ }
+\cs_new_protected_nopar:Npn \regex_build_transition_aux:NN #1#2
+ {
+ \regex_build_new_state:
+ \regex_toks_put_right:Nx \l_regex_left_state_int
+ { #1 { \int_use:N #2 } }
+ }
+\cs_new_protected_nopar:Npn \regex_build_transitions_aux:NNNN #1#2#3#4
+ {
+ \regex_build_new_state:
+ \regex_toks_put_right:Nx \l_regex_left_state_int
+ {
+ #1 { \int_use:N #2 }
+ #3 { \int_use:N #4 }
+ }
+ }
+\cs_new_protected:Npn \regex_build:n #1
+ {
+ \regex_build_setup:
+ \str_aux_escape:NNNn
+ \regex_build_i_unescaped:N
+ \regex_build_i_escaped:N
+ \regex_build_i_raw:N
+ { #1 }
+ \regex_build_open_aux:
+ \g_str_result_tl \prg_do_nothing: \prg_do_nothing:
+ \seq_push:Nn \l_regex_capturing_group_seq { 0 }
+ \regex_build_close_aux: \regex_build_group_:
+ \regex_build_end:
+ }
+\cs_new_nopar:Npn \regex_build_i_unescaped:N #1
+ {
+ \regex_aux_char_if_special:NTF #1
+ { \exp_not:N \regex_build_control:N #1 }
+ { \exp_not:N \regex_build_raw:N #1 }
+ }
+\cs_new_nopar:Npn \regex_build_i_escaped:N #1
+ {
+ \regex_aux_char_if_alphanumeric:NTF #1
+ { \exp_not:N \regex_build_control:N #1 }
+ { \exp_not:N \regex_build_raw:N #1 }
+ }
+\cs_new_nopar:Npn \regex_build_i_raw:N #1
+ { \exp_not:N \regex_build_raw:N #1 }
+\cs_new_protected_nopar:Npn \regex_build_default_control:N #1
+ {
+ \cs_if_exist_use:cF { regex_build_#1: }
+ { \regex_build_default_raw:N #1 }
+ }
+\cs_new_protected_nopar:Npn \regex_build_setup:
+ {
+ \cs_set_eq:NN \regex_build_control:N \regex_build_default_control:N
+ \cs_set_eq:NN \regex_build_raw:N \regex_build_default_raw:N
+ \int_set_eq:NN \l_regex_capturing_group_int \c_zero
+ \int_zero:N \l_regex_left_state_int
+ \int_zero:N \l_regex_right_state_int
+ \int_zero:N \l_regex_max_state_int
+ \regex_build_new_state:
+ \regex_build_new_state:
+ \regex_toks_put_right:Nx \l_regex_left_state_int
+ {
+ \regex_action_start_wildcard:nn
+ { \int_use:N \l_regex_left_state_int }
+ { \int_use:N \l_regex_right_state_int }
+ }
+ }
+\cs_new_protected_nopar:Npn \regex_build_end:
+ {
+ \seq_if_empty:NF \l_regex_capturing_group_seq
+ {
+ \regex_build_error:n {22}
+ \prg_replicate:nn
+ { \seq_length:N \l_regex_capturing_group_seq } % (
+ { \regex_build_close_aux: \regex_build_group_: }
+ }
+ \regex_toks_put_right:Nx \l_regex_right_state_int
+ { \regex_action_success: }
+ }
+\cs_new_protected_nopar:cpn { regex_build_^: }
+ { \regex_build_anchor_start:N \c_zero }
+\cs_new_protected_nopar:Npn \regex_build_A:
+ { \regex_build_anchor_start:N \c_zero }
+\cs_new_protected_nopar:Npn \regex_build_G:
+ { \regex_build_anchor_start:N \l_regex_start_step_int }
+\cs_new_protected_nopar:Npn \regex_build_anchor_start:N #1
+ {
+ \regex_build_new_state:
+ \regex_toks_put_right:Nx \l_regex_left_state_int
+ {
+ \exp_not:N \int_compare:nNnT {#1} = \l_regex_current_step_int
+ { \regex_action_free:n { \int_use:N \l_regex_right_state_int } }
+ }
+ }
+\cs_new_protected_nopar:cpn { regex_build_$: } % $
+ {
+ \regex_build_new_state:
+ \regex_toks_put_right:Nx \l_regex_left_state_int
+ {
+ \exp_not:N \int_compare:nNnT
+ \c_minus_one = \l_regex_current_char_int
+ { \regex_action_free:n { \int_use:N \l_regex_right_state_int } }
+ }
+ }
+\cs_new_eq:Nc \regex_build_Z: { regex_build_$: } %$
+\cs_new_eq:Nc \regex_build_z: { regex_build_$: } %$
+\cs_new_protected_nopar:Npn \regex_build_b:
+ {
+ \bool_set_true:N \l_regex_look_behind_bool
+ \regex_build_new_state:
+ \regex_toks_put_right:Nx \l_regex_left_state_int
+ {
+ \exp_not:N \regex_if_word_boundary:TF
+ { \regex_action_free:n { \int_use:N \l_regex_right_state_int } }
+ { }
+ }
+ }
+\cs_new_protected_nopar:Npn \regex_build_B:
+ {
+ \bool_set_true:N \l_regex_look_behind_bool
+ \regex_build_new_state:
+ \regex_toks_put_right:Nx \l_regex_left_state_int
+ {
+ \exp_not:N \regex_if_word_boundary:TF
+ { }
+ { \regex_action_free:n { \int_use:N \l_regex_right_state_int } }
+ }
+ }
+\cs_new_protected_nopar:Npn \regex_if_word_boundary:TF
+ {
+ \tl_if_empty:NTF \l_regex_look_behind_str
+ { \c_regex_w_tl }
+ {
+ \group_begin:
+ \cs_set_nopar:Npx \regex_tmp:w
+ {
+ \int_set:Nn \l_regex_current_char_int
+ { ` \str_head:N \l_regex_look_behind_str }
+ }
+ \regex_tmp:w
+ \c_regex_w_tl
+ \regex_break_point:TF
+ { \group_end: \c_regex_W_tl }
+ { \group_end: \c_regex_w_tl }
+ }
+ \regex_break_point:TF
+ }
+\cs_new_protected_nopar:Npn \regex_build_default_raw:N #1
+ {
+ \cs_set:Npx \regex_build_tmp_class:n ##1
+ {
+ \exp_not:n { \exp_not:N \if_num:w }
+ \int_value:w `#1 = \l_regex_current_char_int
+ \regex_action_cost:n { ##1 }
+ \exp_not:n { \exp_not:N \fi: }
+ }
+ \regex_build_one_quantifier:
+ }
+\cs_new_protected_nopar:cpn { regex_build_.: }
+ {
+ \cs_set:Npn \regex_build_tmp_class:n ##1
+ {
+ \exp_not:N \if_num:w \c_minus_one < \l_regex_current_char_int
+ \regex_action_cost:n {##1}
+ \exp_not:N \fi:
+ }
+ \regex_build_one_quantifier:
+ }
+\cs_new_protected_nopar:Npn \regex_build_char_type:N #1
+ {
+ \cs_set:Npn \regex_build_tmp_class:n ##1
+ {
+ \exp_not:N #1
+ \exp_not:N \regex_break_point:TF
+ { \regex_action_cost:n {##1} }
+ { }
+ }
+ \regex_build_one_quantifier:
+ }
+\tl_map_inline:nn { dDhHsSvVwWN }
+ {
+ \cs_new_protected_nopar:cpx { regex_build_#1: }
+ {
+ \exp_not:N \regex_build_char_type:N
+ \exp_not:c { c_regex_#1_tl }
+ }
+ }
+\cs_new_protected_nopar:cpn { regex_build_[: }
+ {
+ \tl_clear:N \l_regex_class_tl
+ \cs_set_eq:NN \regex_build_control:N \regex_class_control:N
+ \cs_set_eq:NN \regex_build_raw:N \regex_class_raw:N
+ \regex_class_first:NN
+ }
+\cs_new_protected_nopar:Npn \regex_class_control:N #1
+ {
+ \cs_if_exist_use:cF { regex_class_#1: }
+ { \regex_class_raw:N #1 }
+ }
+\cs_new_protected_nopar:cpn { regex_class_]: }
+ {
+ \tl_if_empty:NTF \l_regex_class_tl %[
+ { \regex_class_raw:N ] }
+ {
+ \cs_set_eq:NN \regex_build_control:N \regex_build_default_control:N
+ \cs_set_eq:NN \regex_build_raw:N \regex_build_default_raw:N
+ \cs_set:Npn \regex_build_tmp_class:n ##1
+ {
+ \exp_not:o \l_regex_class_tl
+ \bool_if:NTF \l_regex_class_bool
+ {
+ \exp_not:N \regex_break_point:TF
+ { \regex_action_cost:n {##1} }
+ { }
+ }
+ {
+ \exp_not:N \regex_break_point:TF
+ { }
+ { \regex_action_cost:n {##1} }
+ }
+ }
+ \regex_build_one_quantifier:
+ }
+ }
+\cs_new_protected_nopar:Npn \regex_class_first:NN #1#2
+ {
+ \str_if_eq:nnTF {#1#2} { \regex_build_control:N ^ }
+ { \bool_set_false:N \l_regex_class_bool }
+ {
+ \bool_set_true:N \l_regex_class_bool
+ #1 #2
+ }
+ }
+\cs_new_protected_nopar:Npn \regex_class_raw:N #1#2#3
+ {
+ \str_if_eq:nnTF {#2#3} { \regex_build_control:N - }
+ { \regex_class_range:Nw #1 }
+ {
+ \regex_class_single:N #1
+ #2 #3
+ }
+ }
+\cs_new_protected_nopar:Npn \regex_class_single:N #1
+ {
+ \tl_put_right:Nx \l_regex_class_tl
+ { \exp_not:N \regex_item_equal:n { \int_value:w `#1 } }
+ }
+\cs_new_protected_nopar:Npn \regex_class_range:Nw #1#2#3
+ {
+ \token_if_eq_meaning:NNTF #2 \regex_build_control:N
+ {
+ \cs_if_exist:cTF { regex_class_#3: }
+ {
+ \regex_class_single:N #1
+ \regex_class_single:N -
+ #2#3
+ }
+ { \regex_class_range_put:NN #1#3 }
+ }
+ { \regex_class_range_put:NN #1#3 }
+ }
+\cs_new_protected_nopar:Npn \regex_class_range_put:NN #1#2
+ {
+ \if_num:w `#1 > `#2 \exp_stop_f:
+ \regex_build_error:n {8}
+ \else:
+ \tl_put_right:Nx \l_regex_class_tl
+ {
+ \if_num:w `#1 = `#2 \exp_stop_f:
+ \exp_not:N \regex_item_equal:n
+ \else:
+ \exp_not:N \regex_item_range:nn { \int_value:w `#1 }
+ \fi:
+ { \int_value:w `#2 }
+ }
+ \fi:
+ }
+\tl_map_inline:nn { dDhHsSvVwWN }
+ {
+ \cs_new_protected_nopar:cpx { regex_class_#1: }
+ {
+ \tl_put_right:Nn \exp_not:N \l_regex_class_tl
+ { \exp_not:c { c_regex_#1_tl } }
+ }
+ }
+\cs_new_protected_nopar:Npn \regex_build_quantifier:w #1#2
+ {
+ \token_if_eq_meaning:NNTF #1 \regex_build_control:N
+ {
+ \cs_if_exist_use:cF { regex_build_quantifier_#2:w }
+ {
+ \regex_build_quantifier_end:n { }
+ #1 #2
+ }
+ }
+ {
+ \regex_build_quantifier_end:n { }
+ #1 #2
+ }
+ }
+\cs_new_protected_nopar:cpn { regex_build_quantifier_?:w }
+ { \regex_build_quantifier_aux:nnNN { } { ? } }
+\cs_new_protected_nopar:cpn { regex_build_quantifier_*:w }
+ { \regex_build_quantifier_aux:nnNN { } { * } }
+\cs_new_protected_nopar:cpn { regex_build_quantifier_+:w }
+ { \regex_build_quantifier_aux:nnNN { } { + } }
+\cs_new_protected_nopar:Npn \regex_build_quantifier_aux:nnNN #1#2#3#4
+ {
+ \str_if_eq:nnTF { #3 #4 } { \regex_build_control:N ? }
+ { \regex_build_quantifier_end:n { #2 #4 } #1 }
+ {
+ \regex_build_quantifier_end:n { #2 } #1
+ #3 #4
+ }
+ }
+\cs_new_protected_nopar:cpn { regex_build_quantifier_ \c_lbrace_str :w }
+ { \regex_get_digits:nw { \regex_build_quantifier_lbrace:n } }
+\cs_new_protected_nopar:Npn \regex_build_quantifier_lbrace:n #1
+ {
+ \tl_if_empty:nTF {#1}
+ {
+ \regex_build_quantifier_end:n { }
+ \exp_after:wN \regex_build_raw:N \c_lbrace_str
+ }
+ { \regex_build_quantifier_lbrace:nw {#1} }
+ }
+\cs_new_protected_nopar:Npx \regex_build_quantifier_lbrace:nw #1#2#3
+ {
+ \exp_not:N \prg_case_str:nnn { #2 #3 }
+ {
+ { \exp_not:N \regex_build_control:N , }
+ {
+ \exp_not:N \regex_get_digits:nw
+ { \exp_not:N \regex_build_quantifier_lbrace:nnw {#1} }
+ }
+ { \exp_not:N \regex_build_control:N \c_rbrace_str }
+ { \exp_not:N \regex_build_quantifier_end:n {n} {#1} }
+ }
+ {
+ \exp_not:N \regex_build_quantifier_end:n { }
+ \exp_not:N \regex_build_raw:N \c_lbrace_str #1#2
+ }
+ }
+\cs_new_protected_nopar:Npn \regex_build_quantifier_lbrace:nnw #1#2#3
+ {
+ \str_if_eq:xxTF { \exp_not:N #3 } { \c_rbrace_str }
+ {
+ \tl_if_empty:nTF {#2}
+ { \regex_build_quantifier_aux:nnN { {#1} {\c_max_int} } {nn} }
+ {
+ \int_compare:nNnT {#1} > {#2}
+ { \regex_build_error:n {4} }
+ \regex_build_quantifier_aux:nnN { {#1} {#2} } {nn}
+ }
+ }
+ {
+ \regex_build_quantifier_end:n { }
+ \use:x
+ {
+ \exp_not:n { \exp_args:No \tl_map_function:nN }
+ { \c_lbrace_str #1 #2 , }
+ \regex_build_raw:N
+ }
+ }
+ }
+\cs_new_protected_nopar:Npn \regex_build_quantifier_end:n #1
+ { \use:c { regex_build_ \l_regex_one_or_group_tl _ #1 : } }
+\cs_new_protected_nopar:Npn \regex_build_one_quantifier:
+ {
+ \tl_set:Nx \l_regex_one_or_group_tl { one }
+ \regex_build_quantifier:w
+ }
+\cs_new_protected_nopar:Npn \regex_build_one_:
+ {
+ \regex_build_transition_aux:NN
+ \regex_build_tmp_class:n \l_regex_right_state_int
+ }
+\cs_new_protected_nopar:cpn { regex_build_one_?: }
+ {
+ \regex_build_transitions_aux:NNNN
+ \regex_build_tmp_class:n \l_regex_right_state_int
+ \regex_action_free:n \l_regex_right_state_int
+ }
+\cs_new_protected_nopar:cpn { regex_build_one_??: }
+ {
+ \regex_build_transitions_aux:NNNN
+ \regex_action_free:n \l_regex_right_state_int
+ \regex_build_tmp_class:n \l_regex_right_state_int
+ }
+\cs_new_protected_nopar:cpn { regex_build_one_*: }
+ {
+ \regex_build_transitions_aux:NNNN
+ \regex_build_tmp_class:n \l_regex_left_state_int
+ \regex_action_free:n \l_regex_right_state_int
+ }
+\cs_new_protected_nopar:cpn { regex_build_one_*?: }
+ {
+ \regex_build_transitions_aux:NNNN
+ \regex_action_free:n \l_regex_right_state_int
+ \regex_build_tmp_class:n \l_regex_left_state_int
+ }
+\cs_new_protected_nopar:cpn { regex_build_one_+: }
+ {
+ \regex_build_one_:
+ \int_set_eq:NN \l_regex_tmpa_int \l_regex_left_state_int
+ \regex_build_transitions_aux:NNNN
+ \regex_action_free:n \l_regex_tmpa_int
+ \regex_action_free:n \l_regex_right_state_int
+ }
+\cs_new_protected_nopar:cpn { regex_build_one_+?: }
+ {
+ \regex_build_one_:
+ \int_set_eq:NN \l_regex_tmpa_int \l_regex_left_state_int
+ \regex_build_transitions_aux:NNNN
+ \regex_action_free:n \l_regex_right_state_int
+ \regex_action_free:n \l_regex_tmpa_int
+ }
+\cs_new_protected_nopar:Npn \regex_build_one_n: #1
+ {
+ \int_set_eq:NN \l_regex_tmpa_int \l_regex_right_state_int
+ \regex_build_new_state:
+ \regex_build_new_state:
+ \regex_toks_put_right:Nx \l_regex_tmpa_int
+ { %^^A safe \if nesting?
+ \exp_not:N \if_num:w #1 > \l_regex_repetition_int
+ \regex_action_repeat_move:n
+ { \int_use:N \l_regex_left_state_int }
+ \exp_not:N \else:
+ \regex_action_no_repeat_move:n
+ { \int_use:N \l_regex_right_state_int }
+ \exp_not:N \fi:
+ }
+ \regex_toks_put_right:Nx \l_regex_left_state_int
+ {
+ \regex_build_tmp_class:n
+ { \int_use:N \l_regex_tmpa_int }
+ }
+ }
+\cs_new_eq:cN { regex_build_one_n?: } \regex_build_one_n:
+\cs_new_protected_nopar:Npn \regex_build_one_nn: #1#2
+ {
+ \regex_build_one_nn_aux:nn {#1}
+ {
+ \exp_not:N \if_num:w #2 > \l_regex_repetition_int
+ \regex_action_repeat_copy:n
+ { \int_use:N \l_regex_left_state_int }
+ \exp_not:N \fi:
+ \regex_action_no_repeat_move:n
+ { \int_use:N \l_regex_right_state_int }
+ }
+ }
+\cs_new_protected_nopar:cpn { regex_build_one_nn?: } #1#2
+ {
+ \regex_build_one_nn_aux:nn {#1}
+ {
+ \regex_action_no_repeat_copy:n
+ { \int_use:N \l_regex_right_state_int }
+ \exp_not:N \if_num:w #2 > \l_regex_repetition_int
+ \regex_action_repeat_move:n
+ { \int_use:N \l_regex_left_state_int }
+ \exp_not:N \fi:
+ }
+ }
+\cs_new_protected_nopar:Npn \regex_build_one_nn_aux:nn #1#2
+ {
+ \int_set_eq:NN \l_regex_tmpa_int \l_regex_right_state_int
+ \regex_build_new_state:
+ \regex_build_new_state:
+ \regex_toks_put_right:Nx \l_regex_tmpa_int
+ {
+ \exp_not:N \if_num:w #1 > \l_regex_repetition_int
+ \regex_action_repeat_move:n
+ { \int_use:N \l_regex_left_state_int }
+ \exp_not:N \else:
+ #2
+ \exp_not:N \fi:
+ }
+ \regex_toks_put_right:Nx \l_regex_left_state_int
+ {
+ \regex_build_tmp_class:n
+ { \int_use:N \l_regex_tmpa_int }
+ }
+ }
+\cs_new_protected_nopar:cpn { regex_build_(: } #1#2
+ {
+ \str_if_eq:nnTF { #1 #2 } { \regex_build_control:N ? }
+ { \regex_build_special_group:NN }
+ {
+ \int_incr:N \l_regex_capturing_group_int
+ \seq_push:Nx \l_regex_capturing_group_seq
+ { \int_use:N \l_regex_capturing_group_int }
+ \regex_build_open_aux:
+ #1 #2
+ }
+ }
+\cs_new_protected_nopar:Npn \regex_build_open_aux:
+ {
+ \regex_build_new_state:
+ \seq_push:Nx \l_regex_left_state_seq
+ { \int_use:N \l_regex_left_state_int }
+ \seq_push:Nx \l_regex_right_state_seq
+ { \int_use:N \l_regex_right_state_int }
+ \regex_build_begin_alternation:
+ }
+\cs_new_protected_nopar:cpn { regex_build_|: }
+ {
+ \regex_build_end_alternation:
+ \regex_build_begin_alternation:
+ }
+\cs_new_protected_nopar:cpn { regex_build_): }
+ {
+ \seq_if_empty:NTF \l_regex_capturing_group_seq
+ { \regex_build_error:n {22} }
+ {
+ \regex_build_close_aux:
+ \regex_build_group_quantifier:
+ }
+ }
+\cs_new_protected_nopar:Npn \regex_build_close_aux:
+ {
+ \regex_build_end_alternation:
+ \seq_pop:NN \l_regex_left_state_seq \l_regex_tmpa_tl
+ \int_set:Nn \l_regex_left_state_int \l_regex_tmpa_tl
+ \seq_pop:NN \l_regex_right_state_seq \l_regex_tmpa_tl
+ \int_set:Nn \l_regex_right_state_int \l_regex_tmpa_tl
+ }
+\cs_new_protected_nopar:Npn \regex_build_begin_alternation:
+ {
+ \regex_build_new_state:
+ \seq_get:NN \l_regex_left_state_seq \l_regex_tmpa_tl
+ \int_set:Nn \l_regex_left_state_int \l_regex_tmpa_tl
+ \regex_toks_put_right:Nx \l_regex_left_state_int
+ { \regex_action_free:n { \int_use:N \l_regex_right_state_int } }
+ }
+\cs_new_protected_nopar:Npn \regex_build_end_alternation:
+ {
+ \seq_get:NN \l_regex_right_state_seq \l_regex_tmpa_tl
+ \regex_toks_put_right:Nx \l_regex_right_state_int
+ { \regex_action_free:n { \l_regex_tmpa_tl } }
+ }
+\cs_new_protected_nopar:Npn \regex_build_special_group:NN #1#2
+ {
+ \cs_if_exist_use:cF { regex_build_special_group_\token_to_str:N #2 : }
+ {
+ \regex_build_error:n { -998 }
+ \regex_build_control:N ( % )
+ \regex_build_raw:N ?
+ #1 #2
+ }
+ }
+\cs_new_protected_nopar:cpn { regex_build_special_group_:: }
+ {
+ \seq_push:Nx \l_regex_capturing_group_seq { * }
+ \regex_build_open_aux:
+ }
+\cs_new_protected_nopar:Npn \regex_build_group_quantifier:
+ {
+ \tl_set:Nn \l_regex_one_or_group_tl { group }
+ \regex_build_quantifier:w
+ }
+\cs_new_protected_nopar:Npn \regex_build_group_submatches:NN #1#2
+ {
+ \seq_pop:NN \l_regex_capturing_group_seq \l_regex_tmpa_tl
+ \str_if_eq:xxF { \l_regex_tmpa_tl } { * }
+ {
+ \regex_toks_put_left:Nx #1
+ { \regex_action_submatch:n { \l_regex_tmpa_tl < } }
+ \regex_toks_put_left:Nx #2
+ { \regex_action_submatch:n { \l_regex_tmpa_tl > } }
+ }
+ }
+\cs_new_protected_nopar:Npn \regex_build_group_:
+ {
+ \regex_build_group_submatches:NN
+ \l_regex_left_state_int \l_regex_right_state_int
+ \regex_build_transition_aux:NN
+ \regex_action_free:n \l_regex_right_state_int
+ }
+\cs_new_protected_nopar:Npn \regex_build_group_shift:N #1
+ {
+ \int_set_eq:NN \l_regex_tmpa_int \l_regex_left_state_int
+ \regex_build_new_state:
+ \tex_toks:D \l_regex_right_state_int = \tex_toks:D \l_regex_tmpa_int
+ \use:x
+ {
+ \tex_toks:D \l_regex_tmpa_int
+ { \s_regex_toks #1 { \int_use:N \l_regex_right_state_int } }
+ }
+ \regex_build_group_submatches:NN
+ \l_regex_right_state_int \l_regex_left_state_int
+ \int_set_eq:NN \l_regex_right_state_int \l_regex_left_state_int
+ }
+\cs_new_protected_nopar:Npn \regex_build_group_qs_aux:NN #1#2
+ {
+ \regex_build_group_shift:N \regex_action_free:n
+ \regex_build_transition_aux:NN \regex_action_free:n #1
+ #2 \l_regex_tmpa_int
+ { \regex_action_free:n { \int_use:N \l_regex_right_state_int } }
+ }
+\cs_new_protected_nopar:cpn { regex_build_group_?: }
+ {
+ \regex_build_group_qs_aux:NN
+ \l_regex_right_state_int \regex_toks_put_right:Nx
+ }
+\cs_new_protected_nopar:cpn { regex_build_group_??: }
+ {
+ \regex_build_group_qs_aux:NN
+ \l_regex_right_state_int \regex_toks_put_left:Nx
+ }
+\cs_new_protected_nopar:cpn { regex_build_group_*: }
+ {
+ \regex_build_group_qs_aux:NN
+ \l_regex_tmpa_int \regex_toks_put_right:Nx
+ }
+\cs_new_protected_nopar:cpn { regex_build_group_*?: }
+ {
+ \regex_build_group_qs_aux:NN
+ \l_regex_tmpa_int \regex_toks_put_left:Nx
+ }
+\cs_new_protected_nopar:cpn { regex_build_group_+: }
+ {
+ \regex_build_group_submatches:NN
+ \l_regex_left_state_int \l_regex_right_state_int
+ \int_set_eq:NN \l_regex_tmpa_int \l_regex_left_state_int
+ \regex_build_transitions_aux:NNNN
+ \regex_action_free:n \l_regex_tmpa_int
+ \regex_action_free:n \l_regex_right_state_int
+ }
+\cs_new_protected_nopar:cpn { regex_build_group_+?: }
+ {
+ \regex_build_group_submatches:NN
+ \l_regex_left_state_int \l_regex_right_state_int
+ \int_set_eq:NN \l_regex_tmpa_int \l_regex_left_state_int
+ \regex_build_transitions_aux:NNNN
+ \regex_action_free:n \l_regex_right_state_int
+ \regex_action_free:n \l_regex_tmpa_int
+ }
+\cs_new_protected_nopar:Npn \regex_build_group_n: #1
+ {
+ \regex_build_group_shift:N \regex_action_repeat_move:n
+ \regex_build_transition_aux:NN
+ \regex_action_free:n \l_regex_tmpa_int
+ \use:x
+ {
+ \tex_toks:D \l_regex_tmpa_int
+ {
+ \s_regex_toks
+ \exp_not:N \if_num:w #1 > \l_regex_repetition_int
+ \tex_the:D \tex_toks:D \l_regex_tmpa_int
+ \exp_not:N \else:
+ \regex_action_no_repeat_move:n
+ { \int_use:N \l_regex_right_state_int }
+ \exp_not:N \fi:
+ }
+ }
+ }
+\cs_new_eq:cN { regex_build_group_n?: } \regex_build_group_n:
+\cs_new_protected_nopar:Npn \regex_build_group_nn: #1#2
+ {
+ \regex_build_group_shift:N \regex_action_repeat_move:n
+ \regex_build_transition_aux:NN
+ \regex_action_free:n \l_regex_tmpa_int
+ \use:x
+ {
+ \tex_toks:D \l_regex_tmpa_int
+ {
+ \s_regex_toks
+ \exp_not:N \if_num:w #1 > \l_regex_repetition_int
+ \tex_the:D \tex_toks:D \l_regex_tmpa_int
+ \exp_not:N \else:
+ \exp_not:N \if_num:w #2 > \l_regex_repetition_int
+ \tex_the:D \tex_toks:D \l_regex_tmpa_int
+ \exp_not:N \fi:
+ \regex_action_no_repeat_copy:n
+ { \int_use:N \l_regex_right_state_int }
+ \exp_not:N \fi:
+ }
+ }
+ }
+\cs_new_protected_nopar:cpn { regex_build_group_nn?: } #1#2
+ {
+ \regex_build_group_shift:N \regex_action_repeat_move:n
+ \regex_build_transition_aux:NN
+ \regex_action_free:n \l_regex_tmpa_int
+ \use:x
+ {
+ \tex_toks:D \l_regex_tmpa_int
+ {
+ \s_regex_toks
+ \exp_not:N \if_num:w #1 > \l_regex_repetition_int
+ \tex_the:D \tex_toks:D \l_regex_tmpa_int
+ \exp_not:N \else:
+ \regex_action_no_repeat_copy:n
+ { \int_use:N \l_regex_right_state_int }
+ \exp_not:N \if_num:w #2 > \l_regex_repetition_int
+ \tex_the:D \tex_toks:D \l_regex_tmpa_int
+ \exp_not:N \fi:
+ \exp_not:N \fi:
+ }
+ }
+ }
+\cs_new_protected:Npn \regex_if_state_free:nT #1
+ {
+ \if_num:w \tex_dimen:D #1 = \l_regex_unique_step_int
+ \exp_after:wN \use_none:n
+ \else:
+ \exp_after:wN \use:n
+ \fi:
+ }
+\cs_new_protected:Npn \regex_store_state:n #1
+ {
+ \int_incr:N \l_regex_max_index_int
+ \tex_skip:D \l_regex_max_index_int #1 sp \scan_stop:
+ \regex_store_submatches:n {#1}
+ }
+\cs_new_protected_nopar:Npn \regex_state_use_submatches:
+ { \regex_state_use_aux:n { } }
+\cs_new_protected_nopar:Npn \regex_state_use:
+ { \regex_state_use_aux:n { \exp_after:wN \regex_state_use_aux_ii:w } }
+\cs_new:Npn \regex_state_use_aux_ii:w #1 \s_regex_toks { }
+\cs_new_protected:Npn \regex_state_use_aux:n #1
+ {
+ \regex_if_state_free:nT { \l_regex_current_state_int }
+ {
+ \tex_dimen:D \l_regex_current_state_int
+ = \l_regex_unique_step_int sp \scan_stop:
+ #1 \tex_the:D \tex_toks:D \l_regex_current_state_int \scan_stop:
+ }
+ }
+\cs_new_protected_nopar:Npn \regex_disable_submatches:
+ {
+ \cs_set_eq:NN \regex_state_use_submatches: \regex_state_use:
+ \cs_set_eq:NN \regex_store_submatches:n
+ \regex_protected_use_none:n
+ \cs_set_eq:NN \regex_action_submatches:n
+ \regex_protected_use_none:n
+ }
+\cs_new_protected:Npn \regex_protected_use_none:n #1 { }
+\cs_new_protected:Npn \regex_store_submatches:n #1
+ {
+ \exp_after:wN \regex_store_submatches_aux:Nw
+ \exp_after:wN \l_regex_current_submatches_prop
+ \tex_the:D \tex_toks:D #1 \scan_stop: \q_stop
+ { #1 }
+ }
+\cs_new_protected:Npn \regex_store_submatches_aux:Nw #1 #2 \s_regex_toks
+ {
+ \exp_args:No \regex_store_submatches_aux_ii:wnnwwn { #1 }
+ #2
+ \regex_state_submatches:nn { \c_minus_one } { \q_prop }
+ \s_regex_toks
+ }
+\cs_new_protected:Npn \regex_store_submatches_aux_ii:wnnwwn
+ #1 \regex_state_submatches:nn #2#3 #4 \s_regex_toks #5 \q_stop #6
+ {
+ \tex_toks:D #6 \exp_after:wN
+ {
+ \exp_after:wN \regex_state_submatches:nn \exp_after:wN
+ { \int_value:w \int_eval:w \l_regex_unique_step_int + \c_one }
+ { #1 }
+ \regex_state_submatches:nn {#2} {#3}
+ \s_regex_toks
+ #5
+ }
+ }
+\cs_new_protected:Npn \regex_state_submatches:nn #1#2
+ {
+ \if_num:w #1 = \l_regex_unique_step_int
+ \tl_set:Nn \l_regex_current_submatches_prop {#2}
+ \fi:
+ }
+\cs_new_protected:Npn \regex_match:n #1
+ {
+ \tl_set:Nx \l_regex_query_str { \tl_to_other_str:n {#1} }
+ \regex_match_initial_setup:
+ \regex_match_once:
+ }
+\cs_new_protected_nopar:Npn \regex_match_once:
+ {
+ \regex_match_setup:
+ \exp_after:wN \regex_match_once_aux: \l_regex_query_str
+ \q_recursion_tail \q_recursion_stop
+ \bool_if:NT \l_regex_success_bool { \l_regex_every_match_tl }
+ }
+\cs_new_protected_nopar:Npn \regex_match_once_aux:
+ { \str_skip_do:nn { \l_regex_start_step_int } { \regex_match_loop:N } }
+\cs_new_protected_nopar:Npn \regex_match_initial_setup:
+ {
+ \tl_clear:N \l_regex_look_behind_str
+ \prg_stepwise_inline:nnnn {1} {1} { \l_regex_max_state_int }
+ { \tex_dimen:D ##1 \c_minus_one sp \scan_stop: }
+ \int_set_eq:NN \l_regex_unique_step_int \c_minus_one
+ \int_set_eq:NN \l_regex_start_step_int \c_minus_one
+ \int_set_eq:NN \l_regex_current_step_int \c_zero
+ \int_set_eq:NN \l_regex_success_step_int \c_zero
+ \bool_set_false:N \l_regex_success_empty_bool
+ }
+\cs_new_protected_nopar:Npn \regex_match_setup:
+ {
+ \prop_clear:N \l_regex_current_submatches_prop
+ \bool_if:NTF \l_regex_success_empty_bool
+ { \cs_set_eq:NN \regex_last_match_empty:F \regex_last_match_empty_yes:F }
+ { \cs_set_eq:NN \regex_last_match_empty:F \regex_last_match_empty_no:F }
+ \int_set_eq:NN \l_regex_start_step_int \l_regex_success_step_int
+ \int_set_eq:NN \l_regex_current_step_int \l_regex_start_step_int
+ \int_decr:N \l_regex_current_step_int
+ \bool_set_false:N \l_regex_success_bool
+ \int_zero:N \l_regex_max_index_int
+ \regex_store_state:n {1}
+ }
+\cs_new_protected_nopar:Npn \regex_match_loop_setup:
+ {
+ \int_incr:N \l_regex_current_step_int
+ \int_incr:N \l_regex_unique_step_int
+ \bool_set_false:N \l_regex_fresh_thread_bool
+ }
+\cs_new_eq:NN \s_regex_step \scan_stop:
+\cs_new:Npn \regex_break_step:w #1 \s_regex_step { }
+\cs_new_protected_nopar:Npn \regex_match_loop:N #1
+ {
+ \regex_match_loop_setup:
+ \token_if_eq_meaning:NNTF #1 \q_recursion_tail
+ { \int_set_eq:NN \l_regex_current_char_int \c_minus_one }
+ { \int_set:Nn \l_regex_current_char_int {`#1} }
+ \cs_set_nopar:Npx \regex_tmp:w
+ {
+ \int_zero:N \l_regex_max_index_int
+ \prg_stepwise_function:nnnN
+ {1} {1} { \l_regex_max_index_int }
+ \regex_match_one_index:n
+ }
+ \regex_tmp:w
+ \s_regex_step
+ \if_num:w \l_regex_max_index_int = \c_zero
+ \exp_after:wN \use_none_delimit_by_q_recursion_stop:w
+ \fi:
+ \quark_if_recursion_tail_stop:N #1
+ \bool_if:NT \l_regex_look_behind_bool
+ { \tl_put_left:Nx \l_regex_look_behind_str {#1} }
+ \regex_match_loop:N
+ }
+\cs_new_nopar:Npn \regex_match_one_index:n #1
+ {
+ \regex_match_one_index_aux:n { \int_value:w \tex_skip:D #1 }
+ }
+\cs_new_protected_nopar:Npn \regex_match_one_index_aux:n #1
+ {
+ \int_set:Nn \l_regex_current_state_int {#1}
+ \prop_clear:N \l_regex_current_submatches_prop
+ \regex_state_use_submatches:
+ }
+\cs_new_protected_nopar:Npn \regex_action_start_wildcard:nn #1#2
+ {
+ \bool_set_true:N \l_regex_fresh_thread_bool
+ \regex_action_free:n {#2}
+ \bool_set_false:N \l_regex_fresh_thread_bool
+ \regex_action_cost:n {#1}
+ }
+\cs_new_protected_nopar:Npn \regex_action_cost:n #1
+ { \regex_store_state:n {#1} }
+\cs_new_protected_nopar:Npn \regex_action_success:
+ {
+ \regex_last_match_empty:F
+ {
+ \bool_set_true:N \l_regex_success_bool
+ \bool_set_eq:NN \l_regex_success_empty_bool
+ \l_regex_fresh_thread_bool
+ \int_set_eq:NN \l_regex_success_step_int
+ \l_regex_current_step_int
+ \prop_set_eq:NN \l_regex_success_submatches_prop
+ \l_regex_current_submatches_prop
+ \regex_break_step:w
+ }
+ }
+\cs_new_protected_nopar:Npn \regex_action_free:n #1
+ {
+ \regex_if_state_free:nT {#1}
+ {
+ \use:x
+ {
+ \int_set:Nn \l_regex_current_state_int {#1}
+ \regex_store_submatches:n { \l_regex_current_state_int }
+ \regex_state_use:
+ \int_set:Nn \l_regex_current_state_int
+ { \int_use:N \l_regex_current_state_int }
+ \tl_set:Nn \exp_not:N \l_regex_current_submatches_prop
+ { \exp_not:o \l_regex_current_submatches_prop }
+ }
+ }
+ }
+\cs_new_protected_nopar:Npn \regex_action_submatch:n #1
+ {
+ \prop_put:Nno \l_regex_current_submatches_prop {#1}
+ { \int_use:N \l_regex_current_step_int }
+ \regex_store_submatches:n { \l_regex_current_state_int }
+ }
+\cs_new_protected_nopar:Npn \regex_action_repeat_copy:n { \ERROR }
+\cs_new_protected_nopar:Npn \regex_action_repeat_move:n { \ERROR }
+\cs_new_protected_nopar:Npn \regex_action_no_repeat_copy:n { \ERROR }
+\cs_new_protected_nopar:Npn \regex_action_no_repeat_move:n { \ERROR }
+\cs_new_protected_nopar:Npn \regex_extract:
+ {
+ \seq_gclear:N \g_regex_submatches_seq
+ \prg_stepwise_inline:nnnn
+ {0} {1} { \l_regex_capturing_group_int }
+ {
+ \regex_extract_aux:nTF { ##1 }
+ {
+ \seq_gput_right:Nx \g_regex_submatches_seq
+ {
+ \str_from_to:Nnn \l_regex_query_str
+ { \l_regex_tmpa_tl }
+ { \l_regex_tmpb_tl }
+ }
+ }
+ { \seq_gput_right:Nn \g_regex_submatches_seq { } }
+ }
+ }
+\cs_new_protected_nopar:Npn \regex_extract_aux:nTF #1#2#3
+ {
+ \prop_get:NnNTF \l_regex_success_submatches_prop
+ { #1 < } \l_regex_tmpa_tl
+ {
+ \prop_get:NnNTF \l_regex_success_submatches_prop
+ { #1 > } \l_regex_tmpb_tl
+ {#2}
+ {#3}
+ }
+ {#3}
+ }
+\cs_new_protected_nopar:Npn \regex_set:Nn
+ { \regex_set_aux:NNn \tl_set_eq:NN }
+\cs_new_protected_nopar:Npn \regex_gset:Nn
+ { \regex_set_aux:NNn \tl_gset_eq:NN }
+\cs_new_protected:Npn \regex_set_aux:NNn #1#2#3
+ {
+ \group_begin:
+ \regex_build:n {#3}
+ \tl_gset:Nx \g_regex_tmpa_tl
+ {
+ \exp_not:N \regex_nfa:Nw \exp_not:N #2
+ \l_regex_max_state_int
+ = \int_use:N \l_regex_max_state_int
+ \l_regex_capturing_group_int
+ = \int_use:N \l_regex_capturing_group_int
+ \bool_if:NTF \l_regex_look_behind_bool
+ { \bool_set_true:N \l_regex_look_behind_bool }
+ { \bool_set_false:N \l_regex_look_behind_bool }
+ \prg_stepwise_function:nnnN
+ {1} {1} {\l_regex_max_state_int}
+ \regex_set_aux:n
+ \regex_nfa_end:
+ }
+ \group_end:
+ #1 #2 \g_regex_tmpa_tl
+ }
+\cs_new_nopar:Npn \regex_set_aux:n #1
+ { \tex_toks:D #1 { \tex_the:D \tex_toks:D #1 } }
+\cs_new:Npn \regex_nfa:Nw #1 #2 \regex_nfa_end:
+ { \msg_expandable_error:n { Automaton~#1 used~incorrectly. } }
+\cs_new_eq:NN \regex_nfa_end: \scan_stop:
+\prg_new_protected_conditional:Npnn \regex_check_nfa:N #1 { TF }
+ { \exp_after:wN \regex_check_nfa_aux:Nw #1 \q_stop }
+\cs_new:Npn \regex_check_nfa_aux:Nw #1 #2 \q_stop
+ {
+ \if_meaning:w \regex_nfa:Nw #1
+ \prg_return_true:
+ \else:
+ \msg_error:nnx { regex } { not-nfa } { \token_to_str:N #1 }
+ \prg_return_false:
+ \fi:
+ }
+\msg_new:nnn { regex } { not-nfa }
+ {
+ I~was~expecting~a~regular~expression~variable.\\
+ Instead,~I~got~#1.
+ }
+\cs_new_protected_nopar:Npn \regex_use:N #1
+ { \exp_after:wN \use_none:nn #1 }
+\cs_new_protected:Npn \regex_user_aux:n #1
+ {
+ \group_begin:
+ \tl_clear:N \l_regex_every_match_tl
+ #1
+ \group_end:
+ }
+\cs_new_protected_nopar:Npn \regex_return_after_group:
+ {
+ \if_bool:N \l_regex_success_bool
+ \group_insert_after:N \prg_return_true:
+ \else:
+ \group_insert_after:N \prg_return_false:
+ \fi:
+ }
+\cs_new_protected_nopar:Npn \regex_extract_after_group:N #1
+ {
+ \if_bool:N \l_regex_success_bool
+ \regex_extract:
+ \group_insert_after:N \seq_set_eq:NN
+ \group_insert_after:N #1
+ \group_insert_after:N \g_regex_submatches_seq
+ \fi:
+ }
+\cs_new_protected_nopar:Npn \regex_count_after_group:N #1
+ {
+ \group_insert_after:N \int_set_eq:NN
+ \group_insert_after:N #1
+ \group_insert_after:N \g_regex_match_count_int
+ }
+\prg_new_protected_conditional:Npnn \regex_match:nn #1#2 { T , F , TF }
+ {
+ \regex_user_aux:n
+ {
+ \regex_disable_submatches:
+ \regex_build:n {#1}
+ \regex_match:n {#2}
+ \regex_return_after_group:
+ }
+ }
+\prg_new_protected_conditional:Npnn \regex_match:Nn #1#2 { T , F , TF }
+ {
+ \regex_check_nfa:NTF #1
+ {
+ \regex_user_aux:n
+ {
+ \regex_disable_submatches:
+ \regex_use:N #1
+ \regex_match:n {#2}
+ \regex_return_after_group:
+ }
+ }
+ { \prg_return_false: }
+ }
+\cs_new_protected:Npn \regex_count:nnN #1#2#3
+ {
+ \regex_user_aux:n
+ {
+ \regex_disable_submatches:
+ \int_gzero:N \g_regex_match_count_int
+ \tl_set:Nn \l_regex_every_match_tl
+ {
+ \int_gincr:N \g_regex_match_count_int
+ \regex_match_once:
+ }
+ \regex_build:n {#1}
+ \regex_match:n {#2}
+ \regex_count_after_group:N #3
+ }
+ }
+\cs_new_protected:Npn \regex_count:NnN #1#2#3
+ {
+ \regex_check_nfa:NTF #1
+ {
+ \regex_user_aux:n
+ {
+ \regex_disable_submatches:
+ \int_gzero:N \g_regex_match_count_int
+ \tl_set:Nn \l_regex_every_match_tl
+ {
+ \int_gincr:N \g_regex_match_count_int
+ \regex_match_once:
+ }
+ \regex_use:N #1
+ \regex_match:n {#2}
+ \regex_count_after_group:N #3
+ }
+ }
+ { }
+ }
+\cs_new_protected:Npn \regex_extract:nnN #1#2#3
+ {
+ \regex_user_aux:n
+ {
+ \regex_build:n {#1}
+ \regex_match:n {#2}
+ \regex_extract_after_group:N #3
+ }
+ }
+\prg_new_protected_conditional:Npnn \regex_extract:nnN #1#2#3 { T , F , TF }
+ {
+ \regex_user_aux:n
+ {
+ \regex_build:n {#1}
+ \regex_match:n {#2}
+ \regex_extract_after_group:N #3
+ \regex_return_after_group:
+ }
+ }
+\cs_new_protected:Npn \regex_extract:NnN #1#2#3
+ {
+ \regex_check_nfa:NTF #1
+ {
+ \regex_user_aux:n
+ {
+ \regex_use:N #1
+ \regex_match:n {#2}
+ \regex_extract_after_group:N #3
+ }
+ }
+ { }
+ }
+\prg_new_protected_conditional:Npnn \regex_extract:NnN #1#2#3 { T , F , TF }
+ {
+ \regex_check_nfa:NTF #1
+ {
+ \regex_user_aux:n
+ {
+ \regex_use:N #1
+ \regex_match:n {#2}
+ \regex_extract_after_group:N #3
+ \regex_return_after_group:
+ }
+ }
+ { \prg_return_false: }
+ }
+\cs_new_protected:Npn \regex_split:nnN #1#2#3
+ {
+ \regex_user_aux:n
+ {
+ \seq_gclear:N \g_regex_split_seq
+ \tl_set:Nn \l_regex_every_match_tl { \regex_split_aux: }
+ \regex_build:n {#1}
+ \regex_match:n {#2}
+ \regex_split_after_group:N #3
+ }
+ }
+\cs_new_protected:Npn \regex_split:NnN #1#2#3
+ {
+ \regex_check_nfa:NTF #1
+ {
+ \regex_user_aux:n
+ {
+ \seq_gclear:N \g_regex_split_seq
+ \tl_set:Nn \l_regex_every_match_tl { \regex_split_aux: }
+ \regex_use:N #1
+ \regex_match:n {#2}
+ \regex_split_after_group:N #3
+ }
+ }
+ { }
+ }
+\cs_new_protected_nopar:Npn \regex_split_aux:
+ {
+ \int_compare:nNnF \l_regex_start_step_int = \l_regex_success_step_int
+ {
+ \regex_extract:
+ \seq_pop:NN \g_regex_submatches_seq \l_regex_tmpa_tl
+ \regex_extract_aux:nTF {0}
+ {
+ \seq_gput_left:Nx \g_regex_submatches_seq
+ {
+ \str_from_to:Nnn \l_regex_query_str
+ { \int_use:N \l_regex_start_step_int }
+ { \l_regex_tmpa_tl }
+ }
+ }
+ { \msg_error:nn { regex } { internal } }
+ \seq_gconcat:NNN \g_regex_split_seq
+ \g_regex_split_seq \g_regex_submatches_seq
+ }
+ \regex_match_once:
+ }
+\cs_new_protected_nopar:Npn \regex_split_after_group:N #1
+ {
+ \int_compare:nNnTF \l_regex_start_step_int = \l_regex_current_step_int
+ {
+ \bool_if:NF \l_regex_success_empty_bool
+ { \seq_gput_right:Nn \g_regex_split_seq { } }
+ }
+ {
+ \seq_gput_right:Nx \g_regex_split_seq
+ {
+ \str_from_to:Nnn \l_regex_query_str
+ { \int_use:N \l_regex_start_step_int }
+ { \int_use:N \l_regex_current_step_int }
+ }
+ }
+ \group_insert_after:N \seq_set_eq:NN
+ \group_insert_after:N #1
+ \group_insert_after:N \g_regex_split_seq
+ }
+\cs_new_protected:Npn \regex_replacement:n #1
+ {
+ \str_aux_escape:NNNn
+ \prg_do_nothing:
+ \regex_replacement_escaped:N
+ \regex_replacement_raw:N
+ {#1}
+ \tl_set_eq:NN \l_regex_replacement_tl \g_str_result_tl
+ \tl_set:Nx \l_regex_replacement_tl
+ { \l_regex_replacement_tl \prg_do_nothing: }
+ }
+\cs_new_nopar:Npn \regex_replacement_raw:N { \exp_not:N \prg_do_nothing: }
+\cs_new_nopar:Npn \regex_replacement_escaped:N #1
+ {
+ \if_num:w 9 < 1 #1 \exp_stop_f:
+ \exp_not:N \regex_replacement_escaped_ii:nN {#1}
+ \else:
+ #1
+ \fi:
+ }
+\cs_new_nopar:Npn \regex_replacement_escaped_ii:nN #1#2
+ {
+ \regex_token_if_other_digit:NTF #2
+ { \regex_replacement_escaped_ii:nN {#1#2} }
+ { \exp_not:N \seq_item:Nn \exp_not:N \g_regex_submatches_seq {#1} #2 }
+ }
+\prg_new_conditional:Npnn \regex_token_if_other_digit:N #1 { TF }
+ {
+ \if_num:w 9 < 1 \exp_not:N #1 \exp_stop_f:
+ \prg_return_true:
+ \else:
+ \prg_return_false:
+ \fi:
+ }
+\cs_new_protected_nopar:Npn \regex_replace_after_group:N #1
+ {
+ \group_insert_after:N \tl_set_eq:NN
+ \group_insert_after:N #1
+ \group_insert_after:N \g_regex_replaced_str
+ }
+\cs_new_protected:Npn \regex_replace_once_aux:Nn #1#2
+ {
+ \group_begin:
+ \regex_replace_after_group:N #1
+ \tl_clear:N \l_regex_every_match_tl
+ #2
+ \exp_args:No \regex_match:n {#1}
+ \regex_extract:
+ \regex_extract_aux:nTF {0}
+ {
+ \tl_gset:Nx \g_regex_replaced_str
+ {
+ \str_from_to:Nnn \l_regex_query_str {0} { \l_regex_tmpa_tl }
+ \l_regex_replacement_tl
+ \str_from_to:Nnn \l_regex_query_str
+ { \l_regex_tmpb_tl } { \c_max_int }
+ }
+ }
+ { \tl_gset_eq:NN \g_regex_replaced_str \l_regex_query_str }
+ \group_end:
+ }
+\cs_new_protected:Npn \regex_replace_once:nnN #1#2#3
+ {
+ \regex_replace_once_aux:Nn #3
+ {
+ \regex_build:n {#1}
+ \regex_replacement:n {#2}
+ }
+ }
+\cs_new_protected:Npn \regex_replace_once:NnN #1#2#3
+ {
+ \regex_replace_once_aux:Nn #3
+ {
+ \regex_use:N #1
+ \regex_replacement:n {#2}
+ }
+ }
+\prg_new_protected_conditional:Npnn \regex_replace_once:nnN #1#2#3 {T,F,TF}
+ {
+ \regex_replace_once_aux:Nn #3
+ {
+ \regex_build:n {#1}
+ \regex_replacement:n {#2}
+ \regex_return_after_group:
+ }
+ }
+\prg_new_protected_conditional:Npnn \regex_replace_once:NnN #1#2#3 {T,F,TF}
+ {
+ \regex_replace_once_aux:Nn #3
+ {
+ \regex_use:N #1
+ \regex_replacement:n {#2}
+ \regex_return_after_group:
+ }
+ }
+\cs_new_protected:Npn \regex_replace_all_aux:Nn #1#2
+ {
+ \group_begin:
+ \regex_replace_after_group:N #1
+ \tl_set:Nn \l_regex_every_match_tl { \regex_replace_all_aux: }
+ \tl_gclear:N \g_regex_replaced_str
+ #2
+ \exp_args:No \regex_match:n {#1}
+ \tl_gput_right:Nx \g_regex_replaced_str
+ {
+ \str_from_to:Nnn \l_regex_query_str
+ { \int_use:N \l_regex_start_step_int }
+ { \c_max_int }
+ }
+ \group_end:
+ }
+\cs_new_protected_nopar:Npn \regex_replace_all_aux:
+ {
+ \regex_extract:
+ \regex_extract_aux:nTF {0}
+ {
+ \tl_gput_right:Nx \g_regex_replaced_str
+ {
+ \str_from_to:Nnn \l_regex_query_str
+ { \int_use:N \l_regex_start_step_int }
+ { \l_regex_tmpa_tl }
+ \l_regex_replacement_tl
+ }
+ }
+ { \msg_error:nn { regex } { internal } }
+ \regex_match_once:
+ }
+\cs_new_protected:Npn \regex_replace_all:nnN #1#2#3
+ {
+ \regex_replace_all_aux:Nn #3
+ {
+ \regex_build:n {#1}
+ \regex_replacement:n {#2}
+ }
+ }
+\cs_new_protected:Npn \regex_replace_all:NnN #1#2#3
+ {
+ \regex_replace_all_aux:Nn #3
+ {
+ \regex_use:N #1
+ \regex_replacement:n {#2}
+ }
+ }
+%%
+%%
+%% End of file `l3regex-trace.sty'.
diff --git a/Master/texmf-dist/tex/latex/l3experimental/l3str/l3regex.sty b/Master/texmf-dist/tex/latex/l3experimental/l3str/l3regex.sty
new file mode 100644
index 00000000000..5da00fdd3d0
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/l3experimental/l3str/l3regex.sty
@@ -0,0 +1,1637 @@
+%%
+%% This is file `l3regex.sty',
+%% generated with the docstrip utility.
+%%
+%% The original source files were:
+%%
+%% l3regex.dtx (with options: `package')
+%%
+%% EXPERIMENTAL CODE
+%%
+%% Do not distribute this file without also distributing the
+%% source files specified above.
+%%
+%% Do not distribute a modified version of this file.
+%%
+%% File: l3regex.dtx Copyright (C) 2011 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 LaTeX3 Project.
+%%
+%% -----------------------------------------------------------------------
+\RequirePackage{expl3}
+\GetIdInfo$Id: l3regex.dtx 2895 2011-10-09 15:58:19Z joseph $
+ {L3 Experimental Regular Expressions}
+\ProvidesExplPackage
+ {\ExplFileName}{\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription}
+\RequirePackage{l3str}
+\cs_new:Npn \regex_tmp:w { }
+\tl_new:N \g_regex_tmpa_tl
+\tl_new:N \l_regex_tmpa_tl
+\tl_new:N \l_regex_tmpb_tl
+\int_new:N \l_regex_tmpa_int
+\tl_new:N \l_regex_pattern_str
+\int_new:N \l_regex_max_state_int
+\int_new:N \l_regex_left_state_int
+\int_new:N \l_regex_right_state_int
+\seq_new:N \l_regex_left_state_seq
+\seq_new:N \l_regex_right_state_seq
+\int_new:N \l_regex_capturing_group_int
+\seq_new:N \l_regex_capturing_group_seq
+\tl_new:N \l_regex_one_or_group_tl
+\int_new:N \l_regex_repetition_int
+\bool_new:N \l_regex_look_behind_bool
+\tl_new:N \l_regex_look_behind_str
+\cs_new_eq:NN \regex_build_tmp_class:n \use_none:n
+\bool_new:N \l_regex_class_bool
+\tl_new:N \l_regex_class_tl
+\tl_const:Nn \c_regex_d_tl
+ {
+ \regex_item_range:nn {48} {57} % 0--9
+ }
+\tl_const:Nn \c_regex_D_tl
+ {
+ \regex_item_more:n {57} % 9
+ \regex_item_range:nn {0} {47} % 0
+ }
+\tl_const:Nn \c_regex_h_tl
+ {
+ \regex_item_equal:n {32} % space
+ \regex_item_equal:n {9} % tab
+ }
+\tl_const:Nn \c_regex_H_tl
+ {
+ \regex_item_neq:n {32} % space
+ \regex_item_neq:n {9} % tab
+ \regex_break_true:w
+ }
+\tl_const:Nn \c_regex_s_tl
+ {
+ \regex_item_equal:n {32} % space
+ \regex_item_neq:n {11} % vtab
+ \regex_item_range:nn {9} {13} % tab, lf, vtab, ff, cr
+ }
+\tl_const:Nn \c_regex_S_tl
+ {
+ \regex_item_more:n {32} % > space
+ \regex_item_range:nn {14} {31} % tab < ... < space
+ \regex_item_range:nn {0} {8} % < tab
+ \regex_item_equal:n {11} % vtab
+ }
+\tl_const:Nn \c_regex_v_tl
+ {
+ \regex_item_range:nn {10} {13} % lf, vtab, ff, cr
+ }
+\tl_const:Nn \c_regex_V_tl
+ {
+ \regex_item_more:n {13} % cr
+ \regex_item_range:nn {0} {9} % < lf
+ }
+\tl_const:Nn \c_regex_w_tl
+ {
+ \regex_item_range:nn {97} {122} % a--z
+ \regex_item_range:nn {65} {90} % A--Z
+ \regex_item_range:nn {48} {57} % 0--9
+ \regex_item_equal:n {95} % _
+ }
+\tl_const:Nn \c_regex_W_tl
+ {
+ \regex_item_range:nn {0} {47} % <`0
+ \regex_item_range:nn {58} {64} % (`9+1)--(`A-1)
+ \regex_item_range:nn {91} {94} % (`Z+1)--(`_-1)
+ \regex_item_equal:n {96} % `
+ \regex_item_more:n {122} % z
+ }
+\tl_const:Nn \c_regex_N_tl
+ {
+ \regex_item_neq:n {10} % lf
+ \regex_break_true:w
+ }
+\tl_new:N \l_regex_query_str
+\int_new:N \l_regex_start_step_int
+\int_new:N \l_regex_current_char_int
+\int_new:N \l_regex_current_step_int
+\int_new:N \l_regex_unique_step_int
+\int_new:N \l_regex_current_state_int
+\prop_new:N \l_regex_current_submatches_prop
+\int_new:N \l_regex_max_index_int
+\tl_new:N \l_regex_every_match_tl
+\cs_new_protected:Npn \regex_last_match_empty_no:F #1 {#1}
+\cs_new_protected:Npn \regex_last_match_empty_yes:F
+ { \int_compare:nNnF \l_regex_start_step_int = \l_regex_current_step_int }
+\cs_new_eq:NN \regex_last_match_empty:F \regex_last_match_empty_no:F
+\bool_new:N \l_regex_success_bool
+\bool_new:N \l_regex_success_empty_bool
+\int_new:N \l_regex_success_step_int
+\prop_new:N \l_regex_success_submatches_prop
+\bool_new:N \l_regex_fresh_thread_bool
+\seq_new:N \g_regex_submatches_seq
+\int_new:N \g_regex_match_count_int
+\seq_new:N \g_regex_split_seq
+\tl_new:N \l_regex_replacement_tl
+\tl_new:N \g_regex_replaced_str
+\cs_new_eq:NN \s_regex_toks \scan_stop:
+\cs_new_protected:Npn \regex_toks_put_left:Nx #1#2
+ {
+ \cs_set_nopar:Npx \regex_tmp:w \s_regex_toks { \s_regex_toks #2 }
+ \tex_toks:D #1 \exp_after:wN \exp_after:wN \exp_after:wN
+ { \exp_after:wN \regex_tmp:w \tex_the:D \tex_toks:D #1 }
+ }
+\cs_new_protected:Npn \regex_toks_put_right:Nx #1#2
+ {
+ \cs_set_nopar:Npx \regex_tmp:w {#2}
+ \tex_toks:D #1 \exp_after:wN
+ { \tex_the:D \tex_toks:D \exp_after:wN #1 \regex_tmp:w }
+ }
+\cs_new_eq:NN \regex_if_tail_stop:N \quark_if_recursion_tail_stop:N
+\cs_new_protected_nopar:Npn \regex_if_tail_error:Nn #1#2
+ { \quark_if_recursion_tail_stop_do:Nn #1 { \regex_build_error:n {#2} } }
+\cs_new_protected_nopar:Npn \regex_build_error:n #1
+ {
+ \msg_error:nnxx { regex } { build-error } {\int_eval:n{#1}}
+ {
+ \prg_case_int:nnn {#1}
+ {
+ {-999} {File~not~found}
+ {-998} {Unsupported~construct}
+ {-997} {The~regular~expression~is~too~large~(32768~states).}
+ {1} {\iow_char:N\\~at~end~of~pattern }
+ {4} {Numbers~out~of~order~in~\iow_char:N\{\iow_char\}~quantifier.}
+ {6} {Missing~terminating~\iow_char:N\]~for~character~class }
+ {7} {Invalid~escape~sequence~in~character~class}
+ {8} {Range~out~of~order~in~character~class}
+ {22} {Mismatched~parentheses}
+ {34} {Character~value~in~\iow_char:N\\x{...}~sequence~is~too~large}
+ }
+ { Internal~bug. }
+ }
+ }
+\msg_new:nnn { regex } { build-error } { (error~#1): ~ #2 }
+\cs_new_nopar:Npn \regex_break_true:w #1 \regex_break_point:TF #2 #3 {#2}
+\cs_new_nopar:Npn \regex_break_false:w #1 \regex_break_point:TF #2 #3 {#3}
+\cs_new_eq:NN \regex_break_point:TF \use_ii:nn
+\cs_new_nopar:Npn \regex_item_equal:n #1
+ {
+ \if_num:w #1 = \l_regex_current_char_int
+ \exp_after:wN \regex_break_true:w
+ \fi:
+ }
+\cs_new_nopar:Npn \regex_item_range:nn #1 #2
+ {
+ \reverse_if:N \if_num:w #1 > \l_regex_current_char_int
+ \reverse_if:N \if_num:w #2 < \l_regex_current_char_int
+ \exp_after:wN \exp_after:wN \exp_after:wN \regex_break_true:w
+ \fi:
+ \fi:
+ }
+\cs_new_nopar:Npn \regex_item_less:n #1
+ {
+ \if_num:w #1 > \l_regex_current_char_int
+ \exp_after:wN \regex_break_true:w
+ \fi:
+ }
+\cs_new_nopar:Npn \regex_item_more:n #1
+ {
+ \if_num:w #1 < \l_regex_current_char_int
+ \exp_after:wN \regex_break_true:w
+ \fi:
+ }
+\cs_new_nopar:Npn \regex_item_neq:n #1
+ {
+ \if_num:w #1 = \l_regex_current_char_int
+ \exp_after:wN \regex_break_false:w
+ \fi:
+ }
+\cs_new_protected:Npn \regex_get_digits:nw #1
+ {
+ \tex_afterassignment:D \regex_tmp:w
+ \cs_set_nopar:Npx \regex_tmp:w
+ {
+ \exp_not:n {#1}
+ { \if_false: } } \fi:
+ \regex_get_digits_aux:N
+ }
+\cs_new_nopar:Npn \regex_get_digits_aux:N #1
+ {
+ \if_num:w 9 < 1 \exp_not:N #1 \exp_stop_f:
+ \else:
+ \if_charcode:w \c_space_token \exp_not:N #1
+ \else:
+ \regex_get_digits_end:w
+ \fi:
+ \fi:
+ #1 \regex_get_digits_aux:N
+ }
+\cs_new_nopar:Npn \regex_get_digits_end:w
+ \fi: \fi: #1 \regex_get_digits_aux:N
+ {
+ \fi: \fi:
+ \if_false: { { \fi: } }
+ #1
+ }
+\prg_new_conditional:Npnn \regex_aux_char_if_special:N #1 { TF }
+ {
+ \if_num:w `#1 < 97 \exp_stop_f:
+ \if_num:w `#1 < 58 \exp_stop_f:
+ \if_num:w \int_eval:w (`#1 - \c_eight)/\c_sixteen = \c_two
+ \prg_return_true:
+ \else:
+ \prg_return_false:
+ \fi:
+ \else:
+ \if_num:w \int_eval:w `#1 / 26 = \c_three
+ \prg_return_false:
+ \else:
+ \prg_return_true:
+ \fi:
+ \fi:
+ \else:
+ \if_num:w \int_eval:w `#1 / \c_five = 25 \exp_stop_f:
+ \prg_return_true:
+ \else:
+ \prg_return_false:
+ \fi:
+ \fi:
+ }
+\prg_new_conditional:Npnn \regex_aux_char_if_alphanumeric:N #1 { TF }
+ {
+ \if_num:w `#1 < 91 \exp_stop_f:
+ \if_num:w `#1 < 65 \exp_stop_f:
+ \if_num:w \c_nine < 1 #1 \exp_stop_f:
+ \prg_return_true:
+ \else:
+ \prg_return_false:
+ \fi:
+ \else:
+ \prg_return_true:
+ \fi:
+ \else:
+ \if_num:w \int_eval:w (`#1-\c_six)/26 = \c_four
+ \prg_return_true:
+ \else:
+ \prg_return_false:
+ \fi:
+ \fi:
+ }
+\cs_new_protected_nopar:Npn \regex_build_new_state:
+ {
+ \int_compare:nNnTF \l_regex_max_state_int > {32766}
+ { \regex_build_error:n {-997} }
+ {
+ \int_incr:N \l_regex_max_state_int
+ \tex_toks:D \l_regex_max_state_int { \s_regex_toks }
+ }
+ \int_set_eq:NN \l_regex_left_state_int \l_regex_right_state_int
+ \int_set_eq:NN \l_regex_right_state_int \l_regex_max_state_int
+ }
+\cs_new_protected_nopar:Npn \regex_build_transition_aux:NN #1#2
+ {
+ \regex_build_new_state:
+ \regex_toks_put_right:Nx \l_regex_left_state_int
+ { #1 { \int_use:N #2 } }
+ }
+\cs_new_protected_nopar:Npn \regex_build_transitions_aux:NNNN #1#2#3#4
+ {
+ \regex_build_new_state:
+ \regex_toks_put_right:Nx \l_regex_left_state_int
+ {
+ #1 { \int_use:N #2 }
+ #3 { \int_use:N #4 }
+ }
+ }
+\cs_new_protected:Npn \regex_build:n #1
+ {
+ \regex_build_setup:
+ \str_aux_escape:NNNn
+ \regex_build_i_unescaped:N
+ \regex_build_i_escaped:N
+ \regex_build_i_raw:N
+ { #1 }
+ \regex_build_open_aux:
+ \g_str_result_tl \prg_do_nothing: \prg_do_nothing:
+ \seq_push:Nn \l_regex_capturing_group_seq { 0 }
+ \regex_build_close_aux: \regex_build_group_:
+ \regex_build_end:
+ }
+\cs_new_nopar:Npn \regex_build_i_unescaped:N #1
+ {
+ \regex_aux_char_if_special:NTF #1
+ { \exp_not:N \regex_build_control:N #1 }
+ { \exp_not:N \regex_build_raw:N #1 }
+ }
+\cs_new_nopar:Npn \regex_build_i_escaped:N #1
+ {
+ \regex_aux_char_if_alphanumeric:NTF #1
+ { \exp_not:N \regex_build_control:N #1 }
+ { \exp_not:N \regex_build_raw:N #1 }
+ }
+\cs_new_nopar:Npn \regex_build_i_raw:N #1
+ { \exp_not:N \regex_build_raw:N #1 }
+\cs_new_protected_nopar:Npn \regex_build_default_control:N #1
+ {
+ \cs_if_exist_use:cF { regex_build_#1: }
+ { \regex_build_default_raw:N #1 }
+ }
+\cs_new_protected_nopar:Npn \regex_build_setup:
+ {
+ \cs_set_eq:NN \regex_build_control:N \regex_build_default_control:N
+ \cs_set_eq:NN \regex_build_raw:N \regex_build_default_raw:N
+ \int_set_eq:NN \l_regex_capturing_group_int \c_zero
+ \int_zero:N \l_regex_left_state_int
+ \int_zero:N \l_regex_right_state_int
+ \int_zero:N \l_regex_max_state_int
+ \regex_build_new_state:
+ \regex_build_new_state:
+ \regex_toks_put_right:Nx \l_regex_left_state_int
+ {
+ \regex_action_start_wildcard:nn
+ { \int_use:N \l_regex_left_state_int }
+ { \int_use:N \l_regex_right_state_int }
+ }
+ }
+\cs_new_protected_nopar:Npn \regex_build_end:
+ {
+ \seq_if_empty:NF \l_regex_capturing_group_seq
+ {
+ \regex_build_error:n {22}
+ \prg_replicate:nn
+ { \seq_length:N \l_regex_capturing_group_seq } % (
+ { \regex_build_close_aux: \regex_build_group_: }
+ }
+ \regex_toks_put_right:Nx \l_regex_right_state_int
+ { \regex_action_success: }
+ }
+\cs_new_protected_nopar:cpn { regex_build_^: }
+ { \regex_build_anchor_start:N \c_zero }
+\cs_new_protected_nopar:Npn \regex_build_A:
+ { \regex_build_anchor_start:N \c_zero }
+\cs_new_protected_nopar:Npn \regex_build_G:
+ { \regex_build_anchor_start:N \l_regex_start_step_int }
+\cs_new_protected_nopar:Npn \regex_build_anchor_start:N #1
+ {
+ \regex_build_new_state:
+ \regex_toks_put_right:Nx \l_regex_left_state_int
+ {
+ \exp_not:N \int_compare:nNnT {#1} = \l_regex_current_step_int
+ { \regex_action_free:n { \int_use:N \l_regex_right_state_int } }
+ }
+ }
+\cs_new_protected_nopar:cpn { regex_build_$: } % $
+ {
+ \regex_build_new_state:
+ \regex_toks_put_right:Nx \l_regex_left_state_int
+ {
+ \exp_not:N \int_compare:nNnT
+ \c_minus_one = \l_regex_current_char_int
+ { \regex_action_free:n { \int_use:N \l_regex_right_state_int } }
+ }
+ }
+\cs_new_eq:Nc \regex_build_Z: { regex_build_$: } %$
+\cs_new_eq:Nc \regex_build_z: { regex_build_$: } %$
+\cs_new_protected_nopar:Npn \regex_build_b:
+ {
+ \bool_set_true:N \l_regex_look_behind_bool
+ \regex_build_new_state:
+ \regex_toks_put_right:Nx \l_regex_left_state_int
+ {
+ \exp_not:N \regex_if_word_boundary:TF
+ { \regex_action_free:n { \int_use:N \l_regex_right_state_int } }
+ { }
+ }
+ }
+\cs_new_protected_nopar:Npn \regex_build_B:
+ {
+ \bool_set_true:N \l_regex_look_behind_bool
+ \regex_build_new_state:
+ \regex_toks_put_right:Nx \l_regex_left_state_int
+ {
+ \exp_not:N \regex_if_word_boundary:TF
+ { }
+ { \regex_action_free:n { \int_use:N \l_regex_right_state_int } }
+ }
+ }
+\cs_new_protected_nopar:Npn \regex_if_word_boundary:TF
+ {
+ \tl_if_empty:NTF \l_regex_look_behind_str
+ { \c_regex_w_tl }
+ {
+ \group_begin:
+ \cs_set_nopar:Npx \regex_tmp:w
+ {
+ \int_set:Nn \l_regex_current_char_int
+ { ` \str_head:N \l_regex_look_behind_str }
+ }
+ \regex_tmp:w
+ \c_regex_w_tl
+ \regex_break_point:TF
+ { \group_end: \c_regex_W_tl }
+ { \group_end: \c_regex_w_tl }
+ }
+ \regex_break_point:TF
+ }
+\cs_new_protected_nopar:Npn \regex_build_default_raw:N #1
+ {
+ \cs_set:Npx \regex_build_tmp_class:n ##1
+ {
+ \exp_not:n { \exp_not:N \if_num:w }
+ \int_value:w `#1 = \l_regex_current_char_int
+ \regex_action_cost:n { ##1 }
+ \exp_not:n { \exp_not:N \fi: }
+ }
+ \regex_build_one_quantifier:
+ }
+\cs_new_protected_nopar:cpn { regex_build_.: }
+ {
+ \cs_set:Npn \regex_build_tmp_class:n ##1
+ {
+ \exp_not:N \if_num:w \c_minus_one < \l_regex_current_char_int
+ \regex_action_cost:n {##1}
+ \exp_not:N \fi:
+ }
+ \regex_build_one_quantifier:
+ }
+\cs_new_protected_nopar:Npn \regex_build_char_type:N #1
+ {
+ \cs_set:Npn \regex_build_tmp_class:n ##1
+ {
+ \exp_not:N #1
+ \exp_not:N \regex_break_point:TF
+ { \regex_action_cost:n {##1} }
+ { }
+ }
+ \regex_build_one_quantifier:
+ }
+\tl_map_inline:nn { dDhHsSvVwWN }
+ {
+ \cs_new_protected_nopar:cpx { regex_build_#1: }
+ {
+ \exp_not:N \regex_build_char_type:N
+ \exp_not:c { c_regex_#1_tl }
+ }
+ }
+\cs_new_protected_nopar:cpn { regex_build_[: }
+ {
+ \tl_clear:N \l_regex_class_tl
+ \cs_set_eq:NN \regex_build_control:N \regex_class_control:N
+ \cs_set_eq:NN \regex_build_raw:N \regex_class_raw:N
+ \regex_class_first:NN
+ }
+\cs_new_protected_nopar:Npn \regex_class_control:N #1
+ {
+ \cs_if_exist_use:cF { regex_class_#1: }
+ { \regex_class_raw:N #1 }
+ }
+\cs_new_protected_nopar:cpn { regex_class_]: }
+ {
+ \tl_if_empty:NTF \l_regex_class_tl %[
+ { \regex_class_raw:N ] }
+ {
+ \cs_set_eq:NN \regex_build_control:N \regex_build_default_control:N
+ \cs_set_eq:NN \regex_build_raw:N \regex_build_default_raw:N
+ \cs_set:Npn \regex_build_tmp_class:n ##1
+ {
+ \exp_not:o \l_regex_class_tl
+ \bool_if:NTF \l_regex_class_bool
+ {
+ \exp_not:N \regex_break_point:TF
+ { \regex_action_cost:n {##1} }
+ { }
+ }
+ {
+ \exp_not:N \regex_break_point:TF
+ { }
+ { \regex_action_cost:n {##1} }
+ }
+ }
+ \regex_build_one_quantifier:
+ }
+ }
+\cs_new_protected_nopar:Npn \regex_class_first:NN #1#2
+ {
+ \str_if_eq:nnTF {#1#2} { \regex_build_control:N ^ }
+ { \bool_set_false:N \l_regex_class_bool }
+ {
+ \bool_set_true:N \l_regex_class_bool
+ #1 #2
+ }
+ }
+\cs_new_protected_nopar:Npn \regex_class_raw:N #1#2#3
+ {
+ \str_if_eq:nnTF {#2#3} { \regex_build_control:N - }
+ { \regex_class_range:Nw #1 }
+ {
+ \regex_class_single:N #1
+ #2 #3
+ }
+ }
+\cs_new_protected_nopar:Npn \regex_class_single:N #1
+ {
+ \tl_put_right:Nx \l_regex_class_tl
+ { \exp_not:N \regex_item_equal:n { \int_value:w `#1 } }
+ }
+\cs_new_protected_nopar:Npn \regex_class_range:Nw #1#2#3
+ {
+ \token_if_eq_meaning:NNTF #2 \regex_build_control:N
+ {
+ \cs_if_exist:cTF { regex_class_#3: }
+ {
+ \regex_class_single:N #1
+ \regex_class_single:N -
+ #2#3
+ }
+ { \regex_class_range_put:NN #1#3 }
+ }
+ { \regex_class_range_put:NN #1#3 }
+ }
+\cs_new_protected_nopar:Npn \regex_class_range_put:NN #1#2
+ {
+ \if_num:w `#1 > `#2 \exp_stop_f:
+ \regex_build_error:n {8}
+ \else:
+ \tl_put_right:Nx \l_regex_class_tl
+ {
+ \if_num:w `#1 = `#2 \exp_stop_f:
+ \exp_not:N \regex_item_equal:n
+ \else:
+ \exp_not:N \regex_item_range:nn { \int_value:w `#1 }
+ \fi:
+ { \int_value:w `#2 }
+ }
+ \fi:
+ }
+\tl_map_inline:nn { dDhHsSvVwWN }
+ {
+ \cs_new_protected_nopar:cpx { regex_class_#1: }
+ {
+ \tl_put_right:Nn \exp_not:N \l_regex_class_tl
+ { \exp_not:c { c_regex_#1_tl } }
+ }
+ }
+\cs_new_protected_nopar:Npn \regex_build_quantifier:w #1#2
+ {
+ \token_if_eq_meaning:NNTF #1 \regex_build_control:N
+ {
+ \cs_if_exist_use:cF { regex_build_quantifier_#2:w }
+ {
+ \regex_build_quantifier_end:n { }
+ #1 #2
+ }
+ }
+ {
+ \regex_build_quantifier_end:n { }
+ #1 #2
+ }
+ }
+\cs_new_protected_nopar:cpn { regex_build_quantifier_?:w }
+ { \regex_build_quantifier_aux:nnNN { } { ? } }
+\cs_new_protected_nopar:cpn { regex_build_quantifier_*:w }
+ { \regex_build_quantifier_aux:nnNN { } { * } }
+\cs_new_protected_nopar:cpn { regex_build_quantifier_+:w }
+ { \regex_build_quantifier_aux:nnNN { } { + } }
+\cs_new_protected_nopar:Npn \regex_build_quantifier_aux:nnNN #1#2#3#4
+ {
+ \str_if_eq:nnTF { #3 #4 } { \regex_build_control:N ? }
+ { \regex_build_quantifier_end:n { #2 #4 } #1 }
+ {
+ \regex_build_quantifier_end:n { #2 } #1
+ #3 #4
+ }
+ }
+\cs_new_protected_nopar:cpn { regex_build_quantifier_ \c_lbrace_str :w }
+ { \regex_get_digits:nw { \regex_build_quantifier_lbrace:n } }
+\cs_new_protected_nopar:Npn \regex_build_quantifier_lbrace:n #1
+ {
+ \tl_if_empty:nTF {#1}
+ {
+ \regex_build_quantifier_end:n { }
+ \exp_after:wN \regex_build_raw:N \c_lbrace_str
+ }
+ { \regex_build_quantifier_lbrace:nw {#1} }
+ }
+\cs_new_protected_nopar:Npx \regex_build_quantifier_lbrace:nw #1#2#3
+ {
+ \exp_not:N \prg_case_str:nnn { #2 #3 }
+ {
+ { \exp_not:N \regex_build_control:N , }
+ {
+ \exp_not:N \regex_get_digits:nw
+ { \exp_not:N \regex_build_quantifier_lbrace:nnw {#1} }
+ }
+ { \exp_not:N \regex_build_control:N \c_rbrace_str }
+ { \exp_not:N \regex_build_quantifier_end:n {n} {#1} }
+ }
+ {
+ \exp_not:N \regex_build_quantifier_end:n { }
+ \exp_not:N \regex_build_raw:N \c_lbrace_str #1#2
+ }
+ }
+\cs_new_protected_nopar:Npn \regex_build_quantifier_lbrace:nnw #1#2#3
+ {
+ \str_if_eq:xxTF { \exp_not:N #3 } { \c_rbrace_str }
+ {
+ \tl_if_empty:nTF {#2}
+ { \regex_build_quantifier_aux:nnN { {#1} {\c_max_int} } {nn} }
+ {
+ \int_compare:nNnT {#1} > {#2}
+ { \regex_build_error:n {4} }
+ \regex_build_quantifier_aux:nnN { {#1} {#2} } {nn}
+ }
+ }
+ {
+ \regex_build_quantifier_end:n { }
+ \use:x
+ {
+ \exp_not:n { \exp_args:No \tl_map_function:nN }
+ { \c_lbrace_str #1 #2 , }
+ \regex_build_raw:N
+ }
+ }
+ }
+\cs_new_protected_nopar:Npn \regex_build_quantifier_end:n #1
+ { \use:c { regex_build_ \l_regex_one_or_group_tl _ #1 : } }
+\cs_new_protected_nopar:Npn \regex_build_one_quantifier:
+ {
+ \tl_set:Nx \l_regex_one_or_group_tl { one }
+ \regex_build_quantifier:w
+ }
+\cs_new_protected_nopar:Npn \regex_build_one_:
+ {
+ \regex_build_transition_aux:NN
+ \regex_build_tmp_class:n \l_regex_right_state_int
+ }
+\cs_new_protected_nopar:cpn { regex_build_one_?: }
+ {
+ \regex_build_transitions_aux:NNNN
+ \regex_build_tmp_class:n \l_regex_right_state_int
+ \regex_action_free:n \l_regex_right_state_int
+ }
+\cs_new_protected_nopar:cpn { regex_build_one_??: }
+ {
+ \regex_build_transitions_aux:NNNN
+ \regex_action_free:n \l_regex_right_state_int
+ \regex_build_tmp_class:n \l_regex_right_state_int
+ }
+\cs_new_protected_nopar:cpn { regex_build_one_*: }
+ {
+ \regex_build_transitions_aux:NNNN
+ \regex_build_tmp_class:n \l_regex_left_state_int
+ \regex_action_free:n \l_regex_right_state_int
+ }
+\cs_new_protected_nopar:cpn { regex_build_one_*?: }
+ {
+ \regex_build_transitions_aux:NNNN
+ \regex_action_free:n \l_regex_right_state_int
+ \regex_build_tmp_class:n \l_regex_left_state_int
+ }
+\cs_new_protected_nopar:cpn { regex_build_one_+: }
+ {
+ \regex_build_one_:
+ \int_set_eq:NN \l_regex_tmpa_int \l_regex_left_state_int
+ \regex_build_transitions_aux:NNNN
+ \regex_action_free:n \l_regex_tmpa_int
+ \regex_action_free:n \l_regex_right_state_int
+ }
+\cs_new_protected_nopar:cpn { regex_build_one_+?: }
+ {
+ \regex_build_one_:
+ \int_set_eq:NN \l_regex_tmpa_int \l_regex_left_state_int
+ \regex_build_transitions_aux:NNNN
+ \regex_action_free:n \l_regex_right_state_int
+ \regex_action_free:n \l_regex_tmpa_int
+ }
+\cs_new_protected_nopar:Npn \regex_build_one_n: #1
+ {
+ \int_set_eq:NN \l_regex_tmpa_int \l_regex_right_state_int
+ \regex_build_new_state:
+ \regex_build_new_state:
+ \regex_toks_put_right:Nx \l_regex_tmpa_int
+ { %^^A safe \if nesting?
+ \exp_not:N \if_num:w #1 > \l_regex_repetition_int
+ \regex_action_repeat_move:n
+ { \int_use:N \l_regex_left_state_int }
+ \exp_not:N \else:
+ \regex_action_no_repeat_move:n
+ { \int_use:N \l_regex_right_state_int }
+ \exp_not:N \fi:
+ }
+ \regex_toks_put_right:Nx \l_regex_left_state_int
+ {
+ \regex_build_tmp_class:n
+ { \int_use:N \l_regex_tmpa_int }
+ }
+ }
+\cs_new_eq:cN { regex_build_one_n?: } \regex_build_one_n:
+\cs_new_protected_nopar:Npn \regex_build_one_nn: #1#2
+ {
+ \regex_build_one_nn_aux:nn {#1}
+ {
+ \exp_not:N \if_num:w #2 > \l_regex_repetition_int
+ \regex_action_repeat_copy:n
+ { \int_use:N \l_regex_left_state_int }
+ \exp_not:N \fi:
+ \regex_action_no_repeat_move:n
+ { \int_use:N \l_regex_right_state_int }
+ }
+ }
+\cs_new_protected_nopar:cpn { regex_build_one_nn?: } #1#2
+ {
+ \regex_build_one_nn_aux:nn {#1}
+ {
+ \regex_action_no_repeat_copy:n
+ { \int_use:N \l_regex_right_state_int }
+ \exp_not:N \if_num:w #2 > \l_regex_repetition_int
+ \regex_action_repeat_move:n
+ { \int_use:N \l_regex_left_state_int }
+ \exp_not:N \fi:
+ }
+ }
+\cs_new_protected_nopar:Npn \regex_build_one_nn_aux:nn #1#2
+ {
+ \int_set_eq:NN \l_regex_tmpa_int \l_regex_right_state_int
+ \regex_build_new_state:
+ \regex_build_new_state:
+ \regex_toks_put_right:Nx \l_regex_tmpa_int
+ {
+ \exp_not:N \if_num:w #1 > \l_regex_repetition_int
+ \regex_action_repeat_move:n
+ { \int_use:N \l_regex_left_state_int }
+ \exp_not:N \else:
+ #2
+ \exp_not:N \fi:
+ }
+ \regex_toks_put_right:Nx \l_regex_left_state_int
+ {
+ \regex_build_tmp_class:n
+ { \int_use:N \l_regex_tmpa_int }
+ }
+ }
+\cs_new_protected_nopar:cpn { regex_build_(: } #1#2
+ {
+ \str_if_eq:nnTF { #1 #2 } { \regex_build_control:N ? }
+ { \regex_build_special_group:NN }
+ {
+ \int_incr:N \l_regex_capturing_group_int
+ \seq_push:Nx \l_regex_capturing_group_seq
+ { \int_use:N \l_regex_capturing_group_int }
+ \regex_build_open_aux:
+ #1 #2
+ }
+ }
+\cs_new_protected_nopar:Npn \regex_build_open_aux:
+ {
+ \regex_build_new_state:
+ \seq_push:Nx \l_regex_left_state_seq
+ { \int_use:N \l_regex_left_state_int }
+ \seq_push:Nx \l_regex_right_state_seq
+ { \int_use:N \l_regex_right_state_int }
+ \regex_build_begin_alternation:
+ }
+\cs_new_protected_nopar:cpn { regex_build_|: }
+ {
+ \regex_build_end_alternation:
+ \regex_build_begin_alternation:
+ }
+\cs_new_protected_nopar:cpn { regex_build_): }
+ {
+ \seq_if_empty:NTF \l_regex_capturing_group_seq
+ { \regex_build_error:n {22} }
+ {
+ \regex_build_close_aux:
+ \regex_build_group_quantifier:
+ }
+ }
+\cs_new_protected_nopar:Npn \regex_build_close_aux:
+ {
+ \regex_build_end_alternation:
+ \seq_pop:NN \l_regex_left_state_seq \l_regex_tmpa_tl
+ \int_set:Nn \l_regex_left_state_int \l_regex_tmpa_tl
+ \seq_pop:NN \l_regex_right_state_seq \l_regex_tmpa_tl
+ \int_set:Nn \l_regex_right_state_int \l_regex_tmpa_tl
+ }
+\cs_new_protected_nopar:Npn \regex_build_begin_alternation:
+ {
+ \regex_build_new_state:
+ \seq_get:NN \l_regex_left_state_seq \l_regex_tmpa_tl
+ \int_set:Nn \l_regex_left_state_int \l_regex_tmpa_tl
+ \regex_toks_put_right:Nx \l_regex_left_state_int
+ { \regex_action_free:n { \int_use:N \l_regex_right_state_int } }
+ }
+\cs_new_protected_nopar:Npn \regex_build_end_alternation:
+ {
+ \seq_get:NN \l_regex_right_state_seq \l_regex_tmpa_tl
+ \regex_toks_put_right:Nx \l_regex_right_state_int
+ { \regex_action_free:n { \l_regex_tmpa_tl } }
+ }
+\cs_new_protected_nopar:Npn \regex_build_special_group:NN #1#2
+ {
+ \cs_if_exist_use:cF { regex_build_special_group_\token_to_str:N #2 : }
+ {
+ \regex_build_error:n { -998 }
+ \regex_build_control:N ( % )
+ \regex_build_raw:N ?
+ #1 #2
+ }
+ }
+\cs_new_protected_nopar:cpn { regex_build_special_group_:: }
+ {
+ \seq_push:Nx \l_regex_capturing_group_seq { * }
+ \regex_build_open_aux:
+ }
+\cs_new_protected_nopar:Npn \regex_build_group_quantifier:
+ {
+ \tl_set:Nn \l_regex_one_or_group_tl { group }
+ \regex_build_quantifier:w
+ }
+\cs_new_protected_nopar:Npn \regex_build_group_submatches:NN #1#2
+ {
+ \seq_pop:NN \l_regex_capturing_group_seq \l_regex_tmpa_tl
+ \str_if_eq:xxF { \l_regex_tmpa_tl } { * }
+ {
+ \regex_toks_put_left:Nx #1
+ { \regex_action_submatch:n { \l_regex_tmpa_tl < } }
+ \regex_toks_put_left:Nx #2
+ { \regex_action_submatch:n { \l_regex_tmpa_tl > } }
+ }
+ }
+\cs_new_protected_nopar:Npn \regex_build_group_:
+ {
+ \regex_build_group_submatches:NN
+ \l_regex_left_state_int \l_regex_right_state_int
+ \regex_build_transition_aux:NN
+ \regex_action_free:n \l_regex_right_state_int
+ }
+\cs_new_protected_nopar:Npn \regex_build_group_shift:N #1
+ {
+ \int_set_eq:NN \l_regex_tmpa_int \l_regex_left_state_int
+ \regex_build_new_state:
+ \tex_toks:D \l_regex_right_state_int = \tex_toks:D \l_regex_tmpa_int
+ \use:x
+ {
+ \tex_toks:D \l_regex_tmpa_int
+ { \s_regex_toks #1 { \int_use:N \l_regex_right_state_int } }
+ }
+ \regex_build_group_submatches:NN
+ \l_regex_right_state_int \l_regex_left_state_int
+ \int_set_eq:NN \l_regex_right_state_int \l_regex_left_state_int
+ }
+\cs_new_protected_nopar:Npn \regex_build_group_qs_aux:NN #1#2
+ {
+ \regex_build_group_shift:N \regex_action_free:n
+ \regex_build_transition_aux:NN \regex_action_free:n #1
+ #2 \l_regex_tmpa_int
+ { \regex_action_free:n { \int_use:N \l_regex_right_state_int } }
+ }
+\cs_new_protected_nopar:cpn { regex_build_group_?: }
+ {
+ \regex_build_group_qs_aux:NN
+ \l_regex_right_state_int \regex_toks_put_right:Nx
+ }
+\cs_new_protected_nopar:cpn { regex_build_group_??: }
+ {
+ \regex_build_group_qs_aux:NN
+ \l_regex_right_state_int \regex_toks_put_left:Nx
+ }
+\cs_new_protected_nopar:cpn { regex_build_group_*: }
+ {
+ \regex_build_group_qs_aux:NN
+ \l_regex_tmpa_int \regex_toks_put_right:Nx
+ }
+\cs_new_protected_nopar:cpn { regex_build_group_*?: }
+ {
+ \regex_build_group_qs_aux:NN
+ \l_regex_tmpa_int \regex_toks_put_left:Nx
+ }
+\cs_new_protected_nopar:cpn { regex_build_group_+: }
+ {
+ \regex_build_group_submatches:NN
+ \l_regex_left_state_int \l_regex_right_state_int
+ \int_set_eq:NN \l_regex_tmpa_int \l_regex_left_state_int
+ \regex_build_transitions_aux:NNNN
+ \regex_action_free:n \l_regex_tmpa_int
+ \regex_action_free:n \l_regex_right_state_int
+ }
+\cs_new_protected_nopar:cpn { regex_build_group_+?: }
+ {
+ \regex_build_group_submatches:NN
+ \l_regex_left_state_int \l_regex_right_state_int
+ \int_set_eq:NN \l_regex_tmpa_int \l_regex_left_state_int
+ \regex_build_transitions_aux:NNNN
+ \regex_action_free:n \l_regex_right_state_int
+ \regex_action_free:n \l_regex_tmpa_int
+ }
+\cs_new_protected_nopar:Npn \regex_build_group_n: #1
+ {
+ \regex_build_group_shift:N \regex_action_repeat_move:n
+ \regex_build_transition_aux:NN
+ \regex_action_free:n \l_regex_tmpa_int
+ \use:x
+ {
+ \tex_toks:D \l_regex_tmpa_int
+ {
+ \s_regex_toks
+ \exp_not:N \if_num:w #1 > \l_regex_repetition_int
+ \tex_the:D \tex_toks:D \l_regex_tmpa_int
+ \exp_not:N \else:
+ \regex_action_no_repeat_move:n
+ { \int_use:N \l_regex_right_state_int }
+ \exp_not:N \fi:
+ }
+ }
+ }
+\cs_new_eq:cN { regex_build_group_n?: } \regex_build_group_n:
+\cs_new_protected_nopar:Npn \regex_build_group_nn: #1#2
+ {
+ \regex_build_group_shift:N \regex_action_repeat_move:n
+ \regex_build_transition_aux:NN
+ \regex_action_free:n \l_regex_tmpa_int
+ \use:x
+ {
+ \tex_toks:D \l_regex_tmpa_int
+ {
+ \s_regex_toks
+ \exp_not:N \if_num:w #1 > \l_regex_repetition_int
+ \tex_the:D \tex_toks:D \l_regex_tmpa_int
+ \exp_not:N \else:
+ \exp_not:N \if_num:w #2 > \l_regex_repetition_int
+ \tex_the:D \tex_toks:D \l_regex_tmpa_int
+ \exp_not:N \fi:
+ \regex_action_no_repeat_copy:n
+ { \int_use:N \l_regex_right_state_int }
+ \exp_not:N \fi:
+ }
+ }
+ }
+\cs_new_protected_nopar:cpn { regex_build_group_nn?: } #1#2
+ {
+ \regex_build_group_shift:N \regex_action_repeat_move:n
+ \regex_build_transition_aux:NN
+ \regex_action_free:n \l_regex_tmpa_int
+ \use:x
+ {
+ \tex_toks:D \l_regex_tmpa_int
+ {
+ \s_regex_toks
+ \exp_not:N \if_num:w #1 > \l_regex_repetition_int
+ \tex_the:D \tex_toks:D \l_regex_tmpa_int
+ \exp_not:N \else:
+ \regex_action_no_repeat_copy:n
+ { \int_use:N \l_regex_right_state_int }
+ \exp_not:N \if_num:w #2 > \l_regex_repetition_int
+ \tex_the:D \tex_toks:D \l_regex_tmpa_int
+ \exp_not:N \fi:
+ \exp_not:N \fi:
+ }
+ }
+ }
+\cs_new_protected:Npn \regex_if_state_free:nT #1
+ {
+ \if_num:w \tex_dimen:D #1 = \l_regex_unique_step_int
+ \exp_after:wN \use_none:n
+ \else:
+ \exp_after:wN \use:n
+ \fi:
+ }
+\cs_new_protected:Npn \regex_store_state:n #1
+ {
+ \int_incr:N \l_regex_max_index_int
+ \tex_skip:D \l_regex_max_index_int #1 sp \scan_stop:
+ \regex_store_submatches:n {#1}
+ }
+\cs_new_protected_nopar:Npn \regex_state_use_submatches:
+ { \regex_state_use_aux:n { } }
+\cs_new_protected_nopar:Npn \regex_state_use:
+ { \regex_state_use_aux:n { \exp_after:wN \regex_state_use_aux_ii:w } }
+\cs_new:Npn \regex_state_use_aux_ii:w #1 \s_regex_toks { }
+\cs_new_protected:Npn \regex_state_use_aux:n #1
+ {
+ \regex_if_state_free:nT { \l_regex_current_state_int }
+ {
+ \tex_dimen:D \l_regex_current_state_int
+ = \l_regex_unique_step_int sp \scan_stop:
+ #1 \tex_the:D \tex_toks:D \l_regex_current_state_int \scan_stop:
+ }
+ }
+\cs_new_protected_nopar:Npn \regex_disable_submatches:
+ {
+ \cs_set_eq:NN \regex_state_use_submatches: \regex_state_use:
+ \cs_set_eq:NN \regex_store_submatches:n
+ \regex_protected_use_none:n
+ \cs_set_eq:NN \regex_action_submatches:n
+ \regex_protected_use_none:n
+ }
+\cs_new_protected:Npn \regex_protected_use_none:n #1 { }
+\cs_new_protected:Npn \regex_store_submatches:n #1
+ {
+ \exp_after:wN \regex_store_submatches_aux:Nw
+ \exp_after:wN \l_regex_current_submatches_prop
+ \tex_the:D \tex_toks:D #1 \scan_stop: \q_stop
+ { #1 }
+ }
+\cs_new_protected:Npn \regex_store_submatches_aux:Nw #1 #2 \s_regex_toks
+ {
+ \exp_args:No \regex_store_submatches_aux_ii:wnnwwn { #1 }
+ #2
+ \regex_state_submatches:nn { \c_minus_one } { \q_prop }
+ \s_regex_toks
+ }
+\cs_new_protected:Npn \regex_store_submatches_aux_ii:wnnwwn
+ #1 \regex_state_submatches:nn #2#3 #4 \s_regex_toks #5 \q_stop #6
+ {
+ \tex_toks:D #6 \exp_after:wN
+ {
+ \exp_after:wN \regex_state_submatches:nn \exp_after:wN
+ { \int_value:w \int_eval:w \l_regex_unique_step_int + \c_one }
+ { #1 }
+ \regex_state_submatches:nn {#2} {#3}
+ \s_regex_toks
+ #5
+ }
+ }
+\cs_new_protected:Npn \regex_state_submatches:nn #1#2
+ {
+ \if_num:w #1 = \l_regex_unique_step_int
+ \tl_set:Nn \l_regex_current_submatches_prop {#2}
+ \fi:
+ }
+\cs_new_protected:Npn \regex_match:n #1
+ {
+ \tl_set:Nx \l_regex_query_str { \tl_to_other_str:n {#1} }
+ \regex_match_initial_setup:
+ \regex_match_once:
+ }
+\cs_new_protected_nopar:Npn \regex_match_once:
+ {
+ \regex_match_setup:
+ \exp_after:wN \regex_match_once_aux: \l_regex_query_str
+ \q_recursion_tail \q_recursion_stop
+ \bool_if:NT \l_regex_success_bool { \l_regex_every_match_tl }
+ }
+\cs_new_protected_nopar:Npn \regex_match_once_aux:
+ { \str_skip_do:nn { \l_regex_start_step_int } { \regex_match_loop:N } }
+\cs_new_protected_nopar:Npn \regex_match_initial_setup:
+ {
+ \tl_clear:N \l_regex_look_behind_str
+ \prg_stepwise_inline:nnnn {1} {1} { \l_regex_max_state_int }
+ { \tex_dimen:D ##1 \c_minus_one sp \scan_stop: }
+ \int_set_eq:NN \l_regex_unique_step_int \c_minus_one
+ \int_set_eq:NN \l_regex_start_step_int \c_minus_one
+ \int_set_eq:NN \l_regex_current_step_int \c_zero
+ \int_set_eq:NN \l_regex_success_step_int \c_zero
+ \bool_set_false:N \l_regex_success_empty_bool
+ }
+\cs_new_protected_nopar:Npn \regex_match_setup:
+ {
+ \prop_clear:N \l_regex_current_submatches_prop
+ \bool_if:NTF \l_regex_success_empty_bool
+ { \cs_set_eq:NN \regex_last_match_empty:F \regex_last_match_empty_yes:F }
+ { \cs_set_eq:NN \regex_last_match_empty:F \regex_last_match_empty_no:F }
+ \int_set_eq:NN \l_regex_start_step_int \l_regex_success_step_int
+ \int_set_eq:NN \l_regex_current_step_int \l_regex_start_step_int
+ \int_decr:N \l_regex_current_step_int
+ \bool_set_false:N \l_regex_success_bool
+ \int_zero:N \l_regex_max_index_int
+ \regex_store_state:n {1}
+ }
+\cs_new_protected_nopar:Npn \regex_match_loop_setup:
+ {
+ \int_incr:N \l_regex_current_step_int
+ \int_incr:N \l_regex_unique_step_int
+ \bool_set_false:N \l_regex_fresh_thread_bool
+ }
+\cs_new_eq:NN \s_regex_step \scan_stop:
+\cs_new:Npn \regex_break_step:w #1 \s_regex_step { }
+\cs_new_protected_nopar:Npn \regex_match_loop:N #1
+ {
+ \regex_match_loop_setup:
+ \token_if_eq_meaning:NNTF #1 \q_recursion_tail
+ { \int_set_eq:NN \l_regex_current_char_int \c_minus_one }
+ { \int_set:Nn \l_regex_current_char_int {`#1} }
+ \cs_set_nopar:Npx \regex_tmp:w
+ {
+ \int_zero:N \l_regex_max_index_int
+ \prg_stepwise_function:nnnN
+ {1} {1} { \l_regex_max_index_int }
+ \regex_match_one_index:n
+ }
+ \regex_tmp:w
+ \s_regex_step
+ \if_num:w \l_regex_max_index_int = \c_zero
+ \exp_after:wN \use_none_delimit_by_q_recursion_stop:w
+ \fi:
+ \quark_if_recursion_tail_stop:N #1
+ \bool_if:NT \l_regex_look_behind_bool
+ { \tl_put_left:Nx \l_regex_look_behind_str {#1} }
+ \regex_match_loop:N
+ }
+\cs_new_nopar:Npn \regex_match_one_index:n #1
+ {
+ \regex_match_one_index_aux:n { \int_value:w \tex_skip:D #1 }
+ }
+\cs_new_protected_nopar:Npn \regex_match_one_index_aux:n #1
+ {
+ \int_set:Nn \l_regex_current_state_int {#1}
+ \prop_clear:N \l_regex_current_submatches_prop
+ \regex_state_use_submatches:
+ }
+\cs_new_protected_nopar:Npn \regex_action_start_wildcard:nn #1#2
+ {
+ \bool_set_true:N \l_regex_fresh_thread_bool
+ \regex_action_free:n {#2}
+ \bool_set_false:N \l_regex_fresh_thread_bool
+ \regex_action_cost:n {#1}
+ }
+\cs_new_protected_nopar:Npn \regex_action_cost:n #1
+ { \regex_store_state:n {#1} }
+\cs_new_protected_nopar:Npn \regex_action_success:
+ {
+ \regex_last_match_empty:F
+ {
+ \bool_set_true:N \l_regex_success_bool
+ \bool_set_eq:NN \l_regex_success_empty_bool
+ \l_regex_fresh_thread_bool
+ \int_set_eq:NN \l_regex_success_step_int
+ \l_regex_current_step_int
+ \prop_set_eq:NN \l_regex_success_submatches_prop
+ \l_regex_current_submatches_prop
+ \regex_break_step:w
+ }
+ }
+\cs_new_protected_nopar:Npn \regex_action_free:n #1
+ {
+ \regex_if_state_free:nT {#1}
+ {
+ \use:x
+ {
+ \int_set:Nn \l_regex_current_state_int {#1}
+ \regex_store_submatches:n { \l_regex_current_state_int }
+ \regex_state_use:
+ \int_set:Nn \l_regex_current_state_int
+ { \int_use:N \l_regex_current_state_int }
+ \tl_set:Nn \exp_not:N \l_regex_current_submatches_prop
+ { \exp_not:o \l_regex_current_submatches_prop }
+ }
+ }
+ }
+\cs_new_protected_nopar:Npn \regex_action_submatch:n #1
+ {
+ \prop_put:Nno \l_regex_current_submatches_prop {#1}
+ { \int_use:N \l_regex_current_step_int }
+ \regex_store_submatches:n { \l_regex_current_state_int }
+ }
+\cs_new_protected_nopar:Npn \regex_action_repeat_copy:n { \ERROR }
+\cs_new_protected_nopar:Npn \regex_action_repeat_move:n { \ERROR }
+\cs_new_protected_nopar:Npn \regex_action_no_repeat_copy:n { \ERROR }
+\cs_new_protected_nopar:Npn \regex_action_no_repeat_move:n { \ERROR }
+\cs_new_protected_nopar:Npn \regex_extract:
+ {
+ \seq_gclear:N \g_regex_submatches_seq
+ \prg_stepwise_inline:nnnn
+ {0} {1} { \l_regex_capturing_group_int }
+ {
+ \regex_extract_aux:nTF { ##1 }
+ {
+ \seq_gput_right:Nx \g_regex_submatches_seq
+ {
+ \str_from_to:Nnn \l_regex_query_str
+ { \l_regex_tmpa_tl }
+ { \l_regex_tmpb_tl }
+ }
+ }
+ { \seq_gput_right:Nn \g_regex_submatches_seq { } }
+ }
+ }
+\cs_new_protected_nopar:Npn \regex_extract_aux:nTF #1#2#3
+ {
+ \prop_get:NnNTF \l_regex_success_submatches_prop
+ { #1 < } \l_regex_tmpa_tl
+ {
+ \prop_get:NnNTF \l_regex_success_submatches_prop
+ { #1 > } \l_regex_tmpb_tl
+ {#2}
+ {#3}
+ }
+ {#3}
+ }
+\cs_new_protected_nopar:Npn \regex_set:Nn
+ { \regex_set_aux:NNn \tl_set_eq:NN }
+\cs_new_protected_nopar:Npn \regex_gset:Nn
+ { \regex_set_aux:NNn \tl_gset_eq:NN }
+\cs_new_protected:Npn \regex_set_aux:NNn #1#2#3
+ {
+ \group_begin:
+ \regex_build:n {#3}
+ \tl_gset:Nx \g_regex_tmpa_tl
+ {
+ \exp_not:N \regex_nfa:Nw \exp_not:N #2
+ \l_regex_max_state_int
+ = \int_use:N \l_regex_max_state_int
+ \l_regex_capturing_group_int
+ = \int_use:N \l_regex_capturing_group_int
+ \bool_if:NTF \l_regex_look_behind_bool
+ { \bool_set_true:N \l_regex_look_behind_bool }
+ { \bool_set_false:N \l_regex_look_behind_bool }
+ \prg_stepwise_function:nnnN
+ {1} {1} {\l_regex_max_state_int}
+ \regex_set_aux:n
+ \regex_nfa_end:
+ }
+ \group_end:
+ #1 #2 \g_regex_tmpa_tl
+ }
+\cs_new_nopar:Npn \regex_set_aux:n #1
+ { \tex_toks:D #1 { \tex_the:D \tex_toks:D #1 } }
+\cs_new:Npn \regex_nfa:Nw #1 #2 \regex_nfa_end:
+ { \msg_expandable_error:n { Automaton~#1 used~incorrectly. } }
+\cs_new_eq:NN \regex_nfa_end: \scan_stop:
+\prg_new_protected_conditional:Npnn \regex_check_nfa:N #1 { TF }
+ { \exp_after:wN \regex_check_nfa_aux:Nw #1 \q_stop }
+\cs_new:Npn \regex_check_nfa_aux:Nw #1 #2 \q_stop
+ {
+ \if_meaning:w \regex_nfa:Nw #1
+ \prg_return_true:
+ \else:
+ \msg_error:nnx { regex } { not-nfa } { \token_to_str:N #1 }
+ \prg_return_false:
+ \fi:
+ }
+\msg_new:nnn { regex } { not-nfa }
+ {
+ I~was~expecting~a~regular~expression~variable.\\
+ Instead,~I~got~#1.
+ }
+\cs_new_protected_nopar:Npn \regex_use:N #1
+ { \exp_after:wN \use_none:nn #1 }
+\cs_new_protected:Npn \regex_user_aux:n #1
+ {
+ \group_begin:
+ \tl_clear:N \l_regex_every_match_tl
+ #1
+ \group_end:
+ }
+\cs_new_protected_nopar:Npn \regex_return_after_group:
+ {
+ \if_bool:N \l_regex_success_bool
+ \group_insert_after:N \prg_return_true:
+ \else:
+ \group_insert_after:N \prg_return_false:
+ \fi:
+ }
+\cs_new_protected_nopar:Npn \regex_extract_after_group:N #1
+ {
+ \if_bool:N \l_regex_success_bool
+ \regex_extract:
+ \group_insert_after:N \seq_set_eq:NN
+ \group_insert_after:N #1
+ \group_insert_after:N \g_regex_submatches_seq
+ \fi:
+ }
+\cs_new_protected_nopar:Npn \regex_count_after_group:N #1
+ {
+ \group_insert_after:N \int_set_eq:NN
+ \group_insert_after:N #1
+ \group_insert_after:N \g_regex_match_count_int
+ }
+\prg_new_protected_conditional:Npnn \regex_match:nn #1#2 { T , F , TF }
+ {
+ \regex_user_aux:n
+ {
+ \regex_disable_submatches:
+ \regex_build:n {#1}
+ \regex_match:n {#2}
+ \regex_return_after_group:
+ }
+ }
+\prg_new_protected_conditional:Npnn \regex_match:Nn #1#2 { T , F , TF }
+ {
+ \regex_check_nfa:NTF #1
+ {
+ \regex_user_aux:n
+ {
+ \regex_disable_submatches:
+ \regex_use:N #1
+ \regex_match:n {#2}
+ \regex_return_after_group:
+ }
+ }
+ { \prg_return_false: }
+ }
+\cs_new_protected:Npn \regex_count:nnN #1#2#3
+ {
+ \regex_user_aux:n
+ {
+ \regex_disable_submatches:
+ \int_gzero:N \g_regex_match_count_int
+ \tl_set:Nn \l_regex_every_match_tl
+ {
+ \int_gincr:N \g_regex_match_count_int
+ \regex_match_once:
+ }
+ \regex_build:n {#1}
+ \regex_match:n {#2}
+ \regex_count_after_group:N #3
+ }
+ }
+\cs_new_protected:Npn \regex_count:NnN #1#2#3
+ {
+ \regex_check_nfa:NTF #1
+ {
+ \regex_user_aux:n
+ {
+ \regex_disable_submatches:
+ \int_gzero:N \g_regex_match_count_int
+ \tl_set:Nn \l_regex_every_match_tl
+ {
+ \int_gincr:N \g_regex_match_count_int
+ \regex_match_once:
+ }
+ \regex_use:N #1
+ \regex_match:n {#2}
+ \regex_count_after_group:N #3
+ }
+ }
+ { }
+ }
+\cs_new_protected:Npn \regex_extract:nnN #1#2#3
+ {
+ \regex_user_aux:n
+ {
+ \regex_build:n {#1}
+ \regex_match:n {#2}
+ \regex_extract_after_group:N #3
+ }
+ }
+\prg_new_protected_conditional:Npnn \regex_extract:nnN #1#2#3 { T , F , TF }
+ {
+ \regex_user_aux:n
+ {
+ \regex_build:n {#1}
+ \regex_match:n {#2}
+ \regex_extract_after_group:N #3
+ \regex_return_after_group:
+ }
+ }
+\cs_new_protected:Npn \regex_extract:NnN #1#2#3
+ {
+ \regex_check_nfa:NTF #1
+ {
+ \regex_user_aux:n
+ {
+ \regex_use:N #1
+ \regex_match:n {#2}
+ \regex_extract_after_group:N #3
+ }
+ }
+ { }
+ }
+\prg_new_protected_conditional:Npnn \regex_extract:NnN #1#2#3 { T , F , TF }
+ {
+ \regex_check_nfa:NTF #1
+ {
+ \regex_user_aux:n
+ {
+ \regex_use:N #1
+ \regex_match:n {#2}
+ \regex_extract_after_group:N #3
+ \regex_return_after_group:
+ }
+ }
+ { \prg_return_false: }
+ }
+\cs_new_protected:Npn \regex_split:nnN #1#2#3
+ {
+ \regex_user_aux:n
+ {
+ \seq_gclear:N \g_regex_split_seq
+ \tl_set:Nn \l_regex_every_match_tl { \regex_split_aux: }
+ \regex_build:n {#1}
+ \regex_match:n {#2}
+ \regex_split_after_group:N #3
+ }
+ }
+\cs_new_protected:Npn \regex_split:NnN #1#2#3
+ {
+ \regex_check_nfa:NTF #1
+ {
+ \regex_user_aux:n
+ {
+ \seq_gclear:N \g_regex_split_seq
+ \tl_set:Nn \l_regex_every_match_tl { \regex_split_aux: }
+ \regex_use:N #1
+ \regex_match:n {#2}
+ \regex_split_after_group:N #3
+ }
+ }
+ { }
+ }
+\cs_new_protected_nopar:Npn \regex_split_aux:
+ {
+ \int_compare:nNnF \l_regex_start_step_int = \l_regex_success_step_int
+ {
+ \regex_extract:
+ \seq_pop:NN \g_regex_submatches_seq \l_regex_tmpa_tl
+ \regex_extract_aux:nTF {0}
+ {
+ \seq_gput_left:Nx \g_regex_submatches_seq
+ {
+ \str_from_to:Nnn \l_regex_query_str
+ { \int_use:N \l_regex_start_step_int }
+ { \l_regex_tmpa_tl }
+ }
+ }
+ { \msg_error:nn { regex } { internal } }
+ \seq_gconcat:NNN \g_regex_split_seq
+ \g_regex_split_seq \g_regex_submatches_seq
+ }
+ \regex_match_once:
+ }
+\cs_new_protected_nopar:Npn \regex_split_after_group:N #1
+ {
+ \int_compare:nNnTF \l_regex_start_step_int = \l_regex_current_step_int
+ {
+ \bool_if:NF \l_regex_success_empty_bool
+ { \seq_gput_right:Nn \g_regex_split_seq { } }
+ }
+ {
+ \seq_gput_right:Nx \g_regex_split_seq
+ {
+ \str_from_to:Nnn \l_regex_query_str
+ { \int_use:N \l_regex_start_step_int }
+ { \int_use:N \l_regex_current_step_int }
+ }
+ }
+ \group_insert_after:N \seq_set_eq:NN
+ \group_insert_after:N #1
+ \group_insert_after:N \g_regex_split_seq
+ }
+\cs_new_protected:Npn \regex_replacement:n #1
+ {
+ \str_aux_escape:NNNn
+ \prg_do_nothing:
+ \regex_replacement_escaped:N
+ \regex_replacement_raw:N
+ {#1}
+ \tl_set_eq:NN \l_regex_replacement_tl \g_str_result_tl
+ \tl_set:Nx \l_regex_replacement_tl
+ { \l_regex_replacement_tl \prg_do_nothing: }
+ }
+\cs_new_nopar:Npn \regex_replacement_raw:N { \exp_not:N \prg_do_nothing: }
+\cs_new_nopar:Npn \regex_replacement_escaped:N #1
+ {
+ \if_num:w 9 < 1 #1 \exp_stop_f:
+ \exp_not:N \regex_replacement_escaped_ii:nN {#1}
+ \else:
+ #1
+ \fi:
+ }
+\cs_new_nopar:Npn \regex_replacement_escaped_ii:nN #1#2
+ {
+ \regex_token_if_other_digit:NTF #2
+ { \regex_replacement_escaped_ii:nN {#1#2} }
+ { \exp_not:N \seq_item:Nn \exp_not:N \g_regex_submatches_seq {#1} #2 }
+ }
+\prg_new_conditional:Npnn \regex_token_if_other_digit:N #1 { TF }
+ {
+ \if_num:w 9 < 1 \exp_not:N #1 \exp_stop_f:
+ \prg_return_true:
+ \else:
+ \prg_return_false:
+ \fi:
+ }
+\cs_new_protected_nopar:Npn \regex_replace_after_group:N #1
+ {
+ \group_insert_after:N \tl_set_eq:NN
+ \group_insert_after:N #1
+ \group_insert_after:N \g_regex_replaced_str
+ }
+\cs_new_protected:Npn \regex_replace_once_aux:Nn #1#2
+ {
+ \group_begin:
+ \regex_replace_after_group:N #1
+ \tl_clear:N \l_regex_every_match_tl
+ #2
+ \exp_args:No \regex_match:n {#1}
+ \regex_extract:
+ \regex_extract_aux:nTF {0}
+ {
+ \tl_gset:Nx \g_regex_replaced_str
+ {
+ \str_from_to:Nnn \l_regex_query_str {0} { \l_regex_tmpa_tl }
+ \l_regex_replacement_tl
+ \str_from_to:Nnn \l_regex_query_str
+ { \l_regex_tmpb_tl } { \c_max_int }
+ }
+ }
+ { \tl_gset_eq:NN \g_regex_replaced_str \l_regex_query_str }
+ \group_end:
+ }
+\cs_new_protected:Npn \regex_replace_once:nnN #1#2#3
+ {
+ \regex_replace_once_aux:Nn #3
+ {
+ \regex_build:n {#1}
+ \regex_replacement:n {#2}
+ }
+ }
+\cs_new_protected:Npn \regex_replace_once:NnN #1#2#3
+ {
+ \regex_replace_once_aux:Nn #3
+ {
+ \regex_use:N #1
+ \regex_replacement:n {#2}
+ }
+ }
+\prg_new_protected_conditional:Npnn \regex_replace_once:nnN #1#2#3 {T,F,TF}
+ {
+ \regex_replace_once_aux:Nn #3
+ {
+ \regex_build:n {#1}
+ \regex_replacement:n {#2}
+ \regex_return_after_group:
+ }
+ }
+\prg_new_protected_conditional:Npnn \regex_replace_once:NnN #1#2#3 {T,F,TF}
+ {
+ \regex_replace_once_aux:Nn #3
+ {
+ \regex_use:N #1
+ \regex_replacement:n {#2}
+ \regex_return_after_group:
+ }
+ }
+\cs_new_protected:Npn \regex_replace_all_aux:Nn #1#2
+ {
+ \group_begin:
+ \regex_replace_after_group:N #1
+ \tl_set:Nn \l_regex_every_match_tl { \regex_replace_all_aux: }
+ \tl_gclear:N \g_regex_replaced_str
+ #2
+ \exp_args:No \regex_match:n {#1}
+ \tl_gput_right:Nx \g_regex_replaced_str
+ {
+ \str_from_to:Nnn \l_regex_query_str
+ { \int_use:N \l_regex_start_step_int }
+ { \c_max_int }
+ }
+ \group_end:
+ }
+\cs_new_protected_nopar:Npn \regex_replace_all_aux:
+ {
+ \regex_extract:
+ \regex_extract_aux:nTF {0}
+ {
+ \tl_gput_right:Nx \g_regex_replaced_str
+ {
+ \str_from_to:Nnn \l_regex_query_str
+ { \int_use:N \l_regex_start_step_int }
+ { \l_regex_tmpa_tl }
+ \l_regex_replacement_tl
+ }
+ }
+ { \msg_error:nn { regex } { internal } }
+ \regex_match_once:
+ }
+\cs_new_protected:Npn \regex_replace_all:nnN #1#2#3
+ {
+ \regex_replace_all_aux:Nn #3
+ {
+ \regex_build:n {#1}
+ \regex_replacement:n {#2}
+ }
+ }
+\cs_new_protected:Npn \regex_replace_all:NnN #1#2#3
+ {
+ \regex_replace_all_aux:Nn #3
+ {
+ \regex_use:N #1
+ \regex_replacement:n {#2}
+ }
+ }
+%%
+%%
+%% End of file `l3regex.sty'.
diff --git a/Master/texmf-dist/tex/latex/l3experimental/l3str/l3str.sty b/Master/texmf-dist/tex/latex/l3experimental/l3str/l3str.sty
new file mode 100644
index 00000000000..9a69d0da0a6
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/l3experimental/l3str/l3str.sty
@@ -0,0 +1,970 @@
+%%
+%% This is file `l3str.sty',
+%% generated with the docstrip utility.
+%%
+%% The original source files were:
+%%
+%% l3str.dtx (with options: `package')
+%%
+%% EXPERIMENTAL CODE
+%%
+%% Do not distribute this file without also distributing the
+%% source files specified above.
+%%
+%% Do not distribute a modified version of this file.
+%%
+%% File: l3str.dtx Copyright (C) 2011 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 LaTeX3 Project.
+%%
+%% -----------------------------------------------------------------------
+\RequirePackage{expl3}
+\GetIdInfo$Id: l3str.dtx 2895 2011-10-09 15:58:19Z joseph $
+ {L3 Experimental Strings}
+\ProvidesExplPackage
+ {\ExplFileName}{\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription}
+\cs_if_exist:NF \cs_if_exist_use:cF
+ {
+ \cs_new:Npn \cs_if_exist_use:cF #1
+ { \cs_if_exist:cTF {#1} { \use:c {#1} } }
+ }
+\cs_if_exist:NF \use_i:nnnnnnnn
+ { \cs_new:Npn \use_i:nnnnnnnn #1#2#3#4#5#6#7#8 {#1} }
+\cs_set:Npn \str_tmp:w #1
+ {
+ \cs_new_protected:cpx { str_#1:Nn } ##1##2
+ { \exp_not:c { tl_#1:Nx } ##1 { \exp_not:N \tl_to_str:n {##2} } }
+ \exp_args:Nc \cs_generate_variant:Nn { str_#1:Nn } { Nx , cn , cx }
+ }
+\str_tmp:w {set}
+\str_tmp:w {gset}
+\str_tmp:w {put_left}
+\str_tmp:w {gput_left}
+\str_tmp:w {put_right}
+\str_tmp:w {gput_right}
+\cs_set_protected_nopar:Npn \str_tmp:w { }
+\tl_new:N \g_str_tmpa_tl
+\tl_new:N \g_str_result_tl
+\int_new:N \l_str_char_int
+\int_new:N \l_str_bytes_int
+\tl_const:Nx \c_backslash_str { \cs_to_str:N \\ }
+\tl_const:Nx \c_lbrace_str { \cs_to_str:N \{ }
+\tl_const:Nx \c_rbrace_str { \cs_to_str:N \} }
+\tl_const:Nx \c_hash_str { \cs_to_str:N \# }
+\tl_const:Nx \c_percent_str { \cs_to_str:N \% }
+\group_begin:
+\char_set_lccode:nn {`\*}{`\ }
+\char_set_lccode:nn {`\A}{`\A}
+\tl_to_lowercase:n {
+ \group_end:
+ \cs_new:Npn \tl_to_other_str:n #1
+ {
+ \exp_after:wN \tl_to_other_str_loop:w \tl_to_str:n {#1} ~ %
+ A ~ A ~ A ~ A ~ A ~ A ~ A ~ A ~ \q_mark \q_stop
+ }
+ \cs_new_nopar:Npn \tl_to_other_str_loop:w
+ #1 ~ #2 ~ #3 ~ #4 ~ #5 ~ #6 ~ #7 ~ #8 ~ #9 \q_stop
+ {
+ \if_meaning:w A #8
+ \tl_to_other_str_end:w
+ \fi:
+ \tl_to_other_str_loop:w
+ #9 #1 * #2 * #3 * #4 * #5 * #6 * #7 * #8 * \q_stop
+ }
+ \cs_new_nopar:Npn \tl_to_other_str_end:w \fi: #1 \q_mark #2 * A #3 \q_stop
+ { \fi: #2 }
+}
+\cs_new_nopar:Npn \tl_to_other_str:N
+ { \exp_args:No \tl_to_other_str:n }
+\cs_new:Npn \str_sanitize_args:Nn #1 #2
+ {
+ \exp_args:Nf #1
+ { \tl_to_other_str:n {#2} }
+ }
+\cs_new:Npn \str_sanitize_args:Nnn #1#2#3
+ {
+ \exp_args:Nff #1
+ { \tl_to_other_str:n {#2} }
+ { \tl_to_other_str:n {#3} }
+ }
+\cs_new_nopar:Npn \str_length:N { \exp_args:No \str_length:n }
+\cs_new:Npn \str_length:n { \str_sanitize_args:Nn \str_length_unsafe:n }
+\cs_new_nopar:Npn \str_length_unsafe:n #1
+ { \str_length_aux:n { \str_length_loop:NNNNNNNNN #1 } }
+\cs_new:Npn \str_length_ignore_spaces:n #1
+ {
+ \str_length_aux:n
+ { \exp_after:wN \str_length_loop:NNNNNNNNN \tl_to_str:n {#1} }
+ }
+\cs_new:Npn \str_length_aux:n #1
+ {
+ \int_eval:n
+ {
+ #1
+ { X \c_eight } { X \c_seven } { X \c_six }
+ { X \c_five } { X \c_four } { X \c_three }
+ { X \c_two } { X \c_one } { X \c_zero }
+ \q_stop
+ }
+ }
+\cs_set:Npn \str_length_loop:NNNNNNNNN #1#2#3#4#5#6#7#8#9
+ {
+ \if_catcode:w X #9
+ \exp_after:wN \use_none_delimit_by_q_stop:w
+ \fi:
+ \c_nine + \str_length_loop:NNNNNNNNN
+ }
+\cs_set_nopar:Npn \str_head:N { \exp_args:No \str_head:n }
+\cs_set:Npn \str_head:n #1
+ {
+ \exp_after:wN \str_head_aux:w
+ \tl_to_str:n {#1}
+ { { } } ~ \q_stop
+ }
+\cs_set_nopar:Npx \str_head_aux:w #1 ~ %
+ { \exp_not:N \use_i_delimit_by_q_stop:nw #1 { ~ } }
+\cs_new:Npn \str_head_ignore_spaces:n #1
+ { \exp_after:wN \use_i_delimit_by_q_stop:nw \tl_to_str:n {#1} { } \q_stop }
+\cs_new_nopar:Npn \str_head_unsafe:n #1
+ { \use_i_delimit_by_q_stop:nw #1 { } \q_stop }
+\cs_new_nopar:Npn \str_tail:N { \exp_args:No \str_tail:n }
+\cs_set:Npn \str_tail:n #1
+ {
+ \exp_after:wN \str_tail_aux:w
+ \reverse_if:N \if_charcode:w
+ \scan_stop: \tl_to_str:n {#1} X X \q_stop
+ }
+\cs_set_nopar:Npn \str_tail_aux:w #1 X #2 \q_stop { \fi: #1 }
+\cs_new:Npn \str_tail_ignore_spaces:n #1
+ {
+ \exp_after:wN \str_tail_aux_ii:w
+ \tl_to_str:n {#1} X { } X \q_stop
+ }
+\cs_new_nopar:Npn \str_tail_unsafe:n #1
+ { \str_tail_aux_ii:w #1 X { } X \q_stop }
+\cs_set_nopar:Npn \str_tail_aux_ii:w #1 #2 X #3 \q_stop { #2 }
+\cs_new:Npn \str_skip_do:nn #1
+ {
+ \int_compare:nNnTF {#1} > \c_seven
+ { \str_skip_aux:nnnnnnnnn }
+ { \str_skip_end:n }
+ {#1}
+ }
+\cs_new:Npn \str_skip_aux:nnnnnnnnn #1#2 #3#4#5#6#7#8#9
+ { \exp_args:Nf \str_skip_do:nn { \int_eval:n { #1 - \c_seven } } {#2} }
+\cs_new:Npn \str_skip_end:n #1
+ {
+ \if_case:w \int_eval:w #1 \int_eval_end:
+ \str_skip_end_ii:nwn { XXXXXXX }
+ \or: \str_skip_end_ii:nwn { XXXXXX }
+ \or: \str_skip_end_ii:nwn { XXXXX }
+ \or: \str_skip_end_ii:nwn { XXXX }
+ \or: \str_skip_end_ii:nwn { XXX }
+ \or: \str_skip_end_ii:nwn { XX }
+ \or: \str_skip_end_ii:nwn { X }
+ \or: \str_skip_end_ii:nwn { }
+ \else: \str_skip_end_ii:nwn { XXXXXXX }
+ \fi:
+ }
+\cs_new:Npn \str_skip_end_ii:nwn #1 #2 \fi: #3
+ { \fi: \use_i:nnnnnnnn {#3} #1 }
+\cs_new:Npn \str_collect_do:nn #1#2
+ { \str_collect_aux:n {#1} { \str_collect_end_iii:nwNNNNNNN {#2} } }
+\cs_new:Npn \str_collect_aux:n #1
+ {
+ \int_compare:nNnTF {#1} > \c_seven
+ { \str_collect_aux:nnNNNNNNN }
+ { \str_collect_end:n }
+ {#1}
+ }
+\cs_new:Npn \str_collect_aux:nnNNNNNNN #1#2 #3#4#5#6#7#8#9
+ {
+ \exp_args:Nf \str_collect_aux:n
+ { \int_eval:n { #1 - \c_seven } }
+ { #2 #3#4#5#6#7#8#9 }
+ }
+\cs_new:Npn \str_collect_end:n #1
+ {
+ \if_case:w \int_eval:w #1 \int_eval_end:
+ \str_collect_end_ii:nwn { {}{}{}{}{}{}{} }
+ \or: \str_collect_end_ii:nwn { {}{}{}{}{}{} }
+ \or: \str_collect_end_ii:nwn { {}{}{}{}{} }
+ \or: \str_collect_end_ii:nwn { {}{}{}{} }
+ \or: \str_collect_end_ii:nwn { {}{}{} }
+ \or: \str_collect_end_ii:nwn { {}{} }
+ \or: \str_collect_end_ii:nwn { {} }
+ \or: \str_collect_end_ii:nwn { }
+ \else: \str_collect_end_ii:nwn { {}{}{}{}{}{}{} }
+ \fi:
+ }
+\cs_new:Npn \str_collect_end_ii:nwn #1 #2 \fi: #3
+ { \fi: #3 \q_stop #1 }
+\cs_new:Npn \str_collect_end_iii:nwNNNNNNN #1 #2 \q_stop #3#4#5#6#7#8#9
+ { #1 {#2#3#4#5#6#7#8#9} }
+\cs_new_nopar:Npn \str_item:Nn { \exp_args:No \str_item:nn }
+\cs_new:Npn \str_item:nn #1#2
+ {
+ \exp_args:Nf \tl_to_str:n
+ { \str_sanitize_args:Nn \str_item_unsafe:nn {#1} {#2} }
+ }
+\cs_new:Npn \str_item_ignore_spaces:nn #1
+ { \exp_args:No \str_item_unsafe:nn { \tl_to_str:n {#1} } }
+\cs_new_nopar:Npn \str_item_unsafe:nn #1#2
+ {
+ \exp_args:Nff \str_item_aux:nn
+ { \int_eval:n {#2} }
+ { \str_length_unsafe:n {#1} }
+ #1
+ \q_stop
+ }
+\cs_new_nopar:Npn \str_item_aux:nn #1#2
+ {
+ \int_compare:nNnTF {#1} < \c_zero
+ {
+ \int_compare:nNnTF {#1} < {-#2}
+ { \use_none_delimit_by_q_stop:w }
+ {
+ \str_skip_do:nn { #1 + #2 }
+ { \use_i_delimit_by_q_stop:nw }
+ }
+ }
+ {
+ \int_compare:nNnTF {#1} < {#2}
+ {
+ \str_skip_do:nn {#1}
+ { \use_i_delimit_by_q_stop:nw }
+ }
+ { \use_none_delimit_by_q_stop:w }
+ }
+ }
+\cs_new_nopar:Npn \str_from_to:Nnn { \exp_args:No \str_from_to:nnn }
+\cs_new:Npn \str_from_to:nnn #1#2#3
+ {
+ \exp_args:Nf \tl_to_str:n
+ { \str_sanitize_args:Nn \str_from_to_unsafe:nnn {#1}{#2}{#3} }
+ }
+\cs_new:Npn \str_from_to_ignore_spaces:nnn #1
+ { \exp_args:No \str_from_to_unsafe:nnn { \tl_to_str:n {#1} } }
+\cs_new:Npn \str_from_to_unsafe:nnn #1#2#3 % <string> <from> <to>
+ {
+ \str_aux_eval_args:Nnnn \str_from_to_aux:nnnw
+ { \str_length_unsafe:n {#1} }
+ {#2}
+ {#3}
+ #1
+ \q_stop
+ }
+\cs_new:Npn \str_from_to_aux:nnnw #1#2#3 % <len> <from> <to>
+ {
+ \exp_args:Nf \str_from_to_aux_ii:nnw
+ { \str_aux_normalize_range:nn {#2} {#1} }
+ { \str_aux_normalize_range:nn {#3} {#1} }
+ }
+\cs_new:Npn \str_from_to_aux_ii:nnw #1#2
+ {
+ \str_skip_do:nn {#1}
+ {
+ \exp_args:Nf \str_collect_do:nn
+ { \int_eval:n { #2 - #1 } }
+ { \use_i_delimit_by_q_stop:nw }
+ }
+ }
+\cs_new:Npn \str_aux_eval_args:Nnnn #1#2#3#4
+ {
+ \exp_after:wN #1
+ \exp_after:wN { \int_value:w \int_eval:w #2 \exp_after:wN }
+ \exp_after:wN { \int_value:w \int_eval:w #3 \exp_after:wN }
+ \exp_after:wN { \int_value:w \int_eval:w #4 }
+ }
+\cs_new:Npn \str_aux_normalize_range:nn #1#2
+ {
+ \int_eval:n
+ {
+ \if_num:w #1 < \c_zero
+ \if_num:w #1 < - #2 \exp_stop_f:
+ \c_zero
+ \else:
+ #1 + #2
+ \fi:
+ \else:
+ \if_num:w #1 < #2 \exp_stop_f:
+ #1
+ \else:
+ #2
+ \fi:
+ \fi:
+ }
+ }
+\cs_new_nopar:Npn \str_map_tokens:Nn
+ { \exp_args:No \str_map_tokens:nn }
+\cs_new_nopar:Npn \str_map_tokens:nn
+ { \str_sanitize_args:Nn \str_map_tokens_aux:nn }
+\cs_new:Npn \str_map_tokens_aux:nn #1#2
+ {
+ \str_map_tokens_loop:nN {#2} #1
+ { ? \use_none_delimit_by_q_recursion_stop:w } \q_recursion_stop
+ }
+\cs_new_nopar:Npn \str_map_tokens_loop:nN #1#2
+ {
+ \use_none:n #2
+ #1 #2
+ \str_map_tokens_loop:nN {#1}
+ }
+\cs_new_eq:NN \str_map_break_do:n \use_i_delimit_by_q_recursion_stop:nw
+\prg_new_conditional:Npnn \str_if_eq:NN #1#2 { p , TF , T , F }
+ {
+ \if_int_compare:w \pdftex_strcmp:D { \tl_to_str:N #1 } { \tl_to_str:N #2 }
+ = \c_zero \prg_return_true: \else: \prg_return_false: \fi:
+ }
+\prg_new_conditional:Npnn \str_if_contains_char:NN #1#2 { p , T , F , TF }
+ {
+ \str_map_tokens:Nn #1 { \str_if_contains_char_aux:NN #2 }
+ \prg_return_false:
+ }
+\prg_new_conditional:Npnn \str_if_contains_char:nN #1#2 { p , T , F , TF }
+ {
+ \str_map_tokens:nn {#1} { \str_if_contains_char_aux:NN #2 }
+ \prg_return_false:
+ }
+\cs_new_nopar:Npn \str_if_contains_char_aux:NN #1#2
+ {
+ \if_num:w `#1 = `#2 \exp_stop_f:
+ \str_if_contains_char_end:w
+ \fi:
+ }
+\cs_new_nopar:Npn \str_if_contains_char_end:w \fi: #1 \prg_return_false:
+ { \fi: \prg_return_true: }
+\prg_new_conditional:Npnn \str_if_bytes:N #1 { p , T , F , TF }
+ {
+ \str_map_tokens:Nn #1 { \str_if_bytes_aux:N }
+ \prg_return_true:
+ }
+\cs_new_nopar:Npn \str_if_bytes_aux:N #1
+ {
+ \int_compare:nNnF {`#1} < \c_two_hundred_fifty_six
+ {
+ \use_i_delimit_by_q_recursion_stop:nw
+ { \prg_return_false: \use_none:n }
+ }
+ }
+\prg_new_protected_conditional:Npnn \str_aux_hexadecimal_test:N #1 { TF }
+ {
+ \tl_if_in:onTF { \tl_to_str:n {abcdef} } {#1}
+ {
+ \int_set:Nn \l_str_char_int
+ { \c_sixteen * \l_str_char_int + `#1 - 87 }
+ \prg_return_true:
+ }
+ {
+ \if_num:w \c_fifteen < "1 \exp_not:N #1 \exp_stop_f:
+ \int_set:Nn \l_str_char_int
+ { \c_sixteen * \l_str_char_int + "#1 }
+ \prg_return_true:
+ \else:
+ \prg_return_false:
+ \fi:
+ }
+ }
+\prg_new_protected_conditional:Npnn \str_aux_octal_test:N #1 { TF }
+ {
+ \if_num:w \c_seven < '1 \exp_not:N #1 \exp_stop_f:
+ \int_set:Nn \l_str_char_int
+ { \c_eight * \l_str_char_int + '#1 }
+ \prg_return_true:
+ \else:
+ \prg_return_false:
+ \fi:
+ }
+\cs_new_protected_nopar:Npn \str_aux_char_if_octal_digit:NTF #1
+ { \tl_if_in:nnTF { 01234567 } {#1} }
+\cs_new_protected:Npn \str_input:Nn #1#2
+ {
+ \str_aux_escape:NNNn \token_to_str:N \token_to_str:N \token_to_str:N {#2}
+ \tl_set_eq:NN #1 \g_str_result_tl
+ }
+\cs_new_protected:Npn \str_ginput:Nn #1#2
+ {
+ \str_aux_escape:NNNn \token_to_str:N \token_to_str:N \token_to_str:N {#2}
+ \tl_gset_eq:NN #1 \g_str_result_tl
+ }
+\cs_new_eq:NN \str_aux_escape_unescaped:N \use:n
+\cs_new_eq:NN \str_aux_escape_escaped:N \use:n
+\cs_new_eq:NN \str_aux_escape_raw:N \use:n
+\cs_new_protected:Npn \str_aux_escape:NNNn #1#2#3#4
+ {
+ \group_begin:
+ \cs_set_nopar:Npn \str_aux_escape_unescaped:N { #1 }
+ \cs_set_nopar:Npn \str_aux_escape_escaped:N { #2 }
+ \cs_set_nopar:Npn \str_aux_escape_raw:N { #3 }
+ \int_set:Nn \tex_escapechar:D {92}
+ \tl_gset:Nx \g_str_result_tl { \tl_to_other_str:n {#4} }
+ \tl_gset:Nx \g_str_result_tl
+ {
+ \exp_after:wN \str_aux_escape_loop:N \g_str_result_tl
+ \q_recursion_tail \q_recursion_stop
+ }
+ \group_end:
+ }
+\cs_new_nopar:Npn \str_aux_escape_loop:N #1
+ {
+ \cs_if_exist_use:cF { str_aux_escape_\token_to_str:N #1:w }
+ { \str_aux_escape_unescaped:N #1 }
+ \str_aux_escape_loop:N
+ }
+\cs_new_nopar:cpn { str_aux_escape_ \c_backslash_str :w }
+ \str_aux_escape_loop:N #1
+ {
+ \cs_if_exist_use:cF { str_aux_escape_/\token_to_str:N #1:w }
+ { \str_aux_escape_escaped:N #1 }
+ \str_aux_escape_loop:N
+ }
+\cs_new_eq:cN
+ { str_aux_escape_ \c_backslash_str q_recursion_tail :w }
+ \use_none_delimit_by_q_recursion_stop:w
+\cs_new_eq:cN
+ { str_aux_escape_ / \c_backslash_str q_recursion_tail :w }
+ \use_none_delimit_by_q_recursion_stop:w
+\cs_new_nopar:cpn { str_aux_escape_~:w } { }
+\cs_new_nopar:cpx { str_aux_escape_/a:w }
+ { \exp_not:N \str_aux_escape_raw:N \iow_char:N \^^G }
+\cs_new_nopar:cpx { str_aux_escape_/t:w }
+ { \exp_not:N \str_aux_escape_raw:N \iow_char:N \^^I }
+\cs_new_nopar:cpx { str_aux_escape_/n:w }
+ { \exp_not:N \str_aux_escape_raw:N \iow_char:N \^^J }
+\cs_new_nopar:cpx { str_aux_escape_/f:w }
+ { \exp_not:N \str_aux_escape_raw:N \iow_char:N \^^L }
+\cs_new_nopar:cpx { str_aux_escape_/r:w }
+ { \exp_not:N \str_aux_escape_raw:N \iow_char:N \^^M }
+\cs_new_nopar:cpx { str_aux_escape_/e:w }
+ { \exp_not:N \str_aux_escape_raw:N \iow_char:N \^^[ }
+\cs_new_nopar:cpn { str_aux_escape_/x:w } \str_aux_escape_loop:N
+ {
+ \if_false: { \fi: }
+ \int_zero:N \l_str_char_int
+ \str_aux_escape_x_test:N
+ }
+\cs_new_protected_nopar:Npx \str_aux_escape_x_test:N #1
+ {
+ \exp_not:N \token_if_eq_charcode:NNTF \c_space_token #1
+ { \exp_not:N \str_aux_escape_x_test:N }
+ {
+ \exp_not:N \token_if_eq_charcode:NNTF \c_lbrace_str #1
+ { \exp_not:N \str_aux_escape_x_braced_loop:N }
+ { \exp_not:N \str_aux_escape_x_unbraced_i:N #1 }
+ }
+ }
+\cs_new_protected_nopar:Npn \str_aux_escape_x_unbraced_i:N #1
+ {
+ \str_aux_hexadecimal_test:NTF #1
+ { \str_aux_escape_x_unbraced_ii:N }
+ { \str_aux_escape_x_end: #1 }
+ }
+\cs_new_protected_nopar:Npn \str_aux_escape_x_unbraced_ii:N #1
+ {
+ \token_if_eq_charcode:NNTF \c_space_token #1
+ { \str_aux_escape_x_unbraced_ii:N }
+ {
+ \str_aux_hexadecimal_test:NTF #1
+ { \str_aux_escape_x_end: }
+ { \str_aux_escape_x_end: #1 }
+ }
+ }
+\cs_new_protected_nopar:Npn \str_aux_escape_x_braced_loop:N #1
+ {
+ \token_if_eq_charcode:NNTF \c_space_token #1
+ { \str_aux_escape_x_braced_loop:N }
+ {
+ \str_aux_hexadecimal_test:NTF #1
+ { \str_aux_escape_x_braced_loop:N }
+ { \str_aux_escape_x_braced_end:N #1 }
+ }
+ }
+\cs_new_protected_nopar:Npx \str_aux_escape_x_braced_end:N #1
+ {
+ \exp_not:N \token_if_eq_charcode:NNTF \c_rbrace_str #1
+ { \exp_not:N \str_aux_escape_x_end: }
+ {
+ \msg_error:nn { str } { x-missing-brace }
+ \exp_not:N \str_aux_escape_x_end: #1
+ }
+ }
+\group_begin:
+ \char_set_catcode_other:N \^^@
+ \cs_new_protected_nopar:Npn \str_aux_escape_x_end:
+ {
+ \group_begin:
+ \char_set_lccode:nn { \c_zero } { \l_str_char_int }
+ \tl_to_lowercase:n
+ {
+ \group_end:
+ \tl_gput_right:Nx \g_str_result_tl
+ { \if_false: } \fi:
+ \str_aux_escape_raw:N ^^@
+ \str_aux_escape_loop:N
+ }
+ }
+\group_end:
+\msg_new:nnn { str } { x-missing-brace }
+ {
+ You~wrote~something~like~
+ `\iow_char:N\\x\{ \int_to_hexadecimal:n { \l_str_char_int }'.~
+ The~closing~brace~is~missing.
+ }
+\group_begin:
+ \char_set_catcode_other:n {`\^^@}
+ \cs_new_protected_nopar:Npn \str_aux_convert_store:
+ {
+ \char_set_lccode:nn {\c_zero} {\l_str_char_int}
+ \tl_to_lowercase:n { \tl_gput_right:Nx \g_str_result_tl {^^@} }
+ }
+ \cs_new_protected_nopar:Npn \str_aux_convert_store:NNn #1#2#3
+ {
+ \char_set_lccode:nn {\c_zero} {#3}
+ \tl_to_lowercase:n { #1 #2 {^^@} }
+ }
+\group_end:
+\cs_new_nopar:Npn \str_aux_byte_to_hexadecimal:N #1
+ {
+ \int_compare:nNnTF {`#1} < {256}
+ {
+ \int_to_letter:n { \int_div_truncate:nn {`#1} \c_sixteen }
+ \int_to_letter:n { \int_mod:nn {`#1} \c_sixteen }
+ }
+ { \msg_expandable_error:n { Invalid~byte~`#1'. } }
+ }
+\cs_new_nopar:Npn \str_aux_byte_to_octal:N #1
+ {
+ \int_compare:nNnTF {`#1} < {64}
+ {
+ 0
+ \int_to_letter:n { \int_div_truncate:nn {`#1} \c_eight }
+ \int_to_letter:n { \int_mod:nn {`#1} \c_eight }
+ }
+ {
+ \int_compare:nNnTF {`#1} < {256}
+ { \int_to_octal:n {`#1} }
+ { \msg_expandable_error:n { Invalid~byte~`#1'. } }
+ }
+ }
+\cs_new_protected_nopar:Npn \str_bytes_escape_hexadecimal:NN #1#2
+ {
+ \str_set:Nx #1
+ { \str_map_tokens:Nn #2 \str_aux_byte_to_hexadecimal:N }
+ }
+\tl_const:Nx \c_str_bytes_escape_name_str
+ { \c_hash_str \c_percent_str \c_lbrace_str \c_rbrace_str () /<>[] }
+\cs_new_protected_nopar:Npn \str_bytes_escape_name:NN #1#2
+ {
+ \str_set:Nx #1
+ { \str_map_tokens:Nn #2 \str_bytes_escape_name_aux:N }
+ }
+\cs_new_nopar:Npn \str_bytes_escape_name_aux:N #1
+ {
+ \int_compare:nNnTF {`#1} < {"21}
+ { \c_hash_str \str_aux_byte_to_hexadecimal:N #1 }
+ {
+ \int_compare:nNnTF {`#1} > {"7E}
+ { \c_hash_str \str_aux_byte_to_hexadecimal:N #1 }
+ {
+ \str_if_contains_char:NNTF \c_str_bytes_escape_name_str #1
+ { \c_hash_str \str_aux_byte_to_hexadecimal:N #1 }
+ {#1}
+ }
+ }
+ }
+\tl_const:Nx \c_str_bytes_escape_string_str { \c_backslash_str ( ) }
+\cs_new_protected_nopar:Npn \str_bytes_escape_string:NN #1#2
+ {
+ \str_set:Nx #1
+ { \str_map_tokens:Nn #2 \str_bytes_escape_string_aux:N }
+ }
+\cs_new_nopar:Npn \str_bytes_escape_string_aux:N #1
+ {
+ \int_compare:nNnTF {`#1} < {"21}
+ { \c_backslash_str \str_aux_byte_to_octal:N #1 }
+ {
+ \int_compare:nNnTF {`#1} > {"7E}
+ { \c_backslash_str \str_aux_byte_to_octal:N #1 }
+ {
+ \str_if_contains_char:NNT \c_str_bytes_escape_string_str #1
+ { \c_backslash_str }
+ #1
+ }
+ }
+ }
+\cs_new_protected_nopar:Npn \str_bytes_unescape_hexadecimal:NN #1#2
+ {
+ \group_begin:
+ \tl_gclear:N \g_str_result_tl
+ \int_zero:N \l_str_char_int
+ \exp_last_unbraced:Nf \str_bytes_unescape_hexadecimal_aux:N
+ { \tl_to_other_str:N #2 } 0
+ \q_recursion_tail \q_recursion_stop
+ \group_end:
+ \tl_set_eq:NN #1 \g_str_result_tl
+ }
+\cs_new_protected_nopar:Npn \str_bytes_unescape_hexadecimal_aux:N #1
+ {
+ \quark_if_recursion_tail_stop:N #1
+ \str_aux_hexadecimal_test:NTF #1
+ { \str_bytes_unescape_hexadecimal_aux_ii:N }
+ { \str_bytes_unescape_hexadecimal_aux:N }
+ }
+\cs_new_protected_nopar:Npn \str_bytes_unescape_hexadecimal_aux_ii:N #1
+ {
+ \quark_if_recursion_tail_stop:N #1
+ \str_aux_hexadecimal_test:NTF #1
+ {
+ \str_aux_convert_store:
+ \int_zero:N \l_str_char_int
+ \str_bytes_unescape_hexadecimal_aux:N
+ }
+ { \str_bytes_unescape_hexadecimal_aux_ii:N }
+ }
+\group_begin:
+ \char_set_lccode:nn {`\*} {`\#}
+ \tl_to_lowercase:n
+ {
+ \group_end:
+ \cs_new_protected_nopar:Npn \str_bytes_unescape_name:NN #1#2
+ {
+ \group_begin:
+ \tl_gclear:N \g_str_result_tl
+ \int_zero:N \l_str_char_int
+ \exp_last_unbraced:Nf \str_bytes_unescape_name_aux:wN
+ { \tl_to_other_str:N #2 }
+ * \q_recursion_tail \q_recursion_stop
+ \group_end:
+ \tl_set_eq:NN #1 \g_str_result_tl
+ }
+ \cs_new_protected_nopar:Npn \str_bytes_unescape_name_aux:wN #1 * #2
+ {
+ \tl_gput_right:Nx \g_str_result_tl {#1}
+ \quark_if_recursion_tail_stop:N #2
+ \str_aux_hexadecimal_test:NTF #2
+ { \str_bytes_unescape_name_aux_ii:NN #2 }
+ {
+ \tl_gput_right:Nx \g_str_result_tl { \c_hash_str }
+ \str_bytes_unescape_name_aux:wN #2
+ }
+ }
+ }
+\cs_new_protected_nopar:Npn \str_bytes_unescape_name_aux_ii:NN #1#2
+ {
+ \str_aux_hexadecimal_test:NTF #2
+ {
+ \str_aux_convert_store:
+ \int_zero:N \l_str_char_int
+ \str_bytes_unescape_name_aux:wN
+ }
+ {
+ \tl_gput_right:Nx \g_str_result_tl { \c_hash_str #1 }
+ \int_zero:N \l_str_char_int
+ \str_bytes_unescape_name_aux:wN #2
+ }
+ }
+\group_begin:
+ \char_set_lccode:nn {`\*} {`\\}
+ \char_set_catcode_other:N \^^J
+ \char_set_catcode_other:N \^^M
+ \tl_to_lowercase:n
+ {
+ \group_end:
+ \cs_new_protected_nopar:Npn \str_bytes_unescape_string:NN #1#2
+ {
+ \group_begin:
+ \tl_gclear:N \g_str_result_tl
+ \exp_last_unbraced:Nf \str_bytes_unescape_string_aux:wN
+ { \tl_to_other_str:N #2 }
+ * \q_recursion_tail \q_recursion_stop
+ \group_end:
+ \tl_set_eq:NN #1 \g_str_result_tl
+ }
+ \cs_new_protected_nopar:Npn \str_bytes_unescape_string_aux:wN #1 * #2
+ {
+ \tl_gput_right:Nx \g_str_result_tl {#1}
+ \quark_if_recursion_tail_stop:N #2
+ \int_zero:N \l_str_char_int
+ \str_aux_octal_test:NTF #2
+ { \str_bytes_unescape_string_aux_d:N }
+ {
+ \int_set:Nn \l_str_char_int
+ {
+ \prg_case_str:xxn {#2}
+ {
+ {n} {10}
+ {r} {13}
+ {t} {9}
+ {b} {8}
+ {f} {12}
+ {(} {40}
+ {)} {41}
+ {\c_backslash_str} {92}
+ {^^J} {-1}
+ {^^M} {-1}
+ }
+ {`#2}
+ }
+ \int_compare:nNnF \l_str_char_int = \c_minus_one
+ { \str_aux_convert_store: }
+ \str_bytes_unescape_string_aux:wN
+ }
+ }
+ }
+\cs_new_protected_nopar:Npn \str_bytes_unescape_string_aux_d:N #1
+ {
+ \str_aux_octal_test:NTF #1
+ { \str_bytes_unescape_string_aux_dd:N }
+ {
+ \str_aux_convert_store:
+ \str_bytes_unescape_string_aux:wN #1
+ }
+ }
+\cs_new_protected_nopar:Npn \str_bytes_unescape_string_aux_dd:N #1
+ {
+ \str_aux_octal_test:NTF #1
+ {
+ \str_aux_convert_store:
+ \str_bytes_unescape_string_aux:wN
+ }
+ {
+ \str_aux_convert_store:
+ \str_bytes_unescape_string_aux:wN #1
+ }
+ }
+\tl_const:Nx \c_str_bytes_percent_encode_str { \tl_to_str:n { [] } }
+\tl_const:Nx \c_str_bytes_percent_encode_not_str { \tl_to_str:n { "-.<> } }
+\cs_new_protected_nopar:Npn \str_bytes_percent_encode:NN #1#2
+ {
+ \str_set:Nx #1
+ { \str_map_tokens:Nn #2 \str_bytes_percent_encode_aux:N }
+ }
+\cs_new_nopar:Npn \str_bytes_percent_encode_aux:N #1
+ {
+ \int_compare:nNnTF {`#1} < {"41}
+ {
+ \str_if_contains_char:NNTF \c_str_bytes_percent_encode_not_str #1
+ { #1 }
+ { \c_percent_str \str_aux_byte_to_hexadecimal:N #1 }
+ }
+ {
+ \int_compare:nNnTF {`#1} > {"7E}
+ { \c_percent_str \str_aux_byte_to_hexadecimal:N #1 }
+ {
+ \str_if_contains_char:NNTF \c_str_bytes_percent_encode_str #1
+ { \c_percent_str \str_aux_byte_to_hexadecimal:N #1 }
+ { #1 }
+ }
+ }
+ }
+\group_begin:
+ \char_set_lccode:nn {`\*} {`\%}
+ \tl_to_lowercase:n
+ {
+ \group_end:
+ \cs_new_protected_nopar:Npn \str_bytes_percent_decode:NN #1#2
+ {
+ \group_begin:
+ \tl_gclear:N \g_str_result_tl
+ \exp_last_unbraced:Nf \str_bytes_percent_decode_aux:wN
+ { \tl_to_other_str:N #2 }
+ * \q_recursion_tail \q_recursion_stop
+ \group_end:
+ \tl_set_eq:NN #1 \g_str_result_tl
+ }
+ \cs_new_protected_nopar:Npn \str_bytes_percent_decode_aux:wN #1 * #2
+ {
+ \tl_gput_right:Nx \g_str_result_tl {#1}
+ \quark_if_recursion_tail_stop:N #2
+ \int_zero:N \l_str_char_int
+ \str_aux_hexadecimal_test:NTF #2
+ { \str_bytes_percent_decode_aux_ii:NN #2 }
+ {
+ \tl_gput_right:Nx \g_str_result_tl { \c_percent_str }
+ \str_bytes_percent_decode_aux:wN #2
+ }
+ }
+ }
+\cs_new_protected_nopar:Npn \str_bytes_percent_decode_aux_ii:NN #1#2
+ {
+ \str_aux_hexadecimal_test:NTF #2
+ {
+ \str_aux_convert_store:
+ \str_bytes_percent_decode_aux:wN
+ }
+ {
+ \tl_gput_right:Nx \g_str_result_tl {#1}
+ \str_bytes_percent_decode_aux:wN #2
+ }
+ }
+\cs_new_protected_nopar:Npn \str_native_from_UTF_viii:NN #1#2
+ {
+ \group_begin:
+ \tl_gclear:N \g_str_result_tl
+ \exp_last_unbraced:Nf \str_native_from_UTF_viii_aux_i:N
+ { \tl_to_other_str:N #2 }
+ \q_recursion_tail \q_recursion_stop
+ \group_end:
+ \tl_set_eq:NN #1 \g_str_result_tl
+ }
+\cs_new_protected_nopar:Npn \str_native_from_UTF_viii_aux_i:N #1
+ {
+ \quark_if_recursion_tail_stop:N #1
+ \int_set:Nn \l_str_char_int { `#1 }
+ \str_native_from_UTF_viii_aux_ii:nN {128} \c_one
+ \str_native_from_UTF_viii_aux_ii:nN {64} \c_zero
+ \str_native_from_UTF_viii_aux_ii:nN {32} \c_two
+ \str_native_from_UTF_viii_aux_ii:nN {16} \c_three
+ \str_native_from_UTF_viii_aux_ii:nN {8} \c_four
+ \msg_error:nnx { str } { utf8-invalid-byte } {#1}
+ \use_i:nnn \str_native_from_UTF_viii_aux_i:N
+ \q_stop
+ \str_native_from_UTF_viii_aux_iii:N
+ }
+\cs_new_protected_nopar:Npn
+ \str_native_from_UTF_viii_aux_ii:nN #1#2
+ {
+ \int_compare:nNnTF \l_str_char_int < {#1}
+ {
+ \int_set_eq:NN \l_str_bytes_int #2
+ \use_none_delimit_by_q_stop:w
+ }
+ { \int_sub:Nn \l_str_char_int {#1} }
+ }
+\cs_new_protected_nopar:Npn
+ \str_native_from_UTF_viii_aux_iii:N #1
+ {
+ \int_compare:nNnTF \l_str_bytes_int < \c_two
+ { \str_native_from_UTF_viii_aux_iv: #1 }
+ {
+ \if_meaning:w \q_recursion_tail #1
+ \msg_error:nn { str } { utf8-premature-end }
+ \exp_after:wN \use_none_delimit_by_q_recursion_stop:w
+ \fi:
+ \quark_if_recursion_tail_stop:N #1
+ \tex_multiply:D \l_str_char_int by 64 \scan_stop: % no interface??
+ \int_decr:N \l_str_bytes_int
+ \int_compare:nNnTF {`#1} < {128}
+ { \use_ii:nn }
+ { \int_compare:nNnTF {`#1} < {192} }
+ {
+ \int_add:Nn \l_str_char_int { `#1 - 128 }
+ \str_native_from_UTF_viii_aux_iii:N
+ }
+ {
+ \msg_error:nnx { str } { utf8-missing-byte } {#1}
+ \str_native_from_UTF_viii_aux_i:N #1
+ }
+ }
+ }
+\cs_new_protected_nopar:Npn
+ \str_native_from_UTF_viii_aux_iv:
+ {
+ \int_compare:nNnTF \l_str_bytes_int = \c_zero
+ {
+ \msg_error:nnx { str } { utf8-extra-byte }
+ { \int_eval:n { \l_str_char_int + 128 } }
+ }
+ {
+ \pdftex_if_engine:TF
+ {
+ \int_compare:nNnTF { \l_str_char_int } < { 256 }
+ { \str_aux_convert_store: }
+ {
+ \msg_error:nnx { str } { utf8-pdftex-overflow }
+ { \int_use:N \l_str_char_int }
+ }
+ }
+ { \str_aux_convert_store: }
+ }
+ \str_native_from_UTF_viii_aux_i:N
+ }
+\msg_new:nnn { str } { utf8-invalid-byte }
+ {
+ \int_compare:nNnTF {`#1} < {256}
+ { Byte~number~\int_eval:n {`#1}~invalid~in~utf-8~encoding. }
+ { The~character~number~\int_eval:n {`#1}~is~not~a~byte. }
+ }
+\msg_new:nnn { str } { utf8-missing-byte }
+ { The~byte~number~\int_eval:n {`#1}~is~not~a~valid~continuation~byte. }
+\msg_new:nnn { str } { utf8-extra-byte }
+ { The~byte~number~\int_eval:n {`#1}~is~only~valid~as~a~continuation~byte. }
+\msg_new:nnnn { str } { utf8-premature-end }
+ { Incomplete~last~utf8~character. }
+ {
+ The~sequence~of~byte~that~I~need~to~convert~to~utf8 \
+ ended~before~the~last~character~was~complete.~Perhaps \
+ it~was~mistakenly~truncated?
+ }
+\msg_new:nnn { str } { utf8-pdftex-overflow }
+ { The~character~number~#1~is~too~big~for~pdfTeX. }
+\cs_new_protected_nopar:Npn \str_UTF_viii_from_native:NN #1#2
+ {
+ \group_begin:
+ \tl_gclear:N \g_str_result_tl
+ \str_map_tokens:Nn #2 \str_UTF_viii_from_native_aux_i:N
+ \group_end:
+ \tl_set_eq:NN #1 \g_str_result_tl
+ }
+\cs_new_protected_nopar:Npn \str_UTF_viii_from_native_aux_i:N #1
+ {
+ \int_set:Nn \l_str_char_int {`#1}
+ \int_compare:nNnTF \l_str_char_int < {128}
+ { \tl_gput_right:Nx \g_str_result_tl {#1} }
+ {
+ \tl_gclear:N \g_str_tmpa_tl
+ \int_set:Nn \l_str_bytes_int { 64 }
+ \str_UTF_viii_from_native_aux_ii:n {32}
+ \str_UTF_viii_from_native_aux_ii:n {16}
+ \str_UTF_viii_from_native_aux_ii:n {8}
+ \ERROR % somehow the unicode char was > "1FFFFF > "10FFFF
+ \tl_gclear:N \g_str_tmpa_tl
+ \use_none:n \q_stop
+ \int_add:Nn \l_str_char_int { 2 * \l_str_bytes_int }
+ \str_aux_convert_store:
+ \tl_gput_right:Nx \g_str_result_tl { \g_str_tmpa_tl }
+ }
+ }
+\cs_new_protected_nopar:Npn \str_UTF_viii_from_native_aux_ii:n #1
+ {
+ \str_aux_convert_store:NNn
+ \tl_gput_left:Nx \g_str_tmpa_tl
+ { 128 + \int_mod:nn { \l_str_char_int } {64} }
+ \tex_divide:D \l_str_char_int by 64 \scan_stop: % no interface??
+ \int_add:Nn \l_str_bytes_int {#1}
+ \int_compare:nNnT \l_str_char_int < {#1}
+ { \use_none_delimit_by_q_stop:w }
+ }
+\cs_gset:Npn \str_length_skip_spaces:N
+ { \exp_args:No \str_length_skip_spaces:n }
+\cs_gset_eq:NN \str_length_skip_spaces:n \str_length_ignore_spaces:n
+%%
+%%
+%% End of file `l3str.sty'.
diff --git a/Master/texmf-dist/tex/latex/l3experimental/xcoffins/xcoffins.sty b/Master/texmf-dist/tex/latex/l3experimental/xcoffins/xcoffins.sty
index cbadf49e9fb..79490432742 100644
--- a/Master/texmf-dist/tex/latex/l3experimental/xcoffins/xcoffins.sty
+++ b/Master/texmf-dist/tex/latex/l3experimental/xcoffins/xcoffins.sty
@@ -47,7 +47,7 @@
%% -----------------------------------------------------------------------
%%
\RequirePackage{xparse}
-\GetIdInfo$Id: xcoffins.dtx 2349 2011-05-11 18:44:37Z joseph $
+\GetIdInfo$Id: xcoffins.dtx 2895 2011-10-09 15:58:19Z joseph $
{L3 Experimental design-level coffins}
\ProvidesExplPackage
{\ExplFileName}{\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription}
diff --git a/Master/texmf-dist/tex/latex/l3experimental/xgalley/l3galley.sty b/Master/texmf-dist/tex/latex/l3experimental/xgalley/l3galley.sty
new file mode 100644
index 00000000000..b626f072d30
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/l3experimental/xgalley/l3galley.sty
@@ -0,0 +1,764 @@
+%%
+%% This is file `l3galley.sty',
+%% generated with the docstrip utility.
+%%
+%% The original source files were:
+%%
+%% l3galley.dtx (with options: `package')
+%%
+%% EXPERIMENTAL CODE
+%%
+%% Do not distribute this file without also distributing the
+%% source files specified above.
+%%
+%% Do not distribute a modified version of this file.
+%%
+%% File: l3galley.dtx Copyright (C) 1999-2001, 2004-2009 Frank Mittelbach
+%% (C) 2010,2011 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{l3names}
+\GetIdInfo$Id: l3galley.dtx 2899 2011-10-09 21:22:06Z joseph $
+ {L3 Experimental galley code}
+\ProvidesExplPackage
+ {\ExplFileName}{\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription}
+\package_check_loaded_expl:
+\cs_new_protected_nopar:Npn \galley_leave_vmode:
+ { \tex_unhbox:D \c_empty_box }
+\clist_new:N \l_galley_parshape_left_indent_clist
+\clist_new:N \l_galley_parshape_right_indent_clist
+\bool_new:N \l_galley_parshape_multipar_bool
+\bool_new:N \l_galley_parshape_resume_std_bool
+\bool_new:N \l_galley_parshape_fixed_lines_bool
+\int_new:N \l_galley_parshape_std_lines_int
+\cs_new_eq:NN \l_galley_text_width_dim \linewidth
+\cs_new_eq:NN \l_galley_total_left_margin_dim \@totalleftmargin
+\dim_new:N \l_galley_total_right_margin_dim
+\int_new:N \l_galley_interpar_penalty_int
+\skip_new:N \l_galley_interpar_vspace_skip
+\cs_new_eq:NN \l_galley_width_dim \tex_hsize:D
+\bool_new:N \g_galley_begin_level_bool
+\bool_new:N \l_galley_begin_level_bool
+\bool_gset_true:N \g_galley_begin_level_bool
+\bool_new:N \g_galley_omit_next_indent_bool
+\bool_new:N \l_galley_omit_next_indent_bool
+\bool_new:N \g_galley_parshape_set_bool
+\bool_new:N \l_galley_parshape_set_bool
+\bool_new:N \g_galley_nobreak_next_bool
+\bool_new:N \l_galley_nobreak_next_bool
+\tl_new:N \g_galley_par_begin_hook_tl
+\tl_new:N \l_galley_par_begin_hook_tl
+\tl_new:N \g_galley_par_end_hook_tl
+\tl_new:N \l_galley_par_end_hook_tl
+\tl_new:N \g_galley_par_after_hook_tl
+\tl_new:N \l_galley_par_after_hook_tl
+\int_new:N \g_galley_previous_par_lines_int
+\int_new:N \l_galley_previous_par_lines_int
+\tl_new:N \g_galley_restore_running_tl
+\tl_new:N \l_galley_restore_running_tl
+\tl_new:N \g_galley_whatsit_next_tl
+\tl_new:N \l_galley_whatsit_next_tl
+\tl_new:N \g_galley_whatsit_previous_tl
+\tl_new:N \l_galley_whatsit_previous_tl
+\tl_new:N \g_galley_interpar_penalty_user_tl
+\tl_new:N \l_galley_interpar_penalty_user_tl
+\tl_new:N \g_galley_interpar_vspace_user_tl
+\tl_new:N \l_galley_interpar_vspace_user_tl
+\cs_new_protected_nopar:Npn \galley_initialise_variables:
+ {
+ \bool_gset_true:N \g_galley_begin_level_bool
+ \tl_gclear:N \g_galley_interpar_penalty_user_tl
+ \tl_gclear:N \g_galley_interpar_vspace_user_tl
+ \bool_gset_true:N \g_galley_omit_next_indent_bool
+ \bool_gset_false:N \g_galley_nobreak_next_bool
+ \tl_gclear:N \g_galley_par_begin_hook_tl
+ \tl_gclear:N \g_galley_par_end_hook_tl
+ \tl_gclear:N \g_galley_par_after_hook_tl
+ \bool_gset_false:N \g_galley_parshape_set_bool
+ \int_gzero:N \g_galley_previous_par_lines_int
+ \tl_gclear:N \g_galley_restore_running_tl
+ \tl_gclear:N \g_galley_whatsits_previous_tl
+ \tl_gclear:N \g_galley_whatsits_next_tl
+ }
+\cs_new_protected_nopar:Npn \galley_initialise_settings:
+ {
+ \dim_set_eq:NN \l_galley_text_width_dim \l_galley_width_dim
+ \dim_zero:N \l_galley_left_margin_dim
+ \dim_zero:N \l_galley_right_margin_dim
+ \dim_zero:N \l_galley_total_left_margin_dim
+ \dim_zero:N \l_galley_total_right_margin_dim
+ }
+\cs_new_protected_nopar:Npn \galley_save_parameters:
+ {
+ \bool_set_eq:NN \l_galley_begin_level_bool
+ \g_galley_begin_level_bool
+ \tl_set_eq:NN \l_galley_interpar_penalty_user_tl
+ \g_galley_interpar_penalty_user_tl
+ \tl_set_eq:NN \l_galley_interpar_vspace_user_tl
+ \g_galley_interpar_vspace_user_tl
+ \bool_set_eq:NN \l_galley_omit_next_indent_bool
+ \g_galley_omit_next_indent_bool
+ \bool_set_eq:NN \l_galley_nobreak_next_bool
+ \g_galley_nobreak_next_bool
+ \tl_set_eq:NN \l_galley_par_begin_hook_tl
+ \g_galley_par_begin_hook_tl
+ \tl_set_eq:NN \l_galley_par_end_hook_tl
+ \g_galley_par_end_hook_tl
+ \tl_set_eq:NN \l_galley_par_after_hook_tl
+ \g_galley_par_after_hook_tl
+ \bool_set_eq:NN \l_galley_parshape_set_bool
+ \g_galley_parshape_set_bool
+ \int_set_eq:NN \l_galley_previous_par_lines_int
+ \g_galley_previous_par_lines_int
+ \tl_set_eq:NN \l_galley_restore_running_tl
+ \g_galley_restore_running_tl
+ \tl_set_eq:NN \l_galley_whatsits_previous_tl
+ \g_galley_whatsits_previous_tl
+ \tl_set_eq:NN \l_galley_whatsits_next_tl
+ \g_galley_whatsits_next_tl
+ }
+\cs_new_protected_nopar:Npn \galley_restore_parameters:
+ {
+ \bool_gset_eq:NN \g_galley_begin_level_bool
+ \l_galley_begin_level_bool
+ \tl_gset_eq:NN \g_galley_interpar_penalty_user_tl
+ \l_galley_interpar_penalty_user_tl
+ \tl_gset_eq:NN \g_galley_interpar_vspace_user_tl
+ \l_galley_interpar_vspace_user_tl
+ \bool_gset_eq:NN \g_galley_omit_next_indent_bool
+ \l_galley_omit_next_indent_bool
+ \bool_gset_eq:NN \g_galley_nobreak_next_bool
+ \l_galley_nobreak_next_bool
+ \tl_gset_eq:NN \g_galley_par_begin_hook_tl
+ \l_galley_par_begin_hook_tl
+ \tl_gset_eq:NN \g_galley_par_end_hook_tl
+ \l_galley_par_end_hook_tl
+ \tl_gset_eq:NN \g_galley_par_after_hook_tl
+ \l_galley_par_after_hook_tl
+ \bool_gset_eq:NN \g_galley_parshape_set_bool
+ \l_galley_parshape_set_bool
+ \int_gset_eq:NN \g_galley_previous_par_lines_int
+ \l_galley_previous_par_lines_int
+ \tl_gset_eq:NN \g_galley_restore_running_tl
+ \l_galley_restore_running_tl
+ \tl_gset_eq:NN \g_galley_whatsits_previous_tl
+ \l_galley_whatsits_previous_tl
+ \tl_gset_eq:NN \g_galley_whatsits_next_tl
+ \l_galley_whatsits_next_tl
+ }
+\cs_new_protected_nopar:Npn \galley_level:
+ {
+ \galley_save_parameters:
+ \group_begin:
+ \galley_initialise_variables:
+ \galley_initialise_settings:
+ \group_insert_after:N \galley_level_end:
+ }
+\cs_new_protected_nopar:Npn \galley_level_end:
+ {
+ \par
+ \galley_restore_parameters:
+ \group_end:
+ }
+\cs_new_protected_nopar:Npn \galley_std_par:
+ {
+ \mode_if_vertical:TF
+ { \tex_par:D }
+ {
+ \g_galley_par_end_hook_tl
+ \galley_set_measure_and_parshape:
+ \group_begin:
+ \tex_par:D
+ \group_end:
+ \int_gadd:Nn \g_galley_previous_par_lines_int \tex_prevgraf:D
+ }
+ \g_galley_par_after_hook_tl
+ \tl_gclear:N \g_galley_par_after_hook_tl
+ \tex_penalty:D \c_ten_thousand
+ }
+\cs_set_protected_nopar:Npn \par { \galley_std_par: }
+\tl_set:Nn \@par { \galley_std_par: }
+\cs_new_protected_nopar:Npn \galley_display_begin:
+ {
+ \group_begin:
+ \galley_save_parameters:
+ \mode_if_vertical:TF
+ {
+ \galley_display_penalty:N \l_galley_display_begin_par_penalty_tl
+ \galley_display_vspace:N \l_galley_display_begin_par_vspace_tl
+ }
+ {
+ \galley_display_penalty:N \l_galley_display_begin_penalty_tl
+ \galley_display_vspace:N \l_galley_display_begin_vspace_tl
+ }
+ \par
+ }
+\cs_new_protected_nopar:Npn \galley_display_penalty:N #1
+ {
+ \tl_if_empty:NF #1
+ {
+ \tl_gput_right:Nx \g_galley_restore_running_tl
+ {
+ \int_gset:Nn \exp_not:N \g_galley_penalty_int
+ { \int_use:N \g_galley_penalty_int }
+ }
+ \int_gset:Nn \g_galley_penalty_int {#1}
+ }
+ }
+\cs_new_protected_nopar:Npn \galley_display_vspace:N #1
+ {
+ \tl_if_empty:NF #1
+ {
+ \tl_gput_right:Nx \g_galley_restore_running_tl
+ {
+ \skip_gset:Nn \exp_not:N \g_galley_vspace_skip
+ { \skip_use:N \g_galley_vspace_skip }
+ }
+ \skip_gset:Nn \g_galley_vspace_int {#1}
+ }
+ }
+\cs_new_protected_nopar:Npn \galley_display_end:
+ {
+ \par
+ \galley_restore_parameters:
+ \group_end:
+ \group_insert_after:N \group_insert_after:N
+ \group_insert_after:N \galley_display_par_setup:
+ }
+\cs_new_protected_nopar:Npn \galley_display_par_setup:
+ {
+ \bool_gset_false:N \g_galley_omit_next_indent_bool
+ \cs_set_eq:NN \par \galley_display_par:
+ }
+\cs_new_protected_nopar:Npn \galley_display_par:
+ {
+ \cs_set_eq:NN \par \galley_std_par:
+ \mode_if_vertical:TF
+ {
+ \par
+ \bool_gset_false:N \g_galley_omit_next_indent_bool
+ \galley_display_penalty:N \l_galley_display_end_par_penalty_tl
+ \galley_display_vspace:N \l_galley_display_end_par_vspace_tl
+ }
+ {
+ \galley_set_measure_and_parshape:
+ \group_begin:
+ \tex_par:D
+ \group_end:
+ \int_gadd:Nn \g_galley_previous_par_lines_int \tex_prevgraf:D
+ \galley_display_penalty:N \l_galley_display_end_penalty_tl
+ \galley_display_vspace:N \l_galley_display_end_vspace_tl
+ }
+ }
+\cs_undefine:N \everypar
+\newtoks \everypar
+\AtBeginDocument
+ {
+ \tex_everypar:D
+ {
+ \bool_if:NTF \g_galley_begin_level_bool
+ { \galley_start_paragraph_first: }
+ { \galley_start_paragraph_std: }
+ \tex_the:D \everypar
+ }
+ }
+\box_new:N \g_galley_last_box
+\cs_new_protected_nopar:Npn \galley_start_paragraph_std:
+ {
+ \group_begin:
+ \box_gset_to_last:N \g_galley_last_box
+ \tex_par:D
+ \galley_insert_vertical_items:
+ \tex_everypar:D { }
+ \tex_noindent:D
+ \group_end:
+ \int_gzero:N \g_galley_previous_par_lines_int
+ \galley_insert_horizontal_items:
+ \galley_restore_running_parameters:
+ }
+\cs_new_protected_nopar:Npn \galley_start_paragraph_first:
+ {
+ \bool_gset_false:N \g_galley_begin_level_bool
+ \mode_if_horizontal:TF
+ {
+ \group_begin:
+ \box_gset_to_last:N \g_galley_last_box
+ \tex_par:D
+ \galley_insert_vspace:
+ \tex_everypar:D { }
+ \tex_noindent:D
+ \group_end:
+ }
+ { \galley_insert_vspace: }
+ \galley_insert_horizontal_items:
+ \galley_restore_running_parameters:
+ }
+\cs_new_protected_nopar:Npn \galley_insert_vertical_items:
+ {
+ \g_galley_whatsit_previous_tl
+ \tl_gclear:N \g_galley_whatsit_previous_tl
+ \tl_if_empty:NTF \g_galley_interpar_penalty_user_tl
+ {
+ \bool_if:NTF \g_galley_nobreak_next_bool
+ { \tex_penalty:D \c_ten_thousand }
+ { \tex_penalty:D \l_galley_interpar_penalty_int }
+ }
+ {
+ \tex_penalty:D
+ \int_eval:w \g_galley_interpar_penalty_user_tl \int_eval_end:
+ \tl_gclear:N \g_galley_interpar_penalty_user_tl
+ }
+ \bool_gset_false:N \g_galley_nobreak_next_bool
+ \galley_insert_vspace:
+ }
+\cs_new_protected_nopar:Npn \galley_insert_vspace:
+ {
+ \tl_if_empty:NTF \g_galley_interpar_vspace_user_tl
+ { \skip_vertical:N \l_galley_interpar_vspace_skip }
+ {
+ \skip_vertical:n { \g_galley_interpar_vspace_user_tl }
+ \tl_gclear:N \g_galley_interpar_vspace_user_tl
+ }
+ }
+\cs_new_protected_nopar:Npn \galley_insert_horizontal_items:
+ {
+ \g_galley_whatsit_next_tl
+ \tl_gclear:N \g_galley_whatsit_next_tl
+ \bool_if:NT \g_galley_omit_next_indent_bool
+ {
+ \box_if_empty:NF \g_galley_last_box
+ { \hbox_to_wd:nn \l_galley_par_indent_dim { } }
+ }
+ \skip_horizontal:N \l_galley_par_begin_skip
+ \g_galley_par_begin_hook_tl
+ \bool_gset_true:N \g_galley_omit_next_indent_bool
+ }
+\cs_new_protected_nopar:Npn \galley_restore_running_parameters:
+ {
+ \g_galley_restore_running_tl
+ \tl_gclear:N \g_galley_restore_running_tl
+ }
+\cs_new_protected_nopar:Npn \galley_margins_set_absolute:nn #1#2
+ {
+ \dim_set:Nn \l_galley_total_left_margin_dim {#1}
+ \dim_set:Nn \l_galley_total_right_margin_dim {#2}
+ \dim_set:Nn \l_galley_text_width_dim
+ {
+ \l_galley_width_dim
+ - \l_galley_total_left_margin_dim
+ - \l_galley_total_right_margin_dim
+ }
+ }
+\cs_new_protected_nopar:Npn \galley_margins_set_relative:nn #1#2
+ {
+ \dim_add:Nn \l_galley_total_left_margin_dim {#1}
+ \dim_add:Nn \l_galley_total_right_margin_dim {#2}
+ \dim_set:Nn \l_galley_text_width_dim
+ {
+ \l_galley_width_dim
+ - \l_galley_total_left_margin_dim
+ - \l_galley_total_right_margin_dim
+ }
+ }
+\cs_new_protected_nopar:Npn \galley_parshape_fixed_lines:nnn #1#2#3
+ {
+ \bool_gset_true:N \g_galley_parshape_set_bool
+ \bool_set_true:N \l_galley_parshape_fixed_lines_bool
+ \int_set:Nn \l_galley_parshape_std_lines_int {#1}
+ \clist_set:Nn \l_galley_parshape_left_indent_clist {#2}
+ \clist_set:Nn \l_galley_parshape_right_indent_clist {#3}
+ \bool_set_true:N \l_galley_parshape_resume_std_bool
+ }
+\cs_new_protected_nopar:Npn \galley_parshape_multi_par:nnnN #1#2#3#4
+ {
+ \bool_gset_true:N \g_galley_parshape_set_bool
+ \bool_set_true:N \l_galley_parshape_multipar_bool
+ \bool_set_false:N \l_galley_parshape_fixed_lines_bool
+ \int_set:Nn \l_galley_parshape_std_lines_int {#1}
+ \clist_set:Nn \l_galley_parshape_left_indent_clist {#2}
+ \clist_set:Nn \l_galley_parshape_right_indent_clist {#3}
+ \bool_set_eq:NN \l_galley_parshape_resume_std_bool #4
+ }
+\cs_new_protected_nopar:Npn \galley_parshape_single_par:nnnN #1#2#3#4
+ {
+ \bool_gset_true:N \g_galley_parshape_set_bool
+ \bool_set_false:N \l_galley_parshape_multipar_bool
+ \bool_set_false:N \l_galley_parshape_fixed_lines_bool
+ \int_set:Nn \l_galley_parshape_std_lines_int {#1}
+ \clist_set:Nn \l_galley_parshape_left_indent_clist {#2}
+ \clist_set:Nn \l_galley_parshape_right_indent_clist {#3}
+ \bool_set_eq:NN \l_galley_parshape_resume_std_bool #4
+ }
+\cs_generate_variant:Nn \galley_parshape_fixed_lines:nnn { nVV }
+\cs_generate_variant:Nn \galley_parshape_multi_par:nnnN { nVV }
+\cs_generate_variant:Nn \galley_parshape_single_par:nnnN { nVV }
+\cs_new_protected_nopar:Npn \galley_set_measure_and_parshape:
+ {
+ \bool_if:NTF \g_galley_parshape_set_bool
+ {
+ \bool_if:NTF \l_galley_parshape_fixed_lines_bool
+ {
+ \int_compare:nNnTF \g_galley_previous_par_lines_int > \c_zero
+ { \galley_generate_parshape_lines: }
+ { \galley_generate_parshape: }
+ }
+ {
+ \bool_gset_eq:NN \g_galley_parshape_set_bool
+ \l_galley_parshape_multipar_bool
+ \galley_generate_parshape:
+ }
+ }
+ {
+ \tex_global:D \tex_parshape:D
+ \c_one
+ \dim_use:N \l_galley_total_left_margin_dim
+ \c_space_tl
+ \dim_use:N \l_galley_text_width_dim
+ }
+ }
+\cs_new_protected_nopar:Npn \galley_generate_parshape:
+ {
+ \tex_global:D \tex_parshape:D
+ \int_eval:w
+ \l_galley_parshape_std_lines_int +
+ \int_min:nn
+ { \clist_length:N \l_galley_parshape_left_indent_clist }
+ { \clist_length:N \l_galley_parshape_right_indent_clist }
+ \bool_if:NT \l_galley_parshape_resume_std_bool { + 1 }
+ \int_eval_end:
+ \prg_replicate:nn \l_galley_parshape_std_lines_int
+ {
+ \dim_use:N \l_galley_total_left_margin_dim
+ \c_space_tl
+ \dim_use:N \l_galley_text_width_dim
+ \c_space_tl
+ }
+ \galley_set_parshape_map:oo
+ \l_galley_parshape_left_indent_clist
+ \l_galley_parshape_right_indent_clist
+ \bool_if:NT \l_galley_parshape_resume_std_bool
+ {
+ \c_space_tl
+ \dim_use:N \l_galley_total_left_margin_dim
+ \c_space_tl
+ \dim_use:N \l_galley_text_width_dim
+ }
+ }
+\cs_new_nopar:Npn \galley_set_parshape_map:nn #1#2
+ { \galley_set_parshape_map_aux:nw { } #1 , \q_mark #2 , \q_stop }
+\cs_generate_variant:Nn \galley_set_parshape_map:nn { oo }
+\cs_new_nopar:Npn \galley_set_parshape_map_aux:nw
+ #1#2 , #3 \q_mark #4 , #5 \q_stop
+ {
+ \bool_if:nTF { \tl_if_empty_p:n {#3} || \tl_if_empty_p:n {#4} }
+ {
+ #1
+ \dim_eval:n { \l_galley_total_left_margin_dim + ( #2 ) }
+ \c_space_tl
+ \dim_eval:n { \l_galley_text_width_dim - ( ( #2 ) + ( #4 ) ) }
+ }
+ {
+ \galley_set_parshape_map_aux:nw
+ {
+ #1
+ \dim_eval:n { \l_galley_total_left_margin_dim + ( #2 ) }
+ \c_space_tl
+ \dim_eval:n { \l_galley_text_width_dim - ( ( #2 ) + ( #4 ) ) }
+ \c_space_tl
+ }
+ #3 \q_mark #5 \q_stop
+ }
+ }
+\cs_new_protected_nopar:Npn \galley_generate_parshape_lines:
+ {
+ \int_compare:nNnTF \tex_parshape:D > \g_galley_previous_par_lines_int
+ {
+ \tex_global:D \tex_parshape:D
+ \int_eval:w \tex_parshape:D - \g_galley_previous_par_lines_int
+ \int_eval_end:
+ \prg_stepwise_function:nnnN
+ { \g_galley_previous_par_lines_int + \c_one }
+ \c_one \tex_parshape:D \galley_generate_parshape_lines_aux:n
+ }
+ {
+ \bool_gset_false:N \g_galley_parshape_set_bool
+ \tex_global:D \tex_parshape:D
+ \c_one
+ \dim_use:N \l_galley_total_left_margin_dim
+ \c_space_tl
+ \dim_use:N \l_galley_text_width_dim
+ }
+ }
+\cs_new_nopar:Npn \galley_generate_parshape_lines_aux:n #1
+ {
+ \etex_parshapeindent:D #1
+ ~
+ \etex_parshapelength:D #1
+ }
+\cs_new_protected_nopar:Npn \galley_set_user_penalty:n #1
+ { \tl_gset:Nx \g_galley_interpar_penalty_user_tl { \int_eval:n {#1} } }
+\cs_new_protected_nopar:Npn \galley_set_user_vspace:n #1
+ { \tl_gset:Nx \g_galley_interpar_vspace_user_tl { \skip_eval:n {#1} } }
+\dim_set:Nn \parskip \c_zero_dim
+\cs_undefine:N \parskip
+\skip_new:N \parskip
+\cs_new_eq:NN \l_galley_line_left_skip \tex_leftskip:D
+\cs_new_eq:NN \l_galley_line_right_skip \tex_rightskip:D
+\dim_new:N \l_galley_par_begin_skip
+\cs_new_eq:NN \l_galley_par_end_skip \tex_parfillskip:D
+\cs_new_eq:NN \l_galley_par_indent_dim \tex_parindent:D
+\cs_new_eq:NN \l_galley_last_line_fit_int \etex_lastlinefit:D
+\cs_new_protected_nopar:Npn \galley_set_interword_spacing:N #1
+ {
+ \bool_if:NTF #1
+ { % TODO Hook for font changes required!
+ \dim_compare:nNnTF { \tex_fontdimen:D \c_three \tex_font:D }
+ = \c_zero_dim
+ { \tex_spaceskip:D \c_zero_dim }
+ { \tex_spaceskip:D \tex_fontdimen:D \c_two \tex_font:D }
+ }
+ { \tex_spaceskip:D \c_zero_dim }
+ }
+\cs_new_eq:NN \l_galley_binop_penalty_int \tex_binoppenalty:D
+\cs_new_eq:NN \l_galley_double_hyphen_demerits_int \tex_doublehyphendemerits:D
+\cs_new_eq:NN \l_galley_emergency_stretch_skip \tex_emergencystretch:D
+\cs_new_eq:NN \l_galley_final_hyphen_demerits_int \tex_finalhyphendemerits:D
+\cs_new_eq:NN \l_galley_linebreak_badness_int \tex_hbadness:D
+\cs_new_eq:NN \l_galley_linebreak_fuzz_dim \tex_hfuzz:D
+\cs_new_eq:NN \l_galley_linebreak_penalty_int \tex_linepenalty:D
+\cs_new_eq:NN \l_galley_linebreak_pretolerance_int \tex_pretolerance:D
+\cs_new_eq:NN \l_galley_mismatch_demerits_int \tex_adjdemerits:D
+\cs_new_eq:NN \l_galley_relation_penalty_int \tex_relpenalty:D
+\cs_new_eq:NN \l_galley_linebreak_tolerance_int \tex_tolerance:D
+\cs_new_eq:NN \l_galley_broken_penalty_int \tex_brokenpenalty:D
+\cs_new_eq:NN \l_galley_interline_penalty_int \tex_interlinepenalty:D
+\cs_new_eq:NN \l_galley_parbreak_badness_int \tex_vbadness:D
+\cs_new_eq:NN \l_galley_parbreak_fuzz_dim \tex_vfuzz:D
+\cs_new_eq:NN \l_galley_post_display_penalty_int \tex_postdisplaypenalty:D
+\cs_new_eq:NN \l_galley_pre_display_penalty_int \tex_predisplaypenalty:D
+\clist_new:N \l_galley_club_penalties_clist
+\clist_new:N \l_galley_line_penalties_clist
+\cs_new_protected_nopar:Npn \galley_set_display_widow_penalties:n #1
+ {
+ \etex_displaywidowpenalties:D
+ \int_eval:w \clist_length:n {#1} + \c_one \int_eval_end:
+ \clist_map_function:nN {#1} \galley_set_aux:n
+ \c_zero
+ }
+\cs_generate_variant:Nn \galley_set_display_widow_penalties:n { V , v }
+\cs_new_protected_nopar:Npn \galley_set_widow_penalties:n #1
+ {
+ \etex_widowpenalties:D
+ \int_eval:w \clist_length:n {#1} + \c_one \int_eval_end:
+ \clist_map_function:nN {#1} \galley_set_aux:n
+ \c_zero
+ }
+\cs_generate_variant:Nn \galley_set_widow_penalties:n { V , v }
+\cs_new_nopar:Npn \galley_set_aux:n #1 { #1 ~ }
+\cs_new_protected_nopar:Npn \galley_set_club_penalties:n #1
+ {
+ \clist_set:Nn \l_galley_club_penalties_clist {#1}
+ \galley_calc_interline_penalties:
+ }
+\cs_generate_variant:Nn \galley_set_club_penalties:n { V , v }
+\cs_new_protected_nopar:Npn \galley_set_interline_penalties:n #1
+ {
+ \clist_set:Nn \l_galley_line_penalties_clist {#1}
+ \galley_calc_interline_penalties:
+ }
+\cs_generate_variant:Nn \galley_set_interline_penalties:n { V , v }
+\cs_new_protected_nopar:Npn \galley_set_display_club_penalties:n #1
+ {
+ \etex_clubpenalties:D
+ \int_eval:w \clist_length:n {#1} + \c_one \int_eval_end:
+ \clist_map_function:nN {#1} \galley_set_aux:n
+ \c_zero
+ \galley_calc_interline_penalties:
+ }
+\cs_generate_variant:Nn \galley_set_display_club_penalties:n { V , v }
+\cs_new_protected_nopar:Npn \galley_set_interline_penalty:n #1
+ {
+ \int_compare:nNnTF { \etex_interlinepenalties:D \c_zero } = \c_zero
+ {
+ \etex_interlinepenalties:D \c_one \int_eval:w #1 \int_eval_end:
+ \galley_calc_interline_penalties:
+ }
+ {
+ \cs_set_nopar:Npn \galley_set_interline_penalty_aux_ii:n ##1
+ {
+ \int_eval:w
+ \etex_interlinepenalties:D ##1
+ - \etex_interlinepenalties:D \etex_interlinepenalties:D \c_zero
+ + #1
+ \int_eval_end:
+ }
+ \exp_args:Nf \galley_set_interline_penalty_aux:nn
+ { \clist_length:N \l_galley_line_penalties_clist } {#1}
+ }
+ }
+\cs_new_protected_nopar:Npn \galley_set_interline_penalty_aux:nn #1#2
+ {
+ \etex_interlinepenalties:D
+ \etex_interlinepenalties:D \c_zero
+ \prg_stepwise_function:nnnN \c_one \c_one {#1}
+ \galley_set_interline_penalty_aux_i:n
+ \prg_stepwise_function:nnnN { #1 + \c_one } \c_one
+ { \etex_interlinepenalties:D \c_zero - \c_one }
+ \galley_set_interline_penalty_aux_ii:n
+ \int_eval:w #2 \int_eval_end:
+ }
+\cs_new_nopar:Npn \galley_set_interline_penalty_aux_i:n #1
+ { \etex_interlinepenalties:D \int_eval:w #1 \int_eval_end: }
+\cs_new_nopar:Npn \galley_set_interline_penalty_aux_ii:n #1 { }
+\cs_new_protected_nopar:Npn \galley_calc_interline_penalties:
+ {
+ \exp_args:Nff \galley_calc_interline_penalties_aux:nn
+ {
+ \int_eval:n
+ {
+ \int_max:nn
+ {
+ \clist_length:N \l_galley_club_penalties_clist
+ + \c_one
+ }
+ {
+ \int_max:nn
+ {
+ \clist_length:N \l_galley_line_penalties_clist
+ + \c_one
+ }
+ { \etex_clubpenalties:D \c_zero }
+ }
+ }
+ }
+ { \clist_length:N \l_galley_line_penalties_clist }
+ }
+\cs_new_protected_nopar:Npn \galley_calc_interline_penalties_aux:nn
+ #1#2
+ {
+ \etex_interlinepenalties:D #1 ~
+ \prg_stepwise_function:nnnN \c_one \c_one {#2}
+ \galley_calc_interline_penalties_aux_i:n
+ \prg_stepwise_function:nnnN { #2 + \c_one } \c_one { #1 - \c_one }
+ \galley_calc_interline_penalties_aux_ii:n
+ \etex_interlinepenalties:D \etex_interlinepenalties:D \c_zero
+ }
+\cs_new_nopar:Npn \galley_calc_interline_penalties_aux_i:n
+ #1
+ {
+ \int_eval:w
+ \clist_item:Nn \l_galley_line_penalties_clist { #1 - \c_one }
+ + 0 \clist_item:Nn \l_galley_club_penalties_clist
+ { #1 - \c_one }
+ - \etex_clubpenalties:D #1 ~
+ \int_eval_end:
+ }
+\cs_new_nopar:Npn \galley_calc_interline_penalties_aux_ii:n
+ #1
+ {
+ \int_eval:w
+ \etex_interlinepenalties:D \etex_interlinepenalties:D \c_zero
+ + 0 \clist_item:Nn \l_galley_club_penalties_clist
+ { #1 - \c_one }
+ - \etex_clubpenalties:D #1 ~
+ \int_eval_end:
+ }
+\cs_new_protected_nopar:Npn \galley_save_club_penalties:N #1
+ { \clist_set_eq:NN #1 \l_galley_club_penalties_clist }
+\cs_new_protected_nopar:Npn \galley_save_interline_penalties:N #1
+ { \clist_set_eq:NN #1 \l_galley_line_penalties_clist }
+\cs_new_protected_nopar:Npn \galley_save_display_club_penalties:N #1
+ {
+ \clist_set:Nx #1
+ {
+ \prg_stepwise_function:nnnN \c_one \c_one
+ { \etex_clubpenalties:D \c_zero - \c_one }
+ \galley_save_display_club_penalties:_aux:n
+ }
+ }
+\cs_new_nopar:Npn \galley_save_display_club_penalties:_aux:n #1
+ { \int_use:N \etex_clubpenaltes:D \int_eval:w #1 \int_eval_end: , }
+\cs_new_protected_nopar:Npn \galley_save_display_widow_penalties:N #1
+ {
+ \clist_set:Nx #1
+ {
+ \prg_stepwise_function:nnnN \c_one \c_one
+ { \etex_displaywidowpenalties:D \c_zero - \c_one }
+ \galley_save_display_widow_penalties:_aux:n
+ }
+ }
+\cs_new_nopar:Npn \galley_save_display_widow_penalties:_aux:n #1
+ { \int_use:N \etex_displaywidowpenalties:D \int_eval:w #1 \int_eval_end: , }
+\cs_new_protected_nopar:Npn \galley_save_widow_penalties:N #1
+ {
+ \clist_set:Nx #1
+ {
+ \prg_stepwise_function:nnnN \c_one \c_one
+ { \etex_widowpenalties:D \c_zero - \c_one }
+ \galley_save_widow_penalties:_aux:n
+ }
+ }
+\cs_new_nopar:Npn \galley_save_widow_penalties:_aux:n #1
+ { \int_use:N \etex_widowpenalties:D \int_eval:w #1 \int_eval_end: , }
+\cs_new_protected_nopar:Npn \galley_interline_penalty:
+ { \int_use:N \etex_interlinepenalties:D \etex_interlinepenalties:D \c_zero }
+\cs_set_protected_nopar:Npn \@afterheading
+ {
+ \bool_gset_true:N \g_galley_no_break_next_bool
+ \if@afterindent
+ \else
+ \bool_gset_true:N \galley_omit_next_indent_bool
+ \fi
+ }
+\cs_set_protected:Npn \@hangfrom #1
+ {
+ \setbox \@tempboxa = \hbox { {#1} }
+ \galley_parshape_single_par:nnnN
+ \c_one
+ { \box_wd:N \@tempboxa }
+ \c_zero_dim
+ \c_false_bool
+ \bool_gset_true:N \g_galley_no_break_next_bool
+ \bool_gset_true:N \galley_omit_next_indent_bool
+ \box \@tempboxa
+ }
+\cs_set_protected:Npn \@makefntext #1
+ {
+ \UseTemplate { justification } { std } { indent-width = 1 em }
+ \bool_gset_true:N \galley_omit_next_indent_bool
+ \galley_leave_vmode:
+ \hb@xt@ 1.8em { \hss \@makefnmark } #1
+ }
+%%
+%%
+%% End of file `l3galley.sty'.
diff --git a/Master/texmf-dist/tex/latex/l3experimental/xgalley/xgalley.sty b/Master/texmf-dist/tex/latex/l3experimental/xgalley/xgalley.sty
new file mode 100644
index 00000000000..160fca57631
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/l3experimental/xgalley/xgalley.sty
@@ -0,0 +1,616 @@
+%%
+%% This is file `xgalley.sty',
+%% generated with the docstrip utility.
+%%
+%% The original source files were:
+%%
+%% xgalley.dtx (with options: `package')
+%%
+%% EXPERIMENTAL CODE
+%%
+%% Do not distribute this file without also distributing the
+%% source files specified above.
+%%
+%% Do not distribute a modified version of this file.
+%%
+%% File: xgalley.dtx Copyright (C) 1999-2001, 2004-2009 Frank Mittelbach
+%% (C) 2010,2011 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{l3names}
+\GetIdInfo$Id: xgalley.dtx 2895 2011-10-09 15:58:19Z joseph $
+ {L3 Experimental galley}
+\ProvidesExplPackage
+ {\ExplFileName}{\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription}
+\RequirePackage{xparse,xtemplate,l3galley}
+\clist_new:N \l_galley_tmpa_clist
+\clist_new:N \l_galley_tmpb_clist
+\DeclareObjectType { measure } { 0 }
+\DeclareTemplateInterface { measure } { absolute } { 0 }
+ {
+ left-margin : length = 0 pt ,
+ right-margin : length = 0 pt
+ }
+\DeclareTemplateInterface { measure } { relative } { 0 }
+ {
+ left-margin : length = 0 pt ,
+ right-margin : length = 0 pt
+ }
+\cs_new_eq:NN \l_galley_left_margin_dim \leftmargin
+\cs_new_eq:NN \l_galley_right_margin_dim \rightmargin
+\DeclareTemplateCode { measure } { absolute } { 0 }
+ {
+ left-margin = \l_galley_left_margin_dim ,
+ right-margin = \l_galley_right_margin_dim
+ }
+ {
+ \AssignTemplateKeys
+ \galley_margins_set_absolute:nn \l_galley_left_margin_dim
+ \l_galley_right_margin_dim
+ }
+\DeclareTemplateCode { measure } { relative } { 0 }
+ {
+ left-margin = \l_galley_left_margin_dim ,
+ right-margin = \l_galley_right_margin_dim
+ }
+ {
+ \AssignTemplateKeys
+ \galley_margins_set_relative:nn \l_galley_left_margin_dim
+ \l_galley_right_margin_dim
+ }
+\DeclareObjectType { parshape } { 0 }
+\DeclareTemplateInterface { parshape } { hang } { 0 }
+ {
+ indent : length = 0 pt ,
+ on-left-side : boolean = true ,
+ lines : integer = 1
+ }
+\DeclareTemplateInterface { parshape } { initial } { 0 }
+ {
+ indent : length = 0 pt ,
+ on-left-side : boolean = true ,
+ lines : integer = 2
+ }
+\DeclareTemplateCode { parshape } { hang } { 0 }
+ {
+ indent = \l_galley_parshape_indent_dim ,
+ on-left-side = \l_galley_parshape_on_left_bool ,
+ lines = \l_galley_parshape_lines_int
+ }
+ {
+ \AssignTemplateKeys
+ \bool_if:NTF \l_galley_parshape_on_left_bool
+ {
+ \galley_parshape_single_par:nVVN
+ \l_galley_parshape_lines_int
+ \l_galley_parshape_indent_dim
+ \c_zero_dim
+ \c_false_bool
+ }
+ {
+ \galley_parshape_single_par:nVVN
+ \l_galley_parshape_lines_int
+ \c_zero_dim
+ \l_galley_parshape_indent_dim
+ \c_false_bool
+ }
+ }
+\DeclareTemplateCode { parshape } { initial } { 0 }
+ {
+ indent = \l_galley_parshape_indent_dim ,
+ on-left-side = \l_galley_parshape_on_left_bool ,
+ lines = \l_galley_parshape_lines_int
+ }
+ {
+ \AssignTemplateKeys
+ \clist_clear:N \l_galley_tmpa_clist
+ \clist_clear:N \l_galley_tmpb_clist
+ \prg_replicate:nn { \l_galley_parshape_lines_int }
+ {
+ \clist_put_right:Nn \l_galley_tmpa_clist
+ { \l_galley_parshape_indent_dim }
+ \clist_put_right:Nn \l_galley_tmpb_clist
+ { \c_zero_dim }
+ }
+ \bool_if:NTF \l_galley_parshape_on_left_bool
+ {
+ \galley_parshape_single_par:nVVN
+ \c_zero
+ \l_galley_tmpa_clist
+ \l_galley_tmpb_clist
+ \c_true_bool
+ }
+ {
+ \galley_parshape_single_par:nVVN
+ \c_zero
+ \l_galley_tmpb_clist
+ \l_galley_tmpa_clist
+ \c_true_bool
+ }
+ }
+\DeclareTemplateInterface { parshape } { std } { 0 } { }
+\DeclareTemplateCode { parshape } { std } { 0 } { } { }
+\DeclareObjectType { hyphenation } { 0 }
+\DeclareTemplateInterface { hyphenation } { std } { 0 }
+ {
+ enable : boolean = true ,
+ enable-upper-case : boolean = true ,
+ penalty : choice { low , medium , high } = low
+ }
+\DeclareTemplateCode { hyphenation } { std } { 0 }
+ {
+ enable = \l_galley_hyphen_enable_bool ,
+ enable-upper-case = \l_galley_hyphen_uppercase_bool ,
+ penalty =
+ {
+ low =
+ {
+ \int_set:Nn \tex_hyphenpenalty:D { 51 }
+ \int_set:Nn \tex_exhyphenpenalty:D { 51 }
+ } ,
+ medium =
+ {
+ \int_set:Nn \tex_hyphenpenalty:D { 151 }
+ \int_set:Nn \tex_exhyphenpenalty:D { 151 }
+ } ,
+ high =
+ {
+ \int_set:Nn \tex_hyphenpenalty:D { 301 }
+ \int_set:Nn \tex_exhyphenpenalty:D { 301 }
+ } ,
+ }
+ }
+ {
+ \AssignTemplateKeys
+ \int_set:Nn \tex_lefthyphenmin:D
+ {
+ \bool_if:NTF \l_galley_hyphen_enable_bool
+ { \l_galley_hyphen_left_int } { 63 }
+ }
+ \int_set:Nn \tex_uchyph:D
+ { \bool_if:NTF \l_galley_hyphen_uppercase_bool { 1 } { 0 } }
+ }
+\tex_defaulthyphenchar:D 45 \scan_stop:
+\tl_new:N \l_galley_justification_other_tl
+\DeclareObjectType { justification } { 0 }
+\DeclareTemplateInterface { justification } { std } { 0 }
+ {
+ end-skip : skip = 0 pt plus 1 fil ,
+ fixed-word-spacing : boolean = false ,
+ indent-width : length ,
+ left-skip : skip = 0 pt ,
+ right-skip : skip = 0 pt ,
+ start-skip : skip = 0 pt ,
+ stretch-last-line : boolean = false
+ }
+\DeclareTemplateInterface { justification } { single } { 0 }
+ {
+ end-skip : skip = 0 pt plus 1 fil ,
+ fixed-word-spacing : boolean = false ,
+ indent-width : length ,
+ left-skip : skip = 0 pt ,
+ right-skip : skip = 0 pt ,
+ start-skip : skip = 0 pt ,
+ stretch-last-line : boolean = false
+ }
+\DeclareTemplateCode { justification } { std } { 0 }
+ {
+ end-skip = \l_galley_par_end_skip ,
+ fixed-word-spacing = \l_galley_fixed_spacing_bool ,
+ indent-width = \l_galley_par_indent_dim ,
+ left-skip = \l_galley_line_left_skip ,
+ right-skip = \l_galley_line_right_skip ,
+ start-skip = \l_galley_par_begin_skip ,
+ stretch-last-line = \l_galley_par_stretch_last_bool
+ }
+ {
+ \AssignTemplateKeys
+ \tl_clear:N \l_galley_justification_other_tl
+ \galley_set_interword_spacing:N \l_galley_fixed_spacing_bool
+ \bool_if:NTF \l_galley_par_stretch_last_bool
+ { \int_set_eq:NN \l_galley_last_line_fit_int \c_one_thousand }
+ { \int_zero:N \l_galley_last_line_fit_int }
+ \skip_set:Nn \@rightskip { \l_galley_line_right_skip }
+ }
+\DeclareTemplateCode { justification } { single } { 0 }
+ {
+ end-skip = \l_galley_par_end_skip ,
+ fixed-word-spacing = \l_galley_fixed_spacing_bool ,
+ indent-width = \l_galley_par_indent_dim ,
+ left-skip = \l_galley_line_left_skip ,
+ right-skip = \l_galley_line_right_skip ,
+ start-skip = \l_galley_par_begin_skip ,
+ stretch-last-line = \l_galley_par_stretch_last_bool
+ }
+ {
+ \tl_put_left:Nx \l_galley_justification_other_tl
+ {
+ \skip_set:Nn \exp_not:N \l_galley_par_end_skip
+ { \skip_use:N \l_galley_par_end_skip }
+ \bool_if:NTF \l_galley_fixed_spacing_bool
+ { \bool_set_true:N \exp_not:N \l_galley_fixed_spacing_bool }
+ { \bool_set_false:N \exp_not:N \l_galley_fixed_spacing_bool }
+ \galley_set_interword_space:N
+ \exp_not:N \l_galley_fixed_spacing_bool
+ \dim_set:Nn \exp_not:N \l_galley_par_indent_dim
+ { \dim_use:N \l_galley_par_indent_dim }
+ \skip_set:Nn \l_galley_line_left_skip
+ { \skip_use:N \l_galley_line_left_skip }
+ \skip_set:Nn \exp_not:N \l_galley_line_right_skip
+ { \skip_use:N \l_galley_line_right_skip }
+ \skip_set:Nn \exp_not:N \l_galley_par_start_skip
+ { \skip_use:N \l_galley_par_start_skip }
+ \int_set:Nn \exp_not:N \l_galley_last_line_fit_int
+ { \int_use:N \l_galley_last_line_fit_int }
+ \skip_set:Nn \exp_not:N \@rightskip
+ { \skip_use:N \l_galley_line_right_skip }
+ }
+ \tl_gput_right:Nn \g_galley_restore_running_tl
+ { \l_galley_justification_other_tl }
+ \AssignTemplateKeys
+ \galley_set_interword_spacing:N \l_galley_fixed_spacing_bool
+ \bool_if:NTF \l_galley_par_stretch_last_bool
+ { \int_set_eq:NN \l_galley_last_line_fit_int \c_one_thousand }
+ { \int_zero:N \l_galley_last_line_fit_int }
+ \skip_set:Nn \@rightskip { \l_galley_line_right_skip }
+ }
+\DeclareInstance { justification } { justified } { std }
+ { indent-width = 15 pt }
+\UseInstance { justification } { justified }
+\DeclareInstance { justification } { noindent } { std }
+ {
+ end-skip = 15 pt plus 1 fil ,
+ indent-width = 0 pt
+ }
+\DeclareInstance { justification } { centered } { std }
+ {
+ end-skip = 0 pt ,
+ fixed-word-spacing = true ,
+ indent-width = 0 pt ,
+ left-skip = 0 pt plus 1 em ,
+ right-skip = 0 pt plus 1 em
+ }
+\DeclareInstance { justification } { ragged-left } { std }
+ {
+ end-skip = 0 pt ,
+ fixed-word-spacing = true ,
+ indent-width = 0 pt ,
+ left-skip = 0 pt plus 2 em ,
+ right-skip = 0 pt
+ }
+\DeclareInstance { justification } { ragged-right } { std }
+ {
+ end-skip = 0 pt plus 1 fil ,
+ fixed-word-spacing = true ,
+ indent-width = 0 pt ,
+ left-skip = 0 pt ,
+ right-skip = 0 pt plus 2 em
+ }
+\DeclareInstance { justification } { centering } { std }
+ {
+ end-skip = 0 pt ,
+ fixed-word-spacing = true ,
+ indent-width = 0 pt ,
+ left-skip = 0 pt plus 1 fil ,
+ right-skip = 0 pt plus 1 fil
+ }
+\DeclareTemplateInterface { justification } { compound } { 0 }
+ {
+ first-paragraph : instance { justification } ,
+ other-paragraphs : instance { justification }
+ }
+\DeclareTemplateCode { justification } { compound } { 0 }
+ {
+ first-paragraph = \galley_justification_first: ,
+ other-paragraphs = \galley_justification_other:
+ }
+ {
+ \AssignTemplateKeys
+ \galley_justification_first:
+ \tl_set:Nn \l_galley_justification_other_tl
+ { \galley_justification_other: }
+ \tl_gput_right:Nn \g_galley_restore_running_tl
+ { \l_galley_justification_other_tl }
+ }
+\DeclareObjectType { line-breaking } { 0 }
+\DeclareTemplateInterface { line-breaking } { std } { 0 }
+ {
+ badness : integer = 1000 ,
+ binop-penalty : integer = 700 ,
+ double-hyphen-demerits : integer = 10 000 ,
+ emergency-stretch : skip = 0 pt ,
+ final-hyphen-demerits : integer = 5000 ,
+ fuzz : length = 0.1 pt ,
+ line-penalty : integer = 10 ,
+ mismatch-demerits : integer = 10 000 ,
+ pretolerance : integer = 100 ,
+ relation-penalty : integer = 500 ,
+ tolerance : integer = 200
+ }
+\DeclareTemplateCode{ line-breaking } { std } { 0 }
+ {
+ badness = \l_galley_linebreak_badness_int ,
+ binop-penalty = \l_galley_binop_penalty_int ,
+ double-hyphen-demerits = \l_galley_double_hyphen_demerits_int ,
+ emergency-stretch = \l_galley_emergency_stretch_skip ,
+ final-hyphen-demerits = \l_galley_final_hyphen_demerits_int ,
+ fuzz = \l_galley_linebreak_fuzz_dim ,
+ line-penalty = \l_galley_linebreak_penalty_int ,
+ mismatch-demerits = \l_galley_mismatch_demerits_int ,
+ pretolerance = \l_galley_linebreak_pretolerance_int ,
+ relation-penalty = \l_galley_relation_penalty_int ,
+ tolerance = \l_galley_linebreak_tolerance_int
+ }
+ { \AssignTemplateKeys }
+\DeclareInstance { line-breaking } { std } { std } { }
+\UseInstance { line-breaking } { std }
+\DeclareObjectType { paragraph-breaking } { 0 }
+\DeclareTemplateInterface { paragraph-breaking } { std } { 0 }
+ {
+ badness : integer = 1000 ,
+ broken-penalty : integer = 100 ,
+ club-penalty : integer = 150 ,
+ display-club-penalty : integer = 150 ,
+ display-widow-penalty : integer = 150 ,
+ fuzz : length = 0.1 pt ,
+ interline-penalty : integer = 0 ,
+ post-display-penalty : integer = 0 ,
+ pre-display-penalty : integer = 10 000 ,
+ widow-penalty : integer = 150
+ }
+\DeclareTemplateCode { paragraph-breaking } { std } { 0 }
+ {
+ badness = \l_galley_parbreak_badness_int ,
+ broken-penalty = \l_galley_broken_penalty_int ,
+ club-penalty = \l_galley_club_penalty_int ,
+ display-club-penalty = \l_galley_display_club_penalty_int ,
+ display-widow-penalty = \l_galley_display_widow_penalty_int ,
+ fuzz = \l_galley_parbreak_fuzz_dim ,
+ interline-penalty = \l_galley_interline_penalty_int ,
+ post-display-penalty = \l_galley_post_display_penalty_int ,
+ pre-display-penalty = \l_galley_pre_display_penalty_int ,
+ widow-penalty = \l_galley_widow_penalty_int
+ }
+ {
+ \AssignTemplateKeys
+ \galley_set_club_penalties:V \l_galley_club_penalty_int
+ \galley_set_display_club_penalties:V \l_galley_display_club_penalty_int
+ \galley_set_display_widow_penalties:V \l_galley_display_widow_penalty_int
+ \galley_set_interline_penalty:n \l_galley_interline_penalty_int
+ \galley_set_widow_penalties:V \l_galley_widow_penalty_int
+ }
+\DeclareInstance { paragraph-breaking } { std } { std } { }
+\UseInstance { paragraph-breaking } { std }
+\DeclareInstance { paragraph-breaking } { nobreak } { std }
+ {
+ interline-penalty = 10 000 ,
+ post-display-penalty = 10 000
+ }
+\DeclareInstance { paragraph-breaking } { nolone } { std }
+ {
+ club-penalty = 10 000 ,
+ display-club-penalty = 10 000 ,
+ display-widow-penalty = 10 000 ,
+ widow-penalty = 10 000
+ }
+\DeclareTemplateInterface { paragraph-breaking } { single } { 0 }
+ {
+ badness : tokenlist ,
+ broken-penalty : tokenlist ,
+ club-penalty : tokenlist ,
+ display-club-penalty : tokenlist ,
+ display-widow-penalty : tokenlist ,
+ fuzz : tokenlist ,
+ interline-penalty : tokenlist ,
+ post-display-penalty : tokenlist ,
+ pre-display-penalty : tokenlist ,
+ widow-penalty : tokenlist
+ }
+\DeclareTemplateCode { paragraph-breaking } { single } { 0 }
+ {
+ badness = \l_galley_parbreak_badness_tl ,
+ broken-penalty = \l_galley_broken_penalty_tl ,
+ club-penalty = \l_galley_club_penalties_tl ,
+ display-club-penalty = \l_galley_display_club_penalties_tl ,
+ display-widow-penalty = \l_galley_display_widow_penalties_tl ,
+ fuzz = \l_galley_parbreak_fuzz_tl ,
+ interline-penalty = \l_galley_interline_penalty_tl ,
+ post-display-penalty = \l_galley_post_display_penalty_tl ,
+ pre-display-penalty = \l_galley_pre_display_penalty_tl ,
+ widow-penalty = \l_galley_widow_penalties_tl
+ }
+ {
+ \AssignTemplateKeys
+ \tl_if_empty:NF \l_galley_interline_penalty_tl
+ {
+ \tl_gput_right:Nx \g_galley_par_after_hook_tl
+ {
+ \int_set:Nn \exp_not:N \l_galley_interline_penalty_int
+ { \galley_interline_penalty: }
+ }
+ \int_set:Nn \l_galley_interline_penalty_int
+ { \l_galley_interline_penalty_tl }
+ }
+ \tl_if_empty:NF \l_galley_parbreak_fuzz_tl
+ {
+ \tl_gput_right:Nx \g_galley_par_after_hook_tl
+ {
+ \dim_set:Nn \exp_not:N \l_galley_parbreak_fuzz_dim
+ { \dim_use:N \l_galley_parbreak_fuzz_dim }
+ }
+ \dim_set:Nn \l_galley_parbreak_fuzz_dim { \l_galley_parbreak_fuzz_tl }
+ }
+ \seq_map_inline:Nn \c_galley_parbreak_single_seq
+ {
+ \tl_if_empty:cF { l_galley_ ##1 _tl }
+ {
+ \tl_gput_right:Nx \g_galley_par_after_hook_tl
+ {
+ \int_set:Nn \exp_not:c { l_galley_ ##1 _int }
+ { \int_use:c { l_galley_ ##1 _int } }
+ }
+ \int_set:cn { l_galley_ ##1 _int }
+ { \tl_use:c { l_galley_ ##1 _tl } }
+ }
+ }
+ \seq_map_inline:Nn \c_galley_parbreak_multi_seq
+ {
+ \tl_if_empty:cF { l_galley_ ##1 _tl }
+ {
+ \use:c { galley_save_ ##1 :N } \l_galley_tmpa_clist
+ \tl_gput_right:Nx \g_galley_par_after_hook_tl
+ {
+ \exp_not:c { galley_set_ ##1 :n }
+ { \exp_not:o \l_galley_tmpa_clist }
+ }
+ \use:c { galley_set_ ##1 :v } { l_galley_ ##1 _tl }
+ }
+ }
+ }
+\seq_new:N \c_galley_parbreak_multi_seq
+\seq_gput_right:Nn \c_galley_parbreak_multi_seq { club_penalties }
+\seq_gput_right:Nn \c_galley_parbreak_multi_seq { display_club_penalties }
+\seq_gput_right:Nn \c_galley_parbreak_multi_seq { display_widow_penalties }
+\seq_gput_right:Nn \c_galley_parbreak_multi_seq { widow_penalties }
+\seq_new:N \c_galley_parbreak_single_seq
+\seq_gput_right:Nn \c_galley_parbreak_single_seq { parbreak_badness }
+\seq_gput_right:Nn \c_galley_parbreak_single_seq { broken_penalty }
+\seq_gput_right:Nn \c_galley_parbreak_single_seq { post_display_penalty }
+\seq_gput_right:Nn \c_galley_parbreak_single_seq { pre_display_penalty }
+\DeclareInstance { paragraph-breaking } { single-std } { single } { }
+\DeclareInstance { paragraph-breaking } { single-nobreak } { single }
+ {
+ interline-penalty = 10 000 ,
+ post-display-penalty = 10 000
+ }
+\DeclareInstance { paragraph-breaking } { single-noclub } { single }
+ {
+ club-penalty = 10 000 ,
+ display-club-penalty = 10 000
+ }
+\DeclareInstance { paragraph-breaking } { single-nolone } { single }
+ {
+ club-penalty = 10 000 ,
+ display-club-penalty = 10 000 ,
+ display-widow-penalty = 10 000 ,
+ widow-penalty = 10 000
+ }
+\DeclareInstance { paragraph-breaking } { single-nowidow } { single }
+ {
+ display-widow-penalty = 10 000 ,
+ widow-penalty = 10 000
+ }
+\DeclareObjectType { display-begin } { 0 }
+\DeclareObjectType { display-end } { 0 }
+\DeclareTemplateInterface { display-begin } { std } { 0 }
+ {
+ par-penalty : tokenlist ,
+ par-space : tokenlist ,
+ penalty : tokenlist ,
+ space : tokenlist
+ }
+\DeclareTemplateInterface { display-end } { std } { 0 }
+ {
+ par-penalty : tokenlist ,
+ par-space : tokenlist ,
+ penalty : tokenlist ,
+ space : tokenlist
+ }
+\DeclareTemplateCode { display-begin } { std } { 0 }
+ {
+ par-penalty = \l_galley_display_begin_par_vpenalty_tl ,
+ par-space = \l_galley_display_begin_par_vspace_tl ,
+ penalty = \l_galley_display_begin_vpenalty_tl ,
+ space = \l_galley_display_begin_vspace_tl
+ }
+ {
+ \AssignTemplateKeys
+ \tl_if_empty:NF \l_galley_display_begin_par_vpenalty_tl
+ {
+ \tl_set:Nx \l_galley_display_begin_par_vpenalty_tl
+ { \int_eval:n { \l_galley_display_begin_par_vpenalty_tl } }
+ }
+ \tl_if_empty:NF \l_galley_display_begin_par_vspace_tl
+ {
+ \tl_set:Nx \l_galley_display_begin_par_vspace_tl
+ { \skip_eval:n { \l_galley_display_begin_par_vspace_tl } }
+ }
+ \tl_if_empty:NF \l_galley_display_begin_vpenalty_tl
+ {
+ \tl_set:Nx \l_galley_display_begin_vpenalty_tl
+ { \int_eval:n { \l_galley_display_begin_vpenalty_tl } }
+ }
+ \tl_if_empty:NF \l_galley_display_begin_vspace_tl
+ {
+ \tl_set:Nx \l_galley_display_begin_vspace_tl
+ { \skip_eval:n { \l_galley_display_begin_vspace_tl } }
+ }
+ }
+\DeclareTemplateCode { display-end } { std } { 0 }
+ {
+ par-penalty = \l_galley_display_end_par_vpenalty_tl ,
+ par-space = \l_galley_display_end_par_vspace_tl ,
+ penalty = \l_galley_display_end_vpenalty_tl ,
+ space = \l_galley_display_end_vspace_tl
+ }
+ {
+ \AssignTemplateKeys
+ \tl_if_empty:NF \l_galley_display_end_par_vpenalty_tl
+ {
+ \tl_set:Nx \l_galley_display_end_par_vpenalty_tl
+ { \int_eval:n { \l_galley_display_end_par_vpenalty_tl } }
+ }
+ \tl_if_empty:NF \l_galley_display_end_par_vspace_tl
+ {
+ \tl_set:Nx \l_galley_display_end_par_vspace_tl
+ { \skip_eval:n { \l_galley_display_end_par_vspace_tl } }
+ }
+ \tl_if_empty:NF \l_galley_display_end_vpenalty_tl
+ {
+ \tl_set:Nx \l_galley_display_end_vpenalty_tl
+ { \int_eval:n { \l_galley_display_end_vpenalty_tl } }
+ }
+ \tl_if_empty:NF \l_galley_display_end_vspace_tl
+ {
+ \tl_set:Nx \l_galley_display_end_vspace_tl
+ { \skip_eval:n { \l_galley_display_end_vspace_tl } }
+ }
+ }
+\RenewDocumentCommand \nobreak { }
+ { \bool_gset_true:N \g_galley_no_break_next_bool }
+\RenewDocumentCommand \noindent { }
+ { \bool_gset_false:N \g_galley_omit_next_indent_bool }
+\RenewDocumentCommand \vspace { s m } { \galley_set_vspace_user:n {#2} }
+%%
+%%
+%% End of file `xgalley.sty'.