# titleps bottom marks are slightly off in multicol document

I am typesetting biblical text using XeLaTeX. I need to print book, chapter, and verse references in the page headers, so I am using titleps with the extramarks option to define custom marksets for these textual divisions. In addition, I want to use a one-column layout for introductory material and a two-column layout for biblical material, so I have incorporated the multicol package.

What I have noticed is that if the verses are short enough, then multicol seems to trip on the calculation of the bottom mark (in this case, the last verse number) on multiple pages. I have attached an image of this (generated from my minimal working example) below.

I've stripped my .tex file and .sty file to the minimal forms below.

mwe.sty

%Declare the package that this file will produce, along with its formal name:
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{mwe}[2020/03/13 Minimal Working Example]

%Include support for multi-column text layout:
\RequirePackage{multicol}
\raggedcolumns

%Include support for page header styles:
\RequirePackage[extramarks]{titleps}

%Page styles and macros:
\newcommand{\BookTitle}{}
\newcommand{\ChapterTitle}{}
\newcommand{\VerseTitle}{}
\newcounter{Book}
\newcounter{Chapter}
\newcounter{Verse}
\newmarkset{Book}
\newmarkset{Chapter}
\newmarkset{Verse}
\newextramark{Book}{\BookTitle}
\newextramark{Chapter}{\ChapterTitle}
\newextramark{Verse}{\VerseTitle}
\newextramark*{Book}{Book}
\newextramark*{Chapter}{Chapter}
\newextramark*{Verse}{Verse}
\newcommand{\Book}[1]{%
%Set the page style:
\pagestyle{BookPage}%
%Set the current book title to the argument of the \Book macro and reset the chapter and verse titles:
\renewcommand\BookTitle{#1}%
\renewcommand\ChapterTitle{1}%
\renewcommand\VerseTitle{1}%
%Increment the book counter, and reset the chapter and verse counters:
\stepcounter{Book}%
\setcounter{Chapter}{1}%
\setcounter{Verse}{1}%
\preextramark{Book}%
\preextramark{Chapter}%
\preextramark{Verse}%
\extramark{Book}%
\extramark{Chapter}%
\extramark{Verse}%
}
\newcommand{\PreChapterSpace}{% adds non-breaking space before a new chapter marker
\hspace{0.5em}
}
\newcommand{\Chapter}[1]{%
%Set the chapter title to the specified value and reset the verse title:
\renewcommand\ChapterTitle{#1}%
\renewcommand\VerseTitle{1}%
%Set the chapter counter to the specified value, and reset the verse counter:
\setcounter{Chapter}{#1}%
\setcounter{Verse}{1}%
%Update the extra marks for references in the heading:
\preextramark{Chapter}%
\preextramark{Verse}%
{\textbf{\ChapterTitle\,:\,\VerseTitle}}\hspace*{0.5em}
\extramark{Chapter}%
\extramark{Verse}%
}
\newcommand{\PreVerseSpace}{% adds non-breaking space before a new verse marker
\hspace{0.5em}
}
\newcommand{\Verse}[1]{%
\renewcommand\VerseTitle{#1}%
\setcounter{Verse}{#1}%
%Update the extra marks for references in the heading:
\preextramark{Chapter}%
\preextramark{Verse}%
\ifnum#1 > 1{%
{\textbf{#1}}\hspace*{0.5em}
}\fi%
\extramark{Chapter}%
\extramark{Verse}%
}

%Macro for collapsing reference ranges as needed:
\newcommand{\RefRange}{%
%We need to declare these here to check for their equality with the current chapter and verse titles;
%otherwise, headers for one-verse pages will be printed as ranges instead of a single verse references:
\firstextramarks{Chapter}%
\firstextramarks{Verse}%
%Check if the current chapter matches the first chapter on the page:
\ifsamemark{\firstextramarks{Chapter}}{\ChapterTitle}{%
%Then check if the current chapter matches the bottom chapter on the page (essentially, we're checking if the first and last chapter marks are equal):
\ifsamemark{\botextramarks{Chapter}}{\ChapterTitle}{%
%Check if the current verse matches that of the first verse on the page:
\ifsamemark{\firstextramarks{Verse}}{\VerseTitle}{%
%Then check if the current verse matches the bottom verse on the page (essentially, we're checking if the first and last verse marks are equal):
\ifsamemark{\botextramarks{Verse}}{\VerseTitle}{%
%If the chapters and verses match, then the page consists of a single verse; use its reference:
\firstextramarks{Chapter}\ChapterTitle:\firstextramarks{Verse}\VerseTitle%
}{%
%If there is no match, then use one chapter and the verse range:
\firstextramarks{Chapter}\ChapterTitle:\firstextramarks{Verse}\VerseTitle--\botextramarks{Verse}\VerseTitle%
}%
}{%
%If there is no match, then use one chapter and the verse range:
\firstextramarks{Chapter}\ChapterTitle:\firstextramarks{Verse}\VerseTitle--\botextramarks{Verse}\VerseTitle%
}%
}{%
%If there is no match, then use the entire reference range:
\firstextramarks{Chapter}\ChapterTitle:\firstextramarks{Verse}\VerseTitle--\botextramarks{Chapter}\ChapterTitle:\botextramarks{Verse}\VerseTitle%
}%
}{%
%If there is no match, then use the entire reference range:
\firstextramarks{Chapter}\ChapterTitle:\firstextramarks{Verse}\VerseTitle--\botextramarks{Chapter}\ChapterTitle:\botextramarks{Verse}\VerseTitle%
}%
}

%Page style:
\makepagestyle{BookPage}
\makeevenfoot{BookPage}{\thepage}{}{} %Page number on left in footer on even pages
\makeoddfoot{BookPage}{}{}{\thepage} %Page number on right in footer on odd pages

%Define a macro to generate consecutive verses of sample text:
\newcommand{\blindtext}[1]{%use a default value of 1 to coerce the argument to a number
\newcounter{i}
\setcounter{i}{1}%
\loop%
\Verse{\thei}In the beginning, God created the heavens and the earth.\PreVerseSpace{}%
\stepcounter{i}%
\ifnum\numexpr\value{i}-1<#1%
\repeat%
}

%Finally, close the input:
\endinput

mwe.tex

\documentclass[twoside, 12pt]{memoir}
\usepackage{../sty/mwe}
\begin{document}
\Book{MWE}
\begin{multicols}{2}
\noindent
\normalsize
\Chapter{1}\blindtext{200}\par
\pagebreak
\end{multicols}
\end{document}


(My apologies that the minimal .sty file is still over 100 lines long; there are probably more succinct ways to write the macros I've written, but I was learning how to use titleps as I went.)

I checked the documentation for titleps, and the only relevant comment I could find was that some classes that play around with the \markboth and \markleft commands might not work as-is with titleps; specifically, "Two columns layout requires the fix2col package by David Carlisle" (p. 2, f. 1). But as far as I can tell, the patches in fix2col have been incorporated into LaTeX, making that package obsolete.

The manual for multicol discusses the package's handling of marks in detail in section 5.1, but the discussion is rather technical, and I'm having trouble keeping up with it. I don't see any mention of titleps, so I don't know if multicol even handles "extramarks" marksets the way it handles the standard ones.

Is the solution as simple as adjusting a penalty parameter that multicol uses? Any advice on how to fix the chapter-verse references in my headers is appreciated!

• multicols doesn't save/restore the extended marks, so you would have to make a feature request, or setup your system so that it works with the standard latex mark commands. Mar 14, 2020 at 10:42
• By "the standard latex mark commands," do you mean \leftmark, \rightmark, \chaptermark, \sectionmark, \subsectionmark, etc.? Mar 14, 2020 at 22:42
• yes, \markboth and \markright. Mar 14, 2020 at 22:51

Many thanks to Ulrike Fischer for pointing me in the right direction! Using the standard LaTeX commands \markboth and \markright and the \firstleftmark, \firstrightmark, \lastleftmark, and \lastrightmark commands from the extramarks package, I was able to get my MWE to work properly and make my code more compact, too! The updated .sty file below is now only 80 lines long!

mwe.sty

%Declare the package that this file will produce, along with its formal name:
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{mwe}[2020/03/13 Minimal Working Example]

%Include support for multi-column text layout:
\RequirePackage{multicol}
\raggedcolumns

%Include support for getting first and last marks:
\RequirePackage{extramarks}

%Define a macro that will be redefined with the current book title whenever it changes (for reference in the header):
\newcommand{\BookTitle}{}

\newcommand{\Book}[1]{%
%Set the page style:
\pagestyle{BookPage}%
%Set the current book title:
\renewcommand{\BookTitle}{#1}%
%Reset the left (= chapter) and right (= verse) marks:
\markboth{1}{1}%
}
\newcommand{\PreChapterSpace}{% adds (breakable) space before a new chapter marker
\hspace{0.5em}
}
\newcommand{\Chapter}[1]{%
%Set the current left (= chapter) mark and reset the right (= verse) mark:
\markboth{#1}{1}%
%Then typeset the chapter number:
{\textbf{#1\,:\,}}%
}
\newcommand{\PreVerseSpace}{% adds (breakable) space before a new verse marker
\hspace{0.5em}
}
\newcommand{\Verse}[1]{%
%Set the current right (= verse) mark:
\markright{#1}%
%Then typeset the verse number:
{\textbf{#1}}\hspace*{0.5em}
}

%Macro for collapsing reference ranges as needed:
\RequirePackage{ifthen}
\newcommand{\RefRange}{%
%Check if the first chapter matches the last chapter on the page:
\ifthenelse{\equal{\firstleftmark}{\lastleftmark}}{%
%If the chapters match, then check if the first verse matches the last verse on the page:
\ifthenelse{\equal{\firstrightmark}{\lastrightmark}}{%
%If the verses match, then the page consists of a single verse; use its reference:
\firstleftmark:\firstrightmark%
}{%
%If the verses do not match, then use one chapter and the verse range:
\firstleftmark:\firstrightmark--\lastrightmark%
}%
}{%
%If the chapters do not match, then use the entire reference range:
\firstleftmark:\firstrightmark--\lastleftmark:\lastrightmark%
}%
}

%Page style:
\makepagestyle{BookPage}
\makeevenfoot{BookPage}{\thepage}{}{} %Page number on left in footer on even pages
\makeoddfoot{BookPage}{}{}{\thepage} %Page number on right in footer on odd pages

%Define a macro to generate consecutive verses of sample text:
\newcounter{i}
\newcommand{\blindtext}[1]{%use a default value of 1 to coerce the argument to a number
\setcounter{i}{1}%
\loop%
\Verse{\thei}In the beginning, God created the heavens and the earth.\PreVerseSpace{}%
\stepcounter{i}%
\ifnum\numexpr\value{i}-1<#1%
\repeat%
}

%Finally, close the input:
\endinput


I was able to check and ensure that all cases in the \RefRange macro were covered using the following .tex file:

mwe.tex

\documentclass[twoside, 12pt]{memoir}
\usepackage{../sty/mwe}
\begin{document}
\Book{MWE}
\begin{multicols}{2}
\noindent
\normalsize
\Chapter{1}\blindtext{2}\Chapter{2}\blindtext{84}\par
\pagebreak
\end{multicols}
\end{document}