From 43261d48f5529c057944a91aa9c043cffb46563c Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Mon, 7 Feb 2022 21:40:53 +0000 Subject: zref-clever (7feb22) git-svn-id: svn://tug.org/texlive/trunk@61935 c570f23f-e606-0410-a88d-b1316a301751 --- .../source/latex/zref-clever/zref-clever.dtx | 1442 ++++++++++++++++++-- 1 file changed, 1333 insertions(+), 109 deletions(-) (limited to 'Master/texmf-dist/source') diff --git a/Master/texmf-dist/source/latex/zref-clever/zref-clever.dtx b/Master/texmf-dist/source/latex/zref-clever/zref-clever.dtx index d850476b4cf..e6c175d33f2 100644 --- a/Master/texmf-dist/source/latex/zref-clever/zref-clever.dtx +++ b/Master/texmf-dist/source/latex/zref-clever/zref-clever.dtx @@ -162,7 +162,7 @@ % % Identify the package. % \begin{macrocode} -\ProvidesExplPackage {zref-clever} {2022-01-28} {0.2.0-alpha} +\ProvidesExplPackage {zref-clever} {2022-02-07} {0.2.1-alpha} {Clever LaTeX cross-references based on zref} % \end{macrocode} % @@ -607,6 +607,11 @@ Option~'ref=#1'~requested~\msg_line_context:.~ But~the~property~'#1'~is~not~declared,~falling-back~to~'default'. } +\msg_new:nnn { zref-clever } { endrange-property-undefined } + { + Option~'endrange=#1'~requested~\msg_line_context:.~ + But~the~property~'#1'~is~not~declared,~'endrange'~not~set. + } \msg_new:nnn { zref-clever } { hyperref-preamble-only } { Option~'hyperref'~only~available~in~the~preamble~\msg_line_context:.~ @@ -667,7 +672,7 @@ % exactly twice, but no further to retrieve the proper value. In case the % property is not found, set \meta{tl var} with \meta{default}. % \begin{syntax} -% \cs{@@_extract_default:Nnnn} \Arg{tl val} +% \cs{@@_extract_default:Nnnn} \Arg{tl var} % ~~\Arg{label} \Arg{prop} \Arg{default} % \end{syntax} % \begin{macrocode} @@ -676,7 +681,7 @@ \exp_args:NNNo \exp_args:NNo \tl_set:Nn #1 { \zref@extractdefault {#2} {#3} {#4} } } -\cs_generate_variant:Nn \@@_extract_default:Nnnn { NVnn } +\cs_generate_variant:Nn \@@_extract_default:Nnnn { NVnn , Nnvn } % \end{macrocode} % \end{macro} % @@ -1103,16 +1108,22 @@ % \contributor{Jonathan P.\ Spratte}, aka `Skillmon', and some discussion % about it, including further insights by \contributor{Phelype Oleinik}, see % \url{https://tex.stackexchange.com/q/614690} and -% \url{https://github.com/latex3/latex3/pull/988}. For booleans, the -% situation is different, since they cannot meaningfully receive an empty -% value and the ``key with no value'' is a handy and expected shorthand for +% \url{https://github.com/latex3/latex3/pull/988}. However, Joseph Wright +% seems to particularly dislike this use and the general idea of a ``key with +% no value'' being somehow meaningful for \pkg{l3keys} (e.g. his comments on +% the previous question, and +% \url{https://tex.stackexchange.com/q/632157/#comment1576404_632157}), which +% does make it somewhat risky to rely on this. For booleans, the situation is +% different, since they cannot meaningfully receive an empty value and the +% ``key with no value'' is a handy and expected shorthand for % \texttt{key=true}. Therefore, for reference format option booleans, we use -% a third value ``\texttt{unset}'' for this purpose. In the language files -% the ``unsetting'' behavior is less meaningful, since they only change any -% variable if it is unset to start with, so that unsetting an unset variable -% would be redundant. However, for UI symmetry also in the language files -% keys with no value should not be considered ``empty'' and boolean -% \texttt{unset} values should exist. They are just no-op. +% a third value ``\texttt{unset}'' for this purpose. And similarly for +% ``choice'' options. In the language files the ``unsetting'' behavior is +% less meaningful, since they only change any variable if it is unset to start +% with, so that unsetting an unset variable would be redundant. However, for +% UI symmetry also in the language files keys with no value should not be +% considered ``empty'' and boolean \texttt{unset} values should exist. They +% are just no-op. % % % \begin{macro} @@ -1191,6 +1202,7 @@ { cap , abbrev , + rangetopair , } % \end{macrocode} % Only ``type names'' are ``necessarily type-specific'', which makes them @@ -1880,6 +1892,225 @@ } , } } +\keys_define:nn { zref-clever/langfile } + { + endrange .code:n = + { + \str_case:nnF {#1} + { + { ref } + { + \tl_if_empty:NTF \l_@@_setup_type_tl + { + \@@_opt_tl_gset_if_new:cn + { + \@@_opt_varname_lang_default:enn + { \l_@@_setup_language_tl } + { endrangefunc } { tl } + } + { } + \@@_opt_tl_gset_if_new:cn + { + \@@_opt_varname_lang_default:enn + { \l_@@_setup_language_tl } + { endrangeprop } { tl } + } + { } + } + { + \@@_opt_tl_gset_if_new:cn + { + \@@_opt_varname_lang_type:eenn + { \l_@@_setup_language_tl } + { \l_@@_setup_type_tl } + { endrangefunc } { tl } + } + { } + \@@_opt_tl_gset_if_new:cn + { + \@@_opt_varname_lang_type:eenn + { \l_@@_setup_language_tl } + { \l_@@_setup_type_tl } + { endrangeprop } { tl } + } + { } + } + } + + { stripprefix } + { + \tl_if_empty:NTF \l_@@_setup_type_tl + { + \@@_opt_tl_gset_if_new:cn + { + \@@_opt_varname_lang_default:enn + { \l_@@_setup_language_tl } + { endrangefunc } { tl } + } + { @@_get_endrange_stripprefix } + \@@_opt_tl_gset_if_new:cn + { + \@@_opt_varname_lang_default:enn + { \l_@@_setup_language_tl } + { endrangeprop } { tl } + } + { } + } + { + \@@_opt_tl_gset_if_new:cn + { + \@@_opt_varname_lang_type:eenn + { \l_@@_setup_language_tl } + { \l_@@_setup_type_tl } + { endrangefunc } { tl } + } + { @@_get_endrange_stripprefix } + \@@_opt_tl_gset_if_new:cn + { + \@@_opt_varname_lang_type:eenn + { \l_@@_setup_language_tl } + { \l_@@_setup_type_tl } + { endrangeprop } { tl } + } + { } + } + } + + { pagecomp } + { + \tl_if_empty:NTF \l_@@_setup_type_tl + { + \@@_opt_tl_gset_if_new:cn + { + \@@_opt_varname_lang_default:enn + { \l_@@_setup_language_tl } + { endrangefunc } { tl } + } + { @@_get_endrange_pagecomp } + \@@_opt_tl_gset_if_new:cn + { + \@@_opt_varname_lang_default:enn + { \l_@@_setup_language_tl } + { endrangeprop } { tl } + } + { } + } + { + \@@_opt_tl_gset_if_new:cn + { + \@@_opt_varname_lang_type:eenn + { \l_@@_setup_language_tl } + { \l_@@_setup_type_tl } + { endrangefunc } { tl } + } + { @@_get_endrange_pagecomp } + \@@_opt_tl_gset_if_new:cn + { + \@@_opt_varname_lang_type:eenn + { \l_@@_setup_language_tl } + { \l_@@_setup_type_tl } + { endrangeprop } { tl } + } + { } + } + } + + { pagecomp2 } + { + \tl_if_empty:NTF \l_@@_setup_type_tl + { + \@@_opt_tl_gset_if_new:cn + { + \@@_opt_varname_lang_default:enn + { \l_@@_setup_language_tl } + { endrangefunc } { tl } + } + { @@_get_endrange_pagecomptwo } + \@@_opt_tl_gset_if_new:cn + { + \@@_opt_varname_lang_default:enn + { \l_@@_setup_language_tl } + { endrangeprop } { tl } + } + { } + } + { + \@@_opt_tl_gset_if_new:cn + { + \@@_opt_varname_lang_type:eenn + { \l_@@_setup_language_tl } + { \l_@@_setup_type_tl } + { endrangefunc } { tl } + } + { @@_get_endrange_pagecomptwo } + \@@_opt_tl_gset_if_new:cn + { + \@@_opt_varname_lang_type:eenn + { \l_@@_setup_language_tl } + { \l_@@_setup_type_tl } + { endrangeprop } { tl } + } + { } + } + } + + { unset } + { } + } + { + \tl_if_empty:nTF {#1} + { + \msg_info:nnn { zref-clever } + { endrange-property-undefined } {#1} + } + { + \zref@ifpropundefined {#1} + { + \msg_info:nnn { zref-clever } + { endrange-property-undefined } {#1} + } + { + \tl_if_empty:NTF \l_@@_setup_type_tl + { + \@@_opt_tl_gset_if_new:cn + { + \@@_opt_varname_lang_default:enn + { \l_@@_setup_language_tl } + { endrangefunc } { tl } + } + { @@_get_endrange_property } + \@@_opt_tl_gset_if_new:cn + { + \@@_opt_varname_lang_default:enn + { \l_@@_setup_language_tl } + { endrangeprop } { tl } + } + {#1} + } + { + \@@_opt_tl_gset_if_new:cn + { + \@@_opt_varname_lang_type:eenn + { \l_@@_setup_language_tl } + { \l_@@_setup_type_tl } + { endrangefunc } { tl } + } + { @@_get_endrange_property } + \@@_opt_tl_gset_if_new:cn + { + \@@_opt_varname_lang_type:eenn + { \l_@@_setup_language_tl } + { \l_@@_setup_type_tl } + { endrangeprop } { tl } + } + {#1} + } + } + } + } + } , + endrange .value_required:n = true , + } \seq_map_inline:Nn \c_@@_rf_opts_tl_type_names_seq { @@ -2167,7 +2398,9 @@ % branch if it is not (insightful comments by \contributor{Ulrike Fischer} at % \url{https://github.com/ho-tex/zref/issues/13}). Therefore, before adding % anything to \cs{l_@@_ref_property_tl}, check if first here with -% \cs{zref@ifpropundefined}: close it at the door. +% \cs{zref@ifpropundefined}: close it at the door. We must also control for +% an empty value, since ``empty'' passes both \cs{zref@ifpropundefined} and +% \cs{zref@ifrefcontainsprop}. % % % \begin{macrocode} @@ -2176,12 +2409,21 @@ { ref .code:n = { - \zref@ifpropundefined {#1} + \tl_if_empty:nTF {#1} { - \msg_warning:nnn { zref-clever } { zref-property-undefined } {#1} + \msg_warning:nnn { zref-clever } + { zref-property-undefined } {#1} \tl_set:Nn \l_@@_ref_property_tl { default } } - { \tl_set:Nn \l_@@_ref_property_tl {#1} } + { + \zref@ifpropundefined {#1} + { + \msg_warning:nnn { zref-clever } + { zref-property-undefined } {#1} + \tl_set:Nn \l_@@_ref_property_tl { default } + } + { \tl_set:Nn \l_@@_ref_property_tl {#1} } + } } , ref .initial:n = default , ref .value_required:n = true , @@ -2286,7 +2528,443 @@ % % % -% \subsubsection*{\opt{range} option} +% \subsubsection*{\opt{endrange} option} +% +% The working of \opt{endrange} option depends on two underlying option values +% / variables: \texttt{endrangefunc} and \texttt{endrangeprop}. +% \texttt{endrangefunc} is the more general one, and \texttt{endrangeprop} is +% used when the first is set to \cs{@@_get_endrange_property:VVN}, which is +% the case when the user is setting \opt{endrange} to an arbitrary \pkg{zref} +% property, instead of one of the \cs{str_case:nn} matches. +% +% \texttt{endrangefunc} \emph{must} receive three arguments and, more +% specifically, its signature \emph{must} be \texttt{VVN}. For this reason, +% \texttt{endrangefunc} should be stored without the signature, which is +% added, and hard-coded, at the calling place. The first argument is +% \meta{beg range label}, the second \meta{end range label}, and the last +% \meta{tl var to set}. Of course, \meta{tl var to set} must be set to a +% proper value, and that's the main task of the function. +% \texttt{endrangefunc} must also handle the case where +% \cs{zref@ifrefcontainsprop} is false, since \cs{@@_get_ref_endrange:nnN} +% cannot take care of that. For this purpose, it may set \meta{tl var to set} +% to the special value \texttt{zc@missingproperty}, to signal a missing +% property for \cs{@@_get_ref_endrange:nnN}. +% +% An empty \texttt{endrangefunc} signals that no processing is to be made to +% the end range reference, that is, that it should be treated like any other +% one, as defined by the \opt{ref} option. This may happen either because +% \opt{endrange} was never set for the reference type, and empty is the value +% ``returned'' by \cs{@@_get_rf_opt_tl:nnnN} for options not set, or because +% \opt{endrange} was set to \texttt{ref} at some scope which happens to get +% precedence. +% +% One thing I was divided about in this functionality was whether to +% (x-)expand the references before processing them, when such processing is +% required. At first sight, it makes sense to do so, since we are aiming at +% ``removing common parts'' as close as possible to the printed representation +% of the references (\pkg{cleveref} does expand them in \cs{crefstripprefix}). +% On the other hand, this brings some new challenges: if a fragile command +% gets there, we are in trouble; also, if a protected one gets there, though +% things won't break as badly, we may ``strip'' the macro and stay with +% different arguments, which will then end up in the input stream. I think +% \pkg{biblatex} is a good reference here, and it offers \cs{NumCheckSetup}, +% \cs{NumsCheckSetup}, and \cs{PagesCheckSetup} aimed at locally redefining +% some commands which may interfere with the processing. This is a good idea, +% thus we offer a similar hook for the same purpose: \texttt{endrange-setup}. +% +% \begin{macrocode} +\NewHook { zref-clever/endrange-setup } +% \end{macrocode} +% +% +% \begin{macrocode} +\keys_define:nn { zref-clever/reference } + { + endrange .code:n = + { + \str_case:nnF {#1} + { + { ref } + { + \tl_clear:c + { + \@@_opt_varname_general:nn + { endrangefunc } { tl } + } + \tl_clear:c + { + \@@_opt_varname_general:nn + { endrangeprop } { tl } + } + } + + { stripprefix } + { + \tl_set:cn + { + \@@_opt_varname_general:nn + { endrangefunc } { tl } + } + { @@_get_endrange_stripprefix } + \tl_clear:c + { + \@@_opt_varname_general:nn + { endrangeprop } { tl } + } + } + + { pagecomp } + { + \tl_set:cn + { + \@@_opt_varname_general:nn + { endrangefunc } { tl } + } + { @@_get_endrange_pagecomp } + \tl_clear:c + { + \@@_opt_varname_general:nn + { endrangeprop } { tl } + } + } + + { pagecomp2 } + { + \tl_set:cn + { + \@@_opt_varname_general:nn + { endrangefunc } { tl } + } + { @@_get_endrange_pagecomptwo } + \tl_clear:c + { + \@@_opt_varname_general:nn + { endrangeprop } { tl } + } + } + + { unset } + { + \@@_opt_tl_unset:c + { + \@@_opt_varname_general:nn + { endrangefunc } { tl } + } + \@@_opt_tl_unset:c + { + \@@_opt_varname_general:nn + { endrangeprop } { tl } + } + } + } + { + \tl_if_empty:nTF {#1} + { + \msg_warning:nnn { zref-clever } + { endrange-property-undefined } {#1} + } + { + \zref@ifpropundefined {#1} + { + \msg_warning:nnn { zref-clever } + { endrange-property-undefined } {#1} + } + { + \tl_set:cn + { + \@@_opt_varname_general:nn + { endrangefunc } { tl } + } + { @@_get_endrange_property } + \tl_set:cn + { + \@@_opt_varname_general:nn + { endrangeprop } { tl } + } + {#1} + } + } + } + } , + endrange .value_required:n = true , + } +% \end{macrocode} +% +% +% \begin{macrocode} +\cs_new_protected:Npn \@@_get_endrange_property:nnN #1#2#3 + { + \tl_if_empty:NTF \l_@@_endrangeprop_tl + { + \zref@ifrefcontainsprop {#2} { \l_@@_ref_property_tl } + { + \@@_extract_default:Nnvn #3 + {#2} { l_@@_ref_property_tl } { } + } + { \tl_set:Nn #3 { zc@missingproperty } } + } + { + \zref@ifrefcontainsprop {#2} { \l_@@_endrangeprop_tl } + { +% \end{macrocode} +% If the range came about by normal compression, we already know the beginning +% and the end references share the same ``form'' and ``prefix'' (this is +% ensured at \cs{@@_labels_in_sequence:nn}), but the same is not true if the +% \opt{range} option is being used, in which case, we have to check the +% replacement \cs{l_@@_ref_property_tl} by \cs{l_@@_endrangeprop_tl} is really +% granted. +% \begin{macrocode} + \bool_if:NTF \l_@@_typeset_range_bool + { + \group_begin: + \bool_set_false:N \l_tmpa_bool + \exp_args:Nxx \tl_if_eq:nnT + { + \@@_extract_unexp:nnn + {#1} { externaldocument } { } + } + { + \@@_extract_unexp:nnn + {#2} { externaldocument } { } + } + { + \tl_if_eq:NnTF \l_@@_ref_property_tl { page } + { + \exp_args:Nxx \tl_if_eq:nnT + { + \@@_extract_unexp:nnn + {#1} { zc@pgfmt } { } + } + { + \@@_extract_unexp:nnn + {#2} { zc@pgfmt } { } + } + { \bool_set_true:N \l_tmpa_bool } + } + { + \exp_args:Nxx \tl_if_eq:nnT + { + \@@_extract_unexp:nnn + {#1} { zc@counter } { } + } + { + \@@_extract_unexp:nnn + {#2} { zc@counter } { } + } + { + \exp_args:Nxx \tl_if_eq:nnT + { + \@@_extract_unexp:nnn + {#1} { zc@enclval } { } + } + { + \@@_extract_unexp:nnn + {#2} { zc@enclval } { } + } + { \bool_set_true:N \l_tmpa_bool } + } + } + } + \bool_if:NTF \l_tmpa_bool + { + \@@_extract_default:Nnvn \l_tmpb_tl + {#2} { l_@@_endrangeprop_tl } { } + } + { + \zref@ifrefcontainsprop + {#2} { \l_@@_ref_property_tl } + { + \@@_extract_default:Nnvn \l_tmpb_tl + {#2} { l_@@_ref_property_tl } { } + } + { \tl_set:Nn \l_tmpb_tl { zc@missingproperty } } + } + \exp_args:NNNV + \group_end: + \tl_set:Nn #3 \l_tmpb_tl + } + { + \@@_extract_default:Nnvn #3 + {#2} { l_@@_endrangeprop_tl } { } + } + } + { + \zref@ifrefcontainsprop {#2} { \l_@@_ref_property_tl } + { + \@@_extract_default:Nnvn #3 + {#2} { l_@@_ref_property_tl } { } + } + { \tl_set:Nn #3 { zc@missingproperty } } + } + } + } +\cs_generate_variant:Nn \@@_get_endrange_property:nnN { VVN } +% \end{macrocode} +% +% +% +% For the technique for smuggling the assignment out of the group, see +% \contributor{Enrico Gregorio}'s answer at +% \url{https://tex.stackexchange.com/a/56314}. +% +% \begin{macrocode} +\cs_new_protected:Npn \@@_get_endrange_stripprefix:nnN #1#2#3 + { + \zref@ifrefcontainsprop {#2} { \l_@@_ref_property_tl } + { + \group_begin: + \UseHook { zref-clever/endrange-setup } + \tl_set:Nx \l_tmpa_tl + { + \@@_extract:nnn + {#1} { \l_@@_ref_property_tl } { } + } + \tl_set:Nx \l_tmpb_tl + { + \@@_extract:nnn + {#2} { \l_@@_ref_property_tl } { } + } + \bool_set_false:N \l_tmpa_bool + \bool_until_do:Nn \l_tmpa_bool + { + \exp_args:Nxx \tl_if_eq:nnTF + { \tl_head:V \l_tmpa_tl } { \tl_head:V \l_tmpb_tl } + { + \tl_set:Nx \l_tmpa_tl { \tl_tail:V \l_tmpa_tl } + \tl_set:Nx \l_tmpb_tl { \tl_tail:V \l_tmpb_tl } + \tl_if_empty:NT \l_tmpb_tl + { \bool_set_true:N \l_tmpa_bool } + } + { \bool_set_true:N \l_tmpa_bool } + } + \exp_args:NNNV + \group_end: + \tl_set:Nn #3 \l_tmpb_tl + } + { \tl_set:Nn #3 { zc@missingproperty } } + } +\cs_generate_variant:Nn \@@_get_endrange_stripprefix:nnN { VVN } +% \end{macrocode} +% +% +% \begin{macro}{\@@_is_integer_rgx:n} +% Test if argument is composed only of digits (adapted from +% \url{https://tex.stackexchange.com/a/427559}). +% \begin{macrocode} +\prg_new_protected_conditional:Npnn + \@@_is_integer_rgx:n #1 { F , TF } + { + \regex_match:nnTF { \A\d+\Z } {#1} + { \prg_return_true: } + { \prg_return_false: } + } +\prg_generate_conditional_variant:Nnn + \@@_is_integer_rgx:n { V } { F , TF } +% \end{macrocode} +% \end{macro} +% +% +% \begin{macrocode} +\cs_new_protected:Npn \@@_get_endrange_pagecomp:nnN #1#2#3 + { + \zref@ifrefcontainsprop {#2} { \l_@@_ref_property_tl } + { + \group_begin: + \UseHook { zref-clever/endrange-setup } + \tl_set:Nx \l_tmpa_tl + { + \@@_extract:nnn + {#1} { \l_@@_ref_property_tl } { } + } + \tl_set:Nx \l_tmpb_tl + { + \@@_extract:nnn + {#2} { \l_@@_ref_property_tl } { } + } + \bool_set_false:N \l_tmpa_bool + \@@_is_integer_rgx:VTF \l_tmpa_tl + { + \@@_is_integer_rgx:VF \l_tmpb_tl + { \bool_set_true:N \l_tmpa_bool } + } + { \bool_set_true:N \l_tmpa_bool } + \bool_until_do:Nn \l_tmpa_bool + { + \exp_args:Nxx \tl_if_eq:nnTF + { \tl_head:V \l_tmpa_tl } { \tl_head:V \l_tmpb_tl } + { + \tl_set:Nx \l_tmpa_tl { \tl_tail:V \l_tmpa_tl } + \tl_set:Nx \l_tmpb_tl { \tl_tail:V \l_tmpb_tl } + \tl_if_empty:NT \l_tmpb_tl + { \bool_set_true:N \l_tmpa_bool } + } + { \bool_set_true:N \l_tmpa_bool } + } + \exp_args:NNNV + \group_end: + \tl_set:Nn #3 \l_tmpb_tl + } + { \tl_set:Nn #3 { zc@missingproperty } } + } +\cs_generate_variant:Nn \@@_get_endrange_pagecomp:nnN { VVN } +% \end{macrocode} +% +% +% \begin{macrocode} +\cs_new_protected:Npn \@@_get_endrange_pagecomptwo:nnN #1#2#3 + { + \zref@ifrefcontainsprop {#2} { \l_@@_ref_property_tl } + { + \group_begin: + \UseHook { zref-clever/endrange-setup } + \tl_set:Nx \l_tmpa_tl + { + \@@_extract:nnn + {#1} { \l_@@_ref_property_tl } { } + } + \tl_set:Nx \l_tmpb_tl + { + \@@_extract:nnn + {#2} { \l_@@_ref_property_tl } { } + } + \bool_set_false:N \l_tmpa_bool + \@@_is_integer_rgx:VTF \l_tmpa_tl + { + \@@_is_integer_rgx:VF \l_tmpb_tl + { \bool_set_true:N \l_tmpa_bool } + } + { \bool_set_true:N \l_tmpa_bool } + \bool_until_do:Nn \l_tmpa_bool + { + \exp_args:Nxx \tl_if_eq:nnTF + { \tl_head:V \l_tmpa_tl } { \tl_head:V \l_tmpb_tl } + { + \bool_lazy_or:nnTF + { \int_compare_p:nNn { \l_tmpb_tl } > { 99 } } + { \int_compare_p:nNn { \tl_head:V \l_tmpb_tl } = { 0 } } + { + \tl_set:Nx \l_tmpa_tl { \tl_tail:V \l_tmpa_tl } + \tl_set:Nx \l_tmpb_tl { \tl_tail:V \l_tmpb_tl } + } + { \bool_set_true:N \l_tmpa_bool } + } + { \bool_set_true:N \l_tmpa_bool } + } + \exp_args:NNNV + \group_end: + \tl_set:Nn #3 \l_tmpb_tl + } + { \tl_set:Nn #3 { zc@missingproperty } } + } +\cs_generate_variant:Nn \@@_get_endrange_pagecomptwo:nnN { VVN } +% \end{macrocode} +% +% +% +% \subsubsection*{\opt{range} and \opt{rangetopair} options} +% +% The \opt{rangetopair} option is being handled with other reference format +% option booleans at \cs{c_@@_rf_opts_bool_maybe_type_specific_seq}. % % \begin{macrocode} \bool_new:N \l_@@_typeset_range_bool @@ -2753,6 +3431,28 @@ % \end{macrocode} % % +% \subsubsection*{\opt{vario} option} +% +% \begin{macrocode} +\keys_define:nn { zref-clever/reference } + { + vario .code:n = { \RequirePackage { zref-vario } } , + vario .value_forbidden:n = true , + } +\AddToHook { begindocument } + { + \keys_define:nn { zref-clever/reference } + { + vario .code:n = + { + \msg_warning:nnn { zref-clever } + { option-preamble-only } { vario } + } + } + } +% \end{macrocode} +% +% % \subsubsection*{\opt{note} option} % % \begin{macrocode} @@ -3244,6 +3944,7 @@ { \tl_set:Nn \l_@@_setup_type_tl {#1} \keys_set:nn { zref-clever/typesetup } {#2} + \tl_clear:N \l_@@_setup_type_tl } % \end{macrocode} % \end{macro} @@ -3271,24 +3972,136 @@ #1 .default:x = \c_novalue_tl , #1 .code:n = { - \tl_if_novalue:nTF {##1} + \tl_if_novalue:nTF {##1} + { + \@@_opt_tl_unset:c + { + \@@_opt_varname_type:enn + { \l_@@_setup_type_tl } {#1} { tl } + } + } + { + \tl_set:cn + { + \@@_opt_varname_type:enn + { \l_@@_setup_type_tl } {#1} { tl } + } + {##1} + } + } , + } + } +\keys_define:nn { zref-clever/typesetup } + { + endrange .code:n = + { + \str_case:nnF {#1} + { + { ref } + { + \tl_clear:c + { + \@@_opt_varname_type:enn + { \l_@@_setup_type_tl } { endrangefunc } { tl } + } + \tl_clear:c + { + \@@_opt_varname_type:enn + { \l_@@_setup_type_tl } { endrangeprop } { tl } + } + } + + { stripprefix } + { + \tl_set:cn + { + \@@_opt_varname_type:enn + { \l_@@_setup_type_tl } { endrangefunc } { tl } + } + { @@_get_endrange_stripprefix } + \tl_clear:c + { + \@@_opt_varname_type:enn + { \l_@@_setup_type_tl } { endrangeprop } { tl } + } + } + + { pagecomp } + { + \tl_set:cn + { + \@@_opt_varname_type:enn + { \l_@@_setup_type_tl } { endrangefunc } { tl } + } + { @@_get_endrange_pagecomp } + \tl_clear:c + { + \@@_opt_varname_type:enn + { \l_@@_setup_type_tl } { endrangeprop } { tl } + } + } + + { pagecomp2 } + { + \tl_set:cn + { + \@@_opt_varname_type:enn + { \l_@@_setup_type_tl } { endrangefunc } { tl } + } + { @@_get_endrange_pagecomptwo } + \tl_clear:c + { + \@@_opt_varname_type:enn + { \l_@@_setup_type_tl } { endrangeprop } { tl } + } + } + + { unset } + { + \@@_opt_tl_unset:c + { + \@@_opt_varname_type:enn + { \l_@@_setup_type_tl } { endrangefunc } { tl } + } + \@@_opt_tl_unset:c + { + \@@_opt_varname_type:enn + { \l_@@_setup_type_tl } { endrangeprop } { tl } + } + } + } + { + \tl_if_empty:nTF {#1} { - \@@_opt_tl_unset:c - { - \@@_opt_varname_type:enn - { \l_@@_setup_type_tl } {#1} { tl } - } + \msg_warning:nnn { zref-clever } + { endrange-property-undefined } {#1} } { - \tl_set:cn + \zref@ifpropundefined {#1} { - \@@_opt_varname_type:enn - { \l_@@_setup_type_tl } {#1} { tl } + \msg_warning:nnn { zref-clever } + { endrange-property-undefined } {#1} + } + { + \tl_set:cn + { + \@@_opt_varname_type:enn + { \l_@@_setup_type_tl } + { endrangefunc } { tl } + } + { @@_get_endrange_property } + \tl_set:cn + { + \@@_opt_varname_type:enn + { \l_@@_setup_type_tl } + { endrangeprop } { tl } + } + {#1} } - {##1} } - } , - } + } + } , + endrange .value_required:n = true , } \keys_define:nn { zref-clever/typesetup } { @@ -3625,6 +4438,247 @@ } , } } +\keys_define:nn { zref-clever/langsetup } + { + endrange .code:n = + { + \str_case:nnF {#1} + { + { ref } + { + \tl_if_empty:NTF \l_@@_setup_type_tl + { + \tl_gclear:c + { + \@@_opt_varname_lang_default:enn + { \l_@@_setup_language_tl } + { endrangefunc } { tl } + } + \tl_gclear:c + { + \@@_opt_varname_lang_default:enn + { \l_@@_setup_language_tl } + { endrangeprop } { tl } + } + } + { + \tl_gclear:c + { + \@@_opt_varname_lang_type:eenn + { \l_@@_setup_language_tl } + { \l_@@_setup_type_tl } + { endrangefunc } { tl } + } + \tl_gclear:c + { + \@@_opt_varname_lang_type:eenn + { \l_@@_setup_language_tl } + { \l_@@_setup_type_tl } + { endrangeprop } { tl } + } + } + } + + { stripprefix } + { + \tl_if_empty:NTF \l_@@_setup_type_tl + { + \tl_gset:cn + { + \@@_opt_varname_lang_default:enn + { \l_@@_setup_language_tl } + { endrangefunc } { tl } + } + { @@_get_endrange_stripprefix } + \tl_gclear:c + { + \@@_opt_varname_lang_default:enn + { \l_@@_setup_language_tl } + { endrangeprop } { tl } + } + } + { + \tl_gset:cn + { + \@@_opt_varname_lang_type:eenn + { \l_@@_setup_language_tl } + { \l_@@_setup_type_tl } + { endrangefunc } { tl } + } + { @@_get_endrange_stripprefix } + \tl_gclear:c + { + \@@_opt_varname_lang_type:eenn + { \l_@@_setup_language_tl } + { \l_@@_setup_type_tl } + { endrangeprop } { tl } + } + } + } + + { pagecomp } + { + \tl_if_empty:NTF \l_@@_setup_type_tl + { + \tl_gset:cn + { + \@@_opt_varname_lang_default:enn + { \l_@@_setup_language_tl } + { endrangefunc } { tl } + } + { @@_get_endrange_pagecomp } + \tl_gclear:c + { + \@@_opt_varname_lang_default:enn + { \l_@@_setup_language_tl } + { endrangeprop } { tl } + } + } + { + \tl_gset:cn + { + \@@_opt_varname_lang_type:eenn + { \l_@@_setup_language_tl } + { \l_@@_setup_type_tl } + { endrangefunc } { tl } + } + { @@_get_endrange_pagecomp } + \tl_gclear:c + { + \@@_opt_varname_lang_type:eenn + { \l_@@_setup_language_tl } + { \l_@@_setup_type_tl } + { endrangeprop } { tl } + } + } + } + + { pagecomp2 } + { + \tl_if_empty:NTF \l_@@_setup_type_tl + { + \tl_gset:cn + { + \@@_opt_varname_lang_default:enn + { \l_@@_setup_language_tl } + { endrangefunc } { tl } + } + { @@_get_endrange_pagecomptwo } + \tl_gclear:c + { + \@@_opt_varname_lang_default:enn + { \l_@@_setup_language_tl } + { endrangeprop } { tl } + } + } + { + \tl_gset:cn + { + \@@_opt_varname_lang_type:eenn + { \l_@@_setup_language_tl } + { \l_@@_setup_type_tl } + { endrangefunc } { tl } + } + { @@_get_endrange_pagecomptwo } + \tl_gclear:c + { + \@@_opt_varname_lang_type:eenn + { \l_@@_setup_language_tl } + { \l_@@_setup_type_tl } + { endrangeprop } { tl } + } + } + } + + { unset } + { + \tl_if_empty:NTF \l_@@_setup_type_tl + { + \@@_opt_tl_gunset:c + { + \@@_opt_varname_lang_default:enn + { \l_@@_setup_language_tl } + { endrangefunc } { tl } + } + \@@_opt_tl_gunset:c + { + \@@_opt_varname_lang_default:enn + { \l_@@_setup_language_tl } + { endrangeprop } { tl } + } + } + { + \@@_opt_tl_gunset:c + { + \@@_opt_varname_lang_type:eenn + { \l_@@_setup_language_tl } + { \l_@@_setup_type_tl } + { endrangefunc } { tl } + } + \@@_opt_tl_gunset:c + { + \@@_opt_varname_lang_type:eenn + { \l_@@_setup_language_tl } + { \l_@@_setup_type_tl } + { endrangeprop } { tl } + } + } + } + } + { + \tl_if_empty:nTF {#1} + { + \msg_warning:nnn { zref-clever } + { endrange-property-undefined } {#1} + } + { + \zref@ifpropundefined {#1} + { + \msg_warning:nnn { zref-clever } + { endrange-property-undefined } {#1} + } + { + \tl_if_empty:NTF \l_@@_setup_type_tl + { + \tl_gset:cn + { + \@@_opt_varname_lang_default:enn + { \l_@@_setup_language_tl } + { endrangefunc } { tl } + } + { @@_get_endrange_property } + \tl_gset:cn + { + \@@_opt_varname_lang_default:enn + { \l_@@_setup_language_tl } + { endrangeprop } { tl } + } + {#1} + } + { + \tl_gset:cn + { + \@@_opt_varname_lang_type:eenn + { \l_@@_setup_language_tl } + { \l_@@_setup_type_tl } + { endrangefunc } { tl } + } + { @@_get_endrange_property } + \tl_gset:cn + { + \@@_opt_varname_lang_type:eenn + { \l_@@_setup_language_tl } + { \l_@@_setup_type_tl } + { endrangeprop } { tl } + } + {#1} + } + } + } + } + } , + endrange .value_required:n = true , + } \keys_define:nn { zref-clever/langsetup } { refpre .code:n = @@ -4207,7 +5261,7 @@ \bool_set_false:N \l_@@_sort_decided_bool % First we check if there's any "external document" difference (coming - % from 'zref-xr') and, if so, sort based on that. + % from `zref-xr') and, if so, sort based on that. \tl_if_eq:NNF \l_@@_label_extdoc_a_tl \l_@@_label_extdoc_b_tl @@ -4589,6 +5643,8 @@ % \l_@@_range_count_int , % \l_@@_range_same_count_int , % \l_@@_range_beg_label_tl , +% \l_@@_range_beg_is_first_bool , +% \l_@@_range_end_ref_tl , % \l_@@_next_maybe_range_bool , % \l_@@_next_is_same_bool , % } @@ -4597,6 +5653,8 @@ \int_new:N \l_@@_range_count_int \int_new:N \l_@@_range_same_count_int \tl_new:N \l_@@_range_beg_label_tl +\bool_new:N \l_@@_range_beg_is_first_bool +\tl_new:N \l_@@_range_end_ref_tl \bool_new:N \l_@@_next_maybe_range_bool \bool_new:N \l_@@_next_is_same_bool % \end{macrocode} @@ -4614,8 +5672,11 @@ % \l_@@_rangesep_tl , % \l_@@_namefont_tl , % \l_@@_reffont_tl , +% \l_@@_endrangefunc_tl , +% \l_@@_endrangeprop_tl , % \l_@@_cap_bool , % \l_@@_abbrev_bool , +% \l_@@_rangetopair_bool , % } % Auxiliary variables for \cs{@@_typeset_refs:} separators, and font and % other options. @@ -4630,8 +5691,11 @@ \tl_new:N \l_@@_rangesep_tl \tl_new:N \l_@@_namefont_tl \tl_new:N \l_@@_reffont_tl +\tl_new:N \l_@@_endrangefunc_tl +\tl_new:N \l_@@_endrangeprop_tl \bool_new:N \l_@@_cap_bool \bool_new:N \l_@@_abbrev_bool +\bool_new:N \l_@@_rangetopair_bool % \end{macrocode} % \end{macro} % @@ -4692,11 +5756,13 @@ \tl_clear:N \l_@@_type_first_label_tl \tl_clear:N \l_@@_type_first_label_type_tl \tl_clear:N \l_@@_range_beg_label_tl + \tl_clear:N \l_@@_range_end_ref_tl \int_zero:N \l_@@_label_count_int \int_zero:N \l_@@_type_count_int \int_zero:N \l_@@_ref_count_int \int_zero:N \l_@@_range_count_int \int_zero:N \l_@@_range_same_count_int + \bool_set_false:N \l_@@_range_beg_is_first_bool \bool_set_false:N \l_@@_type_first_refbounds_set_bool % Get type block options (not type-specific). @@ -4771,9 +5837,9 @@ } % Handle warnings in case of reference or type undefined. - % Test: 'zc-typeset01.lvt': "Typeset refs: warn ref undefined" + % Test: `zc-typeset01.lvt': "Typeset refs: warn ref undefined" \zref@refused { \l_@@_label_a_tl } - % Test: 'zc-typeset01.lvt': "Typeset refs: warn missing type" + % Test: `zc-typeset01.lvt': "Typeset refs: warn missing type" \zref@ifrefundefined { \l_@@_label_a_tl } {} { @@ -4825,6 +5891,14 @@ { \l_@@_label_type_a_tl } { \l_@@_ref_language_tl } \l_@@_reffont_tl + \@@_get_rf_opt_tl:nxxN { endrangefunc } + { \l_@@_label_type_a_tl } + { \l_@@_ref_language_tl } + \l_@@_endrangefunc_tl + \@@_get_rf_opt_tl:nxxN { endrangeprop } + { \l_@@_label_type_a_tl } + { \l_@@_ref_language_tl } + \l_@@_endrangeprop_tl \@@_get_rf_opt_bool:nnxxN { cap } { false } { \l_@@_label_type_a_tl } { \l_@@_ref_language_tl } @@ -4833,6 +5907,10 @@ { \l_@@_label_type_a_tl } { \l_@@_ref_language_tl } \l_@@_abbrev_bool + \@@_get_rf_opt_bool:nnxxN { rangetopair } { true } + { \l_@@_label_type_a_tl } + { \l_@@_ref_language_tl } + \l_@@_rangetopair_bool \@@_get_rf_opt_seq:nxxN { refbounds-first } { \l_@@_label_type_a_tl } { \l_@@_ref_language_tl } @@ -4910,7 +5988,7 @@ { % It is the last label of its type, but also the first one, and that's % what matters here: just store it. - % Test: 'zc-typeset01.lvt': "Last of type: single" + % Test: `zc-typeset01.lvt': "Last of type: single" { 0 } { \tl_set:NV \l_@@_type_first_label_tl @@ -4923,7 +6001,7 @@ } % The last is the second: we have a pair (if not repeated). - % Test: 'zc-typeset01.lvt': "Last of type: pair" + % Test: `zc-typeset01.lvt': "Last of type: pair" { 1 } { \int_compare:nNnTF { \l_@@_range_same_count_int } = { 1 } @@ -4951,7 +6029,7 @@ \int_case:nnF { \l_@@_range_count_int } { % There was no range going on. - % Test: 'zc-typeset01.lvt': "Last of type: not range" + % Test: `zc-typeset01.lvt': "Last of type: not range" { 0 } { \int_compare:nNnTF { \l_@@_ref_count_int } < { 2 } @@ -4973,15 +6051,15 @@ } } % Last in the range is also the second in it. - % Test: 'zc-typeset01.lvt': "Last of type: pair in sequence" + % Test: `zc-typeset01.lvt': "Last of type: pair in sequence" { 1 } { \int_compare:nNnTF { \l_@@_range_same_count_int } = { 1 } { - % We know `range_beg_label' is not empty, since this is the - % second element in the range, but the third or more in the - % type list. + % We know `range_beg_is_first_bool' is false, since this is + % the second element in the range, but the third or more in + % the type list. \tl_put_right:Nx \l_@@_typeset_queue_curr_tl { \exp_not:V \l_@@_pairsep_tl @@ -5017,13 +6095,13 @@ } { % Repetition, not a range. - % Test: 'zc-typeset01.lvt': "Last of type: range to one" + % Test: `zc-typeset01.lvt': "Last of type: range to one" { 0 } { - % If `range_beg_label' is empty, it means it was also the - % first of the type, and hence its typesetting was already - % handled, and we just have to set refbounds. - \tl_if_empty:VTF \l_@@_range_beg_label_tl + % If `range_beg_is_first_bool' is true, it means it was also + % the first of the type, and hence its typesetting was + % already handled, and we just have to set refbounds. + \bool_if:NTF \l_@@_range_beg_is_first_bool { \seq_set_eq:NN \l_@@_type_first_refbounds_seq \l_@@_refbounds_first_sg_seq @@ -5055,11 +6133,11 @@ } % A `range', but with no skipped value, treat as pair if range % started with first of type, otherwise as list. - % Test: 'zc-typeset01.lvt': "Last of type: range to pair" + % Test: `zc-typeset01.lvt': "Last of type: range to pair" { 1 } { % Ditto. - \tl_if_empty:VTF \l_@@_range_beg_label_tl + \bool_if:NTF \l_@@_range_beg_is_first_bool { \seq_set_eq:NN \l_@@_type_first_refbounds_seq \l_@@_refbounds_first_pb_seq @@ -5091,9 +6169,9 @@ } { % An actual range. - % Test: 'zc-typeset01.lvt': "Last of type: range" + % Test: `zc-typeset01.lvt': "Last of type: range" % Ditto. - \tl_if_empty:VTF \l_@@_range_beg_label_tl + \bool_if:NTF \l_@@_range_beg_is_first_bool { \seq_set_eq:NN \l_@@_type_first_refbounds_seq \l_@@_refbounds_first_rb_seq @@ -5127,11 +6205,30 @@ } } } - \tl_put_right:Nx \l_@@_typeset_queue_curr_tl + \bool_lazy_and:nnTF + { ! \tl_if_empty_p:N \l_@@_endrangefunc_tl } + { \cs_if_exist_p:c { \l_@@_endrangefunc_tl :VVN } } { - \exp_not:V \l_@@_rangesep_tl - \@@_get_ref:VN \l_@@_label_a_tl - \l_@@_refbounds_last_re_seq + \use:c { \l_@@_endrangefunc_tl :VVN } + \l_@@_range_beg_label_tl + \l_@@_label_a_tl + \l_@@_range_end_ref_tl + \tl_put_right:Nx \l_@@_typeset_queue_curr_tl + { + \exp_not:V \l_@@_rangesep_tl + \@@_get_ref_endrange:VVN + \l_@@_label_a_tl + \l_@@_range_end_ref_tl + \l_@@_refbounds_last_re_seq + } + } + { + \tl_put_right:Nx \l_@@_typeset_queue_curr_tl + { + \exp_not:V \l_@@_rangesep_tl + \@@_get_ref:VN \l_@@_label_a_tl + \l_@@_refbounds_last_re_seq + } } } } @@ -5154,15 +6251,18 @@ } { \bool_set_false:N \l_@@_next_maybe_range_bool - \zref@ifrefundefined { \l_@@_type_first_label_tl } - { } + \bool_if:NT \l_@@_rangetopair_bool { - \@@_labels_in_sequence:nn - { \l_@@_type_first_label_tl } - { \l_@@_label_a_tl } + \zref@ifrefundefined { \l_@@_type_first_label_tl } + { } + { + \@@_labels_in_sequence:nn + { \l_@@_type_first_label_tl } + { \l_@@_label_a_tl } + } } - % Test: 'zc-typeset01.lvt': "Last of type: option range" - % Test: 'zc-typeset01.lvt': "Last of type: option range to pair" + % Test: `zc-typeset01.lvt': "Last of type: option range" + % Test: `zc-typeset01.lvt': "Last of type: option range to pair" \bool_if:NTF \l_@@_next_maybe_range_bool { \tl_set:Nx \l_@@_typeset_queue_curr_tl @@ -5176,11 +6276,34 @@ \bool_set_true:N \l_@@_type_first_refbounds_set_bool } { - \tl_set:Nx \l_@@_typeset_queue_curr_tl + \bool_lazy_and:nnTF + { ! \tl_if_empty_p:N \l_@@_endrangefunc_tl } + { \cs_if_exist_p:c { \l_@@_endrangefunc_tl :VVN } } { - \exp_not:V \l_@@_rangesep_tl - \@@_get_ref:VN \l_@@_label_a_tl - \l_@@_refbounds_last_re_seq + % We must get `type_first_label_tl' instead of + % `range_beg_label_tl' here, since it is not necessary + % that the first of type was actually starting a range for + % the `range' option to be used. + \use:c { \l_@@_endrangefunc_tl :VVN } + \l_@@_type_first_label_tl + \l_@@_label_a_tl + \l_@@_range_end_ref_tl + \tl_set:Nx \l_@@_typeset_queue_curr_tl + { + \exp_not:V \l_@@_rangesep_tl + \@@_get_ref_endrange:VVN + \l_@@_label_a_tl + \l_@@_range_end_ref_tl + \l_@@_refbounds_last_re_seq + } + } + { + \tl_set:Nx \l_@@_typeset_queue_curr_tl + { + \exp_not:V \l_@@_rangesep_tl + \@@_get_ref:VN \l_@@_label_a_tl + \l_@@_refbounds_last_re_seq + } } \seq_set_eq:NN \l_@@_type_first_refbounds_seq \l_@@_refbounds_first_rb_seq @@ -5210,7 +6333,7 @@ { \bool_if:NTF \l_@@_typeset_ref_bool { - % Test: 'zc-typeset01.lvt': "Last of type: option typeset ref" + % Test: `zc-typeset01.lvt': "Last of type: option typeset ref" \tl_put_left:Nx \l_@@_typeset_queue_curr_tl { \@@_get_ref:VN \l_@@_type_first_label_tl @@ -5220,14 +6343,14 @@ { \bool_if:NTF \l_@@_typeset_name_bool { - % Test: 'zc-typeset01.lvt': "Last of type: option typeset name" + % Test: `zc-typeset01.lvt': "Last of type: option typeset name" \tl_set:Nx \l_@@_typeset_queue_curr_tl { \bool_if:NTF \l_@@_name_in_link_bool { \exp_not:N \group_begin: \exp_not:V \l_@@_namefont_tl - % It's two '@s', but escaped for DocStrip. + % It's two `@s', but escaped for DocStrip. \exp_not:N \hyper@@@@link { \@@_extract_url_unexp:V @@ -5254,7 +6377,7 @@ % it should not occur, given that the options are set up to % typeset either "ref" or "name". Still, leave here a % sensible fallback, equal to the behavior of "both". - % Test: 'zc-typeset01.lvt': "Last of type: option typeset none" + % Test: `zc-typeset01.lvt': "Last of type: option typeset none" \tl_put_left:Nx \l_@@_typeset_queue_curr_tl { \@@_get_ref_first: } } @@ -5280,11 +6403,11 @@ \int_case:nnF { \l_@@_type_count_int } { % Single type. - % Test: 'zc-typeset01.lvt': "Last of type: single type" + % Test: `zc-typeset01.lvt': "Last of type: single type" { 0 } { \l_@@_typeset_queue_curr_tl } % Pair of types. - % Test: 'zc-typeset01.lvt': "Last of type: pair of types" + % Test: `zc-typeset01.lvt': "Last of type: pair of types" { 1 } { \l_@@_tpairsep_tl @@ -5293,7 +6416,7 @@ } { % Last in list of types. - % Test: 'zc-typeset01.lvt': "Last of type: list of types" + % Test: `zc-typeset01.lvt': "Last of type: list of types" \l_@@_tlastsep_tl \l_@@_typeset_queue_curr_tl } @@ -5314,11 +6437,13 @@ \tl_clear:N \l_@@_type_first_label_tl \tl_clear:N \l_@@_type_first_label_type_tl \tl_clear:N \l_@@_range_beg_label_tl + \tl_clear:N \l_@@_range_end_ref_tl \int_zero:N \l_@@_label_count_int \int_zero:N \l_@@_ref_count_int \int_incr:N \l_@@_type_count_int \int_zero:N \l_@@_range_count_int \int_zero:N \l_@@_range_same_count_int + \bool_set_false:N \l_@@_range_beg_is_first_bool \bool_set_false:N \l_@@_type_first_refbounds_set_bool } } @@ -5356,13 +6481,16 @@ \l_@@_label_type_a_tl \int_incr:N \l_@@_ref_count_int - % If the next label may be part of a range, we set `range_beg_label' - % to "empty" (we deal with it as the "first", and must do it there, to - % handle hyperlinking), but also step the range counters. - % Test: 'zc-typeset01.lvt': "Not last of type: first is range" + % If the next label may be part of a range, signal it (we deal with it + % as the "first", and must do it there, to handle hyperlinking), but + % also step the range counters. + % Test: `zc-typeset01.lvt': "Not last of type: first is range" \bool_if:NT \l_@@_next_maybe_range_bool { - \tl_clear:N \l_@@_range_beg_label_tl + \bool_set_true:N \l_@@_range_beg_is_first_bool + \tl_set:NV \l_@@_range_beg_label_tl + \l_@@_label_a_tl + \tl_clear:N \l_@@_range_end_ref_tl \int_incr:N \l_@@_range_count_int \bool_if:NT \l_@@_next_is_same_bool { \int_incr:N \l_@@_range_same_count_int } @@ -5379,6 +6507,7 @@ % There was no range going, we are starting one. \tl_set:NV \l_@@_range_beg_label_tl \l_@@_label_a_tl + \tl_clear:N \l_@@_range_end_ref_tl \int_incr:N \l_@@_range_count_int \bool_if:NT \l_@@_next_is_same_bool { \int_incr:N \l_@@_range_same_count_int } @@ -5396,7 +6525,7 @@ \int_case:nnF { \l_@@_range_count_int } { % There was no range going on. - % Test: 'zc-typeset01.lvt': "Not last of type: no range" + % Test: `zc-typeset01.lvt': "Not last of type: no range" { 0 } { \int_incr:N \l_@@_ref_count_int @@ -5410,11 +6539,11 @@ % Last is second in the range: if `range_same_count' is also % `1', it's a repetition (drop it), otherwise, it's a "pair % within a list", treat as list. - % Test: 'zc-typeset01.lvt': "Not last of type: range pair to one" - % Test: 'zc-typeset01.lvt': "Not last of type: range pair" + % Test: `zc-typeset01.lvt': "Not last of type: range pair to one" + % Test: `zc-typeset01.lvt': "Not last of type: range pair" { 1 } { - \tl_if_empty:VTF \l_@@_range_beg_label_tl + \bool_if:NTF \l_@@_range_beg_is_first_bool { \seq_set_eq:NN \l_@@_type_first_refbounds_seq \l_@@_refbounds_first_seq @@ -5456,10 +6585,10 @@ \l_@@_range_same_count_int } { - % Test: 'zc-typeset01.lvt': "Not last of type: range to one" + % Test: `zc-typeset01.lvt': "Not last of type: range to one" { 0 } { - \tl_if_empty:VTF \l_@@_range_beg_label_tl + \bool_if:NTF \l_@@_range_beg_is_first_bool { \seq_set_eq:NN \l_@@_type_first_refbounds_seq @@ -5478,10 +6607,10 @@ } } } - % Test: 'zc-typeset01.lvt': "Not last of type: range to pair" + % Test: `zc-typeset01.lvt': "Not last of type: range to pair" { 1 } { - \tl_if_empty:VTF \l_@@_range_beg_label_tl + \bool_if:NTF \l_@@_range_beg_is_first_bool { \seq_set_eq:NN \l_@@_type_first_refbounds_seq @@ -5509,8 +6638,8 @@ } } { - % Test: 'zc-typeset01.lvt': "Not last of type: range" - \tl_if_empty:VTF \l_@@_range_beg_label_tl + % Test: `zc-typeset01.lvt': "Not last of type: range" + \bool_if:NTF \l_@@_range_beg_is_first_bool { \seq_set_eq:NN \l_@@_type_first_refbounds_seq @@ -5529,15 +6658,34 @@ } } % For the purposes of the serial comma, and thus for the - % distinction of 'lastsep' and 'pairsep', a "range" counts - % as one. Since 'range_beg' has already been counted + % distinction of `lastsep' and `pairsep', a "range" counts + % as one. Since `range_beg' has already been counted % (here or with the first of type), we refrain from - % incrementing 'ref_count_int'. - \tl_put_right:Nx \l_@@_typeset_queue_curr_tl + % incrementing `ref_count_int'. + \bool_lazy_and:nnTF + { ! \tl_if_empty_p:N \l_@@_endrangefunc_tl } + { \cs_if_exist_p:c { \l_@@_endrangefunc_tl :VVN } } { - \exp_not:V \l_@@_rangesep_tl - \@@_get_ref:VN \l_@@_label_a_tl - \l_@@_refbounds_mid_re_seq + \use:c { \l_@@_endrangefunc_tl :VVN } + \l_@@_range_beg_label_tl + \l_@@_label_a_tl + \l_@@_range_end_ref_tl + \tl_put_right:Nx \l_@@_typeset_queue_curr_tl + { + \exp_not:V \l_@@_rangesep_tl + \@@_get_ref_endrange:VVN + \l_@@_label_a_tl + \l_@@_range_end_ref_tl + \l_@@_refbounds_mid_re_seq + } + } + { + \tl_put_right:Nx \l_@@_typeset_queue_curr_tl + { + \exp_not:V \l_@@_rangesep_tl + \@@_get_ref:VN \l_@@_label_a_tl + \l_@@_refbounds_mid_re_seq + } } } } @@ -5599,7 +6747,8 @@ % \begin{macro}{\@@_get_ref:nN} % Handles a complete reference block to be accumulated in the ``queue'', % including refbounds, and hyperlinking. For use with all labels, except -% the first of its type, which is done by \cs{@@_get_ref_first:}. +% the first of its type, which is done by \cs{@@_get_ref_first:}, and the +% last of a range, which is done by \cs{@@_get_ref_endrange:nnN}. % \begin{syntax} % \cs{@@_get_ref:nN} \Arg{label} \Arg{refbounds} % \end{syntax} @@ -5648,6 +6797,53 @@ % \end{macrocode} % \end{macro} % +% \begin{macro}{\@@_get_ref_endrange:nnN} +% \begin{syntax} +% \cs{@@_get_ref_endrange:nnN} \Arg{label} \Arg{reference} \Arg{refbounds} +% \end{syntax} +% \begin{macrocode} +\cs_new:Npn \@@_get_ref_endrange:nnN #1#2#3 + { + \str_if_eq:nnTF {#2} { zc@missingproperty } + { \@@_ref_default: } + { + \bool_if:nTF + { + \l_@@_hyperlink_bool && + ! \l_@@_link_star_bool + } + { + \exp_not:N \group_begin: + \exp_not:V \l_@@_reffont_tl + \seq_item:Nn #3 { 1 } + % It's two `@s', but escaped for DocStrip. + \exp_not:N \hyper@@@@link + { \@@_extract_url_unexp:n {#1} } + { \@@_extract_unexp:nnn {#1} { anchor } { } } + { + \seq_item:Nn #3 { 2 } + \exp_not:n {#2} + \seq_item:Nn #3 { 3 } + } + \seq_item:Nn #3 { 4 } + \exp_not:N \group_end: + } + { + \exp_not:N \group_begin: + \exp_not:V \l_@@_reffont_tl + \seq_item:Nn #3 { 1 } + \seq_item:Nn #3 { 2 } + \exp_not:n {#2} + \seq_item:Nn #3 { 3 } + \seq_item:Nn #3 { 4 } + \exp_not:N \group_end: + } + } + } +\cs_generate_variant:Nn \@@_get_ref_endrange:nnN { VVN } +% \end{macrocode} +% \end{macro} +% % \begin{macro}{\@@_get_ref_first:} % Handles a complete reference block for the first label of its type to be % accumulated in the ``queue'', including ``pre'' and ``pos'' elements, @@ -5738,7 +6934,7 @@ \exp_not:V \l_@@_reffont_tl \seq_item:Nn \l_@@_type_first_refbounds_seq { 1 } - % It's two '@s', but escaped for DocStrip. + % It's two `@s', but escaped for DocStrip. \exp_not:N \hyper@@@@link { \@@_extract_url_unexp:V @@ -6071,14 +7267,9 @@ % \begin{macrocode} \cs_new_protected:Npn \@@_labels_in_sequence:nn #1#2 { - \@@_extract_default:Nnnn \l_@@_label_extdoc_a_tl - {#1} { externaldocument } { } - \@@_extract_default:Nnnn \l_@@_label_extdoc_b_tl - {#2} { externaldocument } { } - - \tl_if_eq:NNT - \l_@@_label_extdoc_a_tl - \l_@@_label_extdoc_b_tl + \exp_args:Nxx \tl_if_eq:nnT + { \@@_extract_unexp:nnn {#1} { externaldocument } { } } + { \@@_extract_unexp:nnn {#2} { externaldocument } { } } { \tl_if_eq:NnTF \l_@@_ref_property_tl { page } { @@ -6123,8 +7314,14 @@ = { \@@_extract:nnn {#2} { zc@cntval } { -1 } } { - \bool_set_true:N - \l_@@_next_maybe_range_bool +% \end{macrocode} +% If \texttt{zc@counter}s are equal, \texttt{zc@enclval}s are equal, and +% \texttt{zc@enclval}s are equal, but the references themselves are different, +% this means that \cs{@currentlabel} has somehow been set manually (e.g. by an +% \pkg{amsmath}'s \cs{tag}), in which case we have no idea what's in there, +% and we should not even consider this is still a range. If they are equal, +% though, of course it is a range, and it is the same. +% \begin{macrocode} \exp_args:Nxx \tl_if_eq:nnT { \@@_extract_unexp:nvn {#1} @@ -6135,6 +7332,8 @@ { l_@@_ref_property_tl } { } } { + \bool_set_true:N + \l_@@_next_maybe_range_bool \bool_set_true:N \l_@@_next_is_same_bool } @@ -6720,9 +7919,10 @@ % and subsequent discussion. So, for \env{subequations}, we really must % specify manually \opt{currentcounter} and the resetting. Note that, for % \env{subequations}, \cs{zlabel} works just fine (that is, if given -% immediately after \texttt{\\begin\{subequations\}}, to refer to the -% parent equation). +% immediately after \texttt{\textbackslash{}begin\{subequations\}}, to refer +% to the parent equation). % \begin{macrocode} + \bool_new:N \l_@@_amsmath_subequations_bool \AddToHook { env / subequations / begin } { \@@_zcsetup:x @@ -6736,6 +7936,7 @@ currentcounter = parentequation , countertype = { parentequation = equation } , } + \bool_set_true:N \l_@@_amsmath_subequations_bool } % \end{macrocode} % \pkg{amsmath} does use \cs{refstepcounter} for the \texttt{equation} counter @@ -6750,8 +7951,12 @@ % environments ``must appear within an enclosing math environment''. Same % logic applies to other environments defined or redefined by the package, % like \env{array}, \env{matrix} and variations. Finally, \env{split} too can -% only be used as part of another environment. +% only be used as part of another environment. We also arrange, at this +% point, for the provision of the \texttt{subeq} property, for the convenience +% of referring to them directly or to build terse ranges with the +% \opt{endrange} option. % \begin{macrocode} + \zref@newprop { subeq } { \alph { equation } } \clist_map_inline:nn { equation , @@ -6771,7 +7976,11 @@ } { \AddToHook { env / #1 / begin } - { \@@_zcsetup:n { currentcounter = equation } } + { + \@@_zcsetup:n { currentcounter = equation } + \bool_if:NT \l_@@_amsmath_subequations_bool + { \zref@localaddprop \ZREF@mainlist { subeq } } + } } % \end{macrocode} % And a last touch of care for \pkg{amsmath}'s refinements: make the equation @@ -6867,6 +8076,7 @@ % for incrementing the equation counters (see % \url{https://tex.stackexchange.com/a/241150}). % \begin{macrocode} + \bool_new:N \l_@@_breqn_dgroup_bool \AddToHook { env / dgroup / begin } { \@@_zcsetup:x @@ -6880,7 +8090,11 @@ currentcounter = parentequation , countertype = { parentequation = equation } , } + \bool_set_true:N \l_@@_breqn_dgroup_bool } + \zref@ifpropundefined { subeq } + { \zref@newprop { subeq } { \alph { equation } } } + { } \clist_map_inline:nn { dmath , @@ -6889,7 +8103,11 @@ } { \AddToHook { env / #1 / begin } - { \@@_zcsetup:n { currentcounter = equation } } + { + \@@_zcsetup:n { currentcounter = equation } + \bool_if:NT \l_@@_breqn_dgroup_bool + { \zref@localaddprop \ZREF@mainlist { subeq } } + } } \msg_info:nnn { zref-clever } { compat-package } { breqn } } @@ -7154,6 +8372,7 @@ type = page , Name-pl = Pages , name-pl = pages , rangesep = {\textendash} , + rangetopair = false , type = line , Name-sg = Line , @@ -7436,6 +8655,7 @@ type = page , Name-sg = Seite , Name-pl = Seiten , rangesep = {\textendash} , + rangetopair = false , type = line , gender = f , @@ -7853,6 +9073,7 @@ type = page , Name-pl = Pages , name-pl = pages , rangesep = {-} , + rangetopair = false , type = line , gender = f , @@ -8094,6 +9315,7 @@ type = page , Name-pl = Páginas , name-pl = páginas , rangesep = {\textendash} , + rangetopair = false , type = line , gender = f , @@ -8333,6 +9555,7 @@ type = page , Name-pl = Páginas , name-pl = páginas , rangesep = {\textendash} , + rangetopair = false , type = line , gender = f , @@ -8566,6 +9789,7 @@ type = page , Name-pl = Pagina's , name-pl = pagina's , rangesep = {\textendash} , + rangetopair = false , type = line , gender = m , -- cgit v1.2.3