我在写作中经常使用 linguex,有时我想引用一个示例的多个部分。
\ex. \label{X}
\a. This is an example \label{Xa}
\b. This is another example \label{Xb}
\b. yae \label{Xc}
The examples in \ref{Xa} and \ref{Xb} and more awesomer than \ref{Xc}.
这产生...
The examples in (1a) and (1b) are more awesomer than (1c).
不过,如果我能做类似的事情就好了......
The examples in \ref{Xa,Xb} are more awesomer than \ref{Xc}.
...输出...
The examples in (1a-b) are more awesomer than (1c).
我在文档中没有看到任何类似的东西。我如何获得此输出?
答案1
您可以使用cleveref
包来实现这一点。cleveref
允许您定义非常复杂的标签格式,包括范围。该linguex
包使用两个计数器来表示示例和子示例。在下面的示例中,我压缩了子示例范围,而主示例范围未压缩,但这可以轻松更改。
\documentclass{article}
\usepackage{linguex}
\usepackage{cleveref}
\crefname{ExNo}{}{}
\crefname{SubExNo}{}{}
\renewcommand{\theExNo}{\arabic{ExNo}}
\renewcommand{\theSubExNo}{\theExNo\alph{SubExNo}}
\creflabelformat{SubExNo}{(#2#1#3)}
\creflabelformat{ExNo}{(#2#1#3)}
\crefrangelabelformat{SubExNo}{(#3#1#4--#5\crefstripprefix{#1}{#2}#6)}
\crefrangelabelformat{ExNo}{(#3#1#4)--(#5#2#6)}
\begin{document}
\ex.\label{Y}
\ag.
Dette er ein test paa nynorsk.\\
This is a test in Nynorsk\\
\trans `This is a test in Nynorsk.'
\bg.
Dies ist ein Test auf Deutsch.\\
This is a test in German\\
\trans `This is a test in German.'
\c. An single example.
\c. Another example.
\ex. An example.
\ex. Another example.
\ex. \label{X}
\a. This is an example \label{Xa}
\b. This is another example \label{Xb}
\b. A third example \label{Xc}
The examples in \crefrange{Xa}{Xb} are more awesome than \cref{Xc}. In examples \crefrange{Y}{X} we can see lots of things.
\end{document}