我正在尝试使用以下命令完成这项工作Linguex
:
https://tex.stackexchange.com/a/360869/262813
但我总是得到“基础设施“。
\documentclass{report}
\usepackage{linguex}
\usepackage{etoolbox}
% Relative References
\newcommand*{\detectrel}{}
\makeatletter
\newcommand*{\rlabel}[1]{%
\@bsphack%
\label{#1}%
\listadd{\detectrel}{#1}%
\@esphack%
}%
\makeatother
\newcommand*{\supinf}[1]{%
\ifinlist{#1}{\detectrel}%
{\textit{supra}}%
{\textit{infra}}}%
\newcommand*{\relref}[1]{\ref{#1}~\supinf{#1}}
\begin{document}
See \relref{ex} and \relref{subex}.
\ex. First example. \rlabel{ex}
\a. First subexample. \rlabel{subex}
See \relref{ex} and \relref{subex}.
\vspace{6pt}
More text.
\vspace{6pt}
See \relref{ex} and \relref{subex}.
\end{document}
答案1
感谢@Ulrike Fischer,我现在知道我应该使用它\listgadd
来赋予列表一个全局范围。
\documentclass{report}
\usepackage{linguex}
\usepackage{etoolbox}
% Relative References
\newcommand*{\detectrel}{}
\makeatletter
\newcommand*{\rlabel}[1]{%
\@bsphack%
\label{#1}%
\listgadd{\detectrel}{#1}% !! Here is the thing, use \listgadd, not \listadd.
\@esphack%
}%
\makeatother
\newcommand*{\supinf}[1]{%
\ifinlist{#1}{\detectrel}%
{\textit{supra}}%
{\textit{infra}}}%
\newcommand*{\relref}[1]{\ref{#1}~\supinf{#1}}
\begin{document}
See \relref{ex} and \relref{subex}.
\ex. First example. \rlabel{ex}
\a. First subexample. \rlabel{subex}
See \relref{ex} and \relref{subex}.
\vspace{6pt}
More text.
\vspace{6pt}
See \relref{ex} and \relref{subex}.
\end{document}