I tried the patching method in the link that you provided, but it did not work for me either. Also, I had a similar issue because I wanted to use \pageref
, but the solution provided only worked for \getref
and not \getfullref
also.
Fortunately, I was able to get both working by patching two commands: \deftag
and \ep@putlabel@b
.
The first is the one that fixes \getref
. The second is required for \getfullref
because it deals with each expex
part in \pex
...\xe
defined by \a
.
The key benefit here is what you were requesting: no need for \deftagex
or \deftaglabel
The fix I am providing gives you two options. First, you can create new commands to keep the old \getref
and \getfullref
functionality (This method is safer, but requires a find/replace wherever you want they hyperlinks). Second, you can globally patch the commands so that they will all behave with the hyperlinks. I present the first option in comments above the second option in this MWE:
\documentclass[11pt,twoside,openany,notitlepage]{book}
\usepackage{geometry}
\usepackage{graphicx}
\usepackage{expex}
\usepackage[table,xcdraw]{xcolor}
\gathertags
\usepackage{hyperref}
\usepackage{etoolbox}
\makeatletter
\pretocmd\deftag{\hypertarget{#2}{}\label{#2}}{}{\fail}%
\patchcmd{\ep@putlabel@b}
{\deftaglabel{\@optionaltag}}
{\hypertarget{\@localextag.\@optionaltag}{}\label{\@localextag.\@optionaltag}\deftaglabel{\@optionaltag}}
{}
{\fail}%
%% Version 1: SAFE method - new methods for hyperlinking
%\def\gethyperref#1{\hyperlink{#1}{\getref{#1}}}%
%\def\getfullhyperref#1{\hyperlink{#1}{\getfullref{#1}}}%
%% Version 2: UNSAFE - overwrite \getref and \getfull ref globally
\let\old@getref\getref
\def\getref#1{\hyperlink{#1}{\old@getref{#1}}}%
\let\old@getfullref\getfullref
\def\getfullref#1{\hyperlink{#1}{\old@getfullref{#1}}}%
\makeatother
\begin{document}
Here is a bunch of text! and now there's an example (getref=\getref{adj-predicates}) (getfullref=\getfullref{adj-predicates}). Next page has (getref=\getref{ex2}) and (getfullref=\getfullref{ex2.A})--(getfullref=\getfullref{ex2.B}).
\ex<adj-predicates>
\begingl
\gla This way please. //
\glft `Bitte hier entlang' \trailingcitation source //
\endgl
\xe
\clearpage
Here is another bit of text and one more example (getref=\getref{ex2}). (getfullref=\getfullref{ex2.A})--(getfullref=\getfullref{ex2.B}) is much better than (getref=\getref{adj-predicates}) on previous page.
\pex<ex2>
\a<A>
\begingl
\gla Oh no! //
\glft `Oh nein!' \trailingcitation source1 //
\endgl
\a<B>
\begingl
\gla I'm sorry! //
\glft `Es tut mir leid.' \trailingcitation source2 //
\endgl
\xe
\end{document}
Page one:
Page two:
If you don't want to use etoolbox
for whatever reason, you'll need to copy and paste the entire definitions for \deftag
and \ep@putlabel@b
from expex
and redefine them with the patches.
Lastly, I tested with XeLaTeX. The links worked for me in the default TeXworks (for MiKTeX), Adobe Acrobat, and SumatraPDF. I assume this should work in general, but I have not tested it exhaustively.