# lineno workaround reset impossible using pagewise/switch etc

I'm having a difficulty/impossibility with the lineno package. What I want to write is a book, so double-sided, with different sections each anew beginning at 1.

So the setup is quite simple and working well except for the reset to number 1.

\usepackage[switch*]{lineno}


and then, in the document:

\begin{linenumbers}
\modulolinenumbers
%...text...
\end{linenumbers}


So far so good.

In the user manual is a warning that it is impossible to reset the counter in any 'pagewise' mode. Well, that is exactly what I want to do. Every new chapter has to start with number 1. My question: is there any workaround? My document setup is a mainfile and subfiles, quite simple:

\documentclass[a5paper, twoside,11pt]{book}
\usepackage{preambule}
\begin{document}
\subfile{10corvus_et_vulpes}
\newpage
\subfile{20commentarii}
\end{document}


Now my own idea is that it will perhaps help when there is a quite hard break, a new start between the two imported files. However, I do not know how to fix this. And I do not want to start the pagenumbering again. Here I add a MnonWE, using the standard formatting and using \resetlinenumber, obviously without succes:

\documentclass[twoside,11pt]{book}
\usepackage[switch*]{lineno}
\usepackage{lipsum}
\begin{document}
\section{title1}
\begin{linenumbers}
\modulolinenumbers
\lipsum[1-2]
\end{linenumbers}
\newpage
\section{title2}
\begin{linenumbers}
\modulolinenumbers
\resetlinenumber
\lipsum[1-2]
\end{linenumbers}
\end{document}


Jan

• Do you want to restart the numbering at the beginning of each page or at the beginning of each chapter? – DG' Feb 8 at 21:35
• Hi DG, at each chapter/section. So, taken my MnWE: I want to start with 1 at the beginning of the second section. For clarity I just added a \newpage-command between the sections. – J. Bart Feb 8 at 22:38

According to the lineno-manual there are two modes:

1. running, which allows resets, but no margin switching
2. pagewise, which allows margin switching, but no resets

And then you can simulate running numbers in pagewise mode, which still doesn't allow margin switching. In other words: This won't work.

You still could try reledmac which is probably overkill (and rather complicated), but it let's you switch margins and reset the numbering:

\documentclass[twoside,11pt]{book}
\usepackage{reledmac}
\usepackage{lipsum}

\begin{document}
\linenummargin{outer}

\chapter{Something}
\section{This}
\beginnumbering
\pstart
\lipsum[1-2]
\pend
\endnumbering

\section{That}
\beginnumbering
\pstart
\lipsum[3-4]
\pend
\endnumbering

\section{No end in sight}
\beginnumbering
\pstart
\lipsum[5-6]
\pend
\endnumbering

\end{document}


If you really need to switch and reset the line numbers, and switching to ConTeXt is an option, you could start from here:

\setuppapersize[A5]
\setuppagenumbering[alternative=doublesided]
\setuplinenumbering[step=5,
style=\tt\tfxx,
align=outer,
location=inner]

\starttext

\startsection[title={Knuth}]
\startlinenumbering
\input knuth
\stoplinenumbering
\stopsection

\startsection[title={Tufte}]
\startlinenumbering
\dorecurse{2}{\input tufte\par}
\stoplinenumbering

\stoptext


• Yes, you can! Like the author himself declares, to use lineo.sty in a two-sides environment, you have to 'abuse' the pagewise-option. Switch is a pagewise-variant. – J. Bart Feb 8 at 22:43
• Dear DG, thank you for taking time to interpret me... When you compile your own MWE, Latex is indeed succesful to reset the counter at a new section, but the switch doesn't work anymore. So all linenumbers are either in the left or right margin. I want the combination. This seems to be impossible from the lineno-package, and that's the reason I seek for a workaround. – J. Bart Feb 9 at 10:22
• @J.Bart reledmac appears to be able to do, what you want – DG' Feb 9 at 13:50
• Thank you, this works indeed. However, loads of new problems occur: non floating marginnotes/sidenotes, wrapfig disfunctioning/needs reformulation... So, hmm... – J. Bart Feb 11 at 20:03
• @J.Bart How badly do you need switching line numbers? Are they a hard requirement? Many classical editions have the line numbering running on one side despite being set double sided (e.g. Diels/Kranz), so maybe you are willing to reconsider your aesthetical preferences... – DG' Feb 11 at 20:52