1

Writing linguistic texts one often just refers to the preceeding or following example. Usually one does not need labels for this. I would like the (\mex{1}) references to behave more like references using labels and make them hyperlinked like \ref is in connection with hyperref. Is this possible? Right now, the makro \mex does not take the enumerated examples into account. So a, b, and c are not part of the referencing. I just write them down by hand. Is there a clever way to integrated reference to subexamples?

\documentclass{article}

\usepackage{langsci-gb4e}

\makeatletter
\newcommand{\mex}[1]{\the\numexpr\c@equation+#1\relax}
\makeatother


\begin{document}

This is some text referring to example (\mex{1}):
\ea
Test examples are always fun!
\z
As the existance of examples like (\mex{0}) shows.

There are even more complicated cases with enummerations of examples:
\eal
\ex This is the first example.
\ex This is the second example.
\zl
The example in (\mex{0}a) is similar to the one in (\mex{0}b).


\end{document}
  • 1
    The manual says: "In all cases, \label/\ref commands will do The Right Thing." I tried it out on your code, and indeed it does. Very impressive. What do you want the \mex command to do? Refer to last/current item in last/current list? – Cicada May 17 at 15:10
  • Yes, I am overwhelmed by \label/\ref and how good it works everyday. =:-) But I also love my hands and hate writing. (\mex{1}) refers to the next equation (\mex{2}) to the second forthcoming example and (\mex{0}) to the previous one. (\mex{-1}) to the penultimate one. I use labels when referring to an example from far away but locally I use \mex. – Stefan Müller May 18 at 12:37
0

This is a partial answer: I set a label for every example automatically. I guess I should include chapter information, if the chapter resets the example counter.

What I did not solve so far is the subexamples, a., b., c.:

\documentclass{article}

\usepackage{langsci-gb4e}

\makeatletter
\newcommand{\mex}[1]{\ref{ex-\the\numexpr\c@equation+#1}\relax}
\newcommand{\eaautolabel}{\label{ex-\the\numexpr\c@equation+1}}
\makeatother

\let\oldea\ea
\def\ea{\oldea\eaautolabel}

\let\oldeal\eal
\def\eal{\oldeal\eaautolabel}

\usepackage{hyperref}

\begin{document}

This is some text referring to example (\mex{1}):
\ea
Test examples are always fun!
\z
As the existance of examples like (\mex{0}) shows.

There are even more complicated cases with enummerations of examples:
\eal
\ex This is the first example.
\ex This is the second example.
\zl
The example in (\mex{0}a) is similar to the one in (\mex{0}b).


\end{document}
| improve this answer | |
  • tex.stackexchange.com/questions/101832/… may help. enumi, enumii, enumiii and enuniv are the counters for enumerate environments in the standard classes. gb4e's definition of the counter used by \ex needs to be known. – Cicada May 19 at 12:13
  • gb4e.sty, lines 214ff: xnumi, xnumii, etc. But \thexnumi etc are being set to typeset forms. Tricky. – Cicada May 19 at 13:07

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.