<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to HowTo_SectionPageStyle</title><link>https://sourceforge.net/p/koma-script/wiki-en/HowTo_SectionPageStyle/</link><description>Recent changes to HowTo_SectionPageStyle</description><atom:link href="https://sourceforge.net/p/koma-script/wiki-en/HowTo_SectionPageStyle/feed" rel="self"/><language>en</language><lastBuildDate>Mon, 14 Jul 2025 08:22:12 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/koma-script/wiki-en/HowTo_SectionPageStyle/feed" rel="self" type="application/rss+xml"/><item><title>HowTo_SectionPageStyle modified by Markus Kohm</title><link>https://sourceforge.net/p/koma-script/wiki-en/HowTo_SectionPageStyle/</link><description>&lt;div class="markdown_content"&gt;&lt;h1 id="how-to-ensure-that-thispagestyle-is-executed-on-the-correct-page"&gt;How to ensure that &lt;code&gt;\thispagestyle&lt;/code&gt; is executed on the correct page&lt;/h1&gt;
&lt;p&gt;The LaTeX statement \thispagestyle has the problem that it changes the page style of the page on which the statement is executed instead of the page that is active at the time the corresponding position is output.&lt;/p&gt;
&lt;p&gt;As a result, in the following example:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;\documentclass&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;scrreprt&lt;span class="nb"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;\RedeclareSectionCommand&lt;/span&gt;[&lt;span class="c"&gt;%&lt;/span&gt;
  pagestyle=headings
]&lt;span class="nb"&gt;{&lt;/span&gt;chapter&lt;span class="nb"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;\pagestyle&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;headings&lt;span class="nb"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;\usepackage&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;blindtext&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\begin&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;document&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\chapter&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;Test Chapter&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\Blindtext&lt;/span&gt;&lt;span class="na"&gt;[5]&lt;/span&gt;&lt;span class="k"&gt;\thispagestyle&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;plain&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\vspace*&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;5&lt;span class="k"&gt;\baselineskip&lt;/span&gt;&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\Blindtext&lt;/span&gt;&lt;span class="na"&gt;[3]&lt;/span&gt;
&lt;span class="k"&gt;\section&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;Test Section&lt;span class="nb"&gt;}&lt;/span&gt;&lt;span class="k"&gt;\thispagestyle&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;empty&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\Blindtext&lt;/span&gt;
&lt;span class="k"&gt;\blinddocument&lt;/span&gt;
&lt;span class="k"&gt;\end&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;document&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;the second page does not show the &lt;code&gt;plain&lt;/code&gt; page style of the first &lt;code&gt;\thispagestyle&lt;/code&gt; statement, but the empty page style of the second &lt;code&gt;\thispagestyle&lt;/code&gt; statement, although the ”Test Section“ section is output on the third page. The reason for this is that &lt;code&gt;\thispagestyle&lt;/code&gt; is based on a global switch and a global macro that is evaluated in the output routine. The &lt;code&gt;\thispagestyle{empty}&lt;/code&gt; defines both before it is known that the &lt;code&gt;\section&lt;/code&gt; heading causes a page break. Therefore, it affects the page before the heading, although the intention would clearly be the change on the page with the heading.&lt;/p&gt;
&lt;p&gt;The trick now is to delay &lt;code&gt;\thispagestyle&lt;/code&gt; until the page is output. A marker is set for this:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;\NewMarkClass&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;specialpage&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\newcommand*&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\savethispagestyle&lt;/span&gt;&lt;span class="nb"&gt;}&lt;/span&gt;[1]&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
  &lt;span class="k"&gt;\InsertMark&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;specialpage&lt;span class="nb"&gt;}{&lt;/span&gt;#1&lt;span class="nb"&gt;}&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;and immediately before the output of a page via hook &lt;code&gt;build/page/reset&lt;/code&gt;, if this marker is not empty, the last of these markers of the current page is used for &lt;code&gt;\thispagestyle&lt;/code&gt;:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;\AddToHook&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;build/page/reset&lt;span class="nb"&gt;}{&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
  &lt;span class="k"&gt;\Ifstr&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\LastMark&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;specialpage&lt;span class="nb"&gt;}}{}{}{&lt;/span&gt;&lt;span class="c"&gt;% &lt;/span&gt;
    &lt;span class="k"&gt;\thispagestyle&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\LastMark&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;specialpage&lt;span class="nb"&gt;}}&lt;/span&gt;&lt;span class="c"&gt;% last specialpage marker is not empty&lt;/span&gt;
    &lt;span class="k"&gt;\InsertMark&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;specialpage&lt;span class="nb"&gt;}{}&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
  &lt;span class="nb"&gt;}&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Now replace at least the &lt;code&gt;\thispagestyle{empty}&lt;/code&gt; statement after &lt;code&gt;\section{Test Section}&lt;/code&gt; with &lt;code&gt;\savethispagestyle{empty}&lt;/code&gt; in the above example:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;\documentclass&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;scrreprt&lt;span class="nb"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;\NewMarkClass&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;specialpage&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\newcommand*&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\savethispagestyle&lt;/span&gt;&lt;span class="nb"&gt;}&lt;/span&gt;[1]&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
  &lt;span class="k"&gt;\InsertMark&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;specialpage&lt;span class="nb"&gt;}{&lt;/span&gt;#1&lt;span class="nb"&gt;}&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\AddToHook&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;build/page/reset&lt;span class="nb"&gt;}{&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
  &lt;span class="k"&gt;\Ifstr&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\LastMark&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;specialpage&lt;span class="nb"&gt;}}{}{}{&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
    &lt;span class="k"&gt;\thispagestyle&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\LastMark&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;specialpage&lt;span class="nb"&gt;}}&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
    &lt;span class="k"&gt;\InsertMark&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;specialpage&lt;span class="nb"&gt;}{}&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
  &lt;span class="nb"&gt;}&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
&lt;span class="nb"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;\RedeclareSectionCommand&lt;/span&gt;[&lt;span class="c"&gt;%&lt;/span&gt;
  pagestyle=headings
]&lt;span class="nb"&gt;{&lt;/span&gt;chapter&lt;span class="nb"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;\pagestyle&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;headings&lt;span class="nb"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;\usepackage&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;blindtext&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\begin&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;document&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\chapter&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;Test Chapter&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\Blindtext&lt;/span&gt;&lt;span class="na"&gt;[5]&lt;/span&gt;&lt;span class="k"&gt;\savethispagestyle&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;plain&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\vspace*&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;5&lt;span class="k"&gt;\baselineskip&lt;/span&gt;&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\Blindtext&lt;/span&gt;&lt;span class="na"&gt;[3]&lt;/span&gt;
&lt;span class="k"&gt;\section&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;Test Section&lt;span class="nb"&gt;}&lt;/span&gt;&lt;span class="k"&gt;\savethispagestyle&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;empty&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\Blindtext&lt;/span&gt;
&lt;span class="k"&gt;\blinddocument&lt;/span&gt;
&lt;span class="k"&gt;\end&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;document&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;As expected, page 2 shows the page style &lt;code&gt;plain&lt;/code&gt; and page 3 with &lt;code&gt;\section&lt;/code&gt; heading the page style &lt;code&gt;empty&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;If you want to use this solution with the standard classes, you need the &lt;code&gt;scrbase&lt;/code&gt; package for the definition of &lt;code&gt;\Ifstr&lt;/code&gt;. It should also be noted that &lt;code&gt;\IfArgIsEmpty&lt;/code&gt; does not work at this point, as the argument must first be fully expanded before it is tested to see if it is empty.&lt;/p&gt;
&lt;p&gt;Incidentally, the question also answers how to link &lt;code&gt;\thispagestyle{...}&lt;/code&gt; to &lt;code&gt;\section&lt;/code&gt;:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;\documentclass&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;scrreprt&lt;span class="nb"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;\NewMarkClass&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;specialpage&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\newcommand*&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\savethispagestyle&lt;/span&gt;&lt;span class="nb"&gt;}&lt;/span&gt;[1]&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
  &lt;span class="k"&gt;\InsertMark&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;specialpage&lt;span class="nb"&gt;}{&lt;/span&gt;#1&lt;span class="nb"&gt;}&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\AddToHook&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;build/page/reset&lt;span class="nb"&gt;}{&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
  &lt;span class="k"&gt;\Ifstr&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\LastMark&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;specialpage&lt;span class="nb"&gt;}}{}{}{&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
    &lt;span class="k"&gt;\thispagestyle&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\LastMark&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;specialpage&lt;span class="nb"&gt;}}&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
    &lt;span class="k"&gt;\InsertMark&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;specialpage&lt;span class="nb"&gt;}{}&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
  &lt;span class="nb"&gt;}&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
&lt;span class="nb"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;% Pages with chapter headings in `empty` page style:&lt;/span&gt;
&lt;span class="k"&gt;\RedeclareSectionCommand&lt;/span&gt;&lt;span class="na"&gt;[pagestyle=empty]&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;chapter&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="c"&gt;% Pages with section headings in `empty` page style:&lt;/span&gt;
&lt;span class="k"&gt;\AddtoDoHook&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;heading/endgroup/section&lt;span class="nb"&gt;}{&lt;/span&gt;&lt;span class="k"&gt;\savethispagestyle&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;empty&lt;span class="nb"&gt;}&lt;/span&gt;&lt;span class="k"&gt;\csname&lt;/span&gt; @gobble&lt;span class="k"&gt;\endcsname&lt;/span&gt;&lt;span class="nb"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;\pagestyle&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;headings&lt;span class="nb"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;\usepackage&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;blindtext&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\begin&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;document&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\chapter&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;Test Chapter&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\Blindtext&lt;/span&gt;&lt;span class="na"&gt;[5]&lt;/span&gt;
&lt;span class="k"&gt;\vspace*&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;5&lt;span class="k"&gt;\baselineskip&lt;/span&gt;&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\Blindtext&lt;/span&gt;&lt;span class="na"&gt;[3]&lt;/span&gt;
&lt;span class="k"&gt;\section&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;Test Section&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\Blindtext&lt;/span&gt;
&lt;span class="k"&gt;\blinddocument&lt;/span&gt;
&lt;span class="k"&gt;\end&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;document&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Via the do-hook &lt;code&gt;heading/endgroup/section&lt;/code&gt;, &lt;code&gt;\savethispagestyle{empty}&lt;/code&gt; is automatically executed immediately after the processing of the &lt;code&gt;\section&lt;/code&gt; heading. The &lt;code&gt;\csname @gobble\endcsname&lt;/code&gt; at the end of the do-hook definition ensures that the argument passed to the do-hook is ”eaten“. This solution only works with a KOMA-Script class, as only these have do-hooks. With the standard classes, you would have to find another way to execute &lt;code&gt;\savethispagestyle{empty}&lt;/code&gt; at the end of &lt;code&gt;\section{...}&lt;/code&gt; instead.&lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Markus Kohm</dc:creator><pubDate>Mon, 14 Jul 2025 08:22:12 -0000</pubDate><guid>https://sourceforge.neted707f50c3a96bb38ecfc46f330580742577d9a4</guid></item></channel></rss>