diff options
author | Karl Berry <karl@freefriends.org> | 2023-04-12 20:05:51 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2023-04-12 20:05:51 +0000 |
commit | 221c69381bd44fc50af7998b2f3f36acfd7e0a95 (patch) | |
tree | bdada5a0d9868dcfb7e0b2ac3a237f0ca3127ac8 /Master/texmf-dist/tex/latex/cleveref-usedon | |
parent | 5cff9143f7460c64a1b4287a5f2f130f386b3dd0 (diff) |
cleveref-usedon (12apr23)
git-svn-id: svn://tug.org/texlive/trunk@66833 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/cleveref-usedon')
-rw-r--r-- | Master/texmf-dist/tex/latex/cleveref-usedon/cleveref-usedon.sty | 202 |
1 files changed, 202 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/latex/cleveref-usedon/cleveref-usedon.sty b/Master/texmf-dist/tex/latex/cleveref-usedon/cleveref-usedon.sty new file mode 100644 index 00000000000..9f23e91dcdf --- /dev/null +++ b/Master/texmf-dist/tex/latex/cleveref-usedon/cleveref-usedon.sty @@ -0,0 +1,202 @@ +%% +%% This is file `cleveref-usedon.sty', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% cleveref-usedon.dtx (with options: `package') +%% +%% This is a generated file. +%% +%% Copyright (C) 2023 by Sven Pistre +%% +%% Written and maintained by Sven Pistre +%% +%% The development version of this package can be found at +%% +%% http://github.com/SvenPistre/cleveref-usedon +%% +%% for those people who are interested. Please report bugs by creating a +%% github issue or sending an email to cleveref-usedon@sven-pistre.com. +%% --------------------------------------------------------------------------- +%% This file may be distributed and/or modified under the +%% conditions of the LaTeX Project Public License, either +%% version 1.3 of this license or (at your option) any later +%% version. The latest version of this license is in: +%% +%% http://www.latex-project.org/lppl.txt +%% +%% and version 1.3 or later is part of all distributions of +%% LaTeX version 2005/12/01 or later. +%% ----------------------------------------------------------------------- +%% +\def\packageversion{0.2.0} +\def\packagedate{2023-04-07} +\NeedsTeXFormat{LaTeX2e}[2022/06/01] +\RequirePackage{expl3} +\ProvidesExplPackage{cleveref-usedon} + {\packagedate} + {\packageversion} + {Patches the cleveref package and adds forward-referencing functionality} +\RequirePackage{xparse} +\bool_new:N \g_StandardBehaviour_bool +\bool_gset_true:N \g_StandardBehaviour_bool +\DeclareOption{usedon}{ + \OptionNotUsed + \bool_gset_true:N \g_StandardBehaviour_bool +} +\DeclareOption{notusedon}{ + \OptionNotUsed + \bool_gset_false:N \g_StandardBehaviour_bool +} +\DeclareOption*{ + \PackageInfo{cleveref-usedon} + {Passing~to~cleveref:~Option~`\CurrentOption'} + \PassOptionsToPackage{\CurrentOption}{cleveref} +} +\ProcessOptions* +\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 } { TF } +\seq_new:N \g__UsedOn_k_seq +\prop_new:N \g__UsedOn_kv_prop +\NewDocumentCommand{\UsedOnMessage}{m}{ + \emph{(Used~on~#1.)} \\ +} +\NewDocumentCommand{\__UsedOn_PrintUsedOnLabel}{ m }{% +%% % Check if the reference UsedOn@<LabelName>@1 exists +%% % Here the @1 means that <LabelName> has been referenced +%% % with option `UsedOn' at least once + \cs_if_exist:cT {r@UsedOn@#1@1} + { +%% % In a tmp clist we store all the references of the form +%% % `UsedOn@<LabelName>@<Number>` +%% % where Number between 1 and \value{LastRun@UsedOn@<LabelName>} +%% % if the latter exists, otherwise until 1 +%% % Should/will normally need two consecutive runs of pdflatex + \cs_if_free:cTF {c@LastRun@UsedOn@#1} + { \int_set:Nn \l_tmpa_int { 1 } } + { \int_set:Nn \l_tmpa_int { \value{LastRun@UsedOn@#1} } } + \int_set:Nn \l_tmpb_int { 1 } + \int_while_do:nn { \l_tmpb_int <= \l_tmpa_int } + { + \clist_put_right:Nx \l_tmpa_clist { UsedOn@#1@\int_use:N \l_tmpb_int } + \int_incr:N \l_tmpb_int + } +%% % Print `UsedOn` message by calling \cpageref with the parameter clist above +%% % Uncomment the next two lines to see the contents of \l_tmpa_clist +%% %% Arguments~of~cpageref~are: +%% %% \par\clist_use:Nn \l_tmpa_clist {\par}\par + \UsedOnMessage{\cpageref{\l_tmpa_clist}} + } +}% +\NewDocumentCommand{\__UsedOn_Processor}{ o m }{% + \IfValueT{#1}{ + \str_case:xnTF { \str_foldcase:n { #1 } } + { +%% % check if option 'UsedOn' (case-insensitive) was used +%% % in one of the following forms + {usedon} {} + {uo} {} + } + { + { +%% % Loop through (potential) label list in arg of \cref (or \Cref) + \seq_set_from_clist:Nn \l_tmpa_seq {#2} + \seq_map_inline:Nn \l_tmpa_seq + { +%% % if the label has not been referenced yet, +%% % create a counter for the current and last run and save the label in the +%% % global container \g__UsedOn_k_seq + \seq_if_in:NxF \g__UsedOn_k_seq {UsedOn@##1} + { + \newcounter{ThisRun@UsedOn@##1} + \cs_if_free:cT {c@LastRun@UsedOn@##1} + { \newcounter{LastRun@UsedOn@##1} } + \seq_gput_right:Nx \g__UsedOn_k_seq {UsedOn@##1} + } +%% % increase the counters and compare with max counter + \stepcounter{ThisRun@UsedOn@##1} + \setcounter{LastRun@UsedOn@##1}{% + \fp_eval:n { max(% + \value{ThisRun@UsedOn@##1},% + \value{LastRun@UsedOn@##1} ) }% + } +%% % store the value in global key-value property list + \prop_gput:Nxx \g__UsedOn_kv_prop + {UsedOn@##1} {\arabic{LastRun@UsedOn@##1}} +%% % create a label for the UsedOn reference and number this label + \__UsedOn_origlabel{UsedOn@##1@\arabic{ThisRun@UsedOn@##1}} + } + } + } + { +%% % Throw an error, if an unrecognised option was used +%% % for the optional argument to this macro. + \msg_new:nnn {cleveref-usedon} { OptionSpellingError } + { \\ + Spelling~error~\msg_line_context: + \\ + Did~you~mean~to~pass~option\\ + 'UsedOn'~to~cref~or~Cref? + } + \msg_fatal:nn { cleveref-usedon } { OptionSpellingError } + } + } +}% +\NewDocumentCommand{\__UsedOn_cref}{ s o m }{% + \IfBooleanTF{#1}{ \__UsedOn_origcref*{#3} }{ \__UsedOn_origcref{#3} }% + \__UsedOn_Processor[#2]{#3} +}% +\NewDocumentCommand{\__UsedOn_Cref}{ s o m }{% + \IfBooleanTF{#1}{ \__UsedOn_origCref*{#3} }{ \__UsedOn_origCref{#3} }% + \__UsedOn_Processor[#2]{#3} +}% +\NewDocumentCommand{\__UsedOn_ReadFromAux}{ }{% + \prop_map_inline:Nn \g__UsedOn_kv_prop + { + \newcounter{LastRun@##1} + \setcounter{LastRun@##1}{##2} + } +}% +\NewDocumentCommand{\__UsedOn_WriteToAux}{ }{% +%% % First, we clear the global key-value prop list |\g__UsedOn_kv_prop| and +%% % then we rebuild it with the information from the current run. + \prop_clear:N \g__UsedOn_kv_prop + \seq_map_inline:Nn \g__UsedOn_k_seq + { \prop_gput:Nxx \g__UsedOn_kv_prop {##1}{\arabic{ThisRun@##1}} } +%% % Turn on |expl3| functionality in .aux file. + \iow_now:cx { @auxout } + { \token_to_str:N \ExplSyntaxOn } +%% % Loop through the key-val |proplist| and write contents to .aux file. + \prop_map_inline:Nn \g__UsedOn_kv_prop + { + \iow_now:cx { @auxout } + { \prop_gput_from_keyval:Nn \token_to_str:N \g__UsedOn_kv_prop {##1=##2} } + } +%% % Turn off |expl3| functionality in .aux file. + \iow_now:cx { @auxout } + { \token_to_str:N \ExplSyntaxOff } +}% +\AtBeginDocument{% + \__UsedOn_ReadFromAux + \NewCommandCopy{\__UsedOn_origlabel}{\label} + \NewCommandCopy{\__UsedOn_origcref}{\cref} + \NewCommandCopy{\__UsedOn_origCref}{\Cref} + \RenewDocumentCommand{\label}{ m }{% + \__UsedOn_origlabel{#1}\__UsedOn_PrintUsedOnLabel{#1} + }% + \RenewCommandCopy{\cref}{\__UsedOn_cref} + \RenewCommandCopy{\Cref}{\__UsedOn_Cref} +}% +\AtEndDocument{% + \__UsedOn_WriteToAux +}% +\endinput +%% +%% End of file `cleveref-usedon.sty'. |