2

Question: Is there some way to accomplish a \getpageref equivalent of \getref and \getfullpageref equivalent of \getfullref in expex?

Background: I have a lengthy document which uses expex for hundreds of examples. Currently, I am using the expex notation for all examples where the label immediately follows \ex or \pex inside angle brackets i.e. <>. None of these examples uses \label, and so I reference examples using \getfullref.

For a sizeable number of examples, I repeat the example several chapters later and want to reference back to the original using this notation: [(EXNUM), repeated from p. PNUM]

Referencing the example number is not an issue. However, I realized that \pageref cannot recognize ExPex's tags. For example:

\documentclass{article}

\usepackage{expex}

\begin{document}
\ex<expex item>
    \gla test //
    \glft test //
\xe

\getfullref{expex item}

\pageref{expex item}
\end{document}

Will produce 1 and ??, as in the image:

comparison of ExPex example with \getfullref and \pageref

You can solve this by changing \ex<expex item> to \ex<expex item>\label{expex item}. Such as:

\ex<expex item>\label{expex item}
   \gla test //
   \glft test //
\xe

However, there are some reasons why I would prefer hooking into ExPex's system instead, if possible.

  • I have many of these cross-referenced examples. It is not an arbitrary task of adding \label{...} in only a few cases, as you might in a smaller document
  • In principle, it seems like there should be way to also its page number, just like the \label+\ref+\pageref system allows for.

The ExPex package documentation on pp. 60-66 discusses references. However, I can only find hard-coded page numbers in the documentation. So, you lose some benefit of the built-in expex system if you only use \label (discussed on p. 66 under Support for the LaTex \label and \ref commands) or have redundancy issues. It's also problematic to retro-fit large documents which didn't originally use the \label approach. You also need multiple labels in \pex, if you only want to refer to part B, C, D, etc. (which becomes relevant when page breaks occur).

In case it is relevant, my actual document uses hyperref and cleveref packages. I did not include these in the example, because they behavior is identical for me. However, if one of these packages can hook in to the page number, that would also work.

-- Edit --

My example was slightly unclear because I only provided \ex, but not \pex. I hope that any approach can also apply to part A, B, C, etc. in a multipart \pex. Here is an example (with the current patch provided in @ulrike-fischer's answer):

\documentclass{article}

\usepackage{expex}
\usepackage{etoolbox}
\pretocmd\deftag{\label{#2}}{}{\fail}

\begin{document}
    \ex<ex item>
        \gla test //
        \glft test //
    \xe

    Reference:
    \getfullref{ex item} on p. \pageref{ex item}

    \pex<pex item>
        \a<A> test2 //
        \a<B> test3 //
    \xe

    General reference:
    \getfullref{pex item} on p. \pageref{pex item}

    A reference:
    \getfullref{pex item.A} on p. \pageref{pex item.A}

    B reference:
    \getfullref{pex item.B} on p. \pageref{pex item.B}
\end{document}

The result is:

Unresolved references to part A and B in \pex

The original question still applies, but I wanted to clarify that I hope an answer can also hook into these parts and not only the example number.

1
\documentclass{article}

\usepackage{expex}
\usepackage{etoolbox}
\pretocmd\deftag{\label{#2}}{}{\fail}

\begin{document}

\ex<expex item>
\begingl
    \gla test //
    \glft blub //
\endgl
\xe

\getfullref{expex item}

\pageref{expex item}
\end{document}

enter image description here

  • Thanks, I hadn't thought about patching. This only works for \ex, however. I realize I should have explicitly included a \pex in the example also - I will update it. Is there a similar patch that can do the same in multipart \pex examples? For example, \a<B> and referring to it via \pageref{expex item.B}? – whatisit Sep 26 '19 at 17:27
  • Sorry, I mean that it works for \ex and \pex, but does not work for part A, B, C, etc. within \pex. I have updated the question and provided an image with both. You can see \pageref still cannot hook into those parts. Could you also provide a brief explanation in your answer how it copies the ExPex label into \label via \deftag? It might be useful for someone else in the future. – whatisit Sep 26 '19 at 17:50
  • Don't edit your question so that it makes my answer invalid. That is rather unfair. Ask a new question instead. – Ulrike Fischer Sep 26 '19 at 18:05
  • Your answer did manage to work for the provided code, however it did not completely answer the question. It works for \getref but not \getfullref. The problem was that my example was incomplete for my question. I also mentioned this in my paragraph about the ExPex documentation. I apologize for the original omission in the code. – whatisit Sep 26 '19 at 18:57
  • Could you please add the following to your answer? Patching \ep@putlabel@b command by replacing \deftaglabel{\@optionaltag} with \label{\@localextag.\@optionaltag}\deftaglabel{\@optionaltag}. Using both patches, \getfullref works in all situations. – whatisit Sep 30 '19 at 17:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.