From 0b585ecd1647ab179b0640efd64cfbebf50c0b8f Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Tue, 26 Sep 2017 23:19:43 +0000 Subject: knowledge (26sep17) git-svn-id: svn://tug.org/texlive/trunk@45404 c570f23f-e606-0410-a88d-b1316a301751 --- .../texmf-dist/tex/latex/knowledge/knowledge.sty | 1529 +++++++++++--------- 1 file changed, 879 insertions(+), 650 deletions(-) (limited to 'Master/texmf-dist/tex') diff --git a/Master/texmf-dist/tex/latex/knowledge/knowledge.sty b/Master/texmf-dist/tex/latex/knowledge/knowledge.sty index eccc94e1443..1504fe58967 100644 --- a/Master/texmf-dist/tex/latex/knowledge/knowledge.sty +++ b/Master/texmf-dist/tex/latex/knowledge/knowledge.sty @@ -23,14 +23,15 @@ %% LaTeX version 1999/12/01 or later. %% \usepackage{expl3} -\ProvidesExplPackage{knowledge}{2017/07/28}{v1.04}{} +\ProvidesExplPackage{knowledge}{2017/09/26}{v1.05}{} %%%%%%%%%% \RequirePackage{l3keys2e} \RequirePackage{etoolbox} \RequirePackage{xparse} \bool_if_exist:NTF\knowledge_package_loaded_bool {\endinput} - {\bool_set_true:N\knowledge_package_loaded_bool} + {\bool_new:N\knowledge_package_loaded_bool + \bool_set_true:N\knowledge_package_loaded_bool} \usepackage{xparse} \usepackage{currfile} @@ -38,6 +39,25 @@ \c_sys_jobname_str {} {\tl_set_eq:Nc\c_sys_jobname_str{c_job_name_tl}} +\cs_new:Nn\tl_new:Nn + {\tl_new:N#1 + \tl_gset:Nn#1{#2}} +\cs_new:Nn\tl_new_eq:NN + {\tl_new:N#1 + \tl_gset_eq:NN#1#2} +\cs_new:Nn\bool_new_true:N + {\bool_new:N#1 + \bool_gset_true:N#1} +\cs_new:Nn\bool_new_false:N + {\bool_new:N#1 + \bool_gset_false:N#1} +\cs_new:Nn\bool_set_text:Nn + {\use:c{bool_set_#2:N}#1} +\cs_generate_variant:Nn\tl_new:Nn{Nx,cn,cx} +\cs_generate_variant:Nn\tl_new_eq:NN{Nc,cN,cc} +\cs_generate_variant:Nn\bool_new_true:N{c} +\cs_generate_variant:Nn\bool_new_false:N{c} +\cs_generate_variant:Nn\bool_set_text:Nn{cn} \cs_new_protected:Nn\cs_new_protected_with_variants:Nnn {\cs_new_protected:Nn#1{#3} \cs_generate_variant:Nn#1{#2}} @@ -49,8 +69,10 @@ \cs_generate_variant:Nn\cs_new_with_variants:Nnn{cnn} \cs_generate_variant:Nn\tl_show:n{x} -\cs_new:Nn\tl_if_exist_ne:NTF - {\tl_if_exist:NTF#1{\tl_if_empty:NTF#1{#3}{#2}}{#3}} +\cs_new:Npn\tl_if_exist_ne:NTF#1 + {\tl_if_exist:NTF#1{\tl_if_empty:NTF#1\use_ii:nn\use_i:nn}\use_ii:nn} +\cs_new:Npn\tl_if_exist_ne:NT#1 + {\tl_if_exist:NTF#1{\tl_if_empty:NTF#1\use_none:n\use:n}\use_none:n} \cs_generate_variant:Nn\tl_if_empty:nTF{xTF} \cs_new_protected:Npn\kl_apply_inline:nnw#1#2 {\group_begin: @@ -154,14 +176,18 @@ {\tl_put_right:Nn\kaux_posttreatment_tl{#1}} \NewDocumentCommand\KAuxInit{m} {\tl_put_right:Nn\kaux_inittreatment_tl{#1}} +\tl_new:N\kaux_pretreatment_tl \tl_gset:Nn\kaux_pretreatment_tl{} +\tl_new:N\kaux_posttreatment_tl \tl_gset:Nn\kaux_posttreatment_tl{} +\tl_new:N\kaux_inittreatment_tl \tl_gset:Nn\kaux_inittreatment_tl{} \tl_new:N\kaux_command_list_tl \NewDocumentCommand\NewKAuxCommand{ m m m } { \ProvideDocumentCommand#1{#2}{} \KAuxInit {\KAuxWrite*{\KAuxCommand#1{#2}{#3}}} + \tl_new:c{kaux_\cs_to_str:N#1-args_tl} \tl_gset:cn{kaux_\cs_to_str:N#1-args_tl}{#2} \tl_gput_right:Nn\kaux_command_list_tl{#1} } @@ -172,7 +198,7 @@ {\kaux_activate_command_phase:Nn##1{#1}} } \cs_new:Nn\kaux_activate_command_phase:Nn -{ \tl_gclear:c{kaux_\cs_to_str:N#1-active_tl} +{ \tl_clear_new:c{kaux_\cs_to_str:N#1-active_tl} % \kaux_code_set:Nn\tmpa_code{} \clist_map_inline:nn{#2} @@ -243,6 +269,7 @@ {\tl_set:Nn\kauxCurrentFile{#1} \tl_set:Nn\kauxCurrentLine{#2}} +\cs_new:Nn\kaux_current_location:{\kauxCurrentFile :\kauxCurrentLine :} \tl_new:N\kauxCurrentFile \tl_new:N\kauxCurrentLine \bool_new:N\kaux_can_be_used_bool @@ -730,28 +757,29 @@ \cs_new:Nn\kutils_latex_to_obsolete:n {\tl_map_function:nN{#1}\kutils_latex_to_obsolete:N} %%%%%%%%%% +\cs_new:Nn\knowledge_begin_module_if:n + {\bool_if:NF#1\knowledge_skip_module:} \cs_new:Npn\knowledge_skip_module:#1\knowledge_end_module: {} -\cs_new:Nn\knowledge_begin_module_if:N - {\bool_if:NF#1\knowledge_skip_module:} \cs_new:Nn\knowledge_end_module: {} \cs_set_eq:Nc\klparse_ifnextchar:NTF{@ifnextchar} - +\tl_new:N\klparse_novalue_tl \NewDocumentCommand\klparse_setnovalue{o} {\tl_set:Nn\klparse_novalue_tl{#1}} \klparse_setnovalue\relax - \cs_new:Npn\klparse_if_novalue:NTF {\tl_if_eq:NNTF\klparse_novalue_tl} -\cs_new:Nn\knowledge_info:n{\msg_info:nnn{knowledge}{knowledge~info}{#1}} -\cs_new:Nn\knowledge_warning:n{\msg_warning:nnn{knowledge}{knowledge~warning}{#1}} -\cs_new:Nn\knowledge_error:n{\msg_error:nnn{knowledge}{knowledge~error}{#1}} - +\cs_generate_variant:Nn\tl_to_str:n{V} +\cs_new:Nn\knowledge_info:n + {\msg_info:nnn{knowledge}{knowledge~info}{#1}} +\cs_new:Nn\knowledge_warning:n + {\msg_warning:nnn{knowledge}{knowledge~warning}{#1}} +\cs_new:Nn\knowledge_error:n + {\msg_error:nnn{knowledge}{knowledge~error}{#1}} \msg_new:nnnn{knowledge}{knowledge~info}{#1}{#2} \msg_new:nnnn{knowledge}{knowledge~warning}{#1}{#2} \msg_new:nnnn{knowledge}{knowledge~error}{#1}{#2} - \cs_generate_variant:Nn\knowledge_info:n{x} \cs_generate_variant:Nn\knowledge_warning:n{x} \cs_generate_variant:Nn\knowledge_error:n{x} @@ -764,12 +792,10 @@ {The~knowledge~'#1'~could~not~be~found~in~scope~'#3'~(namespace~'#2').} \msg_new:nnn{ knowledge }{ knowledge~unknown~label } {The~label~'#2'~could~not~be~found~while~searching~for~'#1'.~Possibly~rerun~latex.} - \msg_new:nnn{ knowledge }{ package~required } {In~order~to~use~directive~'#1',~please~load~package~or~use~option~'#2'.} \msg_new:nnn{ knowledge }{ knowledge~exists } { The~knowledge~'#1'~in~scope~'#2'~(namespace~'#3')~already~exists. } - \msg_new:nnn{scope}{area~exists}{Area~'#1'~already~exists.} \msg_new:nnn{scope}{area~not~exist}{Area~'#1'~does~not~exist.} \msg_new:nnn{scope}{empty~pop}{Attempt~to~pop~an~empty~area~stack.} @@ -785,43 +811,29 @@ \msg_new:nnn{scope}{area~not~in~context} {\tl_if_empty:nTF{#2}{}{\exp_not:n{#2}}: ~The~area~`#1'~can't~be~found~in~context.~Possibly~rerun~latex.} -\NewKAuxCommand\KAuxErrorKnowledgeRecursive{mmmm} - {Package~'knowledge:~A~knowledge~has~recursive~definition.~ - {namespace}{scope}{undefined~knowledge}{base~knowledge}} - {} -\cs_new:Nn\knowledge_kl_error_recursion: { - \msg_error:nnxxx{ knowledge }{ knowledge~recursion } - {\exp_not:V\knowledge_kl_base_key_tl} - {\exp_not:V\knowledge_kl_namespace_tl} - {\exp_not:V\knowledge_kl_key_tl} - \knowledge_kl_error_display:n{recursive~knowledge} +\msg_new:nnn{knowledge}{recap~unknown~knowledge} + {Some~knowledge~are~not~defined.~See~the~'.diagnose'~file~for~more~information.} +\msg_new:nnn{knowledge}{recap~autoref~introduced~twice} + {Some~knowledge~is~introduced~twice.~See~the~'.diagnose'~file~for~more~information.} +\msg_new:nnn{knowledge}{recap~autoref~not~introduced} + {Some~knowledge~is~used~but~not~introduced.~See~the~'.diagnose'~file~for~more~information.} +\tl_clear_new:N\knowledge_configuration_pending_tl +\NewDocumentCommand\knowledgeconfigure{m}{ + \keys_set:nn{ knowledge~configuration~options }{#1} } -\tl_new:N\knowledge_configuration_pending_tl -\tl_set:Nn\knowledge_configuration_pending_tl{} -\NewDocumentCommand\KnowledgePackageTrigger{mm} - { \keys_define:nn{ knowledge~package~options }{ #1 .code:n = {#2} } } -\NewDocumentCommand\KnowledgeConfigureBooleanOption{om}{ - \tl_set:Nn\l_tmpa_tl{#2} - \tl_remove_all:Nn\l_tmpa_tl{~} - \IfNoValueTF{#1} - {\bool_new:c{knowledge_configuration_#2_bool} - \exp_args:NcnV\knowledge_KnowledgeConfigureBooleanOption:Nnnnn - {knowledge_configuration_#2_bool}{#2}\l_tmpa_tl{}{}} - {\exp_args:NNnV\knowledge_KnowledgeConfigureBooleanOption:Nnnnn - #1{#2}\l_tmpa_tl{}{}} - } +\NewDocumentCommand\KnowledgeConfigureBooleanOption{om} + {\KnowledgeConfigureBooleanOptionTF[#1]{#2}{}{}} \NewDocumentCommand\KnowledgeConfigureBooleanOptionTF{ommm}{ \tl_set:Nn\l_tmpa_tl{#2} \tl_remove_all:Nn\l_tmpa_tl{~} \IfNoValueTF{#1} {\bool_new:c{knowledge_configuration_#2_bool} - \exp_args:NcnV\knowledge_KnowledgeConfigureBooleanOption:Nnnnn + \exp_args:NcnV\__knowledge_KnowledgeConfigureBooleanOption:Nnnnn {knowledge_configuration_#2_bool}{#2}\l_tmpa_tl{#3}{#4}} - {\exp_args:NNnV\knowledge_KnowledgeConfigureBooleanOption:Nnnnn + {\exp_args:NNnV\__knowledge_KnowledgeConfigureBooleanOption:Nnnnn #1{#2}\l_tmpa_tl{#3}{#4}} } - -\cs_new:Nn\knowledge_KnowledgeConfigureBooleanOption:Nnnnn{ +\cs_new:Nn\__knowledge_KnowledgeConfigureBooleanOption:Nnnnn{ \keys_define:nn{ knowledge~package~options }{ #3 .choice:, #3 / true .code:n = {\tl_put_right:Nn\knowledge_configuration_pending_tl{,#2=true}}, @@ -833,8 +845,24 @@ #2 / true .code:n = {\bool_if:NF#1{\bool_set_true:N#1#4}}, #2 / false .code:n = {\bool_if:NT#1{\bool_set_false:N#1#5}}, #2 .default:n = {true} - }} - +}} +\NewDocumentCommand\KnowledgeConfigureTrigger{omm}{ + \IfNoValueTF{#1} + {\tl_set:Nn\l_tmpa_tl{#2} + \tl_remove_all:Nn\l_tmpa_tl{~} + \exp_args:NNV\KnowledgeConfigureTrigger[\l_tmpa_tl]{#2}{#3}} + {\keys_define:nn { knowledge~configuration~options } + { #2 .code:n = {#3}, #2 .default:V = \klparse_novalue_tl } + \keys_define:nn { knowledge~package~options } + { #1 .code:n = {\tl_put_right:Nn\knowledge_configuration_pending_tl{,#2={##1}} }} + } +} +\NewDocumentCommand\KnowledgePackageTrigger{mm} + { \keys_define:nn{ knowledge~package~options }{ #1 .code:n = {#2} } + \keys_define:nn{ knowledge~configuration~options }{ + #1 .code:n = {\knowledge_error:n + {The~configuration~directive~`#1'~can~only~be~used~at~package~loading.}} + }} \NewDocumentCommand\KnowledgePackageBooleanOption{om}{ \tl_set:Nn\l_tmpa_tl{#2} \tl_remove_all:Nn\l_tmpa_tl{~} @@ -853,38 +881,31 @@ #3 .default:n = {true} } \keys_define:nn{ knowledge~configuration~options }{ - #2 .code:n = {\OPTION_CANNOT_BE_USED_IN_knowledgeconfigure} + #2 .code:n = {\knowledge_error:n + {The~configuration~directive~`#2'~can~only~be~used~at~package~loading.}} }} -\NewDocumentCommand\KnowledgeConfigureTrigger{omm}{ - \IfNoValueTF{#1} - {\tl_set:Nn\l_tmpa_tl{#2} - \tl_remove_all:Nn\l_tmpa_tl{~} - \exp_args:NNV\KnowledgeConfigureTrigger[\l_tmpa_tl]{#2}{#3}} - {\keys_define:nn { knowledge~configuration~options } - { #2 .code:n = {#3}, #2 .default:V = \klparse_novalue_tl } - \keys_define:nn { knowledge~package~options } - { #1 .code:n = {\tl_put_right:Nn\knowledge_configuration_pending_tl{,#2={##1}} }} +\cs_new:Nn\knowledge_option_bool_new:nN{ + \keys_define:nn{ knowledge~package~options } { + #1 .choice: , + #1 / true .code:n = { \bool_gset_true:N#2 }, + #1 / false .code:n = { \bool_gset_false:N#2 }, + #1 .default:n = {true} } } -\NewDocumentCommand\KnowledgeConfigureOption{mm}{ - \keys_define:nn { knowledge~configuration~options } - { #1 .code:n = {#2} } -} -\NewDocumentCommand\knowledgeconfigure{m}{ - \keys_set:nn{ knowledge~configuration~options }{#1} -} +\cs_new:Nn\knowledge_option_bool_new:n + {\bool_new:c{knowledge_option_#1_bool} + \exp_args:Nnc\knowledge_option_bool_new:nN{#1}{knowledge_option_#1_bool}} \bool_new:N\knowledge_configuration_quotation_bool \KnowledgeConfigureBooleanOptionTF[\knowledge_configuration_quotation_bool]{quotation}{\klactivatequotation}{\kldeactivatequotation} -\KnowledgeConfigureOption{protect~quotation}{\kl_protect_environment_quotation:n{#1}} +\KnowledgeConfigureTrigger{protect~quotation}{\kl_protect_environment_quotation:n{#1}} \bool_new:N\knowledge_configuration_diagnoseline_bool -\bool_gset_true:N\knowledge_configuration_diagnoseline_bool +\bool_gset_false:N\knowledge_configuration_diagnoseline_bool \KnowledgeConfigureBooleanOption[\knowledge_configuration_diagnoseline_bool]{diagnose~line} \bool_new:N\knowledge_configuration_visibleAP_bool \KnowledgeConfigureBooleanOption[\knowledge_configuration_visibleAP_bool]{visible~anchor~points}\KnowledgeConfigureBooleanOption[\knowledge_configuration_visibleAP_bool]{visible~AP} \bool_new:N\knowledge_hyperlinks_active_bool \bool_set_true:N\knowledge_hyperlinks_active_bool - -\tl_set:Nn\knowledge_option_mode_tl{} +\tl_clear_new:N\knowledge_option_mode_tl \KnowledgePackageTrigger{ paper }{\tl_set:Nn\knowledge_option_mode_tl{paper}} \KnowledgePackageTrigger{ electronic }{\tl_set:Nn\knowledge_option_mode_tl{electronic}} \KnowledgePackageTrigger{ composition }{\tl_set:Nn\knowledge_option_mode_tl{composition}} @@ -924,17 +945,6 @@ \bool_set_false:c{knowledge_#1_syntax_bool}}, #1 .default:n = {active} }} -\cs_new:Nn\knowledge_option_bool_new:nN{ - \keys_define:nn{ knowledge~package~options } { - #1 .choice: , - #1 / true .code:n = { \bool_gset_true:N#2 }, - #1 / false .code:n = { \bool_gset_false:N#2 }, - #1 .default:n = {true} - } -} -\cs_new:Nn\knowledge_option_bool_new:n - {\bool_new:c{knowledge_option_#1_bool} - \exp_args:Nnc\knowledge_option_bool_new:nN{#1}{knowledge_option_#1_bool}} \cs_new:Nn\knowledge_option_aci_autoload:nn{ \bool_if:cTF{knowledge_#1_active_bool} {\package_if_loaded:nTF{#1}{} @@ -945,9 +955,17 @@ \knowledge_option_aci_define:n{xcolor} \knowledge_option_aci_define:n{makeidx} \ProcessKeysOptions{knowledge~package~options} -\tl_if_exist:NTF\knowledgepackagemode - {}{\tl_set:Nn\knowledgepackagemode{}} +\bool_new:N\knowledge_option_composition_bool +\bool_set_false:N\knowledge_option_composition_bool +\bool_new:N\knowledge_option_electronic_bool +\bool_set_false:N\knowledge_option_electronic_bool +\bool_new:N\knowledge_option_paper_bool +\bool_set_false:N\knowledge_option_paper_bool +\tl_if_exist:NTF\knowledgepackagemode + {} + {\tl_new:N\knowledgepackagemode + \tl_set:Nn\knowledgepackagemode{}} \tl_if_empty:NTF\knowledgepackagemode {\tl_if_empty:NTF\knowledge_option_mode_tl {\tl_set:Nn\knowledge_option_mode_tl{composition}} @@ -957,14 +975,6 @@ {\knowledge_info:n{Knowledge~mode~overriden~by~user.} \tl_set_eq:NN\knowledge_option_mode_tl\knowledgepackagemode }} - -\bool_new:N\knowledge_option_composition_bool -\bool_set_false:N\knowledge_option_composition_bool -\bool_new:N\knowledge_option_electronic_bool -\bool_set_false:N\knowledge_option_electronic_bool -\bool_new:N\knowledge_option_paper_bool -\bool_set_false:N\knowledge_option_paper_bool - \keys_define:nn{ knowledge~package~modes }{ paper .code:n = { \bool_set_true:N\knowledge_option_paper_bool @@ -988,29 +998,30 @@ \keys_set:nV{ knowledge~package~modes }{ composition }} } \keys_set:nV{ knowledge~package~modes }\knowledge_option_mode_tl -\knowledge_option_aci_autoload:nn{ hyperref }{hidelinks} +\knowledge_option_aci_autoload:nn{ hyperref }{} \knowledge_option_aci_autoload:nn{ xcolor }{} \knowledge_option_aci_autoload:nn{ makeidx }{} -\tl_gset:Nn\scope_tl{SC@PE:} -\tl_gset:Nn\scopept_tl{K@UX:} +\tl_const:Nn\scope_tl{SC@PE} +\tl_const:Nn\scopept_tl{SC@PE2} \seq_new:N\scope_instances_stack_seq \tl_new:N\scope_top_instance_tl \tl_new:N\scope_top_area_tl +\tl_new:N\l_self_tl \cs_new:Nn\scope_area_show:n{ \group_begin: \scope_area_if_exist:nTF{#1} - { \tl_set:Nx\self{\scope_tl.area[#1]} + { \tl_set:Nx\l_self_tl{\scope_tl.area[#1]} \tl_show:x - {Area~name:~\use:c{\self.name_tl},~ - autoclose=\bool_if:cTF{\self.autoclose_bool}TF,~ - recursive=\bool_if:cTF{\self.recursive_bool}TF,~ - multiple=\bool_if:cTF{\self.multiple_bool}TF,~ - scope=\bool_if:cTF{\self.scope_bool}TF,~ - environment=\bool_if:cTF{\self.environment_bool}TF,~ - forces={\use:c{\self.forces_tl}},~ - accepts~knowledge=\bool_if:cTF{\self.accepts_knowledge_bool}TF,~ - attracts~knowledge=\bool_if:cTF{\self.attracts_knowledge_bool}TF,~ - accepts~labels=\bool_if:cTF{\self.labelizable_bool}TF. + {Area~name:~\use:c{\l_self_tl.name_tl},~ + autoclose=\bool_if:cTF{\l_self_tl.autoclose_bool}TF,~ + recursive=\bool_if:cTF{\l_self_tl.recursive_bool}TF,~ + multiple=\bool_if:cTF{\l_self_tl.multiple_bool}TF,~ + scope=\bool_if:cTF{\l_self_tl.scope_bool}TF,~ + environment=\bool_if:cTF{\l_self_tl.environment_bool}TF,~ + forces={\use:c{\l_self_tl.forces_tl}},~ + accepts~knowledge=\bool_if:cTF{\l_self_tl.accepts_knowledge_bool}TF,~ + attracts~knowledge=\bool_if:cTF{\l_self_tl.attracts_knowledge_bool}TF,~ + accepts~labels=\bool_if:cTF{\l_self_tl.labelizable_bool}TF. } } {\knowledge_error:n{Unknown~area~`#1'~in~`\noexpand\scope_area_show:n'.}} @@ -1018,29 +1029,38 @@ } \cs_new:Nn\scope_area_create:n {\group_begin: - \tl_set:Nx\self{\scope_tl.area[#1]} + \tl_set:Nx\l_self_tl{\scope_tl.area[#1]} % \scope_category_add_area:nn{all}{#1} % - \tl_gset:cn{\self.name_tl}{#1} - \seq_new:c{\self.category_seq} - \seq_gpush:cn{\self.category_seq}{all} - \seq_gpush:cn{\self.category_seq}{#1} - \bool_gset_false:c{\self.autoclose_bool} - \bool_gset_true:c{\self.environment_bool} - \bool_gset_true:c{\self.multiple_bool} - \bool_gset_true:c{\self.attractsknowledge_bool} - \bool_gset_true:c{\self.labelizable_bool} - \bool_gset_false:c{\self.scope_bool} - \bool_gset_true:c{\self.acceptsknowledge_bool} - \tl_gset:cn{\self.pushcode_tl}{} - \tl_gset:cn{\self.popcode_tl}{} - \tl_gset:cn{\self.forces_tl}{} - \seq_new:c{\self.mandatorybase_seq} - \int_new:c{\self.count_int} - \int_gset:cn{\self.count_int}{0} - \int_new:c{\self.nesting_int} - \int_gset:cn{\self.nesting_int}{0} + \tl_new:c{\l_self_tl.name_tl} + \tl_gset:cn{\l_self_tl.name_tl}{#1} + \seq_new:c{\l_self_tl.category_seq} + \seq_gpush:cn{\l_self_tl.category_seq}{all} + \seq_gpush:cn{\l_self_tl.category_seq}{#1} + \bool_new:c{\l_self_tl.autoclose_bool} + \bool_gset_false:c{\l_self_tl.autoclose_bool} + \bool_new:c{\l_self_tl.environment_bool} + \bool_gset_true:c{\l_self_tl.environment_bool} + \bool_new:c{\l_self_tl.multiple_bool} + \bool_gset_true:c{\l_self_tl.multiple_bool} + \bool_new:c{\l_self_tl.attractsknowledge_bool} + \bool_gset_true:c{\l_self_tl.attractsknowledge_bool} + \bool_new:c{\l_self_tl.labelizable_bool} + \bool_gset_true:c{\l_self_tl.labelizable_bool} + \bool_new:c{\l_self_tl.scope_bool} + \bool_gset_false:c{\l_self_tl.scope_bool} + \bool_new:c{\l_self_tl.acceptsknowledge_bool} + \bool_gset_true:c{\l_self_tl.acceptsknowledge_bool} + \bool_new:c{\l_self_tl.recursive_bool} + \tl_gclear_new:c{\l_self_tl.pushcode_tl} + \tl_gclear_new:c{\l_self_tl.popcode_tl} + \tl_gclear_new:c{\l_self_tl.forces_tl} + \seq_new:c{\l_self_tl.mandatorybase_seq} + \int_new:c{\l_self_tl.count_int} + \int_gset:cn{\l_self_tl.count_int}{0} + \int_new:c{\l_self_tl.nesting_int} + \int_gset:cn{\l_self_tl.nesting_int}{0} % \scope_category_if_exist:nTF{#1} {}{\scope_category_create:n{#1} @@ -1064,12 +1084,14 @@ \cs_new:Nn\scope_area_set:nn {\clist_map_inline:nn{#1} {\scope_area_set_i:nn{##1}{#2}}} +\tl_new:N\scope_area_tl \cs_new:Nn\scope_area_set_i:nn { \scope_area_if_exist:nTF{#1} - {}{\scope_area_create:n{#1}} + {}{ + \scope_area_create:n{#1}} \group_begin: \tl_set:Nx\scope_area_tl{#1} - \tl_set:Nx\self{\scope_tl.area[\scope_area_tl]} + \tl_set:Nx\l_self_tl{\scope_tl.area[\scope_area_tl]} \keys_set:nn{ scope~area~set }{#2} \group_end:} \keys_define:nn{ scope~area~set } { @@ -1081,53 +1103,53 @@ }}, autoclose .choice:, autoclose / false .code:n = - {\bool_gset_false:c{\self.autoclose_bool}}, + {\bool_gset_false:c{\l_self_tl.autoclose_bool}}, autoclose / true .code:n = - {\bool_gset_true:c{\self.autoclose_bool}}, + {\bool_gset_true:c{\l_self_tl.autoclose_bool}}, parents .code:n = - {\seq_gset_from_clist:cn{\self.mandatorybase_seq}{#1}}, + {\seq_gset_from_clist:cn{\l_self_tl.mandatorybase_seq}{#1}}, push~code .code:n = - {\tl_gput_right:cn{\self.pushcode_tl}{#1}}, + {\tl_gput_right:cn{\l_self_tl.pushcode_tl}{#1}}, pop~code .code:n = - {\tl_gput_right:cn{\self.popcode_tl}{#1}}, + {\tl_gput_right:cn{\l_self_tl.popcode_tl}{#1}}, occurrences .choice:, occurrences / once .code:n = - {\bool_gset_false:c{\self.multiple_bool} - \bool_gset_false:c{\self.recursive_bool}}, + {\bool_gset_false:c{\l_self_tl.multiple_bool} + \bool_gset_false:c{\l_self_tl.recursive_bool}}, occurrences / multiple .code:n = { - \bool_gset_true:c{\self.multiple_bool} - \bool_gset_false:c{\self.recursive_bool}}, + \bool_gset_true:c{\l_self_tl.multiple_bool} + \bool_gset_false:c{\l_self_tl.recursive_bool}}, occurrences / recursive .code:n = { - \bool_gset_true:c{\self.multiple_bool} - \bool_gset_true:c{\self.recursive_bool}}, + \bool_gset_true:c{\l_self_tl.multiple_bool} + \bool_gset_true:c{\l_self_tl.recursive_bool}}, scope .choice:, scope / true .code:n = { - \bool_gset_true:c{\self.scope_bool}}, + \bool_gset_true:c{\l_self_tl.scope_bool}}, scope / false .code:n = { - \bool_gset_false:c{\self.scope_bool}}, + \bool_gset_false:c{\l_self_tl.scope_bool}}, environment .choice:, environment / true .code:n = { - \bool_gset_true:c{\self.environment_bool}}, + \bool_gset_true:c{\l_self_tl.environment_bool}}, environment / false .code:n = { - \bool_gset_false:c{\self.environment_bool}}, + \bool_gset_false:c{\l_self_tl.environment_bool}}, environment .default:n = {true}, label .choice:, label / none .code:n = { - \bool_gset_false:c{\self.labelizable_bool}}, + \bool_gset_false:c{\l_self_tl.labelizable_bool}}, label / accepts .code:n = { - \bool_gset_true:c{\self.labelizable_bool}}, + \bool_gset_true:c{\l_self_tl.labelizable_bool}}, knowledge .choice:, knowledge / none .code:n = { - \bool_gset_false:c{\self.acceptsknowledge_bool} - \bool_gset_false:c{\self.attractsknowledge_bool}}, + \bool_gset_false:c{\l_self_tl.acceptsknowledge_bool} + \bool_gset_false:c{\l_self_tl.attractsknowledge_bool}}, knowledge / accepts .code:n = { - \bool_gset_true:c{\self.acceptsknowledge_bool} - \bool_gset_false:c{\self.attractsknowledge_bool}}, + \bool_gset_true:c{\l_self_tl.acceptsknowledge_bool} + \bool_gset_false:c{\l_self_tl.attractsknowledge_bool}}, knowledge / attracts .code:n = { - \bool_gset_true:c{\self.acceptsknowledge_bool} - \bool_gset_true:c{\self.attractsknowledge_bool}}, + \bool_gset_true:c{\l_self_tl.acceptsknowledge_bool} + \bool_gset_true:c{\l_self_tl.attractsknowledge_bool}}, forces .code:n = - {\tl_gset:cn{\self.forces_tl}{#1}} + {\tl_gset:cn{\l_self_tl.forces_tl}{#1}} } \cs_new:Npn\scope_category_if_exist:nTF#1 {\tl_if_exist:cTF{\scope_tl.category[#1].name_tl}} @@ -1135,7 +1157,8 @@ {\scope_category_if_exist:nTF {#1}{}{\scope_category_create:n{#1}}} \cs_new:Nn\scope_category_create:n - {\tl_gset:cn{\scope_tl.category[#1].name_tl}{#1} + {\tl_new:c{\scope_tl.category[#1].name_tl} + \tl_gset:cn{\scope_tl.category[#1].name_tl}{#1} \seq_new:c{\scope_tl.category[#1].areas_seq}} \cs_new:Nn\scope_category_add_area:nn {\scope_category_ensure:n{#1} @@ -1268,9 +1291,13 @@ \exp_args:Nx\knowledge_push_visible_instance:n{\scope_top_instance_tl} \seq_push:Nx\scope_instances_stack_seq{\scope_top_instance_tl} % + \tl_new:c + {\scope_tl.instance[\scope_top_instance_tl].area_tl} \tl_gset:cx {\scope_tl.instance[\scope_top_instance_tl].area_tl} {\scope_top_area_tl} + \tl_new:c + {\scope_tl.instance[\scope_top_instance_tl].parent_tl} \tl_gset:cx {\scope_tl.instance[\scope_top_instance_tl].parent_tl} {\l_tmpa_tl} @@ -1358,19 +1385,23 @@ { \kl_hide_begin: \scope_get_labelizable_instance:N\l_tmpb_tl \KAuxWriteX*{\exp_not:n{\KAuxScopeLabel}{#1}{\l_tmpb_tl}} - \tl_gset:cx{\scopept_tl.label[#1].instance_tl}{\l_tmpb_tl} + %\tl_new:cx{\scopept_tl.label[#1].instance_tl}{\l_tmpb_tl} \kl_hide_end: \cs_if_exist:NTF\LaTeXlabel\LaTeXlabel\use_none:n{#1}} \let\label\scopeLabel +\cs_new:Npn\knowledge_latex_label:n{ + \cs_if_exist:NTF\LaTeXlabel\LaTeXlabel\label +} \NewKAuxCommand\KAuxScopeNewInstance{mmm} {Package~scope:~Declares~a~new~instance~of~a~scope.} \DeclareKAuxPhaseCommand\KAuxScopeNewInstance{init} - {\tl_gset:cn{\scopept_tl.instance[#2].area_tl}{#1} - \tl_gset:cn{\scopept_tl.instance[#2].parent_tl}{#3}} + {\tl_new:cn{\scopept_tl.instance[#2].area_tl}{#1} + \tl_new:cn{\scopept_tl.instance[#2].parent_tl}{#3}} \NewKAuxCommand\KAuxScopeLabel{mm} {Package~scope:~Links~a~label~to~the~scope~of~its~definition.} \DeclareKAuxPhaseCommand\KAuxScopeLabel{init} - {\tl_gset:cn{\scopept_tl.label[#1].instance_tl}{#2}} + {\tl_if_exist:cTF{\scopept_tl.label[#1].instance_tl}{} + {\tl_new:cn{\scopept_tl.label[#1].instance_tl}{#2}}} \cs_new:Npn\scopept_label_instance_if_exist:nTF#1 {\tl_if_exist:cTF{\scopept_tl.label[#1].instance_tl}} \cs_new:Nn\scopept_label_instance_use:n @@ -1401,8 +1432,7 @@ #2 }} \NewDocumentCommand\ScopeHackEnvironments{} - { %\ScopeActivate - \scope_area_push:n{document} + { \scope_area_push:n{document} \kutils_secure_latex_command:N\begin \global\let\SUPERbegin\begin \global\def\begin##1 @@ -1480,8 +1510,9 @@ {\iow_now:Nn\knowledge_diagnosefile_iow{#1}} \cs_generate_variant:Nn\knowledge_diagnose:n{x,V} +\tl_new:N\knowledge_diagnose_lastline_tl \cs_new:Nn\knowledge_diagnose_reset_line: - {\tl_gset:Nn\knowledge_diagnose_lastline_tl{...}} + {\tl_gset:Nn\knowledge_diagnose_lastline_tl{...}} \knowledge_diagnose_reset_line: \cs_new:Nn\knowledge_diagnose_line: @@ -1493,15 +1524,6 @@ {\tl_gset_eq:NN\knowledge_diagnose_lastline_tl\g_tmpa_tl \knowledge_diagnose:V\g_tmpa_tl}}} -\msg_new:nnn{knowledge}{unknown~knowledge} - {Some~knowledge~are~not~defined.~See~the~'.diagnose'~file~for~more~information.} -\msg_new:nnn{knowledge}{autoref~introduced~twice} - {Some~knowledge~is~introduced~twice.~See~the~'.diagnose'~file~for~more~information.} -\msg_new:nnn{knowledge}{autoref~not~introduced} - {Some~knowledge~is~used~but~not~introduced.~See~the~'.diagnose'~file~for~more~information.} -\msg_new:nnn{knowledge}{scope~unknown} - {Some~label~is~used~but~not~defined.~See~the~'.diagnose'~file~for~more~information.} - \NewDocumentCommand\KnowledgeDiagnoseOutput{}{ \iow_open:Nn\knowledge_diagnosefile_iow{\c_sys_jobname_str.diagnose} % compute first the list of warnings and important information @@ -1535,7 +1557,7 @@ \knowledge_diagnose:n{} \knowledge_diagnose:n{} % - \msg_warning:nn{knowledge}{unknown~knowledge} + \msg_warning:nn{knowledge}{recap~unknown~knowledge} } % \int_compare:nNnT\kl_digest_autoreftwiceintro_int>0{ @@ -1550,7 +1572,7 @@ \knowledge_diagnose:n{} \knowledge_diagnose:n{} % - \msg_warning:nn{knowledge}{autoref~introduced~twice} + \msg_warning:nn{knowledge}{recap~autoref~introduced~twice} } % \int_compare:nNnT\kl_digest_autorefnointro_int>0{ @@ -1565,7 +1587,7 @@ \knowledge_diagnose:n{} \knowledge_diagnose:n{} % - \msg_warning:nn{knowledge}{autoref~not~introduced} + \msg_warning:nn{knowledge}{recap~autoref~not~introduced} } % \iffalse @@ -1578,9 +1600,9 @@ \fi% \iow_close:N\knowledge_diagnosefile_iow } -\tl_set:Nn\knowledge_knowledge_default_namespace_tl {default} +\tl_new:Nn\knowledge_default_namespace_tl {default} \makeatother -\cell_new_type:nnn{knowledge}{nnnn}{KL@#2@#3@\detokenize{#4}_#1} +\cell_new_type:nnn{knowledge}{nnnn}{KL@#2@#3@\tl_to_str:n{#4}_#1} \cell_new_type:nnn{knowledge}{nnn}{\knowledge_id:nnnn{}{#1}{#2}{#3}} \cs_generate_variant:Nn\knowledge_id:nnn{nnV,nVV,nVn,VVV} \cs_generate_variant:Nn\knowledge_at:Nnnn{NnnV} @@ -1596,6 +1618,7 @@ \knowledge_knowledge_if_exist:nnnTF{VVVTF} \NewDocumentCommand\NewKnowledgeParamBool{smm}{ \ktuple_new_bool_index:n{#2} + \bool_new:N#3 \use:c{ktuple_#2_expands_to:TF} {\bool_set_true:N#3}{\bool_set_false:N#3} % @@ -1621,25 +1644,40 @@ ##1 .default:n = true }} } -\NewDocumentCommand\NewKnowledgeParamTl{smm}{ - \ktuple_new_tl_index:n{#2} - \use:c{ktuple_#2_expands_to:n} - {\tl_set:Nn#3{##1}} - % - \keys_define:nn { knowledgenow~directives }{ - #2 .code:n = - { \knowledge_at:c{ktuple_#2_gset:Nn}{##1} }, - #2~X .code:n = - { \knowledge_at:c{ktuple_#2_gset:Nx}{##1} }, - no~#2 .code:n = - { \knowledge_at:c{ktuple_#2_gdel:N} }} - \IfBooleanTF{#1}{\KnowledgeTransferTl{#2}}{} -} +\NewDocumentCommand\NewKnowledgeParamTl{som}{ + %\tl_show:n{#2} + \IfNoValueTF{#2} + { \tl_set:Nn\l_tmpa_tl{#3} + \tl_remove_all:Nn\l_tmpa_tl{~} + \use:x{ + \exp_not:N\NewKnowledgeParamTl + \IfBooleanT{#1}{*} + [\exp_not:c{knowledge_kl_\l_tmpa_tl _tl}] + {#3} + }} + {\cs_if_exist:cTF{ktuple_#3_expands_to:n} + {} + {\ktuple_new_tl_index:n{#3}} + \tl_if_exist:NTF#2{} + {\tl_new:N#2} + \use:c{ktuple_#3_expands_to:n} + {\tl_set:Nn#2{##1}} + % + \keys_define:nn { knowledgenow~directives }{ + #3 .code:n = + { \knowledge_at:c{ktuple_#3_gset:Nn}{##1} }, + #3~X .code:n = + { \knowledge_at:c{ktuple_#3_gset:Nx}{##1} }, + no~#3 .code:n = + { \knowledge_at:c{ktuple_#3_gdel:N} }} + \IfBooleanTF{#1}{\KnowledgeTransferTl{#3}}{} +}} \NewDocumentCommand\KnowledgeTransferTl{m} {\keys_define:nn { knowledge~directives } {#1 .code:n = {\knowledge_delay_directive:n{#1={##1}}}}} \NewDocumentCommand\NewKnowledgeParamCode{mm}{ \ktuple_new_tl_index:n{#1} + \tl_new:N#2 \use:c{ktuple_#1_expands_to:n} {\tl_set:Nn#2{##1}} % @@ -1665,8 +1703,6 @@ \seq_new:N\knowledge_visible_instances_seq \cs_new:Nn\knowledge_push_visible_instance:n {\seq_gpush:Nn\knowledge_visible_instances_seq{#1}} -\cs_new:Nn\knowledge_lpush_visible_instance:n - {\seq_push:Nn\knowledge_visible_instances_seq{#1}} \cs_new:Npn\knowledge_pop_visible_instance: {\seq_gpop:NN\knowledge_visible_instances_seq\g_tmpa_tl} \cs_new:Nn\knowledge_pop_visible_instances_to:n @@ -1688,6 +1724,7 @@ {\msg_warning:nnnn{scope}{unknown~label}{#1}{\knowledgeimport}} \kl_hide_end: } +%% \keys_define:nn { knowledge~directives } { namespace .code:n = { \tl_set:Nn\knowledge_knowledge_namespace_tl{#1} }, force .choice:, @@ -1720,9 +1757,8 @@ {\knowledge_set_now:nnnn{#1}{#2}{#3}{#4}} \NewKAuxCommand\KAuxExport{mmmm} {Package~knowledge:~undefined~so~far.} -\cs_new:Nn\knowledge_set_now:nnnn +\cs_new:Nn\knowledge_new_now:nnnn {\knowledge_sets_to:nnn{#1}{#2}{#3} - \tl_set:Nn\knowledge_set_now_k_tl{{#1}{#2}{#3}} \knowledge_at:N\ktuple_if_exist:NTF {\bool_if:NTF\knowledge_knowledgestyle_bool {\knowledge_at:N\ktuple_gclear:N} @@ -1730,20 +1766,30 @@ {\knowledge_at:N\ktuple_new:N} \keys_set:nn { knowledgenow~directives } { #4 } } +\cs_new:Nn\knowledge_set_now:nnnn + {\knowledge_sets_to:nnn{#1}{#2}{#3} + \knowledge_at:N\ktuple_if_exist:NTF + {\bool_if:NTF\knowledge_knowledgestyle_bool + {\knowledge_at:N\ktuple_gclear:N} + {}} + {\knowledge_at:N\ktuple_new:N} + \keys_set:nn { knowledgenow~directives } { #4 } +} +\cs_generate_variant:Nn\knowledge_new_now:nnnn{nnVn} \cs_generate_variant:Nn\knowledge_set_now:nnnn{nnVn} \NewDocumentCommand\knowledge{} - {\KAuxWriteLocation\knowledge_II} -\NewDocumentCommand\knowledge_II{m >{\SplitList{|}}o m } + {\KAuxWriteLocation\__knowledge_knowledge} +\NewDocumentCommand\__knowledge_knowledge{m >{\SplitList{|}}o m } { \kl_hide_begin: \group_begin: \tl_set_eq:NN\knowledge_namespace_tl - \knowledge_knowledge_default_namespace_tl + \knowledge_default_namespace_tl % \bool_gset_false:N\knowledge_knowledge_is_synonym_bool % \use:x{ \exp_not:n{\knowledge_knowledge_process:nn{#1}} - {\exp_not:V\kl_knowledgedefault_tl,\exp_not:n{#3}}} + {\exp_not:V\knowledge_knowledgedefault_tl,\exp_not:n{#3}}} % \bool_if:NF\knowledge_knowledge_is_synonym_bool {\tl_gset:Nn\knowledge_knowledge_synonym_tl{#1} @@ -1759,12 +1805,6 @@ \group_end: \kl_hide_end: } -\bool_new:N\knowledge_knowledge_now_bool -\bool_new:N\knowledge_knowledge_is_synonym_bool -\tl_new:N\knowledge_knowledge_synonym_tl -\tl_new:N\knowledge_knowledge_synonyminstance_tl -\tl_gset:Nn\knowledge_knowledge_synonyminstance_tl{} -\bool_new:N\knowledge_knowledgestyle_bool \NewDocumentCommand\knowledgestyle{ s m m } { \kl_hide_begin: \group_begin: @@ -1779,19 +1819,35 @@ \group_end: \kl_hide_end: } +\bool_new:N\knowledge_knowledgestyle_bool +\bool_new:N\knowledge_knowledgestyle_override_bool +\bool_new:N\knowledge_knowledge_now_bool +\bool_new:N\knowledge_knowledge_alsonow_bool +\bool_new:N\knowledge_knowledge_is_synonym_bool +\bool_new:N\knowledge_knowledge_autoref_bool +\tl_clear_new:N\knowledge_knowledge_synonym_tl +\tl_clear_new:N\knowledge_knowledge_synonyminstance_tl +\tl_clear_new:N\knowledge_knowledge_clear_bool +\tl_clear_new:N\knowledge_knowledge_force_bool +\tl_clear_new:N\knowledge_knowledge_export_bool +\tl_clear_new:N\knowledge_knowledge_key_tl +\tl_clear_new:N\knowledge_knowledge_namespace_tl +\tl_clear_new:N\knowledge_knowledge_instance_tl +\tl_clear_new:N\knowledge_knowledge_directives_tl \cs_new:Nn\knowledge_knowledge_process:nn -{ \bool_set_false:N\knowledge_knowledge_now_bool - \bool_set_false:N\knowledge_knowledge_clear_bool +{ \bool_set_false:N\knowledge_knowledge_clear_bool \bool_set_false:N\knowledge_knowledge_force_bool \bool_set_false:N\knowledge_knowledge_export_bool + \bool_set_false:N\knowledge_knowledge_autoref_bool + \bool_set_false:N\knowledge_knowledge_now_bool + \bool_set_false:N\knowledge_knowledge_alsonow_bool % - % - \tl_set:Nn\knowledge_key_tl{#1} + \tl_set:Nn\knowledge_knowledge_key_tl{#1} % \tl_set_eq:NN\knowledge_knowledge_namespace_tl\knowledge_namespace_tl \scope_get_attractive_instance:N\knowledge_knowledge_instance_tl % - \tl_set:Nn\knowledge_directives_tl{} + \tl_set:Nn\knowledge_knowledge_directives_tl{} % \keys_set:nn { knowledge~directives } { #2 } % @@ -1799,20 +1855,37 @@ {\bool_set_true:N\knowledge_knowledge_now_bool} {} % - \bool_if:NTF\knowledge_knowledge_now_bool + \bool_if:nTF{\knowledge_knowledge_now_bool} + {\use:x{ + \exp_not:N\knowledge_new_now:nnnn + {\knowledge_knowledge_namespace_tl} + {\knowledge_knowledge_instance_tl} + {\exp_not:V\knowledge_knowledge_key_tl} + {\exp_not:V\knowledge_knowledge_directives_tl}} + }{} + \bool_if:nTF{\knowledge_knowledge_alsonow_bool} {\use:x{ \exp_not:N\knowledge_set_now:nnnn {\knowledge_knowledge_namespace_tl} {\knowledge_knowledge_instance_tl} - {\exp_not:V\knowledge_key_tl} - {\exp_not:V\knowledge_directives_tl}} - }{ - \KAuxWriteX*{ + {\exp_not:V\knowledge_knowledge_key_tl} + {\exp_not:V\knowledge_knowledge_directives_tl}} + }{} + \bool_if:NTF\knowledge_knowledge_now_bool + {} + { \KAuxWriteX*{ \exp_not:N\KAuxKnowledge {\knowledge_knowledge_namespace_tl} {\knowledge_knowledge_instance_tl} - {\exp_not:V\knowledge_key_tl} - {\exp_not:V\knowledge_directives_tl}} + {\exp_not:V\knowledge_knowledge_key_tl} + {\exp_not:V\knowledge_knowledge_directives_tl}} + } + \bool_if:NT\knowledge_knowledge_autoref_bool + {\KAuxWriteX* + {\exp_not:N\KAuxAutoref + {\knowledge_knowledge_namespace_tl} + {\knowledge_knowledge_instance_tl} + {\exp_not:V\knowledge_knowledge_key_tl}} } % \bool_if:NT\knowledge_knowledge_export_bool @@ -1820,14 +1893,14 @@ \exp_not:N\KAuxExport {\knowledge_knowledge_namespace_tl} {\knowledge_knowledge_instance_tl} - {\exp_not:V\knowledge_key_tl} - {\exp_not:V\knowledge_directives_tl}} + {\exp_not:V\knowledge_knowledge_key_tl} + {\exp_not:V\knowledge_knowledge_directives_tl}} } } \cs_new:Nn\knowledge_delay_directive:n - {\tl_if_empty:NTF\knowledge_directives_tl - {\tl_set:Nn\knowledge_directives_tl{#1}} - {\tl_put_right:Nn\knowledge_directives_tl{,#1}}} + {\tl_if_empty:NTF\knowledge_knowledge_directives_tl + {\tl_set:Nn\knowledge_knowledge_directives_tl{#1}} + {\tl_put_right:Nn\knowledge_knowledge_directives_tl{,#1}}} \cs_generate_variant:Nn\knowledge_delay_directive:n{x} \NewDocumentCommand\knowledgedirective{mom}{ \kl_hide_begin: @@ -1840,15 +1913,15 @@ {\keys_define:nn{ knowledge~directives }{#1 .default:n = {#2}}} \kl_hide_end: } -\tl_new:N\kl_knowledgedefault_tl +\tl_new:N\knowledge_knowledgedefault_tl \NewDocumentCommand\knowledgedefault{sm}{ \kl_hide_begin: \IfBooleanTF{#1} - {\tl_put_right:Nn\kl_knowledgedefault_tl{,#2}} - {\tl_set:Nn\kl_knowledgedefault_tl{#2}} + {\tl_put_right:Nn\knowledge_knowledgedefault_tl{,#2}} + {\tl_set:Nn\knowledge_knowledgedefault_tl{#2}} \kl_hide_end: } -\NewDocumentCommand\kl{d() o d() m}{ +\NewDocumentCommand\__kl:w{d() o d() m}{ \IfNoValueTF{#1} {\IfNoValueTF{#3} {\IfNoValueTF{#2} @@ -1861,64 +1934,84 @@ {\knowledge_klTKS:nnn{#4}{#4}{#1}} {\knowledge_klTKS:nnn{#4}{#2}{#1}}} } +\tl_clear_new:N\knowledge_kl_text_tl +\tl_clear_new:N\knowledge_kl_base_key_tl +\tl_clear_new:N\knowledge_kl_key_tl +\tl_clear_new:N\knowledge_kl_autoref_tl +\tl_clear_new:N\knowledge_kl_resourcetoken_tl +\tl_clear_new:N\knowledge_kl_resourcearguments_tl +\tl_clear_new:N\knowledge_kl_display_process_tl +\tl_clear_new:N\knowledge_kl_display_sequence_tl +\tl_new:N\knowledge_namespace_tl +\tl_new:Nn\knowledge_display_code_tl{INTERNAL~ERROR~DISPLAY~CODE} \NewDocumentCommand\klTKS{}{\knowledge_klTKS:nnn} \cs_new:Nn\knowledge_klTKS:nnn{ \group_begin: - \knowledge_kl_init: - \cs_gset_eq:NN\knowledge_kl_init:\knowledge_defaultkl_init: + % \tl_set:Nn\knowledge_kl_linkscope_tl{#3} - \tl_set:Nn\knowledge_kl_linkinstance_tl{} + \tl_set:Nn\knowledge_kl_instance_tl{} \tl_set:Nn\knowledge_kl_text_tl{#1} \tl_set:Nn\knowledge_kl_base_key_tl{#2} \tl_set_eq:NN\knowledge_kl_key_tl\knowledge_kl_base_key_tl \int_set_eq:NN\knowledge_kl_recursion_int\knowledge_kl_max_recursion_int + % + \tl_if_exist:cTF + {knowledge_kl_\tl_to_str:V\knowledge_kl_modifiers_tl _init_tl} + {\use:c{knowledge_kl_\tl_to_str:V\knowledge_kl_modifiers_tl _init_tl}} + {\knowledge_error:x + {Unknown~variant~modifier~sequence~`\exp_not:V\knowledge_kl_modifiers_tl'.}} + % + \knowledge_kl_modifiers_reset: + % + \knowledge_kl_use_styles:x{\knowledge_kl_default_style_tl} + % \knowledge_kl_find: \group_end: - \knowledge_display_sequence: + \knowledge_display_code_tl } \int_const:Nn\knowledge_kl_max_recursion_int{40} \int_new:N\knowledge_kl_recursion_int \cs_set:Nn\knowledge_kl_find:{ - \tl_if_empty:NTF\knowledge_kl_linkinstance_tl + \knowledge_kl_find_recursion_exceeded:TF + {\knowledge_kl_error_recursion:} + {\tl_if_empty:NTF\knowledge_kl_instance_tl {\tl_if_empty:NTF\knowledge_kl_linkscope_tl \knowledge_kl_find_withoutscope: \knowledge_kl_find_withscope:} - \knowledge_kl_find_withinstance: + \knowledge_kl_find_withinstance:} +} +\cs_set:Npn\knowledge_kl_find_recursion_exceeded:TF{ + \int_decr:N\knowledge_kl_recursion_int + \int_compare:nNnTF\knowledge_kl_recursion_int=0 } \cs_new:Nn\knowledge_kl_find_withinstance:{ \knowledge_knowledge_if_exist:VVVTF \knowledge_kl_namespace_tl - \knowledge_kl_linkinstance_tl + \knowledge_kl_instance_tl \knowledge_kl_key_tl {\knowledge_kl_exec:nnV \knowledge_kl_namespace_tl - \knowledge_kl_linkinstance_tl + \knowledge_kl_instance_tl \knowledge_kl_key_tl} - { \knowledge_kl_error_unknown_in_scope: } + { \knowledge_kl_error_unknown_in_scope_firsttime: } } \cs_new:Nn\knowledge_kl_find_withscope:{ \exp_args:NV \scopept_label_instance_if_exist:nTF\knowledge_kl_linkscope_tl - { \tl_set:Nx\knowledge_kl_linkinstance_tl + { \tl_set:Nx\knowledge_kl_instance_tl {\scopept_label_instance_use:n{\knowledge_kl_linkscope_tl}} \knowledge_kl_find_withinstance: } { \knowledge_kl_error_label_unknown: } } \cs_new:Nn\knowledge_kl_find_withoutscope:{ - \int_decr:N\knowledge_kl_recursion_int - \tl_clear:N\knowledge_kl_link_tl - \tl_clear:N\knowledge_kl_style_tl - \tl_clear:N\knowledge_kl_intro_style_tl - \int_compare:nNnTF\knowledge_kl_recursion_int=0 - \knowledge_kl_error_recursion: - {\knowledge_kl_find_in_scope:VNTF - \knowledge_kl_key_tl\knowledge_kl_linkinstance_tl + \knowledge_kl_find_in_scope:VNTF + \knowledge_kl_key_tl + \knowledge_kl_instance_tl {\knowledge_kl_exec:nnV - \knowledge_kl_namespace_tl - \knowledge_kl_linkinstance_tl - \knowledge_kl_key_tl} - {\knowledge_kl_error_unknown:} - } + \knowledge_kl_namespace_tl + \knowledge_kl_instance_tl + \knowledge_kl_key_tl} + {\knowledge_kl_error_unknown_firsttime:} } \cs_new:Npn\knowledge_kl_find_in_scope:nNTF{ \exp_args:NV\knowledge_kl_find_in_scope:nnNTF @@ -1946,245 +2039,317 @@ \cs_generate_variant:Nn\knowledge_kl_find_in_scope:nnNTF{nVNTF} \cs_generate_variant:Nn\knowledge_kl_find_in_scope:nNTF{VNTF} \cs_new:Nn\knowledge_kl_exec:nnn{ - \exp_args:NNc\tl_set:Nn\knowledge_kl_resource_tl + \tl_set:Nx\knowledge_kl_resourcearguments_tl + {{#1}{#2}{\exp_not:n{#3}}} + \exp_args:NNc\tl_set:Nn\knowledge_kl_resourcetoken_tl {\knowledge_id:nnn{#1}{#2}{#3}} % - \tl_set:Nn\knowledge_kl_link_tl{} - \tl_set:Nn\knowledge_kl_linkscope_tl{} - \tl_set:Nn\knowledge_kl_linkinstance_tl{} - % - \knowledge_kl_resource_tl - % - \tl_if_empty:xTF\knowledge_kl_used_style_tl - {} - {\knowledge_kl_use_style:x - {\knowledge_kl_used_style_tl}} - % - \expandafter\knowledge_kl_update:N\knowledge_kl_resource_tl - % - %\knowledge_kl_exec_to_kaux: + \tl_clear:N\knowledge_kl_link_tl + \tl_clear:N\knowledge_kl_linkscope_tl + \tl_clear:N\knowledge_kl_instance_tl + \tl_map_function:NN + \knowledge_kl_styledirectives_tl + \tl_clear:N % - \tl_if_exist_ne:NTF\knowledge_kl_linkscope_tl{ - \tl_if_exist_ne:NTF\knowledge_kl_link_tl{}{ - \tl_set_eq:NN\knowledge_kl_link_tl - \knowledge_kl_key_tl - }}{} + \knowledge_kl_resourcetoken_tl % - \tl_if_exist_ne:NTF\knowledge_kl_link_tl{ - \tl_set_eq:NN - \knowledge_kl_key_tl - \knowledge_kl_link_tl - \knowledge_kl_find: - }{ - \knowledge_kl_display_code:} + \bool_if:NTF\kl_unknown_knowledge_bool + {\knowledge_kl_error_unknown:} + {\tl_map_function:NN + \knowledge_kl_styledirectives_tl + \knowledge_kl_use_styles:x + % + \tl_if_exist_ne:NTF\knowledge_kl_linkscope_tl{ + \tl_if_exist_ne:NTF\knowledge_kl_link_tl{}{ + \tl_set_eq:NN\knowledge_kl_link_tl + \knowledge_kl_key_tl + }}{} + % + \tl_if_exist_ne:NTF\knowledge_kl_link_tl + { \tl_set_eq:NN + \knowledge_kl_key_tl + \knowledge_kl_link_tl + \knowledge_kl_find:} + \knowledge_kl_compute_code: + } } \cs_generate_variant:Nn\knowledge_kl_exec:nnn{nnV} +\cs_new:Nn\knowledge_kl_use_styles:n + {\clist_map_function:nN{#1}\knowledge_kl_use_style:n} +\cs_generate_variant:Nn\knowledge_kl_use_styles:n {x} \cs_new:Nn\knowledge_kl_use_style:n{ - \knowledge_kl_find_in_scope:nnNTF + \tl_if_empty:nTF{#1}{} + {\knowledge_kl_find_in_scope:nnNTF {style} {#1} \l_tmpa_tl {\use:c{\knowledge_id:nVn{style}\l_tmpa_tl{#1}}} - {\knowledge_error:n{Unknown~style~`#1'}} + {\knowledge_error:n{Unknown~style~`#1'}}} +} +\cs_new:Nn\knowledge_usestyle:nn{ + \group_begin: + \tl_set:Nn\knowledge_kl_forcedtext_tl{#2} + \knowledge_kl_use_styles:x{#1} + \knowledge_kl_compute_code: + \group_end: + \knowledge_display_code_tl } -\cs_generate_variant:Nn\knowledge_kl_use_style:n {x} -\NewKAuxCommand\KAuxErrorKnowledgeUnknown{mmmm} +\NewDocumentCommand\knowledgeusestyle{mm}{\knowledge_usestyle:nn{#1}{#2}} +\NewKAuxCommand\KAuxErrorKnowledgeRecursive{mmmm} + {Package~'knowledge:~A~knowledge~has~recursive~definition.~ + {namespace}{scope}{undefined~knowledge}{base~knowledge}} + {} +\cs_new:Nn\knowledge_kl_error_recursion: { + \msg_error:nnxxx{ knowledge }{ knowledge~recursion } + {\exp_not:V\knowledge_kl_base_key_tl} + {\exp_not:V\knowledge_kl_namespace_tl} + {\exp_not:V\knowledge_kl_key_tl} + \knowledge_kl_error_display:n{ recursive~knowledge } +} +\NewKAuxCommand\KAuxErrorKnowledgeUnknown{mmmmm} {Package~'knowledge:~A~knowledge~is~not~defined.~ - {namespace}{scope/empty}{undefined~knowledge}{base~knowledge}} + {namespace}{scope/empty}{undefined~knowledge}{base~knowledge}{command}} {} \NewKAuxCommand\KAuxErrorLabelUnknown{m} {Package~'knowledge:~A~label~is~not~defined.~ {label}} {} \DeclareKAuxPhaseCommand\KAuxErrorKnowledgeUnknown{diagnose-unknown-suggest} - {\knowledge_diagnose_line: - \tl_if_empty:nTF{#2} - {\knowledge_diagnose:n{\knowledge{#3}{}}} - {\knowledge_diagnose:n{\knowledge{#3}{scope={#2}}}} - } -\cs_new:Nn\knowledge_kl_error_unknown: - {\KAuxWriteX{ - \KAuxErrorKnowledgeUnknown - {\knowledge_kl_namespace_tl} - {} - {\exp_args:NV\detokenize\knowledge_kl_key_tl} - {\exp_args:NV\detokenize\knowledge_kl_base_key_tl} - } - \IfKnowledgePaperModeF{ +{ \knowledge_diagnose_line: + \tl_set_eq:Nc\l_tmpa_tl{knowledge_kl_\cs_to_str:N#5_suggestion_tl} + \tl_if_empty:nTF{#2}{} + {\tl_if_empty:NTF\l_tmpa_tl{} + {\tl_put_right:Nn\l_tmpa_tl{,}} + \tl_put_right:Nn\l_tmpa_tl{scope={#2}}} + \knowledge_diagnose:x + {\exp_not:n{\knowledge{#3}}{\exp_not:V\l_tmpa_tl}} +} +\cs_new:Nn\knowledge_kl_error_unknown_firsttime: + {\bool_if:cTF{\knowledge_variant_var:n{unknownwarning_bool}} + {\IfKnowledgePaperModeF{ \msg_warning:nnxxx{ knowledge }{ knowledge~unknown } {\exp_not:V\knowledge_kl_key_tl} {\exp_not:V\knowledge_kl_namespace_tl} {\seq_use:Nn\knowledge_visible_instances_seq{~|~}}} - \knowledge_kl_use_style:n{unknown} - \knowledge_set_now:nnVn - {default}{base} - \knowledge_kl_key_tl - {style={unknown}} - \knowledge_kl_display_code: -} -\cs_new:Nn\knowledge_kl_error_unknown_in_scope: - {\KAuxWriteX{ + }{} + \bool_if:cTF{\knowledge_variant_var:n{unknowndiagnose_bool}} + {\KAuxWriteX{ \KAuxErrorKnowledgeUnknown {\knowledge_kl_namespace_tl} - {\knowledge_kl_linkscope_tl} - {\exp_args:NV\detokenize\knowledge_kl_key_tl} - {\exp_args:NV\detokenize\knowledge_kl_base_key_tl} - } - \IfKnowledgePaperModeF{ + {} + {\tl_to_str:V\knowledge_kl_key_tl} + {\tl_to_str:V\knowledge_kl_base_key_tl} + {\exp_not:V\knowledge_kl_command_tl} + }}{} + \use:x{\exp_not:N\knowledge_set_now:nnnn + {\knowledge_kl_namespace_tl}{base} + {\exp_not:V\knowledge_kl_key_tl} + {UnKnoWn~KNowLedGE}} + \tl_gset:Nx\knowledge_display_code_tl + {\exp_not:N\knowledge_usestyle:nn + {\use:c{\knowledge_variant_var:n{unknown_style_tl}}} + {\exp_not:V\knowledge_kl_text_tl}} +} +\cs_new:Nn\knowledge_kl_error_unknown:{ + \tl_gset:Nx\knowledge_display_code_tl + {\exp_not:N\knowledge_usestyle:nn + {\use:c{\knowledge_variant_var:n{unknown_style_cont_tl}}} + {\exp_not:V\knowledge_kl_text_tl}} +} +\cs_new:Nn\knowledge_kl_error_unknown_in_scope_firsttime: + {\bool_if:cTF{\knowledge_variant_var:n{unknownwarning_bool}} + {\IfKnowledgePaperModeF{ \msg_warning:nnxxx{ knowledge }{ knowledge~unknown~in~scope } {\exp_not:V\knowledge_kl_key_tl} {\exp_not:V\knowledge_kl_namespace_tl} - {\knowledge_kl_linkscope_tl}} - \knowledge_kl_use_style:n{unknown} - \knowledge_set_now:nnVn - {default}{base} - \knowledge_kl_key_tl - {style={unknown}} - \knowledge_kl_display_code: + {\knowledge_kl_linkscope_tl}}}{} + \bool_if:cTF{\knowledge_variant_var:n{unknowndiagnose_bool}} + {\KAuxWriteX{ + \KAuxErrorKnowledgeUnknown + {\knowledge_kl_namespace_tl} + {\knowledge_kl_linkscope_tl} + {\tl_to_str:V\knowledge_kl_key_tl} + {\tl_to_str:V\knowledge_kl_base_key_tl} + {\exp_not:V\knowledge_kl_command_tl} + }}{} + \use:x{\exp_not:N\knowledge_set_now:nnnn + {\knowledge_kl_namespace_tl} + {\knowledge_kl_linkscope_tl} + {\exp_not:V\knowledge_kl_key_tl} + {UnKnoWn~KNowLedGE}} + \tl_gset:Nx\knowledge_display_code_tl + {\exp_not:N\knowledge_usestyle:nn + {\use:c{\knowledge_variant_var:n{unknown_style_tl}}} + {\exp_not:V\knowledge_kl_text_tl}} } \cs_new:Nn\knowledge_kl_error_label_unknown:{ \KAuxWriteX{ \KAuxErrorKnowledgeUnknown {\knowledge_kl_namespace_tl} {\knowledge_kl_linkscope_tl} - {\exp_args:NV\detokenize\knowledge_kl_key_tl} - {\exp_args:NV\detokenize\knowledge_kl_base_key_tl} + {\tl_to_str:V\knowledge_kl_key_tl} + {\tl_to_str:V\knowledge_kl_base_key_tl} + {\exp_not:V\knowledge_kl_command_tl} } - \knowledge_kl_use_style:n{unknown} - \IfKnowledgePaperModeF{ + % + \IfKnowledgePaperModeF{ \msg_warning:nnxx{ knowledge }{ knowledge~unknown~label } - {\exp_not:V\knowledge_kl_key_tl} - {\knowledge_kl_linkscope_tl}} - \knowledge_kl_display_code: + {\exp_not:V\knowledge_kl_key_tl} + {\knowledge_kl_linkscope_tl}} + % + \tl_gset:Nx\knowledge_display_code_tl + {\exp_not:N\knowledge_usestyle:nn + {\use:c{\knowledge_variant_var:n{unknown_style_tl}}} + {\exp_not:V\knowledge_kl_text_tl}} } \cs_new:Nn\knowledge_kl_error_display:n - {\textcolor{orange}{\exp_args:NV\detokenize\knowledge_kl_text_tl}} -\NewDocumentCommand\intro{s}{ - \kl_activate_intro:\IfBooleanF{#1}\kl} -\NewDocumentCommand\reintro{s}{ - \kl_activate_reintro:\IfBooleanF{#1}\kl} - -\cs_new:Nn\kl_activate_intro: - {\cs_gset_eq:NN\knowledge_kl_init:\knowledge_intro_init:} -\cs_new:Nn\kl_activate_reintro: - {\cs_gset_eq:NN\knowledge_kl_init:\knowledge_reintro_init:} -\NewDocumentCommand\phantomintro{m}{ - \cs_gset_eq:NN\knowledge_kl_init:\knowledge_phantomintro_init: - \kl[{#1}]{} + {\textcolor{orange}{\tl_to_str:V\knowledge_kl_text_tl}} +\tl_clear_new:N\knowledge_kl_modifiers_tl +\cs_new:Nn\knowledge_kl_modifiers_reset: + {\tl_gclear:N\knowledge_kl_modifiers_tl} +\cs_new:Nn\knowledge_kl_modifiers_add:N + {\tl_gput_right:Nn\knowledge_kl_modifiers_tl{#1*} + \knowledge_kl_modifiers_reduce:} +\NewDocumentCommand\knowledgevariantmodifier{mm} + {\tl_new:cn + {KLSV_\tl_to_str:n{#1*} _tl} + {#2*}} +\cs_new:Nn\knowledge_kl_modifiers_reduce: + {\tl_if_exist:cTF + {KLSV_\tl_to_str:V\knowledge_kl_modifiers_tl _tl} + {\tl_gset_eq:Nc\knowledge_kl_modifiers_tl + {KLSV_\tl_to_str:V\knowledge_kl_modifiers_tl _tl}} + {}} +\cs_new:Nn\knowledge_variant_var:n + {knowledge_kl_\expandafter\cs_to_str:N\knowledge_kl_command_tl _#1} +\NewDocumentCommand\knowledgenewvariant{mm}{ + \exp_args:Nc\tl_new:Nn + {knowledge_kl_\cs_to_str:N#1_command_tl} + {#1} + % + % + \NewDocumentCommand#1{s} + {\knowledge_kl_modifiers_add:N#1 + \IfBooleanF{##1}{\__kl:w}} + % + \tl_new_eq:cN + {knowledge_kl_\cs_to_str:N#1_namespace_tl} + \knowledge_default_namespace_tl + \tl_new:cx{knowledge_kl_\cs_to_str:N#1_suggestion_tl}{} + \bool_new_true:c{knowledge_kl_\cs_to_str:N#1_unknownwarning_bool} + \bool_new_true:c{knowledge_kl_\cs_to_str:N#1_unknowndiagnose_bool} + \tl_new:cn{knowledge_kl_\cs_to_str:N#1_default_style_tl}{} + \tl_new:cn{knowledge_kl_\cs_to_str:N#1_unknown_style_tl}{} + \tl_new:cn{knowledge_kl_\cs_to_str:N#1_unknown_style_cont_tl}{} + \tl_new:cx{knowledge_kl_\cs_to_str:N#1_autoknowledge_tl}{} + \tl_new:cx{knowledge_kl_\cs_to_str:N#1_styledirectives_tl}{} + % + \bool_if:NT\knowledge_hyperref_active_bool + {\exp_args:Nx\pdfstringdefDisableCommands + {\exp_not:N\def\exp_not:N#1 + {\exp_not:N\knowledge_variant_arg_absorber:Nw + \exp_not:c{\cs_to_str:N#1_PDFstring}}}} + \exp_args:Nc\newcommand{\cs_to_str:N#1_PDFstring}[3]{##1} + % + \tl_new:cx{knowledge_kl_\tl_to_str:n{#1*} _init_tl} + { + \exp_not:n{\tl_set_eq:NN\knowledge_kl_command_tl} + \exp_not:c{knowledge_kl_\cs_to_str:N#1_command_tl} + \exp_not:n{\tl_set_eq:NN\knowledge_kl_namespace_tl} + \exp_not:c{knowledge_kl_\cs_to_str:N#1_namespace_tl} + \exp_not:n{\tl_set_eq:NN\knowledge_kl_default_style_tl} + \exp_not:c{knowledge_kl_\cs_to_str:N#1_default_style_tl} + \exp_not:n{\tl_set_eq:NN\knowledge_kl_unknown_style_tl} + \exp_not:c{knowledge_kl_\cs_to_str:N#1_unknown_style_tl} + \exp_not:n{\tl_set_eq:NN\knowledge_kl_unknown_style_cont_tl} + \exp_not:c{knowledge_kl_\cs_to_str:N#1_unknown_style_cont_tl} + \exp_not:n{\tl_set_eq:NN\knowledge_kl_styledirectives_tl} + \exp_not:c{knowledge_kl_\cs_to_str:N#1 _styledirectives_tl} + \exp_not:c{knowledge_kl_\cs_to_str:N#1 _autoknowledge_tl} + } + % + %\bool_if:NT\knowledge_hyperref_active_bool + % {\pdfstringdefDisableCommands{\let#1\knowledge_fake_kl:n}} + % + \knowledgesetvariant#1{#2} +} +\DeclareExpandableDocumentCommand\knowledge_variant_arg_absorber:Nw + {m d() o d() m} + {\IfNoValueTF{#2} + {#1{#5}{#2}{#3}} + {#1{#5}{#2}{#1}}} + +\tl_new:N\knowledge_variant_command_tl +\tl_new:N\knowledge_variant_key_tl +\NewDocumentCommand\knowledgesetvariant{mm}{ + \tl_set:Nn\knowledge_variant_command_tl{#1} + \tl_set:Nx\knowledge_variant_key_tl{\cs_to_str:N#1} + % + \keys_set:nn{ knowledge~configure~variant }{#2} +} +\keys_define:nn{ knowledge~configure~variant }{ + namespace .code:n = + {\tl_set:cn{knowledge_kl_\knowledge_variant_key_tl _namespace_tl}{#1}}, + % + unknown~warning .choices:nn = {true,false} + {\bool_set_text:cn{knowledge_kl_\knowledge_variant_key_tl _unknownwarning_bool}{#1}}, + % + unknown~diagnose .choices:nn = {true,false} + {\tl_set:cn{knowledge_kl_\knowledge_variant_key_tl _unknowndiagnose_bool}{#1}}, + % + default~style .code:n = + {\tl_set:cn{knowledge_kl_\knowledge_variant_key_tl _default_style_tl}{#1}}, + unknown~style .code:n = + {\tl_set:cn{knowledge_kl_\knowledge_variant_key_tl _unknown_style_tl}{#1}}, + unknown~style~cont .code:n = + {\tl_set:cn{knowledge_kl_\knowledge_variant_key_tl _unknown_style_cont_tl}{#1}}, + % + auto~knowledge .code:n = + { \tl_set:cx{knowledge_kl_\knowledge_variant_key_tl _autoknowledge_tl} + {\exp_not:N\exp_args:NV + \exp_not:N\knowledge + {\exp_not:N\knowledge_kl_key_tl} + {namespace=\exp_not:N\knowledge_kl_namespace_tl,\exp_not:n{#1}}}}, + % + style~directive .code:n = { + \tl_clear:c{knowledge_kl_\knowledge_variant_key_tl _styledirectives_tl} + \clist_map_inline:nn{#1} + {\use:x{\NewKnowledgeParamTl* + [\exp_not:c{knowledge_kl_##1_tl}]} + {##1} + \tl_put_right:cx{knowledge_kl_\knowledge_variant_key_tl _styledirectives_tl} + {\exp_not:c{knowledge_kl_##1_tl}}} + }, + % + suggestion .code:n = + {\tl_set:cn{knowledge_kl_\knowledge_variant_key_tl _suggestion_tl}{#1}}, + % + PDF~string .code:n = + {\exp_args:Nc\renewcommand{\knowledge_variant_key_tl _PDFstring}[3]{#1}} } \let\nointro\phantomintro -\cs_new:Nn\knowledge_intro_init: - {\tl_set:Nn - \knowledge_kl_command_tl{intro} - \cs_set_eq:NN - \knowledge_kl_update:N - \knowledge_intro_update:N - \cs_set_eq:NN - \knowledge_kl_display_code_preprocess: - \knowledge_intro_display_code_preprocess: - \tl_set:Nn - \knowledge_kl_used_style_tl - {\knowledge_kl_intro_style_tl} - } -\cs_new:Nn\knowledge_phantomintro_init: - {\tl_set:Nn - \knowledge_kl_command_tl{phantomintro} - \cs_set_eq:NN - \knowledge_kl_update:N - \knowledge_intro_update:N - \cs_set_eq:NN - \knowledge_kl_display_code_preprocess: - \knowledge_intro_display_code_preprocess: - \tl_set:Nn - \knowledge_kl_used_style_tl - {\knowledge_kl_intro_style_tl} - \cs_set_eq:NN - \knowledge_kl_display_code: - \knowledge_phantomintro_display_code: - } -\cs_new:Nn\knowledge_reintro_init: - {\tl_set:Nn - \knowledge_kl_command_tl - {reintro} - \tl_set:Nn - \knowledge_kl_used_style_tl - {\knowledge_kl_intro_style_tl} - } -\cs_new:Nn\knowledge_intro_update:N - {\ktuple_countintro_gincr:N#1} - -\tl_set:Nn\knowledge_kl_intro_style_tl - {intro} -\cs_new:Npn\knowledge_intro_display_code_preprocess: - {\tl_if_exist_ne:NTF\knowledge_kl_resource_tl +\tl_new:Nn\knowledge_kl_target_preprocess_tl + {\tl_if_exist_ne:NTF\knowledge_kl_resourcetoken_tl {\expandafter\ktuple_countintro_get_int:NN - \knowledge_kl_resource_tl\l_tmpa_int + \knowledge_kl_resourcetoken_tl\l_tmpa_int \tl_set:Nx\l_tmpa_tl - {\int_compare:nNnTF\l_tmpa_int=1{}{\int_to_alph:n\l_tmpa_int}}} + {\int_compare:nNnTF\l_tmpa_int=1{}{\int_to_alph:n\l_tmpa_int}}} {\tl_set:Nn\l_tmpa_tl{}} - \tl_if_exist_ne:NTF\kl_autoref_tl - {\exp_args:Nx\label{\expandafter\noexpand\kl_autoref_tl\l_tmpa_tl}} + \tl_if_exist_ne:NTF\knowledge_kl_autoref_tl + {\exp_args:Nx\knowledge_latex_label:n + {\expandafter\noexpand\knowledge_kl_autoref_tl\l_tmpa_tl}} {}} \tl_new:N\knowledge_kl_style_tl -\tl_set:Nn\knowledge_kl_used_style_tl{\knowledge_kl_style_tl} -\cs_new:Nn\knowledge_defaultkl_init:{} -\cs_gset:Nn\knowledge_defaultkl_update:N - {\ktuple_countuse_gincr:N#1} -\tl_set:Nn\knowledge_defaultkl_namespace_tl{default} -\tl_set:Nn\knowledge_variablekl_namespace_tl{variable} -\bool_new:N\kl_already_met_bool -\ktuple_new_bool_index:n{already_met_bool} -\ktuple_already_met_bool_expands_to:TF - {\bool_gset_true:N\kl_already_met_bool} - {\bool_gset_false:N\kl_already_met_bool} - -\NewDocumentCommand\introvar{om} - {\IfNoValueTF{#1} - {\introvar:nn{#2}{#2}} - {\introvar:nn{#1}{#2}}} - -\cs_new:Nn\introvar:nn - {\group_begin: - \scope_get_attractive_instance:N - \knowledge_knowledge_instance_tl - \knowledge_sets_to:nnn - \knowledge_variablekl_namespace_tl - \knowledge_knowledge_instance_tl - {#1} - \knowledge_at:N\ktuple_ensure:N - \knowledge_at:N\ktuple_already_met_bool_if:NTF - {\WARNING_VARIABLE_INTRODUCED_TWICE_IN_SAME_SCOPE - \group_end: - \textcolor{orange}{#2}} - {\knowledge_at:N\ktuple_already_met_bool_gset_true:N - \knowledge[\knowledge_variablekl_namespace_tl]{#1}{autorefhere} - \group_end: - #2} -} - -\NewDocumentCommand\klvar{om} - {\group_begin: - \tl_set:Nn\knowledge_kl_command_tl{\klvar} - \tl_set_eq:NN\knowledge_kl_namespace_tl\knowledge_variablekl_namespace_tl - \cs_set_eq:NN\knowledge_kl_display_code:\knowledge_variablekl_display_code: - \kl_base:nn{#1}{#2} - \group_end: -} +\tl_new:N\knowledge_kl_namespace_tl +\tl_new:N\knowledge_kl_command_tl -\cs_new:Nn\knowledge_variablekl_display_code: - {\bool_if:NTF\knowledge_hyperref_active_bool - {\tl_if_exist:NTF\kl_autoref_tl - {\kl_hyperref_silentlabel:nn\kl_autoref_tl\knowledge_kl_text_tl} - {\textcolor{purple}{\knowledge_kl_text_tl}}} - {\knowledge_kl_text_tl}} -\NewKnowledgeParamBool*{protect~link}\kl_protect_link_bool -\NewKnowledgeParamBool*{emphasize}\kl_emphasize_bool -\NewKnowledgeParamBool*{underline}\kl_underline_bool -\NewKnowledgeParamBool*{boldface}\kl_boldface_bool -\NewKnowledgeParamBool*{md}\kl_md_bool +\cs_new:Nn\knowledge_kl_target_update:N + {\ktuple_countintro_gincr:N#1} +\cs_gset:Nn\knowledge_kl_default_update:N + {\ktuple_countuse_gincr:N#1} \NewKnowledgeParamBool*{fbox}\kl_fbox_bool -\NewKnowledgeParamBool*{typewriter}\kl_typewriter_bool \NewKnowledgeParamBool*{ensuremath}\kl_ensuremath_bool +\NewKnowledgeParamBool*{ensuretext}\kl_ensuretext_bool \NewKnowledgeParamBool*{mathord}\kl_mathord_bool \NewKnowledgeParamBool*{mathop}\kl_mathop_bool \NewKnowledgeParamBool*{mathbin}\kl_mathbin_bool @@ -2192,35 +2357,46 @@ \NewKnowledgeParamBool*{mathopen}\kl_mathopen_bool \NewKnowledgeParamBool*{mathclose}\kl_mathclose_bool \NewKnowledgeParamBool*{mathpunct}\kl_mathpunct_bool -\NewKnowledgeParamBool*{ensuretext}\kl_ensuretext_bool +\NewKnowledgeParamBool*{emphasize}\kl_emphasize_bool +\NewKnowledgeParamBool*{underline}\kl_underline_bool +\NewKnowledgeParamBool*{typewriter}\kl_typewriter_bool +\NewKnowledgeParamBool*{autoref~target}\kl_autoreftarget_bool +\NewKnowledgeParamBool*{autoref~link}\kl_autoreflink_bool +\NewKnowledgeParamBool*{invisible}\kl_invisible_bool \NewKnowledgeParamBool*{italic}\kl_italic_bool +\NewKnowledgeParamBool*{sc}\kl_sc_bool +\NewKnowledgeParamBool*{md}\kl_md_bool \NewKnowledgeParamBool*{up}\kl_up_bool +\NewKnowledgeParamBool*{boldface}\kl_boldface_bool +\NewKnowledgeParamBool*{detokenize}\kl_detokenize_bool +\NewKnowledgeParamBool*{remove~space}\kl_removespace_bool +\NewKnowledgeParamBool*{protect~link}\kl_protect_link_bool \NewKnowledgeParamBool*{lowercase}\kl_lowercase_bool \NewKnowledgeParamBool*{uppercase}\kl_uppercase_bool -\NewKnowledgeParamTl*{text}\kowledge_kl_forced_text_tl -\NewKnowledgeParamTl*{link}\knowledge_kl_link_tl -\NewKnowledgeParamTl*{link~scope}\knowledge_kl_linkscope_tl -\NewKnowledgeParamTl*{link~instance}\knowledge_kl_linkinstance_tl -\NewKnowledgeParamTl*{wrap}\knowledge_kl_wrap_tl -\NewKnowledgeParamTl*{style}\knowledge_kl_style_tl -\NewKnowledgeParamTl*{intro~style}\knowledge_kl_intro_style_tl -\NewKnowledgeParamCode{displaycode}\kl_display_code: +\NewKnowledgeParamTl*{link} +\NewKnowledgeParamTl*{link~scope} +\NewKnowledgeParamTl*[\knowledge_kl_instance_tl]{link~instance} +\NewKnowledgeParamTl*[\knowledge_kl_forcedtext_tl]{text} +\NewKnowledgeParamTl*{wrap} + +\NewKnowledgeParamBool*{UnKnoWn~KNowLedGE}\kl_unknown_knowledge_bool +\bool_gset_false:N\kl_unknown_knowledge_bool \ktuple_new_int_index:n{countuse} \ktuple_countuse_expands_to:n{} \ktuple_new_int_index:n{countintro} \ktuple_countintro_expands_to:n{} \keys_define:nn{ knowledge~directives }{ - now .code:n = { \bool_set_true:N\knowledge_knowledge_now_bool } + now .code:n = { \bool_set_true:N\knowledge_knowledge_now_bool }, + also~now .code:n = { \bool_set_true:N\knowledge_knowledge_alsonow_bool } } \int_new:N\knowledge_autoref_count \keys_define:nn{ knowledge~directives }{ autoref .code:n = { - \keys_set:nn{ knowledge~directives } - { intro~style=intro } \int_gincr:N\knowledge_autoref_count \knowledge_delay_directive:x - {autoref = {autoref-\int_use:N\knowledge_autoref_count}}}, + {autoref = {autoref-\int_use:N\knowledge_autoref_count}} + \bool_set_true:N\knowledge_knowledge_autoref_bool}, autorefhere .code:n = { \int_gincr:N\knowledge_autoref_count \exp_args:Nx\label{autoref-\int_use:N\knowledge_autoref_count} @@ -2229,18 +2405,21 @@ \ktuple_new_tl_index:n{autoref} \use:c{ktuple_autoref_expands_to:n} - {\tl_set:Nn\kl_autoref_tl{#1} } + {\tl_set:Nn\knowledge_kl_autoref_tl{#1} } + \keys_define:nn { knowledgenow~directives } { -autoref .code:n = - { \knowledge_at:c{ktuple_autoref_gset:Nn}{#1} - \KAuxWriteX* - {\exp_not:N\KAuxAutoref\exp_not:V\knowledge_set_now_k_tl}} + autoref .code:n = + { \knowledge_at:c{ktuple_autoref_gset:Nn}{#1} } } \int_new:N\kl_countuse_int \int_new:N\kl_countintro_int \NewKAuxCommand\KAuxAutoref{mmm} {Package~knowledge:~Declares~an~autoref~knowledge.~ Arguments~{namespace}{instance}{knowledge}.} +\NewKAuxCommand\KAuxAutorefTarget{mmm} + {Package~knowledge:~Declares~the~use~of~a~target~to~an~autoref~knowledge.~ + Arguments~{namespace}{instance}{knowledge}.} +\DeclareKAuxPhaseCommand\KAuxAutoref{init}{} \int_new:N\kl_digest_autorefused_int \int_new:N\kl_digest_autorefnointro_int @@ -2277,145 +2456,162 @@ autoref .code:n = {\knowledge_diagnose_line: \knowledge_diagnose:n{\nointro{#1}{#2}{#3}}}} \group_end:} -\DeclareKAuxPhaseCommand\KAuxAutoref{autoref-introduced-twice} +\DeclareKAuxPhaseCommand\KAuxAutorefTarget{autoref-introduced-twice} {\group_begin: \knowledge_sets_to:nnn{#1}{#2}{#3} \knowledge_at:N\ktuple_countuse_get_int:NN\kl_countuse_int \knowledge_at:N\ktuple_countintro_get_int:NN\kl_countintro_int \int_compare:nNnT\kl_countintro_int>1 {\knowledge_diagnose_line: - \knowledge_diagnose:n{{#1}{#2}{#3}}} + \knowledge_diagnose:x{\kaux_current_location:\space\exp_not:n{knowledge={#3},namespace=#1,scope=#2}}} \group_end:} \NewKAuxCommand\KAuxUseKnowledge{mmm} {Package~knowledge:~Identifies~the~use~of~some~knowledge.~ Arguments~{namespace}{instance}{knowledge}.} -\cs_new:Nn\knowledge_kl_display_sequence:n - {\knowledge_kl_display_sequence:w#1\display_end:} -\cs_new:Npn\knowledge_kl_display_sequence:w#1#2\display_end: - {\tl_if_empty:nTF{#2}{#1} - {#1{\knowledge_kl_display_sequence:w #2 \display_end:}}} -\cs_new:Nn\knowledge_phantomintro_display_code: - {\knowledge_intro_display_code_preprocess: - \cs_gset:Npx\knowledge_display_sequence:{ - \knowledge_kl_display_sequence:n{ - \knowledge_kl_display_code_index:n - \knowledge_invisible_display_code_text: - }}} -\cs_new:Nn\knowledge_invisible_display_code_text:{} -\cs_new:Nn\knowledge_defaultkl_display_code:{ - \knowledge_kl_display_code_preprocess: - \cs_gset:Npx\knowledge_display_sequence:{ - \knowledge_kl_display_sequence:n{ - \knowledge_kl_display_code_index:n - \knowledge_defaultkl_display_code_fbox:n - \knowledge_defaultkl_display_code_emphasize:n - \knowledge_defaultkl_display_code_ensuremath:n - \knowledge_defaultkl_display_code_ensuretext:n - \knowledge_defaultkl_display_code_mathord:n - \knowledge_defaultkl_display_code_mathop:n - \knowledge_defaultkl_display_code_typewriter:n - \knowledge_defaultkl_display_code_sc:n - \knowledge_defaultkl_display_code_italic:n - \knowledge_defaultkl_display_code_up:n - \knowledge_defaultkl_display_code_boldface:n - \knowledge_defaultkl_display_code_md:n - \knowledge_defaultkl_display_code_ref:n - \knowledge_defaultkl_display_code_url:n - \knowledge_defaultkl_display_code_color:n - \knowledge_defaultkl_display_code_colorbox:n - \knowledge_defaultkl_display_code_underline:n - \knowledge_defaultkl_code_nestingprotect:n - \knowledge_defaultkl_display_code_text:}} -} -\cs_new:Nn\knowledge_kl_display_code_index:n{#1} -\cs_new:Nn\knowledge_defaultkl_display_code_fbox:n - {\bool_if:NTF\kl_fbox_bool{\exp_not:N\fbox{#1}}{#1}} -\cs_new:Npn\knowledge_kl_display_code_preprocess: - {} -\cs_new:Nn\knowledge_defaultkl_display_code_ensuremath:n - {\bool_if:NTF\kl_ensuremath_bool{\exp_not:N\ensuremath}\use:n{#1}} -\cs_new:Nn\knowledge_defaultkl_display_code_ensuretext:n - {\bool_if:NTF\kl_ensuretext_bool{\mode_if_math:TF{\exp_not:N\text}\use:n}\use:n{#1}} -\cs_new:Nn\knowledge_defaultkl_display_code_mathord:n{ - \bool_if:NTF\kl_mathord_bool - {\mode_if_math:TF{\exp_not:N\mathord}\use:n{#1}}{#1}} -\cs_new:Nn\knowledge_defaultkl_display_code_mathop:n{ - \bool_if:NTF\kl_mathop_bool - {\mode_if_math:TF{\exp_not:N\mathop}\use:n{#1}}{#1}} -\cs_new:Nn\knowledge_defaultkl_display_code_mathbin:n{ - \bool_if:NTF\kl_mathbin_bool - {\mode_if_math:TF{\exp_not:N\mathbin}\use:n{#1}}{#1}} -\cs_new:Nn\knowledge_defaultkl_display_code_mathrel:n{ - \bool_if:NTF\kl_mathrel_bool - {\mode_if_math:TF{\exp_not:N\mathrel}\use:n{#1}}{#1}} -\cs_new:Nn\knowledge_defaultkl_display_code_mathopen:n{ - \bool_if:NTF\kl_mathopen_bool - {\mode_if_math:TF{\exp_not:N\mathopen}\use:n{#1}}{#1}} -\cs_new:Nn\knowledge_defaultkl_display_code_mathclose:n{ - \bool_if:NTF\kl_mathclose_bool - {\mode_if_math:TF{\exp_not:N\mathclose}\use:n{#1}}{#1}} -\cs_new:Nn\knowledge_defaultkl_display_code_mathpunct:n{ - \bool_if:NTF\kl_mathpunct_bool - {\mode_if_math:TF{\exp_not:N\mathpunct}\use:n{#1}}{#1}} -\cs_new:Nn\knowledge_defaultkl_display_code_emphasize:n{ - \bool_if:NTF\kl_emphasize_bool - {\mode_if_math:TF\use:n{\exp_not:N\emph}{#1}}{#1}} -\cs_new:Nn\knowledge_defaultkl_display_code_underline:n{ - \bool_if:NTF\kl_underline_bool - {\mode_if_math:TF{#1} - {\exp_not:N\underline{\exp_not:N\smash{#1}}}} - {#1}} -\cs_new:Nn\knowledge_defaultkl_display_code_typewriter:n{ - \bool_if:NTF\kl_typewriter_bool - {\mode_if_math:TF{\exp_not:N\mathtt}{\exp_not:N\texttt}{#1}}{#1}} -\cs_new:Nn\knowledge_defaultkl_display_code_italic:n{ - \bool_if:NTF\kl_italic_bool - {\mode_if_math:TF{\exp_not:N\mathit}{\exp_not:N\textit}{#1}}{#1}} -\cs_new:Nn\knowledge_defaultkl_display_code_sc:n{ - \bool_if:NTF\kl_cs_bool - {\mode_if_math:TF{\exp_not:N\mathsc}{\exp_not:N\textsc}{#1}}{#1}} -\cs_new:Nn\knowledge_defaultkl_display_code_md:n{ - \bool_if:NTF\kl_md_bool - {\mode_if_math:TF{\exp_not:N\mathmd}{\exp_not:N\textmd}{#1}}{#1}} -\cs_new:Nn\knowledge_defaultkl_display_code_up:n{ - \bool_if:NTF\kl_up_bool - {\mode_if_math:TF{\exp_not:N\mathup}{\exp_not:N\textup}{#1}}{#1}} -\cs_new:Nn\knowledge_defaultkl_display_code_boldface:n{ - \bool_if:NTF\kl_boldface_bool - {\mode_if_math:TF{\exp_not:N\mathbf}{\exp_not:N\textbf}{#1}}{#1}} -\cs_new:Nn\knowledge_defaultkl_display_code_ref:n{ - \bool_if:NTF\knowledge_hyperref_active_bool - {\tl_if_exist:NTF\kl_ref_tl - {\exp_not:N\kl_hyperlink_label:nn{\exp_not:V\kl_ref_tl}{#1}} - {\tl_if_exist:NTF\kl_autoref_tl - {\exp_not:N\kl_hyperlink_silentlabel:nn{\exp_not:V\kl_autoref_tl}{#1}} - {#1}}} - {#1}} -\cs_new:Nn\knowledge_defaultkl_display_code_url:n{ - \bool_if:NTF\knowledge_hyperref_active_bool - {\tl_if_exist:NTF\kl_url_tl{\exp_not:N\kl_hyperlink_url:nn{\exp_not:V\kl_url_tl}{#1}}{#1}} - {#1}} -\cs_new:Nn\knowledge_defaultkl_display_code_color:n{ +\cs_new:Nn\knowledge_kl_display_generic:n + {\tl_gset:Nx\knowledge_display_code_tl + {\exp_not:n{#1}{\exp_not:V\knowledge_display_code_tl}}} +\cs_new:Nn\knowledge_kl_display_generic_cond:Nn + {\bool_if:NTF#1 + {\tl_gset:Nx\knowledge_display_code_tl + {\exp_not:n{#2}{\exp_not:V\knowledge_display_code_tl + }}}{}} +\cs_generate_variant:Nn\knowledge_kl_display_generic:n{x} +\cs_generate_variant:Nn\knowledge_kl_display_generic_cond:Nn{Nx} +\cs_new:Nn\knowledge_kl_compute_code:{ + \tl_if_exist_ne:NTF\knowledge_kl_forcedtext_tl + {\tl_gset_eq:NN\knowledge_display_code_tl\knowledge_kl_forcedtext_tl} + {\tl_gset_eq:NN\knowledge_display_code_tl\knowledge_kl_text_tl} + \bool_if:NT\kl_detokenize_bool + {\tl_set:Nx\knowledge_display_code_tl + {\tl_to_str:V\knowledge_display_code_tl}} + \bool_if:NT\kl_removespace_bool + {\tl_remove_all:Nn\knowledge_display_code_tl{~}} + \bool_if:NT\kl_lowercase_bool + {\tl_set:Nx\knowledge_display_code_tl + {\exp_args:NV\tl_lower_case:n\knowledge_display_code_tl}} + \bool_if:NT\kl_uppercase_bool + {\tl_set:Nx\knowledge_display_code_tl + {\exp_args:NV\tl_upper_case:n\knowledge_display_code_tl}} + % + \tl_if_empty:NTF\knowledge_kl_wrap_tl + {} + {\exp_args:NV\knowledge_kl_display_generic:n\knowledge_kl_wrap_tl} + % + \bool_if:NT\knowledge_xcolor_active_bool + \knowledge_kl_compute_code_xcolor: + \bool_if:NT\knowledge_hyperref_active_bool + \knowledge_kl_compute_code_hyperref: + % + \knowledge_kl_display_generic_cond:Nn\kl_underline_bool\kl_underline:n + \knowledge_kl_display_generic_cond:Nn\kl_md_bool\kl_md:n + \knowledge_kl_display_generic_cond:Nn\kl_boldface_bool\kl_bf:n + \knowledge_kl_display_generic_cond:Nn\kl_up_bool\kl_up:n + \knowledge_kl_display_generic_cond:Nn\kl_italic_bool\kl_it:n + \knowledge_kl_display_generic_cond:Nn\kl_sc_bool\kl_sc:n + \knowledge_kl_display_generic_cond:Nn\kl_typewriter_bool\kl_tt:n + % if math + \knowledge_kl_display_generic_cond:Nn\kl_mathop_bool\mathop + \knowledge_kl_display_generic_cond:Nn\kl_mathord_bool\mathord + \knowledge_kl_display_generic_cond:Nn\kl_mathbin_bool\mathbin + \knowledge_kl_display_generic_cond:Nn\kl_mathrel_bool\mathrel + \knowledge_kl_display_generic_cond:Nn\kl_mathclose_bool\mathclose + \knowledge_kl_display_generic_cond:Nn\kl_mathopen_bool\mathopen + \knowledge_kl_display_generic_cond:Nn\kl_mathpunct_bool\mathpunct + % if text + \knowledge_kl_display_generic_cond:Nn\kl_emphasize_bool\kl_em:n + \knowledge_kl_display_generic_cond:Nn\kl_fbox_bool\fbox + % + \knowledge_kl_display_generic_cond:Nn\kl_ensuremath_bool\ensuremath + \knowledge_kl_display_generic_cond:Nn\kl_ensuretext_bool\ensuretext + % + \bool_if:NT\knowledge_makeidx_active_bool + \knowledge_kl_compute_code_makeidx: + % + \bool_if:NT\kl_invisible_bool + {\tl_gclear:N\knowledge_display_code_tl} +} +\cs_new:Nn\knowledge_kl_compute_code_xcolor:{ + \tl_if_empty:NF\knowledge_kl_color_tl + {\knowledge_kl_display_generic:x{\exp_not:N\textcolor{\knowledge_kl_color_tl}}} + \tl_if_empty:NF\knowledge_kl_colorbox_tl + {\knowledge_kl_display_generic:x{\exp_not:N\colorbox{\knowledge_kl_colorbox_tl}}} +} +\cs_new:Nn\knowledge_kl_compute_code_hyperref:{ + \tl_if_exist_ne:NT\knowledge_kl_ref_tl + {\knowledge_kl_display_generic:x + {\exp_not:N\kl_hyperlink_silentref:nn + {\exp_not:V\knowledge_kl_ref_tl}}} + % + \knowledge_kl_compute_code_hyperreftarget: + % + \bool_if:NT\kl_autoreflink_bool + {\tl_if_exist_ne:NT\knowledge_kl_autoref_tl + {\knowledge_kl_display_generic:x + {\exp_not:N\kl_hyperlink_silentref:nn + {\exp_not:V\knowledge_kl_autoref_tl}} + }} + % + \tl_if_exist_ne:NT\knowledge_kl_url_tl + {\knowledge_kl_display_generic:x + {\exp_not:N\kl_hyperlink_url:nn + {\exp_not:V\knowledge_kl_url_tl}}} +} +\cs_new:Nn\knowledge_kl_compute_code_hyperreftarget:{ + \bool_if:NT\kl_autoreftarget_bool + {\tl_if_exist_ne:NT\knowledge_kl_autoref_tl + {\expandafter\ktuple_countintro_get_int:NN + \knowledge_kl_resourcetoken_tl\l_tmpa_int + \tl_set:Nx\l_tmpa_tl + {\int_compare:nNnTF\l_tmpa_int=1 + {} {\int_to_alph:n\l_tmpa_int}} + \exp_args:Nx\label{\exp_not:V\knowledge_kl_autoref_tl\l_tmpa_tl}} + \expandafter\ktuple_countintro_gincr:N + \knowledge_kl_resourcetoken_tl + \KAuxWriteX + {\exp_not:N\KAuxAutorefTarget + \exp_not:o\knowledge_kl_resourcearguments_tl}} +} +\cs_new:Nn\knowledge_kl_compute_code_makeidx:{ + \tl_if_exist_ne:NTF\knowledge_kl_index_tl + {\exp_args:Nx\index + {\tl_if_exist_ne:NTF\knowledge_kl_index_parent_key_tl + {\exp_not:V\knowledge_kl_index_parent_key_tl!}{} + \tl_if_exist_ne:NTF\knowledge_kl_index_key_tl + {\exp_not:V\knowledge_kl_index_key_tl@}{} + \expandafter\tl_to_str:n\expandafter{\knowledge_kl_index_tl} + }}{} +} + +\cs_new:Npn\kl_up:n{\mode_if_math:TF\mathup\textup} +\cs_new:Npn\kl_md:n{\mode_if_math:TF\mathmd\textmd} +\cs_new:Npn\kl_sc:n{\mode_if_math:TF\mathsc\textsc} +\cs_new:Npn\kl_it:n{\mode_if_math:TF\mathit\textit} +\cs_new:Npn\kl_tt:n{\mode_if_math:TF\mathtt\texttt} +\cs_new:Npn\kl_bf:n{\mode_if_math:TF\mathbf\textbf} +\cs_new:Npn\kl_underline:n{\mode_if_math:TF\use:n\underline} +\cs_new:Npn\kl_em:n{\mode_if_math:TF\use:n\emph} +\cs_new:Nn\knowledge_kl_default_display_code_color:n{ \bool_if:NTF\knowledge_xcolor_active_bool - {\tl_if_exist:NTF\kl_color_tl - {\exp_not:N\textcolor{\kl_color_tl}{#1}}{#1}} + {\tl_if_exist_ne:NTF\knowledge_kl_color_tl + {\exp_not:N\textcolor{\knowledge_kl_color_tl}{#1}}{#1}} {#1}} -\cs_new:Nn\knowledge_defaultkl_display_code_colorbox:n{ +\cs_new:Nn\knowledge_kl_default_display_code_colorbox:n{ \bool_if:NTF\knowledge_xcolor_active_bool - {\tl_if_exist:NTF\kl_colorbox_tl - {\exp_not:N\colorbox{\kl_colorbox_tl}{#1}}{#1}} + {\tl_if_exist_ne:NTF\knowledge_kl_colorbox_tl + {\exp_not:N\colorbox{\knowledge_kl_colorbox_tl}{#1}}{#1}} {#1}} -\cs_new:Nn\knowledge_defaultkl_code_nestingprotect:n{ +\cs_new:Nn\knowledge_kl_default_code_nestingprotect:n{ \bool_if:NTF\kl_protect_link_bool {\exp_not:N\kl_kl_nesting_incr:#1\exp_not:N\kl_kl_nesting_decr:}{#1} } -\cs_new:Nn\knowledge_defaultkl_code_wrap:n{ - \tl_if_exist:NTF\knowledge_kl_wrap_tl +\cs_new:Nn\knowledge_kl_default_code_wrap:n{ + \tl_if_exist_ne:NTF\knowledge_kl_wrap_tl {\exp_not:V\knowledge_kl_wrap_tl{#1}}{#1}} -\cs_new:Nn\knowledge_defaultkl_display_code_text:{ - \knowledge_defaultkl_code_wrap:n{ - \tl_if_exist:NTF\kowledge_kl_forced_text_tl - {\exp_not:V\kowledge_kl_forced_text_tl} +\cs_new:Nn\knowledge_kl_default_display_code_text:{ + \knowledge_kl_default_code_wrap:n{ + \tl_if_exist_ne:NTF\knowledge_kl_forcedtext_tl + {\exp_not:V\knowledge_kl_forcedtext_tl} {\exp_not:V\knowledge_kl_text_tl} } } @@ -2441,14 +2637,14 @@ autoref .code:n = {\int_gdecr:N\kl_hyperref_kl_nesting_count_int \bool_gset:Nn\kl_hyperref_active_here_bool {\int_compare_p:nNn\kl_hyperref_kl_nesting_count_int=0}} -\cs_new:Npn\kl_hyperlink_label:nn#1 +\cs_new:Npn\kl_hyperlink_ref:nn#1 {\kl_if_hyperlinks_active_here:TF{\hyperref[{#1}]}{\use:n}} \cs_new:Npn\kl_hyperlink_url:nn {\kl_if_hyperlinks_active_here:TF\href\use_ii:nn} -\cs_new:Nn\kl_hyperlink_silentlabel:nn +\cs_new:Npn\kl_hyperlink_silentref:nn#1 {\kl_if_hyperref_exist:nTF{#1} - {\kl_hyperlink_label:nn{#1}{#2}} - {#2}} + {\kl_hyperlink_ref:nn{#1}} + \use:n} \cs_new:Npn\kl_if_hyperref_exist:nTF#1 {\expandafter\ifx\csname r@#1\endcsname\relax \expandafter\use_ii:nn\else @@ -2473,38 +2669,14 @@ autoref .code:n = \hbox_overlap_left:n {\knowledge_AP_mark:\hspace{1em}} } -\cs_new:Nn\knowledge_kl_TKS:nnn{ - \group_begin: - \knowledge_warning:n{#1/#2/#3} - \knowledge_kl_init: - \cs_gset_eq:NN\knowledge_kl_init:\knowledge_defaultkl_init: - - \scopept_label_instance_if_exist:nTF{#3} - { \exp_args:Nx\knowledge_lpush_visible_instance:n - {\scopept_label_instance_use:n{#3}} - \kl_base:nn{#2}{#1} - } - { \tl_set:Nn\knowledge_kl_text_tl{#1} - \knowledge_kl_error_label_unknown: - \knowledge_warning:n - {Unknown~label~in~scope=`#3'.~Possibly~rerun~latex.} - } - \group_end: - \exp_args:No\knowledge_warning:n\knowledge_display_sequence: -\knowledge_warning:n{before} - \knowledge_display_sequence: -\knowledge_warning:n{after} - %\tl_show:n{\fskljkqlffk} -} -\NewDocumentCommand\klInnerTKSnnn{}\knowledge_kl_TKS:nnn +\tl_new:Nn\knowledge_variant_quote_modifier_tl{\kl*} +\tl_new:Nn\knowledge_variant_doublequote_modifier_tl{\intro*} \ExplSyntaxOff \def\makequotationactive {\catcode`"13\relax} \def\makequotationletter {\catcode`"12\relax} - -\let\quotationmark" - +\let\quotesymbol" \ExplSyntaxOn \makequotationactive \edef\klactivequotationmark#1"{ @@ -2528,15 +2700,17 @@ autoref .code:n = \cs_set_eq:NN\tl_if_novalue:nTF\IfNoValueTF +\cs_new:Npn\klquotation_expand:nnn + {\knowledge_variant_quote_modifier_tl + \klquotation_expand_base:nnn} \cs_new:Npn\kldoublequotation_expand:nnn - {\kl_activate_intro:\klquotation_expand:nnn} - -\cs_new:Nn\klquotation_expand:nnn{ + {\knowledge_variant_doublequote_modifier_tl + \klquotation_expand:nnn} +\cs_new:Nn\klquotation_expand_base:nnn{ \tl_if_empty:nTF{#2} {\klTKS{#1}{#1}{#3}} {\klTKS{#1}{#2}{#3}} } - \def\klactivatequotation {\makequotationactive \let"\klactivequotationmark} @@ -2544,13 +2718,13 @@ autoref .code:n = {\makequotationletter} \kldeactivatequotation - \cs_new:Nn\kl_protect_environment_quotation:n {\clist_map_inline:nn{#1} {\scope_area_set:nn{#1} { push~code={\knowledgeconfigure{quotation=false}}, pop~code={\knowledgeconfigure{quotation=true}}}} } + \cs_new:Nn\klparse_absorb_modifiers: {\tl_set_eq:NN\klparse_primes_tl\c_empty_tl \bool_if:NTF\klparse_load_primes_bool @@ -2610,56 +2784,52 @@ autoref .code:n = \cs_new:Nn\knowledge_directives_require_aci_package:nn {\bool_if:cTF{knowledge_#2_syntax_bool}{}{ \NewKnowledgeParamPackageError{#1}{#2}}} -\NewKnowledgeParamTl*{color}\kl_color_tl -\NewKnowledgeParamTl*{colorbox}\kl_colorbox_tl +\NewKnowledgeParamTl*{color} +\NewKnowledgeParamTl*{colorbox} \knowledge_directives_require_aci_package:nn {color,colorbox}{xcolor} -\NewKnowledgeParamTl*{url}\kl_url_tl -\NewKnowledgeParamTl*{ref}\kl_ref_tl +\NewKnowledgeParamTl*{url} +\NewKnowledgeParamTl*{ref} \knowledge_directives_require_aci_package:nn {url,ref,autoref}{hyperref} \bool_if:NT\knowledge_hyperref_active_bool{ - \DeclareExpandableDocumentCommand\knowledge_fake_kl{om}{#2} - \DeclareExpandableDocumentCommand\knowledge_fake_intro{som}{#3} - \DeclareExpandableDocumentCommand\knowledge_fake_reintro{som}{#3} - + \hypersetup{hidelinks} + \DeclareExpandableDocumentCommand\knowledge_fake_klTKS{mmm}{#1} \pdfstringdefDisableCommands{% - \let\kl\knowledge_fake_kl - \let\intro\knowledge_fake_intro - \let\reintro\knowledge_fake_reintro + \let\klTKS\knowledge_fake_klTKS } } \bool_if:NT\knowledge_makeidx_active_bool{ \makeindex \cs_gset:Npn\knowledge_kl_display_code_index:n - {\knowledge_defaultkl_display_code_index:n} + {\knowledge_kl_default_display_code_index:n} - \cs_new:Npn\knowledge_defaultkl_display_code_index:n - {\tl_if_exist:NT\kl_index_tl + \cs_new:Npn\knowledge_kl_default_display_code_index:n + {\tl_if_exist_ne:NT\knowledge_kl_index_tl {\exp_not:N\index {{\tl_if_exist_ne:NTF\kl_index_parent_key_tl {\exp_not:V\kl_index_parent_key_tl!}{} - \tl_if_exist_ne:NTF\kl_index_key_tl - {\exp_not:V\kl_index_key_tl@}{} - \expandafter\detokenize\expandafter{\kl_index_tl} + \tl_if_exist_ne:NTF\knowledge_kl_indexkey_tl + {\exp_not:V\knowledge_kl_indexkey_tl@}{} + \expandafter\tl_to_str:n\expandafter{\knowledge_kl_index_tl} }}}} } -\NewKnowledgeParamTl{index}\kl_index_tl +\NewKnowledgeParamTl{index} \keys_define:nn { knowledge~directives } { index .code:n = { \tl_if_empty:nTF{#1} - {\knowledge_delay_directive:x{index={\exp_not:V\knowledge_key_tl}}} + {\knowledge_delay_directive:x{index={\exp_not:V\knowledge_knowledge_key_tl}}} {\knowledge_delay_directive:n{index={#1}}}}, index .default:n = {} } -\NewKnowledgeParamTl*{index~style}\kl_index_style_tl -\NewKnowledgeParamTl*{index~parent~key}\kl_index_parent_tl -\NewKnowledgeParamTl*{index~key}\kl_index_key_tl +\NewKnowledgeParamTl*{index~style} +\NewKnowledgeParamTl*{index~parent~key} +\NewKnowledgeParamTl*{index~key} \ExplSyntaxOff\makeatletter \newcommand\knowledgeFixHyperrefTwocolumn{ \RequirePackage{etoolbox} @@ -2724,44 +2894,103 @@ autoref .code:n = \IfXcolorTF \Xcolortrue \Xcolorfalse -\cs_gset_eq:NN\knowledge_kl_init:\knowledge_defaultkl_init: -\tl_gset_eq:NN\knowledge_kl_namespace_tl\knowledge_defaultkl_namespace_tl -\cs_gset_eq:NN\knowledge_kl_display_code:\knowledge_defaultkl_display_code: -\cs_gset_eq:NN\knowledge_kl_update:N\knowledge_defaultkl_update:N -\tl_gset:Nn\knowledge_kl_command_tl{\kl} +\tl_new:Nn\knowledge_kl_default_style_tl{kl} +\tl_new:Nn\knowledge_kl_unknown_style_tl{kl~unknown} +\tl_new:Nn\knowledge_kl_unknown_style_cont_tl{kl~unknown~cont} +\tl_new:Nn\knowledge_kl_styledirectives_tl{\knowledge_kl_style_tl} + +\ExplSyntaxOff +\knowledgestyle{autoref link}{autoref link} +\knowledgestyle{autoref target}{autoref target} +\knowledgestyle{invisible}{invisible} + +\knowledgenewvariant\kl{ + namespace=default, + default style={kl,autoref link}, + unknown style= kl unknown, + unknown style cont=kl unknown cont, + style directive={style} +} +\knowledgenewvariant\intro{ + namespace=default, + default style={intro,autoref target}, + unknown style= intro unknown, + unknown style cont= intro unknown cont, + style directive=intro style +} +\knowledgenewvariant\phantomintro{ + namespace=default, + default style={invisible,autoref target}, + unknown style=invisible, + unknown style cont=invisible +} +\knowledgenewvariant\reintro{ + namespace=default, + default style=intro, + unknown style=intro unknown, + unknown style cont=intro unknown cont, + style directive=intro style +} +\knowledgevariantmodifier{\intro*\kl}{\intro} +\knowledgevariantmodifier{\reintro*\kl}{\reintro} + +\ExplSyntaxOn +\tl_gset_eq:NN\knowledge_kl_namespace_tl\knowledge_default_namespace_tl \newcommand\robustdisplay[1] - {\expandafter\tl_trim_spaces:n\expandafter{\detokenize{#1}}} + {\expandafter\use:n%\tl_trim_spaces:n + \expandafter{\tl_to_str:n{#1}}} \newcommand\robustdisplaybracket[1] {[\robustdisplay{#1}]} +\ExplSyntaxOff \IfKnowledgePaperModeTF{ - \knowledgestyle{intro}{emphasize} - \knowledgestyle{unknown}{} - \knowledgestyle{intro unknown}{emphasize} + \knowledgestyle{kl}{} + \knowledgestyle{kl unknown}{} + \knowledgestyle{kl unknown cont}{} + \knowledgestyle{intro}{emphasize} + \knowledgestyle{intro unknown}{emphasize} + \knowledgestyle{intro unknown cont}{emphasize} }{} \IfKnowledgeCompositionModeTF{ \IfXcolorTF{ - \knowledgestyle{intro}{emphasize} - \knowledgestyle{unknown}{color=brown} - \knowledgestyle{intro unknown}{emphasize,color=red} + \knowledgestyle{kl}{color={blue!70!black}} + \knowledgestyle{kl unknown}{color=orange} + \knowledgestyle{kl unknown cont}{color=brown} + \knowledgestyle{intro}{emphasize,color=blue} + \knowledgestyle{intro unknown}{emphasize,color=orange} + \knowledgestyle{intro unknown cont}{emphasize,color=brown} }{ + \knowledgestyle{kl}{} + \knowledgestyle{kl unknown}{underline} + \knowledgestyle{kl unknown cont}{underline} \knowledgestyle{intro}{emphasize} - \knowledgestyle{unknown}{underline} - \knowledgestyle{intro unknown}{emphasize,underline}} + \knowledgestyle{intro unknown}{emphasize,underline} + \knowledgestyle{intro unknown cont}{emphasize,underline} + } }{} \IfKnowledgeElectronicModeTF{ \IfXcolorTF{ - \knowledgestyle{intro}{emphasize} - \knowledgestyle{unknown}{color=brown} - \knowledgestyle{intro unknown}{emphasize,color=red} + \knowledgestyle{kl}{color={blue!70!black}} + \knowledgestyle{kl unknown}{} + \knowledgestyle{kl unknown cont}{} + \knowledgestyle{intro}{emphasize,color=blue} + \knowledgestyle{intro unknown}{emphasize} + \knowledgestyle{intro unknown cont}{emphasize} }{ + \knowledgestyle{kl}{} + \knowledgestyle{kl unknown}{} + \knowledgestyle{kl unknown cont}{} \knowledgestyle{intro}{emphasize} - \knowledgestyle{unknown}{underline} - \knowledgestyle{intro unknown}{emphasize,underline}} + \knowledgestyle{intro unknown}{emphasize} + \knowledgestyle{intro unknown cont}{emphasize} + } }{} +\ExplSyntaxOn +\let\nointro\phantomintro + \ExplSyntaxOff \newrobustcmd\KnowledgeConfigureNotion[2][blue]{ \knowledgedirective{#2}{autoref,style=#2,intro style=intro #2} @@ -2795,7 +3024,7 @@ autoref .code:n = } \ExplSyntaxOn -\knowledge_begin_module_if:N\knowledge_option_scope_bool +\knowledge_begin_module_if:n\knowledge_option_scope_bool \scope_area_set:nn {part, section,subsection,subsubsection, paragraph,subparagraph,subsubparagraph} -- cgit v1.2.3