% mandefs.tex style definition for the Lollipop manual
% copyright 1992/3 Victor Eijkhout
% copyright 2014--2016 Vafa Khalighi
%
%
%    This program is free software: you can redistribute it and/or modify
%    it under the terms of the GNU General Public License as published by
%    the Free Software Foundation, either version 3 of the License, or
%    (at your option) any later version.
%
%    This program is distributed in the hope that it will be useful,
%    but WITHOUT ANY WARRANTY; without even the implied warranty of
%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%    GNU General Public License for more details.
%
%    You should have received a copy of the GNU General Public License
%    along with this program.  If not, see <http://www.gnu.org/licenses/>.
%
%
\def\con#1{{\tt#1}}
\def\n#1{{\tt#1}}
\def\file#1{{\tt#1}}

\def\Lollipop{Lollipop}

\Distance:rightmarginstretch={0cm plus 2.54cm}
\Distance:whitebefore={6pt plus 3pt minus 2pt}
\Distance:whiteafter=whitebefore
\FlushRight:no

\DefineExternalFile:contents=toc

\DefineHeading:Chapter
    breakbefore:yes whiteafter:20pt
    line:start PointSize:14 Style:bold literal:Chapter 
        Spaces:1 ChapterCounter line:stop
    vwhite:15pt
    line:start PointSize:16 Style:bold title line:stop
    external:contents title external:stop
    Stop

\AdaptiveDistance:WidestLabel=15pt
\def\MeasureLabel{\ifdim\BlockWidth>\WidestLabel
    \global\WidestLabel\BlockWidth\fi}
\StartCommand{\Distance:parindent=WidestLabel }
\DefineHeading:Section
    whitebefore:{20pt plus 2pt} whiteafter:14pt
    line:start PointSize:14 Style:italic 
        block:start block:start ChapterCounter . SectionCounter
              Spaces:1 block:stop MeasureLabel
              fillupto:WidestLabel
        title line:stop
    external:contents title external:stop
    label:start ChapterCounter . SectionCounter label:stop
    Stop
\GoverningCounter:Section=Chapter

\DefineHeading:SubSection
    whitebefore:{14pt plus 2pt} whiteafter:8pt
    line:start PointSize:10 Style:italic 
        ChapterCounter . SectionCounter . SubSectionCounter 
        Spaces:1 title line:stop
    label:start ChapterCounter . Spaces:.2 SectionCounter 
        . Spaces:.2 SubSectionCounter label:stop
    Stop
\GoverningCounter:SubSection=Section

\DefineExternalFile:impnotes=imp
\DefineHeading:iSection
    whitebefore:{10pt plus 1pt} whiteafter:8pt
    line:start PointSize:12 Style:bold I - 
        Style:italic iSectionCounter
        Spaces:1 title line:stop
    label:start I - iSectionCounter label:stop
    external:impnotes title external:stop
    Stop
%\GoverningCounter:iSection=Chapter
\DefineExternalItem:iSection file:impnotes PushIndentLevel
    item:left I - Style:italic iSectionLabel item:stop
    title begingroup Spaces:2 Style:italic Page endgroup
    Stop

\DefineExternalItem:Chapter file:contents
    item:left ChapterLabel item:stop
    title begingroup Spaces:2 Style:italic Page endgroup
    Stop
\DefineExternalItem:Section file:contents PushIndentLevel 
    item:left ChapterLabel . SectionLabel item:stop
    title begingroup Spaces:2 Style:italic Page endgroup
    Stop

