I have read that one should not use \everypar
but rather \AddToHook{para/begin}
for automatic paragraph enumeration and related operations. In principle, this works fine (mwe without counting, just printing a simple symbol):
\documentclass{scrartcl}
\usepackage{lipsum}
\begin{document}
\AddToHook{para/begin}{*}
\lipsum
\end{document}
Once scrlayer-scrpage
is loaded things go bad (see below). There appear to be a lot more paragraphs in the header and footer of the document that now apply the new para/begin
settings. This issue does not arise with \everypar
.
My question would be: how does scrlayer-scrpage
manage \everypar
, and why doesn't this work for \AddToHook
? Is there an exclusion pattern one could use with \RemoveFromHook
to avoid the issue?
\everypar
, but it uses\parbox
and\parbox
calls\@arrayparboxrestore
which contains\everypar{}
. You could add something similar for your hooks to\@arrayparboxrestore
, but it is not clear if you really want to suppress your para-hooks everywhere where\@arrayparboxrestore
is called, probably a more fine-grained control as suggested by @cabohah is better.\everypar{*}
is the same that using\AddToHook{para/begin}{*}
globally: that you have\par
s everywhere, not only in headers and footers. They also will type the "*" before sections titles, after the item numbers, etc. Even if you can use a conditional to not type the * in some place, it can appear later in unsuspected places. So, if you want this only in "normal" paragrahs, IMHO the best to avoid surprises is use that commands only locally, inside a group ({ }
) o a environment (\begin{whatever} \end{whatever}
).