For extracting the ordinal representation of a line number, you can set a \linelabel
and retrieve it using a combination of regular \getrefnumber
(from refcount
; to avoid extracting it to a counter) and \ordinalnum
(from fmtcount
).
\documentclass{article}
\usepackage{lineno,refcount,fmtcount,xcolor}
\setlength{\parindent}{0pt}
\renewcommand{\thelinenumber}{-\arabic{linenumber}-}
\renewcommand{\theLineNumber}{\arabic{linenumber}}
\newcounter{linecntr}
\newcommand{\ordinalline}{%
\stepcounter{linecntr}%
\begingroup\edef\x{\endgroup\noexpand\linelabel{linecntr-\thelinecntr}}\x%
\textcolor{red}{\ordinalstringnum{\getrefnumber{linecntr-\thelinecntr}}}}
\begin{document}
\linenumbers
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed dapibus
facilisis magna, id sodales ante convallis vitae. In a porttitor nibh,
We are in the \ordinalline{} line.
eget vehicula dui. Integer feugiat dui nec neque porttitor, non eleifend
erat lobortis. Sed varius malesuada nisi, id vulputate ante commodo vitae.
Nam non felis at ante mollis commodo eget porttitor ex. Donec in quam diam.
We are in the \ordinalline{} line.
Maecenas fringilla, turpis a egestas pulvinar, massa lacus molestie enim,
vel vulputate lorem ante ac velit. Nam ex nulla, venenatis et tortor at,
We are in the \ordinalline{} line.
efficitur fringilla ante.
\end{document}
\thepage
, which is not fully known at the time of setting it. From thelineno
user manual: "Whenever you want to attach something to your text, after a paragraph was broken into lines, across pagebreaks,lineno
may do the job." Since you're using\\
to denote a line-break, the paragraph has not been broken into lines. This only happens with the occurrence of\par
or a blank line. What about a\label
-\ref
to extract the correct number?\ifnum
like this\ifnum\value{linenumber}=2 we are in the second line \fi