1

For a > 2000 page book with topics and verses, I want to show on the header, for the left page, the first verse # and the corresponding topic #. For the right page, I want to show the last topic # with the corresponding last verse #.

The code I have below works for the pages on the right (last topic and verse) For the left pages, I encountered a problem: if a topic starts in previous page but the verses continue on the following page, and if a new topic is entered after in the same page then I get the current topic # from the new topic but not the one from the previous page. (Note: Topic # is embedded usually in verse 1 paragraph. It is not in stand alone paragraph)

I want in page # 4: Topic 2.3 (I get 3.3) Any suggestions? does the memoir class can handle this strategy (I used fancyhdr)? I have not tried titleps, but is it possible with this package?

\documentclass[12pt, twoside, openright]{memoir}
\usepackage{fancyhdr}
\usepackage{lipsum}

\newmarks\versemark
\newcounter{verses}

\newcommand{\versecounter}{%
    \leavevmode
    \stepcounter{verses}%
    \marks\versemark{\arabic{verses}}%
}

\newmarks\topicmark
\newcounter{topics}

\newcommand{\topicounter}{%
    \leavevmode
    \stepcounter{topics}%
    \marks\topicmark{\arabic{topics}}%
}

\newcommand{\firsttopicverse}{%
    \begingroup
    \edef\firstverse{\firstmarks\versemark}%
    \edef\firsttopic{\firstmarks\topicmark}%
    Topic \firsttopic .\firstverse
    \endgroup
}

\newcommand{\lasttopicverse}{%
    \begingroup
    \edef\lastverse{\botmarks\versemark}%
    \edef\lasttopic{\botmarks\topicmark}%

    Topic \lasttopic .\lastverse
\endgroup   
}

\pagestyle{fancy}
\fancyhf{}
\fancyhead[RE]{Should show 1st verse and current topic}
\fancyhead[LE]{\firsttopicverse}
\fancyhead[LO]{\lasttopicverse}
\fancyhead[RO]{Shows last topic \& verse}
\fancyfoot[LE,RO]{\thepage}

