SvenPistre / cleveref-usedon

Patches the cleveref package and adds forward-referencing functionality
LaTeX Project Public License v1.3c
6 stars 1 forks source link

Miscellaneous improvements #7

Open Jinwen-XU opened 1 year ago

Jinwen-XU commented 1 year ago

The documentation might needed to be updated accordingly. I have tried to updated some part of it, but there could still be something missing...


The code in #12 contains all these changes with many more improvements that should be able to solve #5 , #9 , #10 , #11 and #12 . However, there are so many new commands that the documentation might need an extensive revision. For this reason I haven't included that version within this pull request.

Jinwen-XU commented 12 months ago
Just for record, below is the code modified from #12 after the renaming of macros. ```latex \def\UsedOnPackageVersion{0.4.0x} \def\UsedOnPackageDate{2023-11-10} \NeedsTeXFormat{LaTeX2e}[2021-06-01] \ProvidesExplPackage{cleveref-usedon} {\UsedOnPackageDate} {\UsedOnPackageVersion} {Patches the cleveref package and adds forward-referencing functionality} %% \providecommand\IfFormatAtLeastTF{\@ifl@t@r\fmtversion} \IfFormatAtLeastTF{2021-06-01}{% % LaTeX2e version new enough }{% \PackageError{cleveref-usedon}{% Mismatched~LaTeX~support~files~detected.\MessageBreak Your~LaTeX~format~is~dated~\fmtversion,\MessageBreak but~the~package~cleveref-usedon\MessageBreak requires~at~least~2021-06-01.\MessageBreak Update~your~TeX~distribution.\MessageBreak \MessageBreak Loading~cleveref-usedon~will~abort!}% {Update~your~TeX~distribution~using~your~TeX~package~manager.}% } \providecommand\IfExplAtLeastTF{\@ifl@t@r\ExplLoaderFileDate} \RequirePackage{expl3}[2021-05-16] \IfExplAtLeastTF{2021-05-16}{% % expl3 version new enough }{% \PackageError{cleveref-usedon}{% Support~package~expl3~too~old.\MessageBreak The~L3~programming~layer~in~the~LaTeX~format\MessageBreak is~dated~\ExplLoaderFileDate,\MessageBreak but~the~package~cleveref-usedon\MessageBreak requires~at~least~2021-05-16.\MessageBreak Update~your~TeX~distribution.\MessageBreak \MessageBreak Loading~cleveref-usedon~will~abort!}% {Update~your~TeX~distribution~using~your~TeX~package~manager.}% } \keys_define:nn { cleveref-usedon } { , Default .tl_set:N = \l__UsedOn_default_package_option_tl , Default .initial:n = { } , Default .value_required:n = true , UsedOn .meta:n = { Default = UsedOn } , usedon .meta:n = { Default = UsedOn } , uo .meta:n = { Default = UsedOn } , UsedBy .meta:n = { Default = UsedBy } , usedby .meta:n = { Default = UsedBy } , ub .meta:n = { Default = UsedBy } , UsedByAndOn .meta:n = { Default = UsedByAndOn } , usedbyandon .meta:n = { Default = UsedByAndOn } , ubao .meta:n = { Default = UsedByAndOn } , unknown .code:n = { \PassOptionsToPackage { \CurrentOption } { cleveref } } } \ProcessKeyOptions [ cleveref-usedon ] \RequirePackage{cleveref}[2018/03/27] \newcommand*{\@setcpagerefrange}[3]{% \@@setcpagerefrange{#1}{#2}{cref}{#3}} \newcommand*{\@setCpagerefrange}[3]{% \@@setcpagerefrange{#1}{#2}{Cref}{#3}} \newcommand*{\@setlabelcpagerefrange}[3]{% \@@setcpagerefrange{#1}{#2}{labelcref}{#3}} \prg_generate_conditional_variant:Nnn \str_case:nn { x } { T, TF } \cs_generate_variant:Nn \str_case:nn { x } \seq_new:N \g__UsedOn_k_seq \prop_new:N \g__UsedOn_kv_prop \clist_new:N \g__UsedOn_Options_clist \clist_set:Nn \g__UsedOn_Options_clist { UsedOn, UsedBy, UsedByAndOn } \cs_new:Nn \__UsedOn_UsedOnMessageText:n { } \cs_new:Nn \__UsedOn_UsedByMessageText:n { } \cs_new:Nn \__UsedOn_UsedByAndOnMessageText:nn { } \NewDocumentCommand \UsedOnMessageText { m } { \__UsedOn_UsedOnMessageText:n { #1 } } \NewDocumentCommand \UsedByMessageText { m } { \__UsedOn_UsedByMessageText:n { #1 } } \NewDocumentCommand \UsedByAndOnMessageText { m m } { \__UsedOn_UsedByAndOnMessageText:nn { #1 } { #2 } } \NewDocumentCommand \SetUsedOnMessageText { m } { \cs_set:Nn \__UsedOn_UsedOnMessageText:n { #1 } } \NewDocumentCommand \SetUsedByMessageText { m } { \cs_set:Nn \__UsedOn_UsedByMessageText:n { #1 } } \NewDocumentCommand \SetUsedByAndOnMessageText { m } { \cs_set:Nn \__UsedOn_UsedByAndOnMessageText:nn { #1 } } \RequirePackage{iflang} \SetUsedOnMessageText { \IfLanguageName{english} { (Used~on~#1.) } {} \IfLanguageName{french} { (Apparaît~en~#1.) } {} \IfLanguageName{ngerman} { (Wird~auf~#1.) } {} \IfLanguageName{spanish} { (Aparece~en~#1.) } {} } \SetUsedByMessageText { \IfLanguageName{english} { (Used~by~#1.) } {} \IfLanguageName{french} { (Apparaît~dans~#1.) } {} \IfLanguageName{ngerman} { (Wird~in~#1.) } {} \IfLanguageName{spanish} { (Aparece~en~#1.) } {} } \SetUsedByAndOnMessageText { \IfLanguageName{english} { (Used~by~#1~on~#2.) } {} \IfLanguageName{french} { (Apparaît~dans~#1~en~#2.) } {} \IfLanguageName{ngerman} { (Wird~in~#1~auf~#2.) } {} \IfLanguageName{spanish} { (Aparece~en~#1~en~#2.) } {} } \NewDocumentCommand \UsedOnMessage { m } { \emph{ \__UsedOn_UsedOnMessageText:n { #1 } } \\[.3\baselineskip] } \NewDocumentCommand \UsedByMessage { m } { \emph{ \__UsedOn_UsedByMessageText:n { #1 } } \\[.3\baselineskip] } \NewDocumentCommand \UsedByAndOnMessage { m m } { \emph{ \__UsedOn_UsedByAndOnMessageText:nn { #1 } { #2 } } \\[.3\baselineskip] } \def\UsedOnMessageMath{} \def\UsedByMessageMath{} \def\UsedByAndOnMessageMath{} \NewDocumentCommand \UsedOnMessageInsideMath { m } { % By default does nothing } \NewDocumentCommand \UsedByMessageInsideMath { m } { % By default does nothing } \NewDocumentCommand \UsedByAndOnMessageInsideMath { m m } { % By default does nothing } \NewDocumentCommand \UsedOnMessageOutsideMath { m } { % By default does nothing } \NewDocumentCommand \UsedByMessageOutsideMath { m } { % By default does nothing } \NewDocumentCommand \UsedByAndOnMessageOutsideMath { m m } { % By default does nothing } \tl_new:N \g__UsedOn_tmpa_tl \NewDocumentCommand \SetUsedOnMessageStyle { m } { \RenewDocumentCommand \UsedOnMessage { m } { #1 } } \NewDocumentCommand \SetUsedByMessageStyle { m } { \RenewDocumentCommand \UsedByMessage { m } { #1 } } \NewDocumentCommand \SetUsedByAndOnMessageStyle { m } { \RenewDocumentCommand \UsedByAndOnMessage { m m } { #1 } } \bool_new:N \g__UsedOn_inside_math_bool \NewDocumentCommand \SetUsedOnMessageStyleInsideMath { m } { \bool_set_true:N \g__UsedOn_inside_math_bool \RenewDocumentCommand \UsedOnMessageInsideMath { m } { #1 } } \NewDocumentCommand \SetUsedByMessageStyleInsideMath { m } { \bool_set_true:N \g__UsedOn_inside_math_bool \RenewDocumentCommand \UsedByMessageInsideMath { m } { #1 } } \NewDocumentCommand \SetUsedByAndOnMessageStyleInsideMath { m } { \bool_set_true:N \g__UsedOn_inside_math_bool \RenewDocumentCommand \UsedByAndOnMessageInsideMath { m m } { #1 } } \clist_new:N \l__UsedOn_supported_equation_env_clist \clist_set:Nn \l__UsedOn_supported_equation_env_clist { equation, align, flalign, alignat, gather, multline, dmath, } \cs_new:Nn \__UsedOn_message_outsidemath_hook_gremove_code:nn { \clist_map_inline:Nn \l__UsedOn_supported_equation_env_clist { \hook_gremove_code:nn { env/##1/#1 } { cleveref-usedon- #2 -message-outsidemath } } } \cs_new:Nn \__UsedOn_message_outsidemath_hook_gput_code:nnn { \clist_map_inline:Nn \l__UsedOn_supported_equation_env_clist { \hook_gput_code:nnn { env/##1/#1 } { cleveref-usedon- #2 -message-outsidemath } { #3 } } } \cs_new:Nn \__UsedOn_message_outsidemath_hook_gset_rule:nnnn { \clist_map_inline:Nn \l__UsedOn_supported_equation_env_clist { \hook_gset_rule:nnnn { env/##1/#1 } { cleveref-usedon- #2 -message-outsidemath } { #3 } { cleveref-usedon- #4 -message-outsidemath } } } \__UsedOn_message_outsidemath_hook_gput_code:nnn { before } { UsedOn } { } \__UsedOn_message_outsidemath_hook_gput_code:nnn { before } { UsedBy } { } \__UsedOn_message_outsidemath_hook_gput_code:nnn { before } { UsedByAndOn } { } \__UsedOn_message_outsidemath_hook_gput_code:nnn { after } { UsedOn } { } \__UsedOn_message_outsidemath_hook_gput_code:nnn { after } { UsedBy } { } \__UsedOn_message_outsidemath_hook_gput_code:nnn { after } { UsedByAndOn } { } \cs_new:Nn \__UsedOnMessageOutsideMath:n {} \NewDocumentCommand \SetUsedOnMessageStyleOutsideMath { m } { \bool_set_false:N \g__UsedOn_inside_math_bool \RenewDocumentCommand \UsedOnMessageOutsideMath { m } { \__UsedOn_message_outsidemath_hook_gset_rule:nnnn { after } { UsedOn } { voids } { UsedBy } \__UsedOn_message_outsidemath_hook_gset_rule:nnnn { after } { UsedOn } { voids } { UsedByAndOn } \tl_gset:Ne \g__UsedOn_tmpa_tl { ##1 } } \cs_set:Nn \__UsedOnMessageOutsideMath:n { \bool_if:NF \g__UsedOn_label_no_use_bool { \tl_if_empty:NF \g__UsedOn_tmpa_tl { #1 } } } \__UsedOn_message_outsidemath_hook_gremove_code:nn { before } { UsedOn } \__UsedOn_message_outsidemath_hook_gput_code:nnn { before } { UsedOn } { \tl_gclear:N \g__UsedOn_tmpa_tl } \__UsedOn_message_outsidemath_hook_gremove_code:nn { after } { UsedOn } \__UsedOn_message_outsidemath_hook_gput_code:nnn { after } { UsedOn } { \__UsedOnMessageOutsideMath:n { \tl_use:N \g__UsedOn_tmpa_tl } } } \cs_new:Nn \__UsedByMessageOutsideMath:n {} \NewDocumentCommand \SetUsedByMessageStyleOutsideMath { m } { \bool_set_false:N \g__UsedOn_inside_math_bool \RenewDocumentCommand \UsedByMessageOutsideMath { m } { \__UsedOn_message_outsidemath_hook_gset_rule:nnnn { after } { UsedBy } { voids } { UsedOn } \__UsedOn_message_outsidemath_hook_gset_rule:nnnn { after } { UsedBy } { voids } { UsedByAndOn } \tl_gset:Ne \g__UsedOn_tmpa_tl { ##1 } } \cs_set:Nn \__UsedByMessageOutsideMath:n { \bool_if:NF \g__UsedOn_label_no_use_bool { \tl_if_empty:NF \g__UsedOn_tmpa_tl { #1 } } } \__UsedOn_message_outsidemath_hook_gremove_code:nn { before } { UsedBy } \__UsedOn_message_outsidemath_hook_gput_code:nnn { before } { UsedBy } { \tl_gclear:N \g__UsedOn_tmpa_tl } \__UsedOn_message_outsidemath_hook_gremove_code:nn { after } { UsedBy } \__UsedOn_message_outsidemath_hook_gput_code:nnn { after } { UsedBy } { \__UsedByMessageOutsideMath:n { \tl_use:N \g__UsedOn_tmpa_tl } } } \cs_new:Nn \__UsedByAndOnMessageOutsideMath:nn {} \NewDocumentCommand \SetUsedByAndOnMessageStyleOutsideMath { m } { \bool_set_false:N \g__UsedOn_inside_math_bool \RenewDocumentCommand \UsedByAndOnMessageOutsideMath { m m } { \__UsedOn_message_outsidemath_hook_gset_rule:nnnn { after } { UsedByAndOn } { voids } { UsedOn } \__UsedOn_message_outsidemath_hook_gset_rule:nnnn { after } { UsedByAndOn } { voids } { UsedBy } \tl_gset:Ne \g__UsedOn_tmpa_tl { ##1 } \tl_gset:Ne \g__UsedOn_tmpb_tl { ##2 } } \cs_set:Nn \__UsedByAndOnMessageOutsideMath:nn { \bool_if:NF \g__UsedOn_label_no_use_bool { \tl_if_empty:NF \g__UsedOn_tmpa_tl { #1 } } } \__UsedOn_message_outsidemath_hook_gremove_code:nn { before } { UsedByAndOn } \__UsedOn_message_outsidemath_hook_gput_code:nnn { before } { UsedByAndOn } { \tl_gclear:N \g__UsedOn_tmpa_tl \tl_gclear:N \g__UsedOn_tmpb_tl } \__UsedOn_message_outsidemath_hook_gremove_code:nn { after } { UsedByAndOn } \__UsedOn_message_outsidemath_hook_gput_code:nnn { after } { UsedByAndOn } { \__UsedByAndOnMessageOutsideMath:nn { \tl_use:N \g__UsedOn_tmpa_tl } { \tl_use:N \g__UsedOn_tmpb_tl } } } \cs_new:Nn \__UsedOn_Printer_generic:nnn { %% % Check if the reference #1@@1 exists %% % Here the @1 means that has been referenced %% % with option #1 at least once where #1 is %% % 'UsedOn', 'UsedBy' or 'UsedByAndOn' \cs_if_exist:cT {r@#1@#2@1} { %% % In a tmp clist we store all the references of the form %% % `