All page references here correspond to the English KOMA-Script manual, version number 2.28.
Consider the following TeX file.
\documentclass[12pt,headheight=30pt,headinclude,firsthead=false,firstfoot=false,foldmarks=false,foldmarks=blmtP,fromalign=center,fromphone,fromemail,version=last, backaddress=false, subject=titled, twoside=semi, cleardoublepage=current]{scrletter}
\usepackage{scrlayer-scrpage}
\usepackage{lipsum}
\usepackage{lastpage}
\ohead{\jobname.tex\hspace{0.5cm}\today}
\renewcommand\pagemark{{\usekomafont{pagenumber}\thepage\ of \pageref{LastPage}}}
\ofoot*{}
\cfoot{\pagemark}
\RequirePackage[T1]{fontenc}
\begin{document}
\def\today{19th February, 2022}
\begin{letter}{Name}
\opening{Dear Name,}
\thispagestyle{scrheadings}
\lipsum
\end{letter}
\lipsum
\end{document}
The document generated with PDFLaTeX has 4 pages. My question is about
the page numbers. As you can see, the page numbers are Page 1
, Page 2
, 3 of 4
, 4 of 4
. This is unexpected behavior.
If one replaces scrletter
with scrlttr2
, one gets the expected
behavior, namely 1 of 4
, 2 of 4
, 3 of 4
, 4 of 4
.
This is probably related to the fact that scrletter
defines its own
page styles, namely plain.letter
and letter
. It seems that this
page style has been created for letters that are embedded in documents
of other classes, which is the scrletter
use case. And it also seems
that this page style silently overrides the style i've set, at least
for the page numbers. But this is all semi-guesswork. I've been
reading the manual, trying to make sense of it.
For example, in Section 4.13: "Headers and Footers with the Default
Page Style" pg 231 is written:
scrletter letter Since the headings page style is generally already in
use by the classes, the scrletter package instead
defines the letter page style. This is accomplished
with the help of scrlayer-scrpage in chapter 5, page
254. With the automark=true setting enabled, letter
then assumes the role played by headings in
scrlttr2. With automark=false set, letter assumes the
role of myheadings.
I've read this a number of times, but it still reads like borderline
gibberish. But perhaps I haven't read it often enough. I've also read
the relevant parts of Ch 5, which make sense on their own, but I don't
see how they relate to the issue here.
On pg 229 it says:
See section 22.2 for more information about the characteristics of
the page style of the scrletter package.
Section 22.2 says
Currently, additional information on this topic can be found at the
same point in the German KOMA-Script book [Koh20a] only.
If anyone has the German book, and would like to summarize the
contents of that section, please do.
And also on pg 229, it says
Example: You are using the scrletter package and want letters to
use the same page style that was set for the rest of the document
with \pagestyle. To do this, put the command
\renewcommand{\letterpagestyle}{} in your document preamble. Notice
the star in \renewcommand*.
This seems like it might do what I want, but it didn't work for me.
Best Answer
The class
scrletter
is an undocumented wrapper-class. It loads classscrartcl
with font size12pt
and packagescrletter
.\pagemark
is already defined by the KOMA-Scriptscrartcl
. Therefore packagescrletter
defines\letterpagemark
for the letters in the document. If the format of the page numbers in the letters should be the same as in the other part of the document, use\let\letterpagemark\pagemark
before environment
letter
.Note:
can be replaced by
The result would be the same.