![无需标记即可轻松引用本地示例和方程式](https://linux22.com/image/414110/%E6%97%A0%E9%9C%80%E6%A0%87%E8%AE%B0%E5%8D%B3%E5%8F%AF%E8%BD%BB%E6%9D%BE%E5%BC%95%E7%94%A8%E6%9C%AC%E5%9C%B0%E7%A4%BA%E4%BE%8B%E5%92%8C%E6%96%B9%E7%A8%8B%E5%BC%8F.png)
撰写语言文本时,人们通常只引用前面或后面的例子。通常不需要为此添加标签。我希望 (\mex{1}) 引用更像使用标签的引用,并使它们像 \ref 与 hyperref 连接一样超链接。这可能吗?目前,makro\mex
不考虑枚举的示例。因此 a、b 和 c 不是引用的一部分。我只是手写它们。有没有一种巧妙的方法可以将引用集成到子示例中?
\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
这是部分答案:我自动为每个示例设置一个标签。我想我应该包括章节信息,如果章节重置了示例计数器。
我至今还没有解决的是子示例 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}