# Change from old style numbers to lining numbers in lineno's linenumbers environment

I am using old style numbers in my document, but I prefer lining numbers in my line numbering environments (lineno's \linenumbers environment). How can I enforce this (without changing to another font)?

\documentclass{article}
\usepackage{fontspec,lineno}
\setmainfont[Numbers=OldStyle]{Linux Libertine O}
\renewcommand\linenumberfont{\normalfont\scriptsize\rmfamily}

\begin{document}
\begin{linenumbers}
\noindent Continual delighted\linelabel{1stword} as elsewhere am convinced unfeeling. Introduced stimulated attachment no by projection. To loud lady whom my mile sold four. Need miss all four case fine age tell. He families my pleasant speaking it bringing\linelabel{2ndword} it thoughts. View busy dine oh in knew if even. Boy these along far own other equal old fanny charm. Difficulty invitation put introduced\linelabel{3rdword} see middletons nor preference.
\end{linenumbers}
\vspace{\baselineskip}
\noindent I like the words I find in line \lineref{1stword}, \lineref{2ndword}, and \lineref{3rdword}.
\end{document}


-
Hint: define a custom environment wrapping the linenumbers and changing font to new, with desired numbers style. –  m0nhawk Apr 6 '13 at 15:53
I'm afraid I'm not savvy enough to be able to know what to do with hints like that. –  Sverre Apr 6 '13 at 15:58

To just change the numbers, use the fontspec command \addfontfeatures{Numbers={Lining, Monospaced}} (see section 10.3 of the fontspec manual). (You probably don’t even need to specify Monospaced, but it doesn’t hurt to specify it.) \normalfont and \rmfamily aren’t necessary either.

\documentclass{article}
\usepackage{fontspec,lineno}
\setmainfont[Numbers=OldStyle]{Linux Libertine O}

\begin{document}
\begin{linenumbers}
\noindent Continual delighted\linelabel{1stword} as elsewhere am convinced unfeeling.
Introduced stimulated attachment no by projection. To loud lady whom my mile sold
four. Need miss all four case fine age tell. He families my pleasant speaking it
bringing\linelabel{2ndword} it thoughts. View busy dine oh in knew if even. Boy these
along far own other equal old fanny charm. Difficulty invitation put
introduced\linelabel{3rdword} see middletons nor preference.
\end{linenumbers}
\vspace{\baselineskip}
\noindent I like the words I find in line \lineref{1stword}, \lineref{2ndword}, and
\lineref{3rdword}.
\end{document}


-
Works. Answer accepted. Is there a convention of having monospaced characters in line numbers? –  Sverre Apr 6 '13 at 16:42
@Sverre Not that I know of; however, there is sort of a convention to use monospaced numbers/digits in tables (just so that everything vertically aligns neatly), and the line numbers seemed to be table-like enough for me. Note that I didn’t check if monospaced numbers would’ve been used at any rate (i.e. without me specifying), it actually seems to be like that. One way or the other, I’d expect this to look better, especially once you get into the double- and triple-digit ranges. –  doncherry Apr 6 '13 at 16:46

For Type 1 font (pdflatex) users the following would work:

\documentclass{article}
\usepackage[osf]{libertine}
\usepackage[T1]{fontenc}
\usepackage{lineno}

\renewcommand\linenumberfont{\fontfamily{LinuxLibertineT-TLF}\scriptsize\selectfont}

\begin{document}
\begin{linenumbers}
\noindent Continual delighted\linelabel{1stword} as elsewhere am convinced unfeeling. Introduced stimulated attachment no by projection. To loud lady whom my mile sold four. Need miss all four case fine age tell. He families my pleasant speaking it bringing\linelabel{2ndword} it thoughts. View busy dine oh in knew if even. Boy these along far own other equal old fanny charm. Difficulty invitation put introduced\linelabel{3rdword} see middletons nor preference.
\end{linenumbers}
\vspace{\baselineskip}
\noindent I like the words I find in line \lineref{1stword}, \lineref{2ndword}, and \lineref{3rdword}.
\end{document}

-
And for fontspec users? :) –  Sverre Apr 6 '13 at 16:12
@Sverre I am a LaTeX oldtimer, I don't have the slightest clue how that newfangled stuff works ;-) –  mafp Apr 6 '13 at 16:14
@Sverre I tested with lmr instead of that Linux font and it works! –  Sigur Apr 6 '13 at 16:17
@Sigur: I don't understand. –  Sverre Apr 6 '13 at 16:22
@mafp I guess not explicitly, even though the question does call for fontspec. Pehaps you could complement the code in your answer to a full MWE and make it really obvious that this is a pdfLaTeX solution? Then we’d actually have covered all of our bases. –  doncherry Apr 6 '13 at 16:57