TransWikia.com

Easy way to refer to local examples and equations without labeling them

TeX - LaTeX Asked by Stefan Müller on November 11, 2020

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]{thenumexprc@equation+#1relax}
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}

One Answer

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-thenumexprc@equation+#1}relax}
newcommand{eaautolabel}{label{ex-thenumexprc@equation+1}}
makeatother

letoldeaea
defea{oldeaeaautolabel}

letoldealeal
defeal{oldealeaautolabel}

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}

Answered by Stefan Müller on November 11, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP