In a document I'm working on, I'd like whitespace to be added before a custom environment, but only if that environment doesn't immediately follow a sectioning command (\section
, \subsection
, etc). I figured I could set up a paragraph counter via the everyhook package, and use the etoolbox package's \pretocmd
macro to patch \@startsection
to reset the paragraph counter. That seemed to work fine, but I noticed some odd behavior in the spacing produced... after some debugging, I whittled it down to a strange interaction between everyhook and fancyhdr. Here's a minimal example demonstrating what's happening:
\documentclass[12pt]{article}
\usepackage{blindtext}
\usepackage{everyhook}
\usepackage{fancyhdr}
\newcounter{paranum}
\PushPreHook{par}{\stepcounter{paranum}}
\pagestyle{fancy}
\begin{document}
\section*{Heading}
\theparanum: \blindtext
\theparanum: \blindtext
\theparanum: \blindtext
\section*{Heading}
\theparanum: \blindtext
\theparanum: \blindtext
\theparanum: \blindtext
\end{document}
This generates
Everything counts along fine on the first page, but on the second, the count jumps from 5 to 12. Removing the \pagestyle{fancy}
command fixes this. Why? And more importantly, how can I keep using the fancyhdr package while also being able to accurately number paragraphs?