# Refer to a specific token of a cross-ref label / Clarifications on refcount and zref

First, before any downvoting, I am aware of the existence and content of this post https://tex.stackexchange.com/a/577464/262813 and let me point out that I am not asking this question out of nowhere, without having thought it through many times and having spent time on writing complete questions and answers.

I am a beginner and I really do not understand something, i.e. how to refer to one specific token of a reference having only one global label at your disposal.

Let's say you set a subexample which is numbered 2b.i, and you label it label-of-2bi; now if want my ref to print in the shape of i, skipping both first and second tokens, well, I'm sure it's quite simple, but I still do not get it.

All I understand is that the print string I seek is \theSubSubExNo or \theSubExNo, but those commands do not take arguments, they print the current value of the corresponding counter (\SubSubExNo and \SubExNo). What I need is to be able to refer to what their value was at a specific point. But I don't know how to assign labels to them. And package zref is far beyond my level of comprehension.

I believe I am seeing a solution, based on several answers and comments by @Ulrich Diez's so valuable help; it involves \getrefbykeydefault from package refcount.

I have read the documentation of the package about that valuable command, I know it takes 3 arguments, i.e. label, key, default, but I do not know what values I should assign to variables 2 and 3 (for example, in Ulrich's \KeepOnlyStuffBehindLastDot proposal, I can see that the third is a double question mark, I have absolutely no idea what this means).

I use linguex or linguex-based packages.

My previous interrogations :

MWE

\documentclass{report}
\usepackage{linguex}
\begin{document}
\ex. \label{lakintpur}
\a. \label{lakintpura}\a. Greg's intention was to overthrow the
government. \label{intention}
\b. Greg's purpose was to overthrow the government. \label{purpose}
\z.\b.\label{lakintpurb}\a. Greg intended to overthrow the
government. \label{intendv}
\b.*Greg purposed to overthrow the government. \label{purposev}

\textbackslash ref\{intention\} prints as \ref{intention} but I would like to print only (i) (if being discussing (1-a) extensively),
\vspace{1em}

or (as \textbackslash rfx from the package philex achieves) print (a.i) if being discussing (1) globally.

\end{document}



• With \getrefbykeydefault the default denotes the tokens to deliver in case referencing does not work out. E.g., because the corresponding referencing-label is not defined. So with ?? as default you get two question-marks in the text when using \getrefbykeydefault for attempting to reference a label where no corresponding \label-command is in the source code of your document. May 12 at 15:33
• With \getrefbykeydefault the key denotes which piece of data associated to the referencing-label you which to obtain. That could be the textual phrase denoting the page-number which you get via \pageref. That could be the textual phrase of what you get via \ref. That could be the name of the destination for the hyperlink which \ref/\pageref creates besides delivering textual phrase. May 12 at 15:41
• I could not understand, when reading the documentation, what "key" I should use for the sublevel or subsublevel. May 12 at 15:43
• Cross-references don't have such things as level/sublevel/subsublevel. In my answer to How to prevent reference to enumeration inside new environment? I tried to give an outline of how cross-referencing is implemented in LaTeX. May 12 at 15:47

If you look at the aux-file you can see that the label is stored like this:

\newlabel{intention}{{\hbox {(1-a-i)}}{1}}


While it is not impossible to extract the i from this, is not trivial how to do it and refcount can't help with it.

If you really want access to sub counters, you should use a more powerful reference system like zref that allows you to store and retrieve more values independently

\documentclass{report}
\usepackage{linguex}
\usepackage{zref-user}
\makeatletter
\zref@newprop{exno}{\arabic{ExNo}}
\zref@newprop{subexno}{\alph{SubExNo}}
\zref@newprop{subsubexno}{(\roman{SubSubExNo})}

\makeatother
\begin{document}
\ex. \zlabel{lakintpur}
\a. \zlabel{lakintpura}\a. Greg's intention was to overthrow the
government. \zlabel{intention}
\b. Greg's purpose was to overthrow the government. \zlabel{purpose}
\z.\b.\zlabel{lakintpurb}\a. Greg intended to overthrow the
government. \zlabel{intendv}
\b.*Greg purposed to overthrow the government. \zlabel{purposev}

\textbackslash ref\{intention\} prints as \zref[subsubexno]{intention} but I would like to print only (i)

Test: \zref{intention}, \zref[exno]{intention}, \zref[subexno]{intention}
\end{document}


• Now I can define whatever formats I want, such as \zref[exno]{#1}.\zref[subexno]{#1}. Is it possible to factorize? May 12 at 17:25
• sorry I don't know what you mean by factorize. You can define more properties, e.g. exno+subexno, you can also extract the values and make comparisions. May 12 at 17:33
• Sorry I meant put the #1 only once in common factor such as {\zref[exno].\zref[subexno]}{#1}. I guess this is basic LaTeX syntax but it just came to my mind. I guess I just have to define a combined property exno+subexno as you suggest. May 12 at 17:35
• No that won't work. But in a definition it shouldn't matter much that you have to repeat the #1. But as I said you can also define a new property \zref@newprop{exno+subexno}{\arabic{ExNo}.\alph{SubExNo}} and then use \zref[exno+subexno]{label}. May 12 at 17:38
• yes, zref is much easier to adapt then cleveref. You could also check ctan.org/pkg/zref-clever May 12 at 17:55