\begin{document}
    \chapter{Let's Talk About Topics}

    \topicounter
    {\Large{Topic \# \thetopics}}

    \versecounter
    {\textbf{\theverses.} }
    \lipsum[\theverses]
    \par

    \versecounter
    {\textbf{\theverses.} }
    \lipsum[\theverses]
    \par

    \versecounter
    {\textbf{\theverses.} }
    \lipsum[\theverses]
    \par
\pagebreak

    \versecounter
    {\textbf{\theverses.} }%
    \lipsum[\theverses]%
    \par
    \setcounter{verses}{0}
    \topicounter%
    {\Large{Topic \# \thetopics}}\\
    \versecounter
{\textbf{\theverses.} }
\lipsum[\theverses]
\par
\versecounter
{\textbf{\theverses.} }
\lipsum[\theverses]
\par
\pagebreak
\versecounter
{\textbf{\theverses.} }
\lipsum[\theverses]
\par
\par 
    \setcounter{verses}{0}
\topicounter
{\Large{Topic \# \thetopics}}

\versecounter
{\textbf{\theverses.} }
\lipsum[\theverses]
\par
\par 

\setcounter{verses}{0}
\topicounter
{\Large{Topic \# \thetopics}}
\versecounter
{\textbf{\theverses.} }
\lipsum[\theverses]
\par
\end{document}

2 Answers 2

2

Assuming that you will prevent a page break between the "Topic X" title and the following verse, you can simply put everything in the mark of the verse:

\documentclass[12pt, twoside, openright]{memoir}
\usepackage{fancyhdr}
\usepackage{lipsum}


\newcommand{\versecounter}{%
    \leavevmode
    \stepcounter{verses}%
    \marks\versemark{Topic~\arabic{topics}.\arabic{verses}}%
}

\newmarks\topicmark
\newcounter{topics}

\newmarks\versemark
\newcounter{verses}[topics] %reset with topics counter

\newcommand{\topicounter}{%
    \leavevmode
    \stepcounter{topics}}

\newcommand{\firsttopicverse}{%
    \firstmarks\versemark}

\newcommand{\lasttopicverse}{\botmarks\versemark}

\pagestyle{fancy}
\fancyhf{}
\fancyhead[RE]{Should show 1st verse and current topic}
\fancyhead[LE]{\firsttopicverse}
\fancyhead[LO]{\lasttopicverse}
\fancyhead[RO]{Shows last topic \& verse}
\fancyfoot[LE,RO]{\thepage}

\begin{document}
    \chapter{Let's Talk About Topics}

    \topicounter
    {\Large{Topic \# \thetopics}}

    \versecounter
    {\textbf{\theverses.} }
    \lipsum[\theverses]
    \par

    \versecounter
    {\textbf{\theverses.} }
    \lipsum[\theverses]
    \par

    \versecounter
    {\textbf{\theverses.} }
    \lipsum[\theverses]
    \par
\pagebreak

    \versecounter
    {\textbf{\theverses.} }%
    \lipsum[\theverses]%
    \par
    \topicounter%
    {\Large{Topic \# \thetopics}}\\
    \versecounter
{\textbf{\theverses.} }
\lipsum[\theverses]
\par
\versecounter
{\textbf{\theverses.} }
\lipsum[\theverses]
\par
\pagebreak
\versecounter
{\textbf{\theverses.} }
\lipsum[\theverses]
\par
\par
\topicounter
{\Large{Topic \# \thetopics}}

\versecounter
{\textbf{\theverses.} }
\lipsum[\theverses]
\par
\par

\topicounter
{\Large{Topic \# \thetopics}}
\versecounter
{\textbf{\theverses.} }
\lipsum[\theverses]
\par
\end{document}
2

I would not use fancyhdr with memoir as it has its own build in setup. So here is Ulrikes answer adjusted to memoir-only headers

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


\newcommand{\versecounter}{%
    \leavevmode
    \stepcounter{verses}%
    \marks\versemark{Topic~\arabic{topics}.\arabic{verses}}%
}

\newmarks\topicmark
\newcounter{topics}

\newmarks\versemark
\newcounter{verses}[topics] %reset with topics counter

\newcommand{\topicounter}{%
    \leavevmode
    \stepcounter{topics}}

\newcommand{\firsttopicverse}{%
    \firstmarks\versemark}

\newcommand{\lasttopicverse}{\botmarks\versemark}

\makepagestyle{hpcolos}
\makeoddfoot{hpcolos}{}{}{\thepage}
\makeevenfoot{hpcolos}{\thepage}{}{}
\makeoddhead{hpcolos}{\lasttopicverse}{}{Shows last topic \& verse}
\makeevenhead{hpcolos}{\firsttopicverse}{}{Should show 1st verse and current topic}
\pagestyle{hpcolos}


\begin{document}
    \chapter{Let's Talk About Topics}

    \topicounter
    {\Large{Topic \# \thetopics}}

    \versecounter
    {\textbf{\theverses.} }
    \lipsum[\theverses]
    \par

    \versecounter
    {\textbf{\theverses.} }
    \lipsum[\theverses]
    \par

    \versecounter
    {\textbf{\theverses.} }
    \lipsum[\theverses]
    \par
\pagebreak

    \versecounter
    {\textbf{\theverses.} }%
    \lipsum[\theverses]%
    \par
    \topicounter%
    {\Large{Topic \# \thetopics}}\\
    \versecounter
{\textbf{\theverses.} }
\lipsum[\theverses]
\par
\versecounter
{\textbf{\theverses.} }
\lipsum[\theverses]
\par
\pagebreak
\versecounter
{\textbf{\theverses.} }
\lipsum[\theverses]
\par
\par
\topicounter
{\Large{Topic \# \thetopics}}

\versecounter
{\textbf{\theverses.} }
\lipsum[\theverses]
\par
\par

\topicounter
{\Large{Topic \# \thetopics}}
\versecounter
{\textbf{\theverses.} }
\lipsum[\theverses]
\par
\end{document}
1

You must log in to answer this question.

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