# Having trouble understanding error message

I am trying to use the answer supplied in question Change \headheight for a \pagestyle in my own document, but am having trouble understanding the error messages that come up.

Here is the document: (UPDATED)

\documentclass{scrartcl}
\usepackage{lecturenotes}

\begin{lecture}{01}{Sample Lecture Notes}{Tom Jack}{01/01/2000}{Chris Karl}{PHYSICS 130: Physics of Energy}

\end{lecture}
\end{document}


And the style file lecturenotes.sty: (UPDATED)

\def\fileversion{1.0}
\def\filedate{2014/02/05}
\NeedsTeXFormat{LaTeX2e}

\usepackage{amsmath,amssymb,amsthm,amsfonts}
\usepackage[top=2cm, bottom=2cm, outer=5.5cm, inner=2cm, heightrounded, marginparwidth=3.5cm, marginparsep=0.4cm, includeheadfoot]{geometry}

\framebox{
\vbox{
\hbox to 12.5cm { {\bfseries {\course}} \hfill {Lecture \lecturenum\ -- \lecturedate} }
\vspace{4mm}
\hbox to 12.5cm { {\Large \hfill {\lecturetitle}  \hfill} }
\vspace{2mm}
\hbox to 12.5cm { {\itshape {Lecturer: \lecturer} \hfill {Notes by: \lecturescribe}} }
}
}

}

\usepackage{scrpage2}

\newpagestyle{normalpage}{
{{\rlap{\lecturedate}\hfill \lecturetitle\hfill\llap{Lecture \lecturenum}}}
{{\rlap{\lecturedate}\hfill \lecturetitle\hfill\llap{Lecture \lecturenum}}}
{{\rlap{\lecturedate}\hfill \lecturetitle\hfill\llap{Lecture \lecturenum}}}
}{
{{\rlap{}\hfill \thepage\hfill\llap{}}}
{{\rlap{}\hfill \thepage\hfill\llap{}}}
{{\rlap{}\hfill \thepage\hfill\llap{}}}
}

\newpagestyle{firstpage}{
}{
{{\rlap{}\hfill \thepage\hfill\llap{}}}
{{\rlap{}\hfill \thepage\hfill\llap{}}}
{{\rlap{}\hfill \thepage\hfill\llap{}}}
}

\usepackage{afterpage}
\pagestyle{normalpage}

\AtBeginDocument{
\thispagestyle{firstpage}
\afterpage{
}
}

\newenvironment{lecture}[6]{
\global \def \lecturenum {#1}
\global \def \lecturetitle {#2}
\global \def \lecturescribe {#3}
\global \def \lecturedate {#4}
\global \def \lecturer {#5}
\global \def \course {#6}
\begin{document}
}{}

-
Consider switching to the new package scrlayer-scrpage. It is downwards compatible to scrpage2, but offers more features. –  Speravir Feb 8 at 23:30

Your use of new page styles is completely incorrect. To define a new page style, the KOMA-Script syntax is (see the KOMA-Script documentation, section 5.2.2. The Interface for Experts, p 217 onward):

\newpagestyle{<name>}{<header definition>}{<footer definition>}


where <header definition> and <footer definition> should resemble

(<ALL>,<ALT>){<EP>}{<OP>}{<OS>}(<BLL>,<BLT>)


Specifically,

• <ALL> – above line length: (header = outside, footer = separation line)
• <ALT> – above line thickness
• <EP> – deﬁnition for even pages
• <OP> – deﬁnition for odd pages
• <OS> – deﬁnition for one-sided layout
• <BLL> – below line length: (header = separation line, footer = outside)
• <BLT> – below line thickness


\newenvironment{lecture}
{<begin>}% \begin{lecture}
{<end>}% \end{lecture}

-
Also, there's no \begin{document}... OK. There is, but it is in completely the wrong place... –  cfr Feb 7 at 4:07
Thanks for the comprehensive rundown @Werner, I ended up getting completely confused trying to mix the code I saw in the "Change \headheight for a \pagestyle" question with the stuff I already had, which as you probably guessed used fancyhdr. I've straightened everything out, and it runs perfectly. Just one final question, with the code as it is now the header on the first page is lower than other header, and I'm not really sure why? Ill update the code in the question. –  Heisenbugs Feb 7 at 5:25
@Heisenbugs: This may be partially as a result of spurious spaces in your definitions (like \firstpagehead) as well as \AtBeginDocument (see What is the use of percent signs (%) at the end of lines?). However, it's sometimes better to mock up what you want and supply what you've tried, than to try and force something into something that it's not. Perhaps a follow-up question could be just that... –  Werner Feb 7 at 6:21
@Heisenbugs: Did you notice cfr’s comment? \begin{document} does not belong in a package definition and not even in an environment definition. –  Speravir Feb 7 at 22:28

For example, though this makes no attempt to emulate your formatting as I don't understand what it is meant to look like. This does, however, include the information in a fairly sane way:

\documentclass{scrartcl}
\usepackage{lipsum}
\usepackage{filecontents}
\begin{filecontents}{lecturenotes.sty}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{lecturenotes}[2014/02/05 v1.0 lecturenotes]
\def\fileversion{1.0}
\def\filedate{2014/02/05}

\RequirePackage{amsmath,amssymb,amsthm}% use \RequirePackage in a package or class file; \usepackage in the preamble; amssymb calls amsfonts
% \RequirePackage[top=2cm, bottom=2.5cm, outer=5.5cm, inner=2cm, heightrounded, marginparwidth=3.5cm, marginparsep=0.4cm, includeheadfoot]{geometry}% don't use geometry with the koma-script classes - koma-script manages this differently - or you could use a different class and use geometry, of course.

\newcommand*{\lecturenum}{}% make sure stuff is defined
\newcommand*{\lecturetitle}{}
\newcommand*{\lecturescribe}{}
\newcommand*{\lecturedate}{}
\newcommand*{\lecturer}{}
\newcommand*{\course}{}

\RequirePackage{scrpage2}

\ihead[\bfseries\course]{\lecturedate}% use \bfseries/\textbf{} - not \bf
\cfoot{\pagemark}

% \RequirePackage{afterpage}
% \addtolength{\textheight}{-3cm}% don't do this (either use geometry with other classes or koma-script's facilities)
\AtBeginDocument{%
%     \thispagestyle{firstpage}
%     \afterpage{
%     }
}

\newcommand{\lecture}[6]{%
\renewcommand* \lecturetitle {#2}%
\renewcommand* \lecturescribe {#3}%
\renewcommand*\lecturedate {#4}%
\renewcommand* \lecturer {#5}%
\renewcommand* \course {#6}%
\cleardoublepage
\thispagestyle{scrplain}%
\begin{center}
\Large\lecturetitle
\end{center}
{\itshape Lecturer: \lecturer\hfill Notes by: \lecturescribe}\bigskip\par% \itshape or \textit{} - not \it
}
\end{filecontents}
\usepackage{lecturenotes}

\begin{document}

\lecture{01}{Sample Lecture Notes}{James Cook}{01/01/2000}{Mark Cook}{PHYSICS 130: Physics of Energy}

\lipsum[1-20]% optional arguments in square brackets not curly ones

\end{document}


Obviously this isn't how you want it to look. My code is rather intended to give you an idea about how to go about it. The Koma-Script manual has a lot of information, as Werner indicated.

-