%% Library of some plainTeX macros for convenient transcription of
%% mathematical lectures.
%% Extremely work-in-progress version.
%%
%% Note that a lot of macros is obsolete and isn't really supposed
%% to exist anymore.
%%
%% TODO: There should be a fastex (and csfastex) script which would
%% take parameters like whether to generate single-side or double-side
%% document etc, and which would automagically include this file
%% and a book-wide configuration file. (Scanning the directories
%% up and up, stopping when a file contains \stopWalking.)
%%
%% (c) Petr Baudis <pasky@ucw.cz>  2004 (new-style BSD licence)

% FIXME: Makes sense only if the file is version-controlled.
\catcode`\$=11
%\def\librev{$Revision$}
% 1: first public release
% 1.6: added \Vec
% 1.61: integer set is now called \intgr; maximal indentation level for scpart
% 1.616: introduced \M,\D, \iproof*impl; (sub)chapters don't indent;
%        \defined usage description, some more \short* macros, integrals and
%        convergence, AMSTeX symbols
% 1.616a: \restring as \upharpoonright (restringed operations)
\def\librev{1.616} % \phi
\catcode`\$=3



% Temporarily allow @ in macro names, to isolate internals. We use @@s in our
% internal macro names, not to conflict with plainTeX macros.
\catcode`@=11


\parindent=1em



%%% flow control

% From TeXbook:
\def\ifundefined#1{\expandafter\ifx\csname#1\endcsname\relax}

% The d@@ubleLoaded ``if'' says whether we are already loaded. That's useful
% for indexes - in the per-file loads we are double-loaded and in \bend we
% don't \bye.
\newif\ifd@@ubleLoaded
\ifundefined{loadedOnce}\def\loadedOnce{}\d@@ubleLoadedfalse\else\d@@ubleLoadedtrue\fi

\def\f@@rewell{\par\vfill\supereject}
\def\by@@{\fi\end} % together with \f@@rewell behaves as \bye
% Conditionally ends the processing
\def\bend{\f@@rewell\ifd@@ubleLoaded\indentlevel=0\antindent=10\else\by@@\fi}


%% If we are already loaded, let it die now. Otherwise TeX capacity may overflow
%% when processing large indexes.
\let\fastexinternalidl=\ifd@@ubleLoaded
\catcode`@=12
\fastexinternalidl\endinput\fi
\catcode`@=11



%%% general trickery

% take contents of group following the macro, and execute #1 at the start of
% the group and #2 at the end of the group
\def\nextgroupsurround#1#2{
	\global\def\ngs@@passpre{#1}
	\global\def\ngs@@passpost{#2}
	\futurelet\next\nextgr@@upsurround
}

\def\nextgr@@upsurround{
	\bgroup % Start the outer group
	% User contents inside the outer group (to till have counters and other
	% local defs in passpost).
	\ngs@@passpre
	% To be re-entrant, we now define a group-local \ngs@@localpost which
	% contains expanded content of \ngs@@passpost. We define it in the
	% current group but then start another group - \aftergroup is called
	% after local group definitions are already undone. That's after }
	% was hit and the inner group is over, thus \ngs@@localpost does its
	% job (it has no trouble expanding since it was defined in the outer
	% loop) and then terminates the outer group too.
	\edef\ngs@@localpost{\ngs@@passpost\egroup}\bgroup\aftergroup\ngs@@localpost
	% Clear the pass registers.
	\global\def\ngs@@passpre{\relax}\global\def\ngs@@passpost{\relax}
	% Kill the {, we already began all the groups necessary.
	\let\next
}

% Takes the first and third parameter and passes them to output, putting
% the second parameter inbetween if both parameters were non-empty.
% TODO: Just a dummy stub now.
\def\maybeDelimit#1#2#3{#1#2#3}



%%% some cheap font stuff

\font\thirtybf=csbx30
\font\twentyfiverm=csr25
\font\eighteenbf=csbx18
\font\eighteenrm=csr18
\font\eighteenbf=csbx18
\font\seventeenrm=csr17
\font\fourteenrm=csr14
\font\fourteenbf=csbx14
\font\twelverm=csr11
\font\twelvebf=csbx11
\font\elevenrm=csr11
\font\elevenbf=csbx11
\font\tenrm=csr10
\font\tenbf=csbx10
\font\ninerm=csr9
\font\eightrm=csr8
\font\eighttt=cstt8
\font\sixrm=csr6

\let\sc=\tenrm
\let\bfsc=\tenbf
\let\fourteen=\fourteenrm
\def\textsc#1{\uppercase{\sc #1}}
\def\textbfsc#1{\uppercase{\bfsc #1}}



%%% sets and "lowlevel" symbols

% Property of AMSTeX:
\def\n@@wmsbfam{\alloc@8\fam\chardef\sixt@@n\msbfam} %\newfam\msbfam
\ifundefined{msbfam}\n@@wmsbfam\fi
\font\tenmsb=msbm10 \font\sevenmsb=msbm7 \font\fivemsb=msbm5
\textfont\msbfam=\tenmsb
\scriptfont\msbfam=\sevenmsb \scriptscriptfont\msbfam=\fivemsb
\def\Mf{\fam\msbfam}

% Woo-hoo!
\input amssym.tex


% general notation: \s<capital_letter>
\def\sC{{\Mf C}}
\def\sK{{\Mf K}}
\def\sM{{\Mf M}}
\def\sN{{\Mf N}}
\def\sP{{\Mf P}}
\def\sQ{{\Mf Q}}
\def\sR{{\Mf R}}
\def\sX{{\Mf X}}
\def\sZ{{\Mf Z}}

\def\zeroSet{\emptyset} % obsolete
% \...Set macros are obsolete
\def\nat{\sN} \def\naturalSet{\sN}
\def\intgr{\sZ} \def\integerSet{\sZ}
\def\rat{\sQ} \def\rationalSet{\sQ}
\def\real{\sR} \def\realSet{\sR}
\def\cmplx{\sC} \def\complexSet{\sC}
\def\K{\sK} % brave

\def\cO{{\cal O}}
\def\cP{{\cal P}}
\def\cU{{\cal U}}
\def\cV{{\cal V}}
\def\cW{{\cal W}}
\def\cT{{\cal T}}
\def\cB{{\cal B}}
\def\cN{{\cal N}}
\def\cA{{\cal A}}
\def\cC{{\cal C}}



%%% Special macros

\def\M#1{$\displaystyle{#1}$}
\def\D#1{\displaystyle{#1}}



%%% indentation

% Internals

\newcount\indentlevel
\indentlevel=0
\newcount\antindent
\antindent=10
\def\changantindent#1{\advance\antindent by -#1 \ifnum\antindent<2\antindent=2\fi \vskip\antindent pt}
\def\changeindent#1{\advance\indentlevel by #1 \leftskip\indentlevel em}
%\long\def\indentLevel#1{\changantindent{2} \changeindent{2} \par {%
%				%\newcount\setlevel \ifnum\listitem>0\advance\listlevel by 1\setlevel=1\else\setlevel=0\fi%
%				%\newcount\listitem \listReset%
%				{#1}%
%				%\ifnum\setlevel=1\advance\listlevel by -1\fi%
%			} \par \changeindent{-2} \changantindent{-2}}
\def\start@@ndent{\changantindent{2} \changeindent{2} \par}
\def\end@@ndent{\par \changeindent{-2} \changantindent{-2}}

% Public functions

% Takes the block to be indented as an argument - group which must immediatelly follow this command
\def\indentLevel{\nextgroupsurround{\start@@ndent}{\end@@ndent}}

\long\def\centered#1{$$\vbox{#1}$$}



%%% lists

% Internals

\newcount\listitem
\newcount\listlevel
\listlevel=0
\def\listReset{\listitem=0}
\listReset
\long\def\coreListItem#1{%
	\par\smallbreak%
	\item{\bf #1}%
	%{#2}%
}

\def\startL@@st{\listReset\advance\listlevel by 1 \smallskip \start@@ndent}
\def\endL@@st{\end@@ndent \smallbreak \advance\listlevel by -1}

% Public functions
% All of them should (\list must) be followed by a group containing the contents of the item/list.

\long\def\namedListItem#1{\coreListItem{(#1)}}
\long\def\olistItem{\coreListItem{$\bullet$}}

\long\def\advListItem#1{\advance\listitem by 1\coreListItem{#1}}
\long\def\alistItem{\advListItem{(\advance\listitem by 96\char\listitem\advance\listitem by -96)}}
\long\def\nlistItem{\advListItem{(\the\listitem)}}
\long\def\tlistItem{\advListItem{\the\listitem.}}
\long\def\rlistItem{\advListItem{(\romannumeral\listitem)}}
\long\def\RlistItem{\advListItem{\uppercase\expandafter{\romannumeral\listitem}.}}
\long\def\listItem{%
	\ifcase\listlevel%
		    \advListItem{(UGH?)}%
		\or \rlistItem%
		\or \nlistItem%
		\or \RlistItem%
		\or \nlistItem%
	\fi%
}

\def\list{\nextgroupsurround{\startL@@st}{\endL@@st}}



%%% structure construtors

% Internals

\long\def\corecapt#1#2#3{\vskip #1{#2 #3}}

\newcount\captlevel
\captlevel=1

\def\startScp@@rt{\advance\captlevel by 1 \ifnum\indentlevel<8\start@@ndent\else\def\no@@indent{}\par\fi}
\def\endScp@@rt{\ifundefined{no@@indent}\end@@ndent\else\par\fi \advance\captlevel by -1}


% Public functions

% Each file contains one or more complete subchapters. They are usually grouped
% to chapters in the index file.

% TODO: Page binding.

% Note that all of these MUST be immediatelly followed with a group containing
% the contents of the section.


% These are fixed, because they are often off-file
\long\def\chapter#1{\vskip 1em\chaptername={#1}\mark{}{\eighteenbf #1}\nobreak\vskip 1em}
\long\def\subchapter#1{\vskip 1em\mark{#1}{\fourteenbf #1}\nobreak\vskip 0.5em}

%% \scpart machinery - captions automatically scaling based on nesting level

\long\def\scpart#1{
	\ifcase\captlevel%
	           \corecapt{20em}{\sl}{BZZZZZZ #1}%
	       \or \corecapt{0.7em}{\twelvebf}{#1}%
	       \or \corecapt{0.5em}{\elevenbf}{#1}%
	       \or \corecapt{0.4em}{\tenbf}{#1}%
	       \else \corecapt{0.2em}{\tenbf}{#1}%
	\fi%
	\nobreak\nextgroupsurround{\nobreak\startScp@@rt\nobreak}{\endScp@@rt}%
}

%% some predefined \scparts
% Do not forget to immediatelly follow them by a group immediatelly.

\long\def\proof{\scpart{\textbfsc{D�kaz}:}}
\long\def\example{\scpart{P��klad:}}
\long\def\examples{\scpart{P��klady:}}
\long\def\exercise{\scpart{Cvi�en�:}}
\long\def\exercises{\scpart{Cvi�en�:}}
\long\def\note{\scpart{Pozn�mka:}}
\long\def\nnote#1{\scpart{Pozn�mka #1:}}
\long\def\notes{\scpart{Pozn�mky:}}

\long\def\definition{\scpart{Definice:}}
\long\def\declaration{\scpart{Tvrzen�:}}
\long\def\observation{\scpart{Pozorov�n�:}}
\long\def\impl{\scpart{D�sledek:}}

\long\def\lemma#1{\scpart{\textbfsc{Lemma}#1:}}
\long\def\theorem#1#2{\scpart{\textbfsc{V�ta #1}{ (#2):}}}

\long\def\proofleftimpl{\scpart{``$\Leftarrow$''}}
\long\def\proofrightimpl{\scpart{``$\Rightarrow$''}}
\long\def\iproofleftimpl{\coreListItem{``$\Leftarrow$'':}}
\long\def\iproofrightimpl{\coreListItem{``$\Rightarrow$'':}}

% TODO: \nextgroupsurround
\long\def\optnote#1{\medskip\hbox{\hskip\leftskip\hskip\parskip\vbox{\halign{##&##\cr\vrule&\parindent=0pt\leftskip=1em \vbox{\ninerm #1}\cr}\medskip}}}
%\long\def\optnote{\medskip\nextgroupsurround{\parindent=0pt\ninerm\start@@ndent}{\end@@ndent}}


%% single-line (prefixing) caption (to be followed with a group immediatelly)

\def\shortdef#1{\par{\bf #1: }}
\def\shortnote{\shortdef{Pozn.}}
\def\shortproof{\shortdef{D�kaz}}
\def\shortexerc{\shortdef{Cvi�en�}}
\def\shortexample{\shortdef{P��klad}}
\def\shortobs{\shortdef{Pozorov�n�}}
\def\shortimpl{\shortdef{D�sledek}}



%%% proof terminators

\def\qed{\par{\bf\it Q.E.D.}\par}
\def\sqed{{\bf\it Q.E.D.}}
\def\XXX{\par{\bf\it$\not\hskip-0.85pt\sharp$ Spor}\par}

\def\TODO#1{{\bf T-O-D-O:} {#1}}
\def\DCV{$\<$cvi�en�\/$\>$}



%%% simple substitutions, mostly obsoleted

\def\a{\alpha}
\def\s{\sigma}
\def\ee{e}
\def\x{\times}
\def\eps{\varepsilon}
\def\ro{\varrho}
\def\approximately{\approx}
\def\common{\cap}
\def\restring{\upharpoonright}
\def\grad{\bigtriangledown}



%%% TODO
\def\pascaltriangle{
$\<$Pascal�v $\triangle$ $\>$
}




%%% custom math operators and other useful symbolic aliases

\def\infim{\mathop{\rm inf}}
\def\tg{\mathop{\rm tg}}
\def\cotg{\mathop{\rm cotg}}
\def\tgh{\mathop{\rm tgh}}
\def\cotgh{\mathop{\rm cotgh}}
\def\arctg{\mathop{\rm arctg}}
\def\arccotg{\mathop{\rm arccotg}}
\def\sign{\mathop{\rm sign}}
\def\sgn{\mathop{\rm sgn}}
\def\bool{\mathop{\rm bool}}
\def\GF{\mathop{\rm GF}}
\def\mod{\mathop{\rm mod}}
%\edef\oldcong{\cong{}}
\def\oldcong{\cong}
%\def\cong{\mathop{\,|\,}}
\def\sspan{\mathop{\rm span}}
\def\Ker{\mathop{\rm Ker}}
\def\rank{\mathop{\rm rank}}
\def\Int{\mathop{\rm Int}}
\def\vol{\mathop{\rm vol}}
\def\adj{\mathop{\rm adj}}
\def\avg{\mathop{\rm avg}}
\def\id{\mathop{\rm id}}
\def\cl{\mathop{\rm cl}}

\def\cn#1#2{{{#1} \choose {#2}}}
\def\ceil#1{\left\lceil{}{#1}\right\rceil{}}
\def\floor#1{\left\lfloor{}{#1}\right\rfloor{}}
\def\broot#1{\root{\scriptstyle{#1}}}

\def\undernote#1#2{\underbrace{#1}_{\scriptstyle #2}}

% These may change since they clash with perhaps-useful plainTeX stuff.
\def\<{\langle}
\def\>{\rangle}

\def\existss{\exists\,}
\def\onexists{\exists!\,}

\def\dg{^\circ}

\def\riemint#1#2{\hbox{\eightrm(R)}\int_{#1}^{#2}}
\def\driemint#1#2{\riemint{\underline{#1}}{#2}}
\def\hriemint#1#2{\riemint{#1}{\underline{#2}}}

\def\newtint#1#2{\hbox{\eightrm(N)}\int_{#1}^{#2}}
\def\dnewtint#1#2{\newtint{\underline{#1}}{#2}}
\def\hnewtint#1#2{\newtint{#1}{\underline{#2}}}

\def\diff#1#2{{\delta #1 \over \delta #2}}
\def\diffi#1#2{{\delta #1/\delta #2}}

\def\conP{\rightarrow}
\def\conS{\rightrightarrows}
\def\conSL{\becauseof{loc}{\conS}}
\def\con@@i#1#2#3{#1 #2\ {\rm na}\ #3}
\def\conPi#1#2{\con@@i{\conP}{#1}{#2}}
\def\conSi#1#2{\con@@i{\conS}{#1}{#2}}
\def\conSLi#1#2{\con@@i{\conSL}{#1}{#2}}

% normal overrightarrow overrides part of the letter, so make the
% arrow head appear after the end of the arrow.
\def\Vec#1{\overrightarrow{\hskip1.5pt #1 \hskip3.5pt}}

\def\nil{{\bf nil}}


%% obsoleted ones

\def\each{\hskip3pt plus 6pt\forall}
\def\abs#1{|#1|}
\def\setjoin#1#2#3{\bigcup_{#1}^{#2}{#3}}
\def\setcommon#1#2#3{\bigcap_{#1}^{#2}{#3}}
\def\summ#1#2#3{\sum_{#1}^{#2}{#3}}
\def\limm#1#2{\lim_{#1}{#2}}



%%% relational operators

\def\opupon#1#2{{\buildrel \hbox{\eightrm #1} \over #2}}

% shall we use {} rather than \  ?
% we should define those as proper math operators in the first place
\def\hypothetically#1{\ \opupon{?}{#1}\ } % obsolete name
\def\hypo{\hypothetically}
\def\becauseof#1#2{\ \opupon{#1}{#2}\ }
% this is for "global" definitions (log \defined exp^{-1});
% we use := for definitions which are just local to a proof etc.
% (A := lim_{x \to 0} a/x)
\def\defined{\ \opupon{def}{=}\ }
\def\bijection{\ \opupon{1--1}{\longleftrightarrow}\ }
\def\disjoin{\ \opupon{.}{\cup}\ }
\def\disjmerge{\ \opupon{.}{\cap}\ }
\def\bigdisjoin{\mathop{\opupon{.}{\bigcup}}\limits}

\def\homeomorf{\oldcong}

\def\pathin#1{\sim_{#1}}

\def\derived{\rightsquigarrow}

\def\Avereq#1#2{\lower.5pt\vbox{\lineskiplimit\maxdimen\lineskip-.5pt
    \ialign{$#1\hfil##\hfil$\crcr#2\crcr=\crcr}}}
\def\isom{\mathrel{\mathpalette\Avereq\sim}}

\def\et{\land} % people preferring '&' may redefine it here
\def\nin{\notin} % obsolete



%%% text-in-math etc

% ugly bordered cell
\def\boxit#1{\vbox{\hrule\vskip3pt\hbox{\vrule\kern3pt #1\kern3pt\vrule}\vskip3pt\hrule}}

\def\textbox#1{\hbox{\hskip 0.25em #1 \hskip 0.1em}}
\def\textnote#1{\hbox{\hskip 0.5em \sl ({#1}) \hskip 0.25em}}
\def\opt#1{\boxit{$^{#1}$}}



%%% hypertext

% TODO
\def\reference#1{#1}
\def\ref#1{\reference{#1}}
\def\href#1#2{\reference{#1}} % #2 is the real target
\def\fileReference#1{\input #1}
\def\figref#1{$\<$diagram #1$\>$}

\def\ias#1#2#3{\reference{V#1.#2-#3}}



%%% asciiart pains

\chardef\other=12
\def\ttverbatim{
 % Redefine catcodes
 %\catcode`\\=\other
 %\catcode`\{=\other
 %\catcode`\}=\other
 %\catcode`\$=\other
 \catcode`\&=\other
 \catcode`\#=\other
 \catcode`\%=\other
 \catcode`\~=\other
 \catcode`\_=\other
 \catcode`\^=\other
 % Our \par will prepend ~s to starts of lines so that spaces at the start of
 % the line don't get collapsed away (\obeyspaces doesn't seem to help there).
 % \edef so that ~ gets expanded before it's too late.
  \edef\mypar{\endgraf~} \let\par\mypar
 % Obey!
  \obeyspaces \obeylines \tt}

\def\asciiart{\nextgroupsurround{\start@@ndent~\ttverbatim}{}}



%%% \cases reversed
% ...
% ... } ...
% ...

\long\def\sesac#1#2{\left.\hbox{$\displaystyle{#1}$}\,\right\}\,\hbox{$\displaystyle{#2}$}}



%%% multi-column \eqalign

% multi-column \eqalign, with middle columns centered
\def\eqmalign#1{
	\vcenter{\ialign{\strut\hfil$\displaystyle{##}$&&\hfil$\displaystyle{{}##}$\hfil\cr#1\cr}}
}
% middle columns aligned to right
\def\eqmralign#1{
	\vcenter{\ialign{\strut\hfil$\displaystyle{##}$&&\hfil$\displaystyle{{}##}$\cr#1\cr}}
}

% Obsolete:

% multi-column \eqalign stub
\def\eqcorealign#1#2{
	\vcenter{\ialign{\strut\hfil$\displaystyle{##}$&#1$\displaystyle{{}##}\hfil$\cr#2\cr}}
}

% 3-column \eqalign
\def\eqtrialign#1{\eqcorealign{$\displaystyle{{}##}$&}{#1}}

% 4-column \eqalign
\def\eqartalign#1{\eqcorealign{$\displaystyle{{}##}$&$\displaystyle{{}##}$&}{#1}}




%%% generic tables

% Defines ruled table (with dynamic no. of columns, each centered, the table
% itself centered too).
% \halign is extremely fragile and hates bgroups/egroups spanning over columns
% inside, so we can't use \surroundgroup.
\def\startRuledTable{
	% Horizontal rules
	%\everycr{\noalign{\hbox{\vrule height 2pt} \hrule \hbox{\vrule height 2pt}}}
	\everycr{\noalign{\hrule}}
	$$
	\hbox\bgroup
		\vbox\bgroup
			\halign\bgroup%{
				% \strut makes the \vrules connected between rules
				\strut\vrule
				\quad\hfil \vbox{\kern2pt \hbox{##} \vfil\kern2pt} \hfil\quad\vrule
				&& % makes the last column's template repeat over and over
				\quad\hfil \vbox{\kern2pt \hbox{##} \vfil\kern2pt} \hfil\quad\vrule
				\cr
}

\def\endRuledTable{
			\egroup%}
		\egroup%vbox
	\egroup%hbox
	$$
	\everycr{}
}

% \hbox to 4cm {\vbox{\noindent #}}
% \hbox{\vbox{\noindent\hsize4cm #}}

% Hyp: continuation on another page:
% \noalign{\nobreak\hrule\penalty0\kern-0.4pt\hrule}
% ale nezopakuje popisky

% roztazeni pres vice sloupcu:
% \omit\span\omit (\multispan 2)




%%% headers/footers

% Variables to be set by user:
\newtoks\author % e.g. Pavel Valtr
\newtoks\trauthor % Transcription author; e.g. Petr Baudis
\newtoks\title % e.g. Discrete Mathematics
\newtoks\acyear % Academical year; e.g. 2004/2005
\newtoks\tiragequote
\newtoks\localrev % Each v-c file should contain \setlocalrev{$Revision$} at the start
% TODO: Kill the $Revision$ junk by using some \newif-like trick.
%\def\s@@tlocalrev#1{\localrev=#1}
%\def\setlocalrev{\nextgroupsurround{\catcode`\$=11\localrev=}{\egroup\catcode'\$=3}}
\def\printrev{\the\localrev/L:\librev}

% Makes a title page; after all above was set

\def\tirage{
	{\headline{\hfil}\footline{\hfil}
	\chaptername={}
	\mark{}
	\phantom{.}
	{}
	\ifundefined{twoPageLayout}\vskip 5em\else\vskip 15em\fi
	\the\tiragequote
	\ifundefined{twoPageLayout}\vskip 3em\else\vskip 10em\fi
	\xvfil
	{\noindent\hrule\vskip 4mm\noindent\eightrm\copyright{}~\the\acyear~\the\author{}, \the\trauthor\hfil\break
	Verze \printrev. Tato verze nen� garantov�na, nemus� b�t kompletn� a m��e obsahovat chyby.\hfil\break
	Aktu�ln� verzi v�dy najdete na {\eighttt http://math.or.cz/}.\hfil\break
	Sazba v programu \TeX.\hfil\break}
	}
}

\def\maketitlepage{
	{\headline{\hfil}\footline{\hfil}
	\vskip 5em
	$$\hbox{\vbox{\hfil\twentyfiverm\the\author\hfil}}$$
	\vskip 10em
	$$\hbox{\vbox{\hfil\thirtybf\the\title\hfil}}$$
	\vfill
	$$\hbox{\vbox{\hfil\seventeenrm P�epsal \the\trauthor{}\hfil}}$$
	$$\hbox{\vbox{\hfil\seventeenrm v~ak.~roce \the\acyear\hfil}}$$
	\vskip 12em
	\ifundefined{twoPageLayout}\let\xvfil\relax\tirage\else\let\xvfil\vfil\break\tirage\fi
	\pageno=0
	\vfil\break
	}
}


\newtoks\chaptername % e.g. Functions

% TODO: Optionally differentiate odd/succ pages.

% Having non-mark chaptername is not a problem since chapters always start
% on a new page.
\def\rightH@@adline{\tenrm \the\author~--- \the\title   \hfil   \maybeDelimit{\the\chaptername}{ {}--- }{\firstmark}}
\def\leftH@@adline{\tenrm \maybeDelimit{\the\chaptername}{ {}--- }{\firstmark}   \hfil   \the\author~--- \the\title}
\headline={\ifundefined{twoPageLayout}\rightH@@adline\else\ifodd\pageno\rightH@@adline\else\leftH@@adline\fi\fi}

\def\devprintrev{\ifundefined{final}\printrev\else\relax\fi}
\def\rightF@@tline{\tenrm \devprintrev\hfil\folio}
\def\leftF@@tline{\tenrm \folio\hfil\devprintrev}
\footline={\ifundefined{twoPageLayout}\rightF@@tline\else\ifodd\pageno\rightF@@tline\else\leftF@@tline\fi\fi}




% No more @s in macro names.
\catcode`@=12


%% And that's all. Now it's your game.
