6

In this question, David Carlisle provided some code to create a second page-counter in the header to indicate pages and page-breaks for critical editions. This is pretty cool. However, as documents grow complex, I run into problems. Here is a MWE detailing two:

\documentclass{scrbook}

\usepackage{lipsum}
\usepackage{scrlayer-scrpage}
\ohead{\textbf{\pagemark}}
\def\lastoldpagemark{\topmarks\oldpagemark}
\ihead{\textit{\lastoldpagemark\ifnum\lastoldpagemark<\botmarks\oldpagemark--\botmarks\oldpagemark\fi
               \xdef\lastoldpagemark{\botmarks\oldpagemark}}}
\ofoot{}
\pagestyle{scrheadings}
\newmarks\oldpagemark % etex marks not completely reliable in latex, but probably OK here
\newcounter{oldpage}
\setcounter{oldpage}{1}

\newcommand{\markoldpage}{
[mark]
\marks\oldpagemark{\theoldpage}\marginpar{\centering\footnotesize\theoldpage}
\stepcounter{oldpage}
}

\begin{document}

\chapter{First Chapter}
\markoldpage{} This is the first oldpage. 

\markoldpage{} Now the second oldpage has begun. 
\lipsum[1]
\lipsum[3] \markoldpage{} 
\lipsum \markoldpage{} 
\lipsum[1-10] \markoldpage{}
\lipsum[1]

\chapter{Second Chapter}
\section{First Section}
\setcounter{oldpage}{20}
\markoldpage{} This is the first oldpage. \markoldpage{} Now the second oldpage has begun.

\newpage

\lipsum[1-3] \markoldpage{} \lipsum[1-3] \markoldpage{}

\section{Second Section}
\setcounter{oldpage}{17} \markoldpage
\lipsum[1] 

\end{document}
  1. Sometimes, the oldpage counter in the page following a new chapter is incorrect, as exemplified on pages two and six of the output. Can someone help me understand what’s going on?
  2. If I place a new item on the same page which has a lower oldpage (e.g. with a \section instead of a \chapter as indicated in the MWE), then, of course, the page-counter also doesn’t work, as the macro only specifies this for larger oldpage-numbers. Would it be possible in this case to use the marks to typeset it like this: [OldpageSection1], [OldpageSection2]
4
  • 1
    topmarks is not reliable in latex as latex can call the output routine more than once while creating a page. Jan 20, 2022 at 14:52
  • Is it possible to employ a mechanism that doesn’t rely on \topmarks?
    – Kubo
    Jan 20, 2022 at 16:12
  • 2
    I don't remember what this was about and I don't have the time to look, but you could check if the new marks code in a current latex (texdoc ltmarks) helps you. Jun 26, 2023 at 12:28
  • Looks very promising! I’ll give it a try.
    – Kubo
    Jun 26, 2023 at 16:09

1 Answer 1

1

The new mark-system described in ltmarks (maybe to be read together with the new LaTeX-Companion, I, pp. 390–395) provides an easy mechanism to achieve the desired outcome.

\documentclass{scrbook}

\usepackage{lipsum}
\usepackage{scrlayer-scrpage}
\addtokomafont{pagenumber}{\bfseries}

\NewMarkClass{oldpagemark}

\newcounter{oldpage}
\setcounter{oldpage}{1}

\ohead{\pagemark}

\ihead{\IfMarksEqualTF{oldpagemark}{top}{last}{(\TopMark{oldpagemark})}{(\TopMark{oldpagemark}--\LastMark{oldpagemark})}}
\ofoot{}

\pagestyle{scrheadings}

\newcommand{\markoldpage}{¦\stepcounter{oldpage}\InsertMark{oldpagemark}{\theoldpage}\marginpar{\centering\footnotesize\theoldpage}}

\begin{document}

\chapter{First chapter}
\lipsum[1-2] \markoldpage{}
\lipsum[1-10] \markoldpage{}
\lipsum[1-2] \markoldpage{}
\lipsum[1-4] \markoldpage{}

\chapter{Second chapter with new numbering} \setcounter{oldpage}{43}
\lipsum[1-2] \markoldpage{}
\lipsum[1-4] \markoldpage{}
\lipsum[1-2] \markoldpage{}
\lipsum[1-4] \markoldpage{}

\chapter{Third chapter with new numbering} \setcounter{oldpage}{25}
\lipsum[1-2] \markoldpage{}
\lipsum[1-4] \markoldpage{}
\lipsum[1-2] \markoldpage{}
\lipsum[1-4] \markoldpage{}

\end{document}

Some prose descriptions: Since 2022, \NewMarkClass provides a mark-mechanism that doesn’t run into problems like eTeX’s marks and primitive TeX’s mark-commands like \topmark when compiled with LaTeX.

The new corresponding commands \TopMark, \LastMark and \InsertMark enable LaTeX to grab the relevant page-numbering-information without interfering.

\markoldpage makes use of these features in combination with a counter (oldpage) which is simply marked at the correct location via \InsertMark.

\IfMarksEqualTF then uses a simple conditional also defined in ltmarks to print the correct information in the header. The bold numbers represent the page-numbers of the document, and the italic numbers in brackets represent the oldpage-numbers. The character signifying a page-break (»¦«) and the numbering of the old-page in the margin are also added.

Depending on the page range of the, lets say, »phantom-oldpage-numbering«, either a single digit number is written in the header if the range is one, e.g. here on output-page 2 ...

enter image description here

... or a page-range if it is larger than one, e.g. output page 10.

enter image description here

Previously, I ran into problems as soon as I changed the counter-value between chapters, but this seems to be fine, so far!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .