无需标记即可轻松引用本地示例和方程式

无需标记即可轻松引用本地示例和方程式

撰写语言文本时,人们通常只引用前面或后面的例子。通常不需要为此添加标签。我希望 (\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}

相关内容