!if@twoside
!def!ps@bfheadings<!def!@oddfoot<>!def!@evenfoot<>%
!def!@evenhead<!bf !thepage!hfil !bf !leftmark>%
!def!@oddhead<!hbox<>!bf !rightmark !hfil !bf!thepage>%
!def!chaptermark##1<!markboth <!ifnum !c@secnumdepth !>!m@ne
!thechapter ! ! !fi ##1><>>%
!def!sectionmark##1<!markright <!ifnum !c@secnumdepth !>!z@
!thesection ! ! !fi ##1>>>
!else
!def!ps@bfheadings<!def!@oddfoot<>!def!@evenfoot<>%
!def!@oddhead<!hbox <>!bf !rightmark !hfil !bf!thepage>%
!def!chaptermark##1<!markright <!ifnum !c@secnumdepth !>!m@ne
!thechapter ! ! !fi ##1>>>
!fi
!let!@oldenddocument!enddocument
!def!enddocument<!label<@lastpage>!@oldenddocument>
!if@twoside
!def!ps@numheadings<!def!@oddfoot<>!def!@evenfoot<>%
!def!@evenhead<!rm !thepage/!pageref<@lastpage>!hfil !sl !leftmark>%
!def!@oddhead<!hbox<>!sl !rightmark !hfil !rm!thepage/!pageref<@lastpage>>%
!def!chaptermark##1<!markboth <!ifnum !c@secnumdepth !>!m@ne
!thechapter ! ! !fi ##1><>>%
!def!sectionmark##1<!markright <!ifnum !c@secnumdepth !>!z@
!thesection ! ! !fi ##1>>>
!else
!def!ps@numheadings<!def!@oddfoot<>!def!@evenfoot<>%
!def!@oddhead<!hbox <>!sl !rightmark !hfil !rm!thepage/!pageref<@lastpage>>%
!def!chaptermark##1<!markright <!ifnum !c@secnumdepth !>!m@ne
!thechapter ! ! !fi ##1>>>
!fi
!def!ps@mynumheadings<!let!@mkboth!@gobbletwo
!def!@oddhead<!hbox<>!sl!rightmark !hfil !rm!thepage/!pageref<@lastpage>>%
!def!@oddfoot<>!def!@evenhead<!rm !thepage/!pageref<@lastpage>%
!hfil!sl!leftmark!hbox <>>%
!def!@evenfoot<>!def!sectionmark##1<>!def!subsectionmark##1<>>
!if@twoside
!def!ps@bfnumheadings<!def!@oddfoot<>!def!@evenfoot<>%
!def!@evenhead<!bf !thepage/!pageref<@lastpage>!hfil !bf !leftmark>%
!def!@oddhead<!hbox<>!bf !rightmark !hfil !bf!thepage/!pageref<@lastpage>>%
!def!chaptermark##1<!markboth <!ifnum !c@secnumdepth !>!m@ne
!thechapter ! ! !fi ##1><>>%
!def!sectionmark##1<!markright <!ifnum !c@secnumdepth !>!z@
!thesection ! ! !fi ##1>>>
!else
!def!ps@bfnumheadings<!def!@oddfoot<>!def!@evenfoot<>%
!def!@oddhead<!hbox <>!bf !rightmark !hfil !bf!thepage/!pageref<@lastpage>>%
!def!chaptermark##1<!markright <!ifnum !c@secnumdepth !>!m@ne
!thechapter ! ! !fi ##1>>>
!fi