From 7a8d1925127ad121a8f591db931524f9b8eacb93 Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Mon, 28 Feb 2022 03:02:40 +0000 Subject: CTAN sync 202202280302 --- macros/latex/contrib/crefthe/crefthe.sty | 80 +++++++++++++++++++++++--------- 1 file changed, 59 insertions(+), 21 deletions(-) (limited to 'macros/latex/contrib/crefthe/crefthe.sty') diff --git a/macros/latex/contrib/crefthe/crefthe.sty b/macros/latex/contrib/crefthe/crefthe.sty index 7edf7e1788..213f3d2e60 100644 --- a/macros/latex/contrib/crefthe/crefthe.sty +++ b/macros/latex/contrib/crefthe/crefthe.sty @@ -13,7 +13,7 @@ \RequirePackage{l3keys2e} \ProvidesExplPackage {crefthe} - {2022/02/20} {} + {2022/02/27} {} {Cross referencing with proper definite articles} \keys_define:nn { crefthe } @@ -26,6 +26,7 @@ \ProcessKeysOptions { crefthe } \RequirePackage { cleveref } +\RequirePackage { regexpatch } \NewCommandCopy \crefthe_cref_original:w \cref \NewCommandCopy \crefthe_Cref_original:w \Cref @@ -41,20 +42,28 @@ \tl_new:N \l__crefthe_prep_once_tl \tl_new:N \l__crefthe_prep_each_tl -\bool_new:N \l__crefthe_uppercase_bool +\bool_new:N \g__crefthe_uppercase_bool +\bool_new:N \g__crefthe_has_prep_bool \NewDocumentCommand \crefthe { s t- t+ O{} m } { - \bool_set_false:N \l__crefthe_uppercase_bool + \bool_gset_false:N \g__crefthe_uppercase_bool \__crefthe_cref_general:NNNnnN #1 #2 #3 { #4 } { #5 } \crefthe_cref_original:w } \NewDocumentCommand \Crefthe { s t- t+ O{} m } { - \bool_set_true:N \l__crefthe_uppercase_bool + \bool_gset_true:N \g__crefthe_uppercase_bool \__crefthe_cref_general:NNNnnN #1 #2 #3 { #4 } { #5 } \crefthe_Cref_original:w } -\cs_new_protected:Npn \__crefthe_cref_general:NNNnnN #1 #2 #3 #4 #5 #6 +\cs_new_protected:Nn \__crefthe_cref_general:NNNnnN { + \tl_if_blank:eTF #4 + { + \bool_gset_false:N \g__crefthe_has_prep_bool + } + { + \bool_gset_true:N \g__crefthe_has_prep_bool + } \bool_if:NTF #2 { \tl_set:Nn \l__crefthe_prep_once_tl { #4 } } { @@ -78,7 +87,7 @@ } % \__crefthe_prep_mode: defines the default mode for supported languages -\cs_new:Npn \__crefthe_prep_mode: +\cs_new:Nn \__crefthe_prep_mode: { \str_case:Vn \languagename { @@ -94,51 +103,80 @@ { \__crefthe_name_general:nnnnnn { #1 } { #2 } { #3 } { #4 } { #5 } { c } } + \NewDocumentCommand \Crefthename { m O{} m O{} m } { \__crefthe_name_general:nnnnnn { #1 } { #2 } { #3 } { #4 } { #5 } { C } } -\cs_new_protected:Npn \__crefthe_name_general:nnnnnn #1 #2 #3 #4 #5 #6 + +\cs_new_protected:Nn \__crefthe_name_general:nnnnnn { % #6 is c or C \tl_if_blank:nTF { #2 } { - \cs:w crefthe_#6refname_original:w \cs_end: { #1 } { #3 } { #5 } - \cs_set:cn { #6ref_#1_format:nnn } { ##2 #3 ~ ##1 ##3 } - \cs_set:cn { #6ref_#1_format_first:nnn } { ##2 #5 ~ ##1 ##3 } + \__crefthe_name_general_do:nnnnnn { #1 } {} { #3 } {} { #5 } { #6 } } { - \cs:w crefthe_#6refname_original:w \cs_end: { #1 } { \crefthemark { #2 } #3 } { \crefthemark { #4 } #5 } - \cs_set:cn { #6ref_#1_format:nnn } { \crefthemark { #2 } ##2 #3 ~ ##1 ##3 } - \cs_set:cn { #6ref_#1_format_first:nnn } { \crefthemark { #4 } ##2 #5 ~ ##1 ##3 } + \__crefthe_name_general_do:nnnnnn { #1 } { \crefthemark { #2 } } { #3 } { \crefthemark { #4 } } { #5 } { #6 } } + } + +\cs_new_protected:Nn \__crefthe_name_general_do:nnnnnn + { + \use:c { crefthe_#6refname_original:w } { #1 } { #2 #3 } { #4 #5 } \hook_gput_code:nnn { begindocument } { crefthe } { - \cs_set_eq:cc { #6ref@ #1 @format } { #6ref_#1_format:nnn } - \cs_set_eq:cc { #6ref@ #1 @format@first } { #6ref_#1_format_first:nnn } + \crefthe_patch_format:nnnnn { 2 } { #6ref@#1@format } { #6ref@#1@name } { #2 } { #3 } + \crefthe_patch_format:nnnnn { 2 } { #6ref@#1@format@first } { #6ref@#1@name@plural } { #4 } { #5 } + \crefthe_patch_format:nnnnn { 3 } { #6refrange@#1@format } { #6ref@#1@name@plural } { #4 } { #5 } + \crefthe_patch_format:nnnnn { 3 } { #6refrange@#1@format@first } { #6ref@#1@name@plural } { #4 } { #5 } + } + } + +\seq_new:N \g__crefthe_already_patched_seq + +\cs_new_protected:Nn \crefthe_patch_format:nnnnn + % #1 = the # number for the beginning mark of hyperlink + % #2 = name of the format command + % #3 = name of the command after hyperlink mark + % #4 = new content before the mark + % #5 = new content after the mark + { + \seq_if_in:NnF \g__crefthe_already_patched_seq { #2 - #3 } + { + \makeatletter + \tl_set:Nn \l_tmpa_tl { #4 } + \tl_set:Nn \l_tmpb_tl { #5 } + \exp_args:Nc \regexpatchcmd { #2 } + { \cP. #1 \c{ #3 } } + { \u{l_tmpa_tl} \cP\# #1 \u{l_tmpb_tl} } + { } { \PatchFailed } + \makeatother + \seq_gput_right:Nn \g__crefthe_already_patched_seq { #2 - #3 } } } + \cs_generate_variant:Nn \text_lowercase:n { V } \NewDocumentCommand \crefthemark { m } { \crefthe_contraction:Ve \l__crefthe_prep_each_tl { \crefthe_contraction:Vn \l__crefthe_prep_once_tl { #1 } } \tl_gclear:N \l__crefthe_prep_once_tl - \tl_set:Nx \l__crefthe_prep_each_tl + \tl_gset:Nx \l__crefthe_prep_each_tl { \text_lowercase:V \l__crefthe_prep_each_tl } \str_if_eq:eeF { \str_tail:n { #1 } } { ' } { ~ } - \bool_set_false:N \l__crefthe_uppercase_bool + \bool_gset_false:N \g__crefthe_uppercase_bool } \prg_generate_conditional_variant:Nnn \str_case_e:nn { nv } { T, F, TF } -\cs_new:Npn \crefthe_contraction:nn #1#2 +\cs_new:Nn \crefthe_contraction:nn { \exp_args:Ne \__crefthe_contraction:nnn { \text_lowercase:n { #2 } } { #1 } { #2 } } \cs_generate_variant:Nn \crefthe_contraction:nn { V, Ve } -\cs_new:Npn \__crefthe_contraction:nnn #1 #2 #3 +\cs_new:Nn \__crefthe_contraction:nnn { % #1 is \text_lowercase:n { #3 } % #2 is the preposition @@ -157,9 +195,9 @@ { #2~#3 } } } -\cs_new:Npn \__crefthe_conditional_uppercase:n #1 +\cs_new:Nn \__crefthe_conditional_uppercase:n { - \bool_if:NTF \l__crefthe_uppercase_bool + \bool_if:NTF \g__crefthe_uppercase_bool { \text_titlecase_first:n } { \use:n } { #1 } -- cgit v1.2.3