-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample29b.tex
174 lines (129 loc) · 5.02 KB
/
example29b.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
\documentclass{report}
\usepackage{lipsum}
\usepackage{boxedminipage}
\usepackage[a5paper]{geometry}
\usepackage{extramarks}
\usepackage{afterpage}
\usepackage{fancyhdr}
\pagestyle{fancy}
\newcommand\ContiText{}
\newcommand*{\LM}{\noindent
Continued from previous page\ldots\\[1ex]}
%\newcommand*{\DEBUG}[1]{#1} % For debugging
\newcommand*{\DEBUG}[1]{} % To disable debugging
\newcommand*{\APcommand}{}
\newcommand*{\setAPcommand}{\gdef\APcommand{\ContiText\setAP}}
\newcommand*{\clearAPcommand}{\DEBUG{CLEAR}\gdef\APcommand{}}
\newcommand*{\setAP}{\afterpage{\DEBUG{AFTERPAGE:}\APcommand}}
\newcommand*{\startAP}{\ifx\APcommand\empty\setAPcommand\setAP\fi}
\fancyhead[L]{Example 29b}
\fancyhead[R]{\rightmark}
\fancyfoot[R]{\lastrightxmark}
\fancyfoot[L]{\xdef\ContiText{\lastleftxmark}}
\fancypagestyle{plain}{\fancyhead{}\renewcommand{\headrule}{}}
\newenvironment{continued}{%
\par\startAP
\extramarks{}{}%
\noindent\rule{\textwidth}{1mm}%
\extramarks{\LM}{Continued on next page\ldots}%
\\*\ignorespaces
}{%
\unskip\noindent\rule{\textwidth}{1mm}%
\extramarks{\LM}{}%
\extramarks{}{\protect\clearAPcommand}\par
}
\begin{document}
\pagenumbering{roman}
\tableofcontents
\thispagestyle{plain}
\bigskip
\noindent
\begin{boxedminipage}{\textwidth}
\small
This is example 29b in the fancyhdr documentation.
It demonstrates the use of the \texttt{extramarks} package to implement
a ``Continued\ldots'' header/footer.
It defines a \texttt{continued} environment that puts \verb|\extramarks| commands around its body to force the proper header and footer when the body crosses a page boundary, and empty ones when it doesn't cross them.
However, in this example, the text ``Continued from previous page\ldots'' is not put in the page header, but on the top of the page body. The page header is used for normal headers. This is done by using an \verb|\afterpage| to place it there. The text that \verb|\afterpage| has to put there is put in the mark (\verb|\firstxmark|). To make it a bit more dramatic, we also highlight that text.
This example differs from Example 29a, in that we stop the sequence of \verb|\afterpage| commands as soon as possible, and restart it when it is needed again.
\end{boxedminipage}
\noindent
\begin{boxedminipage}{\textwidth}
\small
For debugging purposes we add some extra text ``AFTERPAGE:'' to the \verb|\afterpage|, so that we can see the difference between an empty \texttt{afterpage} (pages 4, 7, 10) and no \texttt{afterpage} (pages 2, 8, 11, 12). Also we put ``CLEAR'' in those footers where \verb|\clearAPcommand| is called.
\begin{verbatim}
\newcommand\ContiText{}
\newcommand*{\LM}{\noindent
Continued from previous page\ldots\\[1ex]}
%\newcommand*{\DEBUG}[1]{#1} % For debugging
\newcommand*{\DEBUG}[1]{} % To disable debugging
\newcommand*{\APcommand}{}
\newcommand*{\setAPcommand}{%
\gdef\APcommand{\ContiText\setAP}}
\newcommand*{\clearAPcommand}{%
\DEBUG{CLEAR}\gdef\APcommand{}}
\newcommand*{\setAP}{\afterpage{%
\DEBUG{AFTERPAGE:}\APcommand}}
\newcommand*{\startAP}{%
\ifx\APcommand\empty\setAPcommand\setAP\fi}
\fancyhead[L]{Example 29b}
\fancyhead[R]{\rightmark}
\fancyfoot[R]{\lastrightxmark}
\fancyfoot[L]{\xdef\ContiText{\lastleftxmark}}
\fancypagestyle{plain}{\fancyhead{}\renewcommand{\headrule}{}}
\newenvironment{continued}{%
\par\startAP
\extramarks{}{}%
\noindent\rule{\textwidth}{1mm}%
\extramarks{\LM}{Continued on next page\ldots}%
\\*\ignorespaces
}{%
\unskip\noindent\rule{\textwidth}{1mm}%
\extramarks{\LM}{}%
\extramarks{}{\protect\clearAPcommand}\par
}
\end{verbatim}
\end{boxedminipage}
\pagestyle{fancy}
\newpage
\pagenumbering{arabic}
\chapter{Introduction}
\lipsum[1-4]
\section{The Problem}
\label{sec:problem}
\begin{continued}
\textbf{We want to indicate that this block of text belongs together, with
`Continued' in header and footer.}
\textit{This block crosses one page boundary.}
\lipsum[2]
\textbf{Here ends the block of text that belongs together.}\\
\end{continued}
\section{Evaluation}
\lipsum[3-6]
\begin{continued}
\textbf{We want to indicate that this block of text belongs together, with
`Continued' in header and footer if it crosses a page boundary.}
\textit{This block stays within a page. Therefore no header/footer.}
\textbf{Here ends the block of text that belongs together.}\\
\end{continued}
A second one.
\begin{continued}
\textbf{We want to indicate that this block of text belongs together, with
`Continued' in header and footer.}
\textit{This block crosses several page boundaries.}
\lipsum[2-7]
\textbf{Here ends the block of text that belongs together.}\\
\end{continued}
\lipsum
\chapter{Another chapter}
\label{cha:another-chapter}
\lipsum[2]
\begin{continued}
\textbf{We want to indicate that this block of text belongs together, with
`Continued' in header and footer if it crosses a page boundary.}
\textit{This block stays within a page. Therefore no header/footer.}
\textbf{Here ends the block of text that belongs together.}\\
\end{continued}
\section{Another section}
\lipsum
\end{document}