%
% example2.latex
% 
% See smalltalkToTexMacro.tex for documentation
%
% -----------------------------------------------------
%
% This file is an example of importing a Smalltalk file
% into a Latex file.
% 

\def\imwrite#1{\immediate\write16{#1}}
\newcount\demo\demo=0
\newcount\demoB\demoB=0
\newtoks\demofile


\imwrite{       }
\imwrite{Please Choose Demo:}
\imwrite{    1) Very simple page, and unformatted methods}
\imwrite{    2) Formatted methods, and different sectioning}
\imwrite{    3) Finds class starts}
\imwrite{    4) Above with small fonts, different method formatting}
\imwrite{    5) Line numbers (ich)}
\imwrite{    6) File with TeXCommands in it}
\imwrite{    7) Above with monospaced comments}
\imwrite{    8) Format change log type of file}
\message{    9) Change log with line numbers}
\read16 to \inline\demo=\inline


\imwrite{       }
\imwrite{Please Choose Demo Option:}
\imwrite{    1) 11pt, One-sided, Seperate sectioning (non-latex)}
\imwrite{    2) 10pt, Two-sided, Latex sectioning}
\imwrite{    3) 12pt, One-sided, Latex sectioning, indexing}
\message{    4) 11pt, Two-sided, Marks On, Non-latex sectioning, index}
\read16 to \inline\demoB=\inline

\ifnum\demo<6
  \demofile={exampleNoCommands.st}
\else\ifnum\demo<8
  \demofile={exampleCommands.st}
\else
  \demofile={exampleChange.st}
\fi\fi

\imwrite{}
\message{Format what file (blank implies default to \the\demofile):}
\read16 to \inline

\def\setBangMode{}

\if\par\inline\else %they enterred a different file
\demofile=\expandafter{\inline}

\imwrite{}
\imwrite{Choose chunk file format}
\imwrite{    1) Bangs ('!') doubled  (eg: ! in comment -> !!)}
\message{    2) Bangs ('!') modal    (eg: ! in comment left alone)}
\read16 to \inline

\if\par\inline\else%
\bgroup
\count0=\inline
\ifnum\count0=2
\gdef\setBangMode{\setBangModal}
\fi
\egroup
\fi

\fi% 


\input epsf    % only neccesary for exampleCommands.st


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\ifcase\demoB\or        %Group 1
  \documentstyle[11pt]{article}       
\or                     %Group 2
  \documentstyle[twoside]{article}       
\or                     %Group 3
  \documentstyle[12pt]{article}       
  \makeindex
\or                     %Group 4
  \documentstyle[11pt,twoside]{article}       
  \makeindex
\fi



\hoffset -0.6in
\textwidth 6in     %Latex pages are generally too narrow for the code
                   %and causes a lot of line wrapping


\pagestyle{headings}

\begin{document}

\tableofcontents\cleardoublepage

\section{Introduction}          


This file is an example of importing a Smalltalk file
into a Latex file. 
There are a number of different formats in here which
you can sample by choosing one of the demos:
\begin{enumerate}
   \item  Very simple page, and unformatted methods
   \item  Formatted methods, and different sectioning
   \item  Finds class starts
   \item  Above with small fonts, different method formatting
   \item  Line numbers (ich)
   \item  File with TeXCommands in it
   \item  Above with monospaced comments
   \item  Format change log type of file
   \item  Change log with line numbers
\end{enumerate}

\section{Classes}

We can now import the Smalltalk classes.
          
\input smalltalkToTexMacro.tex


\ifcase\demoB\or        %Group 1
   \fromLatexDocument
   \useCenteredTitles
   \clearpage
\or                    %Group 2
   \fromLatexDocument
   \cleardoublepageLeft
   \def\nextClassEject{\cleardoublepageLeft}
\or                    %Group 3
   \fromLatexDocument
   \useAlternateDoneMethodB   % indexes at method selectors
\or                    %Group 4
   \fromLatexDocument
   \useCenteredTitles
   \useAlternateDoneMethodB % this is a SNEAK since this method
                            % is defined in \useLatexTitles, but
							% happens not to be  
reset in \useCenteredTitles
   \marksOn
   \cleardoublepageLeft
   \def\nextClassEject{\cleardoublepageLeft}
\fi

%%%%%%%%% Independent of the column formatting %%%%%%%%%%%%

\ifcase\demo\or  % 1
   \useProcessingWithNoClasses
   \dontFormatMethods
\or              % 2 
\or              % 3 
   \findClasses
   \class{Boiler}{Components} % FindClasses wont find                                                                    
                              % the first class in the file
\or              % 4 
   \findClasses
   \startClassDef{Boiler}{Components}
   \setClassSection{Diagram}%
   \setCategory{Testing}%
   \endClassDef
   \hbox to \hsize{\hss\vbox to 2in{\vss}\hss}%
   \startClassSection{Definition}
\or              % 5 
   \findClasses
   \class{Boiler}{Components} %                                                                     
   \useAlternateDoneMethodA

   \linenumberstrue
      %the next definition is to reset line numbers at the start
	  %of each class (as opposed to numbering the whole output
	  %sequetially
   \def\classDefined{%
     \lineno=1%  -- the added line
     \edef\temp{\printClass}%
     \expandafter\printTitle\expandafter{\temp}}
   

\or              % 6 
\or              % 7 
   \useMonospacedComments
\or              % 8 
   \useProcessingWithNoClasses
   

\or              % 9 
   \linenumberstrue
   \useProcessingWithNoClasses
   
\fi


%%%%%%% Now let's read the file

\def\diagram#1{% for the \diagram command in exampleCommand.st
	\vfil
	\beginNormalSpecials% NECCESARY TO ALLOW READING OF EXTERNAL FILE
	\vbox {
	\startClassSection{Diagram}
	\medskip
	\epsfxsize=\hsize
	\line{\hss\epsfbox{BoilerDiagram.eps}\hss}%
	}
	\vfil\eject
	\endNormalSpecials
}

\ifnum\demoB<4
   \expandafter\startAndRead\expandafter{\the\demofile}
   \clearpage

\else
	\begingroup
	%%% Save the old formatting commands, and set new ones
		\xdef\saveLeft{\leftmark}  %must be global since it will be  
accessed
		\xdef\saveRight{\rightmark}%outside the group
	
		\def\leftmark{\pageClass\ \pageFirstSection}  %or whatever you  
want
		\def\rightmark{\pageClass\ \pageLastSection}  %
	
	
   		\expandafter\startAndRead\expandafter{\the\demofile}
	
		\clearpage
	%%% Restore the old format
		\markboth{\saveLeft}{\saveRight}

	\endgroup%return \leftmark, \rightmark back to normal
\fi

\section{After Smalltalk}
\subsection{After smalltalk}


\end{document}



