summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2023-07-22 20:19:27 +0000
committerKarl Berry <karl@freefriends.org>2023-07-22 20:19:27 +0000
commit41b4083c4760c1aa464faa675e3bf1832f71ab6a (patch)
tree4e2d7e5e242abb33e73bbcfd41aeecfc0272775f /Master/texmf-dist/tex
parent4c5778f024115953ee66abaf048fe7bfc5b1beb7 (diff)
crefthe (22jul23)
git-svn-id: svn://tug.org/texlive/trunk@67706 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex')
-rw-r--r--Master/texmf-dist/tex/latex/crefthe/crefthe.sty261
1 files changed, 240 insertions, 21 deletions
diff --git a/Master/texmf-dist/tex/latex/crefthe/crefthe.sty b/Master/texmf-dist/tex/latex/crefthe/crefthe.sty
index a561c4e1dee..e1ce211bb61 100644
--- a/Master/texmf-dist/tex/latex/crefthe/crefthe.sty
+++ b/Master/texmf-dist/tex/latex/crefthe/crefthe.sty
@@ -1,5 +1,5 @@
%%
-%% Copyright (C) 2021-2022 by Jinwen XU
+%% Copyright (C) 2021-2023 by Jinwen XU
%% ------------------------------------
%%
%% This file may be distributed and/or modified under the conditions of
@@ -12,7 +12,7 @@
\NeedsTeXFormat{LaTeX2e}[2022-06-01]
\ProvidesExplPackage
{crefthe}
- {2022/09/24} {}
+ {2023/07/22} {}
{Cross referencing with proper definite articles}
\keys_define:nn { crefthe }
@@ -87,34 +87,104 @@
\__crefthe_cref_general:NNNnnN \c_false_bool #1 #2 { #3 } { #4 } \crefthe_nameCrefs_original:w
}
+\keys_define:nn { crefthe-setting }
+ {
+ , variant .tl_set:N = \l__crefthe_variant_tl
+
+ % , nom .meta:n = { variant = Nominativ }
+ % , nom. .meta:n = { variant = Nominativ }
+ % , Nom .meta:n = { variant = Nominativ }
+ % , Nom. .meta:n = { variant = Nominativ }
+ % , gen .meta:n = { variant = Genitiv }
+ % , gen. .meta:n = { variant = Genitiv }
+ % , Gen .meta:n = { variant = Genitiv }
+ % , Gen. .meta:n = { variant = Genitiv }
+ % , dat .meta:n = { variant = Dativ }
+ % , dat. .meta:n = { variant = Dativ }
+ % , Dat .meta:n = { variant = Dativ }
+ % , Dat. .meta:n = { variant = Dativ }
+ % , akk .meta:n = { variant = Akkusativ }
+ % , akk. .meta:n = { variant = Akkusativ }
+ % , Akk .meta:n = { variant = Akkusativ }
+ % , Akk. .meta:n = { variant = Akkusativ }
+
+ % , unknown .code:n = {
+ % \bool_gset_true:N \g__crefthe_has_prep_bool
+ % \tl_set:No \l__crefthe_prep_tl { \l_keys_key_tl }
+ % }
+
+ , unknown .code:n = {}
+ }
+
+\bool_new:N \l__crefthe_variant_matched_bool
\cs_new_protected:Nn \__crefthe_cref_general:NNNnnN
+ % #1 = star or not
+ % #2 = -
+ % #3 = +
+ % #4 = key-value
+ % #5 = label
+ % #6 = original command, such as \crefthe_cref_original:w or \crefthe_Cref_original:w
{
- \tl_if_blank:eTF { #4 }
- {
- \bool_gset_false:N \g__crefthe_has_prep_bool
- }
+ \tl_set:Nn \l__crefthe_variant_tl {}
+ \bool_gset_false:N \g__crefthe_has_prep_bool
+ \tl_set:Nn \l__crefthe_prep_tl {}
+
+ \keys_set:nn { crefthe-setting } { #4 }
+
+ % This should actually be part of the keys parsing
+ \clist_map_inline:nn { #4 }
{
- \bool_gset_true:N \g__crefthe_has_prep_bool
+ \bool_set_false:N \l__crefthe_variant_matched_bool
+ \str_if_in:nnF { ##1 } { = }
+ {% for keys without values
+ \str_if_eq:VnT \languagename { ngerman }
+ {
+ \str_case:nnT { ##1 }
+ {
+ { nom } { \tl_set:Nn \l__crefthe_variant_tl { Nominativ } }
+ { nom. } { \tl_set:Nn \l__crefthe_variant_tl { Nominativ } }
+ { Nom } { \tl_set:Nn \l__crefthe_variant_tl { Nominativ } }
+ { Nom. } { \tl_set:Nn \l__crefthe_variant_tl { Nominativ } }
+ { gen } { \tl_set:Nn \l__crefthe_variant_tl { Genitiv } }
+ { gen. } { \tl_set:Nn \l__crefthe_variant_tl { Genitiv } }
+ { Gen } { \tl_set:Nn \l__crefthe_variant_tl { Genitiv } }
+ { Gen. } { \tl_set:Nn \l__crefthe_variant_tl { Genitiv } }
+ { dat } { \tl_set:Nn \l__crefthe_variant_tl { Dativ } }
+ { dat. } { \tl_set:Nn \l__crefthe_variant_tl { Dativ } }
+ { Dat } { \tl_set:Nn \l__crefthe_variant_tl { Dativ } }
+ { Dat. } { \tl_set:Nn \l__crefthe_variant_tl { Dativ } }
+ { akk } { \tl_set:Nn \l__crefthe_variant_tl { Akkusativ } }
+ { akk. } { \tl_set:Nn \l__crefthe_variant_tl { Akkusativ } }
+ { Akk } { \tl_set:Nn \l__crefthe_variant_tl { Akkusativ } }
+ { Akk. } { \tl_set:Nn \l__crefthe_variant_tl { Akkusativ } }
+ } { \bool_set_true:N \l__crefthe_variant_matched_bool }
+ }
+ \bool_if:NF \l__crefthe_variant_matched_bool
+ {
+ \tl_set:Nn \l__crefthe_prep_tl { ##1 }
+ }
+ }
}
+
\bool_if:NTF #2
- { \tl_set:Nn \l__crefthe_prep_once_tl { #4 } }
+ { \tl_set:No \l__crefthe_prep_once_tl { \l__crefthe_prep_tl } }
{
\bool_if:NTF #3
- { \tl_set:Nn \l__crefthe_prep_each_tl { #4 } }
+ { \tl_set:No \l__crefthe_prep_each_tl { \l__crefthe_prep_tl } }
{
% \str_set:Nx fully expands \__crefthe_prep_mode: into a string,
% then \str_case:Vn compares the value of the resulting string:
\str_set:Nx \l__crefthe_tmpa_str { \__crefthe_prep_mode: }
\str_case:Vn \l__crefthe_tmpa_str
{
- { - } { \tl_set:Nn \l__crefthe_prep_once_tl { #4 } }
- { + } { \tl_set:Nn \l__crefthe_prep_each_tl { #4 } }
+ { - } { \tl_set:No \l__crefthe_prep_once_tl { \l__crefthe_prep_tl } }
+ { + } { \tl_set:No \l__crefthe_prep_each_tl { \l__crefthe_prep_tl } }
}
}
}
\group_begin:
\bool_if:NTF #1
- { #6 * { #5 } } % here #6 is \crefthe_cref_original:w or \crefthe_Cref_original:w
+ { #6 * { #5 } }
{ #6 { #5 } }
\group_end:
\tl_gclear:N \l__crefthe_prep_each_tl
@@ -123,14 +193,15 @@
% \__crefthe_prep_mode: defines the default mode for supported languages
\cs_new:Nn \__crefthe_prep_mode:
{
- \str_case:Vn \languagename
+ \str_case:VnF \languagename
{
{french} { + }
+ {ngerman} { - }
{italian} { + }
{spanish} { - }
{portuguese} { + }
{brazilian} { + }
- }
+ } { + }
}
\NewDocumentCommand \crefthename { m O{} m O{} m }
@@ -143,13 +214,13 @@
\__crefthe_name_general:nnnnnn { #1 } { #2 } { #3 } { #4 } { #5 } { C }
}
-\cs_new:Npn \crefthe_width_of_space_dim { \tex_fontdimen:D 2 \tex_font:D~plus -\tex_fontdimen:D 3 \tex_font:D~minus -\tex_fontdimen:D 4 \tex_font:D }
+\cs_new:Npn \crefthe_retrieve_space: { \skip_horizontal:n { -\tex_fontdimen:D 2 \tex_font:D~plus -\tex_fontdimen:D 3 \tex_font:D~minus -\tex_fontdimen:D 4 \tex_font:D } }
\cs_new:Nn \crefthe_empty_adjust:n
{
\tl_if_blank:nTF { #1 }
{
- \skip_horizontal:n { -\crefthe_width_of_space_dim }
+ \crefthe_retrieve_space:
}
{
#1
@@ -157,8 +228,13 @@
}
\cs_new_protected:Nn \__crefthe_name_general:nnnnnn
+ % #1 = environment name
+ % #2 = singular definite article
+ % #3 = singular name
+ % #4 = plural definite article
+ % #5 = plural name
+ % #6 = c or C
{
- % #6 is c or C
\__crefthe_name_general_do:nnnnnn
{ #1 }
{ \crefthemark { \crefthe_empty_adjust:n { #2 } } }
@@ -183,6 +259,130 @@
}
}
+\NewDocumentCommand \crefthevariantname { m m }
+ {
+ \crefthe_parse_variant:n { #2 }
+ \crefthe_pass_variant_to:n { \crefthename { #1 } }
+ }
+
+\NewDocumentCommand \Crefthevariantname { m m }
+ {
+ \crefthe_parse_variant:n { #2 }
+ \crefthe_pass_variant_to:n { \Crefthename { #1 } }
+ }
+
+\tl_new:N \l__crefthe_variant_noun_singular_tl
+\tl_new:N \l__crefthe_variant_noun_plural_tl
+\tl_new:N \l__crefthe_variant_article_singular_tl
+\tl_new:N \l__crefthe_variant_article_plural_tl
+\tl_new:N \l__crefthe_variant_default_noun_singular_tl
+\tl_new:N \l__crefthe_variant_default_noun_plural_tl
+\tl_new:N \l__crefthe_variant_default_article_singular_tl
+\tl_new:N \l__crefthe_variant_default_article_plural_tl
+\bool_new:N \l__crefthe_variant_default_bool
+\cs_new_protected:Npn \crefthe_parse_variant:n #1
+ {
+ \tl_clear:N \l__crefthe_variant_noun_singular_tl
+ \tl_clear:N \l__crefthe_variant_noun_plural_tl
+ \tl_clear:N \l__crefthe_variant_article_singular_tl
+ \tl_clear:N \l__crefthe_variant_article_plural_tl
+ \tl_clear:N \l__crefthe_variant_default_noun_singular_tl
+ \tl_clear:N \l__crefthe_variant_default_noun_plural_tl
+ \tl_clear:N \l__crefthe_variant_default_article_singular_tl
+ \tl_clear:N \l__crefthe_variant_default_article_plural_tl
+ \bool_set_false:N \l__crefthe_variant_default_bool
+ \keyval_parse:NNn
+ \__crefthe_parse_variant_default:n
+ \__crefthe_parse_variant_value:nn
+ { #1 }
+ }
+\tl_new:N \l__crefthe_parsed_tl
+\NewDocumentCommand \__crefthe_variant_parser:w { O{} m O{} m }
+ {
+ \tl_if_blank:nTF { #1 }
+ {
+ \tl_set:Nn \l__crefthe_parsed_tl { { \crefthe_retrieve_space: } { #2 } { \crefthe_retrieve_space: } { #4 } }
+ }
+ {
+ \tl_set:Nn \l__crefthe_parsed_tl { { #1 } { #2 } { #3 } { #4 } }
+ }
+ \use_none_delimit_by_q_stop:w
+ }
+\cs_new_protected:Npn \__crefthe_parse_variant_default:n #1
+ {
+ \bool_set_true:N \l__crefthe_variant_default_bool
+ \__crefthe_variant_parser:w #1 \q_stop
+ \tl_set:Nx \l__crefthe_variant_default_article_singular_tl
+ { \tl_item:Nn \l__crefthe_parsed_tl { 1 } }
+ \tl_set:Nx \l__crefthe_variant_default_noun_singular_tl
+ { \tl_item:Nn \l__crefthe_parsed_tl { 2 } }
+ \tl_set:Nx \l__crefthe_variant_default_article_plural_tl
+ { \tl_item:Nn \l__crefthe_parsed_tl { 3 } }
+ \tl_set:Nx \l__crefthe_variant_default_noun_plural_tl
+ { \tl_item:Nn \l__crefthe_parsed_tl { 4 } }
+ }
+\cs_new_protected:Npn \__crefthe_parse_variant_value:nn #1#2
+ {
+ \__crefthe_variant_parser:w #2 \q_stop
+ \tl_put_right:Nx \l__crefthe_variant_article_singular_tl
+ { { \tl_to_str:n { #1 } } { \tl_item:Nn \l__crefthe_parsed_tl { 1 } } }
+ \tl_put_right:Nx \l__crefthe_variant_noun_singular_tl
+ { { \tl_to_str:n { #1 } } { \tl_item:Nn \l__crefthe_parsed_tl { 2 } } }
+ \tl_put_right:Nx \l__crefthe_variant_article_plural_tl
+ { { \tl_to_str:n { #1 } } { \tl_item:Nn \l__crefthe_parsed_tl { 3 } } }
+ \tl_put_right:Nx \l__crefthe_variant_noun_plural_tl
+ { { \tl_to_str:n { #1 } } { \tl_item:Nn \l__crefthe_parsed_tl { 4 } } }
+ }
+
+\cs_new_protected:Npn \crefthe_pass_variant_to:n #1
+ {
+ \use:e
+ {
+ \exp_not:n { #1 }
+ \bool_if:NTF \l__crefthe_variant_default_bool
+ {
+ [
+ \exp_not:n { \str_case:NnF \l__crefthe_variant_tl }
+ { \exp_not:o \l__crefthe_variant_article_singular_tl }
+ { \exp_not:o \l__crefthe_variant_default_article_singular_tl }
+ ]
+ {
+ \exp_not:n { \str_case:NnF \l__crefthe_variant_tl }
+ { \exp_not:o \l__crefthe_variant_noun_singular_tl }
+ { \exp_not:o \l__crefthe_variant_default_noun_singular_tl }
+ }
+ [
+ \exp_not:n { \str_case:NnF \l__crefthe_variant_tl }
+ { \exp_not:o \l__crefthe_variant_article_plural_tl }
+ { \exp_not:o \l__crefthe_variant_default_article_plural_tl }
+ ]
+ {
+ \exp_not:n { \str_case:NnF \l__crefthe_variant_tl }
+ { \exp_not:o \l__crefthe_variant_noun_plural_tl }
+ { \exp_not:o \l__crefthe_variant_default_noun_plural_tl }
+ }
+ }
+ {
+ [
+ \exp_not:n { \str_case:Nn \l__crefthe_variant_tl }
+ { \exp_not:o \l__crefthe_variant_article_singular_tl }
+ ]
+ {
+ \exp_not:n { \str_case:Nn \l__crefthe_variant_tl }
+ { \exp_not:o \l__crefthe_variant_noun_singular_tl }
+ }
+ [
+ \exp_not:n { \str_case:Nn \l__crefthe_variant_tl }
+ { \exp_not:o \l__crefthe_variant_article_plural_tl }
+ ]
+ {
+ \exp_not:n { \str_case:Nn \l__crefthe_variant_tl }
+ { \exp_not:o \l__crefthe_variant_noun_plural_tl }
+ }
+ }
+ }
+ }
+
\seq_new:N \g__crefthe_already_patched_seq
\cs_new_protected:Nn \crefthe_patch_format:nnnn
@@ -209,19 +409,18 @@
{ format-patch-failed }
{ Failed~to~patch~the~format~"\iow_char:N \\#1"! }
-\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_gset:Nx \l__crefthe_prep_each_tl
- { \text_lowercase:V \l__crefthe_prep_each_tl }
+ { \text_lowercase:n { \l__crefthe_prep_each_tl } }
\str_if_eq:eeF { \str_tail:n { #1 } } { ' } { ~ }
\bool_gset_false:N \g__crefthe_uppercase_bool
}
-\prg_generate_conditional_variant:Nnn \str_case_e:nn { nv } { T, F, TF }
+\prg_generate_conditional_variant:Nnn \str_case_e:nn { ev } { T, F, TF }
\cs_new:Nn \crefthe_contraction:nn
{
\exp_args:Ne \__crefthe_contraction:nnn
@@ -239,7 +438,7 @@
{
\exp_args:Ne \__crefthe_conditional_uppercase:n
{
- \str_case_e:nvF { #2~#1 }
+ \str_case_e:evF { #2~#1 }
{ c_crefthe_contraction_rule_ \languagename _tl }
{ #2~#1 }
}
@@ -249,6 +448,7 @@
}
\cs_new:Nn \__crefthe_conditional_uppercase:n
{
+ % \bool_set_false:N \l_text_titlecase_check_letter_bool
\bool_if:NTF \g__crefthe_uppercase_bool
{ \text_titlecase_first:n }
{ \use:n }
@@ -293,6 +493,25 @@
{ De~le } { Du }
{ De~les } { Des }
}
+\tl_const:Nn \c_crefthe_contraction_rule_ngerman_tl
+ {
+ { an~dem } { am }
+ { an~das } { ans }
+ { bei~dem } { beim }
+ { in~dem } { im }
+ { in~das } { ins }
+ { von~dem } { vom }
+ { zu~dem } { zum }
+ { zu~der } { zur }
+ { An~dem } { Am }
+ { An~das } { Ans }
+ { Bei~dem } { Beim }
+ { In~dem } { Im }
+ { In~das } { Ins }
+ { Von~dem } { Vom }
+ { Zu~dem } { Zum }
+ { Zu~der } { Zur }
+ }
\tl_const:Nn \c_crefthe_contraction_rule_italian_tl
{
{ a~il } { al }