我有一份包含采访记录的文档,我想自动获取正确的行号作为参考。因此,我\linelabel
在lineno
环境中使用 XeTeX 进行编译,以标记参考的开始和结束。我解决了这一部分。
但是当行号相同时,我也想只打印第一个标签。下面是我想做的一个示例:
\documentclass{scrartcl}
\usepackage{lineno}
\usepackage{pdftexcmds}
\makeatletter
\newcommand*{\test}[2]{%
\ifnum\pdf@strcmp{\unexpanded{#1}}{\unexpanded{#2}}=0 #1\else #1--#2\fi
}
\makeatother
\begin{document}
\section{Text}
This text is derived from the transcript:
example of some transcript (transcript: \test{\ref{begin}}{\ref{end}}).
\section{Transcript}
\begin{linenumbers}
This is the \linelabel{begin} example of some transcript\linelabel{end}
that is going to have linenumbers. I want to get the beginning position
of a certain citation and the ending position of the very same citation.
\end{linenumbers}
\end{document}
如您所见,这两个数字没有被识别为相同。它应该只是显示“(transcript: 1)”。有办法吗?
答案1
通常的\ref
命令是不可扩展的——宏\pdf@strcmp
在这里不起作用,无法测试行号是否相等。
使用refcount
包及其\getrefnumber
宏作为示例,并从切换\test{\ref{begin}}{\ref{end}}
到。这也\test{begin}{end}
可以避免每次繁琐的书写。\ref
\documentclass{scrartcl}
\usepackage{lineno}
\usepackage{refcount}
\usepackage{pdftexcmds}
\newcommand*{\test}[2]{%
\ifnum\getrefnumber{#1}=\getrefnumber{#2}%
\ref{#1}%
\else
\ref{#1}--\ref{#2}%
\fi
}
\begin{document}
\section{Text}
This text is derived from the transcript:
example of some transcript (transcript: \test{begin}{end}).
However, see \test{begin}{otherend}.
\section{Transcript}
\begin{linenumbers}
This is the \linelabel{begin} example of some transcript\linelabel{end}
that is going to have linenumbers. I want to get the beginning position
of a certain citation and the ending position of the very same citation. \linelabel{otherend}
\end{linenumbers}
\end{document}