I'm trying to write Latex documents that will automatically satisfy government requirements for labeling certain classes of information:
- Each paragraph starts with a label indicating its importance.
- The header and footer of each page include a label indicating the
most important paragraph on that page (even if it started on the
previous page).
This is the closest I have come:
\documentclass[12pt]{report}
\usepackage{fancyhdr}
\usepackage{ifthen}
\usepackage{afterpage}
\usepackage{color}
\usepackage{lipsum}
\setlength\parskip{.6\baselineskip}
\setlength\parindent{0pt}
\setlength\headheight{15pt}
\setlength\textheight{21\baselineskip}
\newcommand\pageimport{TRIVIAL}
\newcommand\paraimport{TRIVIAL}
\pagestyle{fancy}
\lhead{}\chead{\leftmark}\rhead{}
\lfoot{}\cfoot{\leftmark}\rfoot{\thepage}
\newcommand{\IMP}[1]{\renewcommand\paraimport{IMPORTANT}
\renewcommand\pageimport{IMPORTANT}
\markboth{\pageimport}{\paraimport}
\afterpage{\renewcommand\pageimport{\protect\paraimport}\markboth{\protect\paraimport}{}}
\textcolor{red}{(I) #1}\renewcommand\paraimport{TRIVIAL}}
\newcommand{\TRI}[1]{\renewcommand\paraimport{TRIVIAL}
\markboth{\pageimport}{\paraimport}
\afterpage{\renewcommand\pageimport{\protect\paraimport}\markboth{\protect\paraimport}{}}
(U) #1\renewcommand\paraimport{TRIVIAL}}
\begin{document}
\immediate\typeout{a. pageimport = \pageimport\space paraimport = \paraimport}
\TRI{\lipsum[1]}
\TRI{\lipsum[2]}
\TRI{\lipsum[3]}
\immediate\typeout{b. pageimport = \pageimport\space paraimport = \paraimport}
\IMP{\lipsum[4]}
\immediate\typeout{c. pageimport = \pageimport\space paraimport = \paraimport}
\TRI{\lipsum[5]}
\TRI{\lipsum[6]}
\TRI{\lipsum[7]}
\TRI{\lipsum[8]}
\immediate\typeout{d. pageimport = \pageimport\space paraimport = \paraimport}
\IMP{\lipsum[9]}
\immediate\typeout{e. pageimport = \pageimport\space paraimport = \paraimport}
\TRI{\lipsum[10]}
\TRI{\lipsum[11]}
\TRI{\lipsum[12]}
\end{document}
(I've changed the labels here to avoid causing needless alarm. For convenience, I have also set the "important" text in red.) My idea is to keep the "importance" of each paragraph in \paraimport. That gets reset at the end of each paragraph. The header and footer get their labels from \pageimport, which records the highest importance on the current page. At the end of each page, \pageimport gets reset to the value of \paraimport.
This document has one "important" paragraph on page 2, and another that starts on page 4 and ends on page 5. All the paragraphs are correctly labeled. The first two pages have the right labels, but pages 3 and 6 should be marked "trivial". The tracing statements before and after each "important" paragraph show that \pageimport is not getting reset at the pagebreaks.
I suspect I'm moving something fragile, but rewriting the \afterpage commands as
\afterpage{\renewcommand\pageimport{\protect\paraimport}\markboth{\protect\paraimport}{}}
makes no difference.
I've seen secret.sty, but it's attacking a different problem. I have not been able to adapt it for page marking.
I'd appreciate any suggestions.
\afterpage
is not sufficient here. In my impression there must be check about the last 'state' (TRIVIAL/IMPORTANT)