\def\impnotetxt{Implementor's Note}
\DefineTextBlock:ImpNote PushIndentLevel 
    whitebefore:12pt whiteafter:11pt
    line:start PointSize:12 Style:italic impnotetxt line:stop
    SansFace PointSize:9 SetFont text
    Stop
\excludecomment{ImpNote}

\DefineTextBlock:WizNote
  PushIndentLevel PointSize:9 SetFont text
  Stop

\DefineList:Description
  item:left description Spaces:2 item:stop whitebetween:6pt
  Stop

\DefineList:cDescription
  item:left tt char busje description Spaces:2 item:stop 
  whitebetween:6pt
  Stop

\DefineList:Enumerate
  item:left itemCounter item:stop
  Stop

\DefineList:Itemize
  item:left itemsign item:stop
  Stop

\DefineBBL 
  item:left [ - itemCounter - ] item:stop
  Stop

\SerifFace \SetFont

\newwrite\exfile
\def\HereAndOut#1{\immediate\write\exfile{#1}}
\specialcomment{Example}
   {\EExample
    \immediate\openout\exfile=example.tex\relax 
    \let\ThisComment\HereAndOut}
   {\immediate\closeout\exfile 
    \begingroup \tt \SetFont 
                \verbatimfile{example.tex}\endgroup
    \SaveAlloc \input example.tex\relax \RestoreAlloc
    \EExampleStop}
\DefineTextBlock:EExample whiteafter:{6pt plus 5pt}
    noimplicitclose rule:h vwhite:3pt
    line:start literal:Example Spaces:1.5 
                   ChapterCounter . EExampleCounter 
               line:stop
    vwhite:3pt rule:h vwhite:3pt text vwhite:3pt rule:h
    Stop
\GoverningCounter:EExample=Chapter

\specialcomment{OutExample}
 {\EExample
    \immediate\openout\exfile=example.tex\relax 
    \let\ThisComment\HereAndOut}
   {\immediate\closeout\exfile 
    \begingroup \tt \SetFont 
                \verbatimfile{example.tex}\endgroup
    \par\penalty0\relax
    \SaveAlloc \SuspendOutput \begingroup \CountSheetsno 
        \global\setbox\PageRow\hbox{}%
               \let\CurrentShipout\ToPageRow
        \xInputFile:example
        \endgroup
    \ResumeOutput \RestoreAlloc 
    \noindent\unhbox\PageRow\hbox{}\par
    \EExampleStop}
\newbox\PageRow\newbox\RowPage
\def\ToPageRow{\setbox\RowPage\box\WholePage \xToPageRow}
\def\xToPageRow{\global\setbox\PageRow
    \hbox{\unhbox\PageRow\box\RowPage\hfill}}

\def\opt#1{{\tt#1}}
\DefineExternalFile:optindex=oix
\def\refopt#1{\OptToIdx #1\par}
\DefineHeading:OptToIdx embedded:yes
    block:start tt title block:stop
    external:optindex title external:stop 
    nomarks Stop
\DefineExternalItem:OptToIdx file:optindex
    embedded:yes
    begingroup tt title endgroup 
    nobreak Spaces:1.5 Page Spaces:2.5 Stop

\DefineExternalFile:csindex=cix
\def\refcs#1{\CsToIdx #1\par}
\DefineHeading:CsToIdx embedded:yes
    block:start tt char busje title block:stop
    external:csindex title external:stop 
    nomarks Stop
\DefineExternalItem:CsToIdx file:csindex
    embedded:yes
    begingroup tt char busje title endgroup
    nobreak Spaces:1.5 Page Spaces:2.5 Stop

\topskip20pt
\OptionsMacro:PageDims=width:page=15cm height:page=23cm Stop
\DefinePageGrid:LeftPage macro:PageDims
    band:start block:start PointSize:9 Style:italic
               FirstPlaced:ChapterCounter Spaces:2 stickout:left
         FirstPlaced:ChapterTitle band:stop
    textband:start text textband:stop
    band:invisible block:start PointSize:9 Style:bold
         PageCounter Spaces:2 stickout:left band:stop
    NextPageGrid:RightPage Stop
\DefinePageGrid:RightPage macro:PageDims
    band:start fillup PointSize:9 Style:italic
        LastPlaced:SectionTitle
        block:start Spaces:2 LastPlaced:ChapterCounter . 
            LastPlaced:SectionCounter stickout:right
        band:stop
    textband:start text textband:stop
    band:invisible fillup 
        block:start PointSize:9 Style:bold Spaces:2
            PageCounter stickout:right band:stop
    NextPageGrid:LeftPage Stop
\DefinePageGrid:EmptyPage macro:PageDims
    textband:start text textband:stop
    NextPageGrid:LeftPage Stop

\AdaptiveCounter:LastInPage \CounterRepresentation:LastInPage=i
\AdaptiveCounter:LastRegPage \CounterRepresentation:LastRegPage=1
%\SetCounter:LastInPage=PageValue -- at the end of prelim.tex
%\SetCounter:LastRegPage=PageValue -- at the end of manual.tex

\endinput

% 92/11/05 stretch added
% 92/11/18 adaptive label width
% 92/11/19 adaptive last page