0

Background: I am editing the transcription of a historical manuscript using the memoir class. The transcription includes the folio numbers of the original manuscript, which are displayed in bold within square brackets at the points where each folio starts. These starting points can be anywhere on the transcribed page. There can be zero, one, or two new folio numbers on a transcribed page. The folio "numbers" are not purely numeric, so cannot be stored in a counter. The folio number is inserted with a custom command in the text, \folio.

Desired outcome: For each page, I want to have the running head display the range of numbers for the folios whose text appears on that page. So if the first text on a page comes from folio 5a, and then a few lines down folio 6 starts and takes up the rest of the page, I want the running head to display "folios 5a-6."

The MWE below comes close to working, but not quite. It runs into two problems.

First -- I used AtBegShi to place the last folio number on each page into a variable. But page shipout runs only after the last line on a page has been fully processed. If that line continues onto the following page, and contains a \folio command that displays on that following page, the folio range of the former page will be printed incorrectly, as on pages (1) and (8) of the output.

Second -- look at page (10), which starts with folio number [10], but shows a folio range starting with 9 in the header because the page technically starts before the folio number [10] is processed.

How can I solve these two problems?

Essentially the same questions have been asked and answered before (links below), but the answers are ten years old now and use different packages and classes, some obsolete. In any case I could not figure out how to apply any of the previous solutions to my problem.

Saving the value of a text macro at the start of the page.

Displaying the range of sections on the page in the header

section numbers (\thesection) and names have next page's values

How to define macros that are executed at begin and end of the page body or text column(s)?

\documentclass[a4,12pt]{memoir}
\usepackage{lipsum}

\usepackage{extramarks}
\usepackage{atbegshi}

% define page style with folio range in header and page number in footer
\makepagestyle{mystyle}
\makeevenhead{mystyle}{}{\lastleftmark}{}
\makeoddhead{mystyle}{}{\lastrightmark}{}
\makeevenfoot{mystyle}{(\thepage)}{}{}
\makeoddfoot{mystyle}{}{}{(\thepage)}

% command to write folio range in header
\NewDocumentCommand{\foliomarks}{}%
    {%
    \markboth{\hfill Folios \protect\PrevFolio--\protect\CurrFolio \hfill}{\hfill Folios \protect\PrevFolio--\protect\CurrFolio \hfill}%
}

% command to print folio number in text and save value for header
\NewDocumentCommand{\folio}{m}%
   {%
   {\textsf{\large{[#1.]}}}%
   \xdef\CurrFolio{#1}%
   \foliomarks{}%
}

\begin{document}

% initialize folio variables
\xdef\PrevFolio{1}
\xdef\CurrFolio{0}

% copy current folio number to previous folio number at top of each page
\AtBeginShipout{%
  \xdef\PrevFolio{\CurrFolio}
}

\pagestyle{mystyle}

\folio{1}
\lipsum[1]\folio{2}
\lipsum[1-3]\folio{3}
\lipsum[1-2]\folio{4}
\lipsum[1]\folio{5}
\lipsum[1-2]\folio{5a}
\lipsum[1]\folio{6}
\lipsum[1-2]\folio{7}
\lipsum[1]\folio{8}
\lipsum[1-20]\folio{9}
\lipsum[1]\clearpage\folio{10}
\lipsum[1]

\end{document}
6
  • It's not clear why you need to maintain previous folio "by hand" and use page hooks? Normally I'd expect a simple mark with just the current folio would be enough, then tex will provide the page head with the folio current at the top of the page and the last folio on the page, which should be enough? Mar 13, 2022 at 15:34
  • @DavidCarlisle Can you explain a little more -- how would TeX provide the number of the first folio on the page?
    – 35royan2
    Mar 13, 2022 at 15:51
  • that is the sole function of the \mark system you put marks on the page and tex tells you the mark current at the top of the page and the first and last mark on the page. in latex you don't normally use the first mark on the page but \leftmark and \rightmark or the underlying \topmark, \firstmark and \botmark are designed for exactly this Mar 13, 2022 at 16:20
  • @DavidCarlisle Thank you, I admit that I had never encountered \topmark and botmark before! Using them solves the first problem I mentioned and you are so right that I didn't need to maintain the previous folio number "by hand." My second problem remains -- cases where the first text on a page is destined for a mark, but \topmark holds the previous mark. I'm looking at previous discussions of this issue ...
    – 35royan2
    Mar 13, 2022 at 17:16
  • Tried using \topmark and \botmark but it doesn't solve the first problem, as \topmark does not update properly when \mark{} is issued from within environments. It works in the MWE I gave, but not in more complex documents. Indeed I see many references to \topmark not working correctly in LaTeX. Then there is still the second problem (getting top marks to reflect sections that start at the beginning of a page). There's a brief discussion of this issue in Javier Bezos's docs for the titleps package, section 5 (Marks). I haven't figured out whether using titleps would help.
    – 35royan2
    Mar 14, 2022 at 12:07

0

You must log in to answer this question.

Browse other questions tagged .