2

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?

The above MWE with scrlayer-scrpage

2
  • 1
    scrlayer-scrpage doesn't do anything with \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. Aug 28 at 16:30
  • The issue using \everypar{*} is the same that using \AddToHook{para/begin}{*} globally: that you have \pars 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} ).
    – Fran
    Aug 28 at 17:40

1 Answer 1

2

scrlayer and scrlayer-scrpage do not use \everypar nor AFAIK generic hooks. But, e.g., scrlayer-scrpage uses several \parbox commands for the page head and page foot. So it has also several logical paragraphs inside the header and footer.

If you don't want to count paragraphs in page header and footer, you can use, e.g., a switch:

\documentclass{scrartcl}
\newif\ifatpageheadfoot
\usepackage[onpsinit=\protect\atpageheadfoottrue]{scrlayer-scrpage}
\usepackage{lipsum}
\begin{document}
\AddToHook{para/begin}{\ifatpageheadfoot \else *\fi}
\lipsum
\end{document}

enter image description here

2
  • Thank you, I believe \ifatpageheadfoot is what I was missing! Can you recommend a resource to find \ifatpageheadfoot and related things? Or does it come down to studying the source code? Aug 28 at 17:04
  • 1
    @FelixEmanuel It is a new switch, I've defined in the example using \newif, which is a LaTeX kernel command and therefore a basic LaTeX feature. Setting it to true for the page header and footer is done using option onpsinit, which is documented in the KOMA-Script user manual. Instead of a boolean switch you could alternatively also use a command and redefine this in the page style initialization, if you are more familiar with that concept.
    – cabohah
    Aug 29 at 6:32

You must log in to answer this question.

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