# Comparing linenumbers derived from \linelabel as numeric variables in XeTeX

I have a document with transcripts of interviews and I'd like to automate the process of getting the right linenumbers as a reference. So compiling with XeTeX I use \linelabel in a lineno environment to mark the beginning and the end of the reference. I worked that part out.

But I also want to just print the first label, when the linenumbers are the same. Here is an example of what I'm trying to do:

\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}


As you can see the two numbers are not recognized as the same. It should just say "(transcript: 1)". Is there a way to do this?

## 1 Answer

The usual \ref command is unexpandable -- the macro \pdf@strcmp won't work here in order to test whether the line numbers are equal.

Use the refcount package and its \getrefnumber macro for example and switch from \test{\ref{begin}}{\ref{end}} to \test{begin}{end}. This prevents tedious writing of \ref each time as well.

\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}


• @BerndMi: You're welcome. Happy TeXing! – user31729 May 31 '17 at 19:22