I would like to modify the following personal cross-reference macro (the initial idea comes from the question: macro supra/infra using zlabel).
% !TEX encoding = UTF-8 Unicode
% !TEX program = lualatex
\documentclass{article}
\usepackage{polyglossia}
\setmainlanguage{italian}
\usepackage{zref-vario}
\usepackage{varioref}
\usepackage{lipsum}
\usepackage{hyperref}
\newcounter{labelcount}
\AddToHook{cmd/zlabel/before}{\stepcounter{labelcount}}
\makeatletter
\ExplSyntaxOn
\zref@newprop{labelcount}{\arabic{labelcount}}
\zref@addprop{main}{labelcount}
\cs_new:Npn \suprainfra_text:n #1
{
\int_compare:nNnF { \clist_count:n {#1} } > { 1 }
{
\int_compare:nNnTF
{ \arabic{labelcount} }
<
{ \zref@extractdefault {#1} {labelcount} {0} }
{ infra }
{ supra }
}
}
\cs_new_protected:Npn \tl_zcref_ref:n #1 { \zcref{#1} }
\cs_new_protected:Npn \tl_zcref_page:n #1 { \zvpageref{#1} }
\keys_define:nn {option}
{
type .choice: ,
type / ref .code:n = \tl_set:Nn \l__option_type_tl {\tl_zcref_ref:n} ,
type / page .code:n = \tl_set:Nn \l__option_type_tl {\tl_zcref_page:n} ,
type .initial:n = page ,
ref .meta:n = { type = ref } ,
ref .value_forbidden:n = true ,
}
\bool_new:N \l__option_parent_bool
\keys_define:nn {option}
{
parent .bool_set:N = \l__option_parent_bool ,
parent .initial:n = true ,
noparent .meta:n = { parent = false } ,
noparent .value_forbidden:n = true ,
}
\cs_new_protected:Npn \ts_suprainfra_text_type_noparent:nn #1#2
{ \emph { \suprainfra_text:n {#2} }, ~ \l__option_type_tl {#2} }
\cs_new_protected:Npn \ts_suprainfra_text_type_parent:nn #1#2
{ ( \ts_suprainfra_text_type_noparent:nn {#1}{#2} ) }
\cs_new_protected:Npn \ts_suprainfra:nn #1#2
{
\group_begin:
\keys_set:nn {option} {#1}
\bool_if:NTF \l__option_parent_bool
{ \ts_suprainfra_text_type_parent:nn {#1}{#2} }
{ \ts_suprainfra_text_type_noparent:nn {#1}{#2} }
\group_end:
}
\NewDocumentCommand {\supinf} {O{} m}
{ \ts_suprainfra:nn {#1} {#2} }
\ExplSyntaxOff
\makeatother
\begin{document}
\section{First Section}\zlabel{sec1}
\lipsum[1][1-4]
\section{Second Section}
\verb|\supinf[type=ref]{sec1}|\quad \supinf[type=ref]{sec1}
\par\medskip
\verb|\supinf[type=page]{sec1}|\quad \supinf[type=page]{sec1}
\par\medskip
\verb|\supinf{sec3}|\quad \supinf{sec3}
\par\medskip
\verb|\supinf[ref]{sec3}|\quad \supinf[ref]{sec3}
\par\medskip
\verb|\supinf[noparent]{sec3}|\quad \supinf[noparent]{sec3}
\par\medskip
\verb|\supinf[noparent,ref]{sec3}|\quad \supinf[noparent,ref]{sec3}
\section{Third Section}\zlabel{sec3}
\lipsum[2][1-4]
\end{document}
The macro \supinf
takes two optional parameters: type=ref|page
and parent=true|false
.
type
parameter call \zcref
function (by zref-clever
package) and \zvpageref
function (by zref-vario
package).
Now I would like to implement two things that I cannot do independently:
- a
\supinf*
(starred) version, depending on\zcref*
and\zvpageref*
; - modify some default terms about italian localization (the changes should only apply within the personal macro), as followed:
zref-clever
italian term:- type = chapter
- name-sg|name-pl = cap.
- type = section
- name-sg|name-pl = §
- type = page
- name-sg|name-pl = p.
- type = footnote|endnote|note
- name-sg|name-pl = n.
- type = chapter
zref-vario
italian expressions:- reftextfaceafter = {\zvhyperlink{p. a fianco}}
- reftextfacebefore = {\zvhyperlink{p. a fianco}}
- reftextafter = {\zvhyperlink{p. successiva}}
- reftextbefore = {\zvhyperlink{p. successiva}}
- reftextcurrent = {\zvhyperlink{p. corrente}}
- reftextfaraway = {\zcpageref{#1}}
- reftextpagerange = {\zcpageref[range]{#1,#2}}
- reftextlabelrange = {\zcref[range]{#1,#2}}
Finally, I am fully aware that my code does not respect expl3 conventions, but I could not do better :-) I would be grateful if anyone would give me suggestions.
\zcref
, so you loose the ability to control\zcref
. For the sake of having an option that controls a parenthesis wrapping, and such?\zcref
options.