%
%  A Guide to PAD Style File
%       written by S.Kuramochi (satoshi@ueda.info.waseda.ac.jp)
%
%                                       Sep 14-16, 1995
%                                       Jun 12,15-17,Jul 8,15,17, 1996

\documentstyle[fullpage,titlepage,pad]{article}

\def\figref#1{Fig~\ref{#1}}
\def\tabref#1{Table~\ref{#1}}
\def\bs{$\backslash$}

\begin{document}

\title{A Guide to PAD Style File}
\author{Satoshi Kuramochi \\
        {\small\tt satoshi@ueda.info.waseda.ac.jp}}
\date{July 17, 1996}
\maketitle

\section{The Usage of the Macros}

In this section, the usage of the macros, defined in this style file,
will be explained. In the following explanation, letters in {\tt
typewriter} typeface mean that the letters appear `as they are' in the
input file, while the part in {\it italics\/} means a part that varies
for the purpose.

\subsection{Drawing Commands}

\begin{description}
\item[{\tt \bs padbox\{{\em text\/}\}}] \mbox{}

Draws a frame for procedure. {\em text\/} is typeset in LR mode. 

\item[%
  \begin{tabular}{@{}l@{}}
    {\tt \bs padwhile\{{\em cond\/}\}\{{\em proc\/}\}} \\
    {\tt \bs padrepeat\{{\em cond\/}\}\{{\em proc\/}\}}
  \end{tabular}%
] \mbox{}

{\tt \bs padwhile} draws a frame for pre-conditional loop, while {\tt
\bs padrepeat} draws a frame for general (or post-conditional)
loop. {\em cond\/} specifies its condition. {\em proc\/} specifies its
procedure. {\em cond\/} is typeset in LR mode. When {\em proc\/}
contain nothing (not even one whitespace), the flow line between
condition and procedure would not be drawn.

\item[{\tt \bs padcond\{{\em cond\/}\}\{{\em proc1\/}\}\{{\em proc2\/}\}}] 
\mbox{}

Draws a frame for selection. {\em cond\/} specifies its condition. {\em
proc1\/} and {\em proc2\/} specify its procedures. {\em cond\/} is
typeset in LR mode. The same as {\tt \bs padwhile} and {\tt \bs
padrepeat}, the flow line will not be drawn if {\em proc1\/} and/or {\em
proc2\/} contains nothing.

\item[{\tt \bs padcase\{{\em expr\/}\}\{{\em cases}\}}] \mbox{}

Draws a frame for selection. Use this macro, rather than {\tt \bs
padcond}, if there are more than two conditional cases. {\em expr\/} is
typeset in LR mode and is positioned in middle of the frame. {\em
cases\/} specifies the case and the corresponding procedure in
pairs. These pairs are separated by `\verb|,|', while their case and
procedure are separated by `\verb|:|'. The cases are typeset in LR mode.

When case or procedure contains `\verb|:|' or `\verb|,|', it should be
parenthesized by braces. 

\item[{\tt \bs padsub\{{\em text\/}\}}] \mbox{}

Draws a frame for subroutine. {\em text\/} is typeset in LR mode. 

\item[{\tt \bs padseq\{{\em procs\/}\}}] \mbox{}

Draws a sequence of the procedures. {\em procs\/} specifies a sequence
of procedures. Each procedures are separated by a \verb|\\|.

You can put some extra space by setting the optional argument {\em
len\/} of a \verb|\\|. This will add {\em len\/} space between
procedures.

\item[{\tt \bs padlabel\{{\em label\/}\}}] \mbox{}

Draws a label named {\em label\/}. 

\item[{\tt \bs padref\{{\em label\/}\}}] \mbox{}

Draws a frame for reference to a label named {\em label\/}. 

\item[%
  \begin{tabular}{@{}l@{}}
    {\tt \bs padboxss\{{\em texts\/}\}} \\
    {\tt \bs padsubss\{{\em texts\/}\}}
  \end{tabular}%
] \mbox{}

These are defined for writing a text spreading over multiple lines
inside {\tt \bs padbox} and {\tt \bs padsub}. Each line is separated by
a \verb|\\|.

These macros just call the corresponding macro with argument {\tt \bs
shortstack\{{\em texts\/}\}}. When you want to write multiple lines
inside loop or selection, just call the macro with the same argument.

\item[{\tt \bs padmessage\{{\em message\/}\}}] \mbox{}

Writes a comment. Use this macro when you want to write a comment inside
{\tt \bs padseq}, otherwise the vertical flow line on left won't be
drawn.

\item[{\tt \bs padcomment\{{\em comment\/}\}}] \mbox{}

Writes a comment on right of the procedure. {\em comment\/} is typeset
in LR mode, and is positioned in the middle.
\end{description}


\subsection{Box Commands}

\begin{description}
\item[{\tt \bs savepad\{{\em name\/}\}\{{\em pad\/}\}}] \mbox{}

Saves a PAD specified by {\em pad\/} into the container specified by
{\em name\/}. {\em name\/} is a regular command name. You do not need to
create a container using \LaTeX\ command {\tt \bs newsavebox}.

\item[{\tt \bs usepad\{{\em name\/}\}}] \mbox{}

Draws a PAD saved in the container {\em name\/} by {\tt \bs savepad}. 

To save or draw a PAD, do not use \LaTeX\ command {\tt \bs savebox} or 
{\tt \bs usebox}. Instead, use these macros.
\end{description}


\subsection{Style Parameters}

\begin{description}
\item[{\tt \bs padboxrule}] \mbox{}

Sets the width of lines in a PAD. This does not change width of slanted
lines or circles. The width of the frame will be twice as bold as this
value.

\item[{\tt \bs padboxsep}] \mbox{}

Sets the amount of space inserted between the frame of a PAD and its
contents.

\item[{\tt \bs padcolsep}] \mbox{}

Sets the minimum width between columns in {\tt \bs padseq}, {\tt \bs
padcond} and {\tt \bs padcase}.
\end{description}


\section{Notes}

\begin{itemize}
\item The size of the PAD frame varies according to the size of its
contents. To adjust the size, use {\tt \bs makebox}, {\tt \bs raisebox}, 
strut, and so forth. Please note that there is the minimum size, though.

\item The baseline of items, such as {\tt \bs padbox}, {\tt \bs
padcond}, and so forth, coincides with the bottom of its bounding box.

\begin{quote}
  \makebox[0pt][l]{\rule[-\fboxrule]{390pt}{\fboxrule}}
  \padbox{\bs padbox}, 
  \padboxss{proc1 \\ proc2}, 
  \padwhile{\bs padwhile}{\padbox{proc}},
  \padrepeat{\bs padrepeat}{},
  \padcond{\bs padcond}{\padbox{true}}{\padbox{false}},
  \padseq{\padbox{proc1} \\ \padbox{proc2}}
\end{quote}

By using the {\tt *}-variants of these macros, you can coincides the
baseline with that of its first argument. With regard to {\tt \bs
padseq*}, its baseline is located in $-0.5 {\rm ex}$ lower to the center
of its body.

\begin{quote}
  \makebox[0pt][l]{\rule[-\fboxrule]{390pt}{\fboxrule}}
  \padbox*{\bs padbox}, 
  \padboxss*{proc1 \\ proc2}, 
  \padwhile*{\bs padwhile}{\padbox{proc}},
  \padrepeat*{\bs padrepeat}{},
  \padcond*{\bs padcond}{\padbox{true}}{\padbox{false}},
  \padseq*{\padbox{proc1} \\ \padbox{proc2}}
\end{quote}
\end{itemize}


\clearpage

\section{Examples}

\begin{figure}[htbp]
\begin{center}
${\rm f}() = $
\padseq*{
  \padsubss{nesting\\test} \\
  \padbox{1} \\
  \padrepeat{cond}{%
    \padseq{
      \padbox{2} \\
      \padwhile{cond}{%
        \padseq{
          \padbox{3} \\
          \padcond{cond}{\padbox{true}}{%
            \padseq{
              \padbox{4} \\
              \padwhile{cond}{%
                \padseq{
                  \padbox{5} \\
                  \padcond{cond}{%
                    \padseq{
                      \padbox{6} \\
                      \padrepeat{cond}{%
                        \padseq{
                          \padbox{7} \\
                          \padbox{7}
                        }
                      }
                    }
                  }
                  {%
                    \padseq{
                      \padbox{6} \\
                      \padbox{false}
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  } \\
  \padcond{cond}{\padbox{true}}{\padbox{false}}
}
\end{center}
\caption{Nesting test}
\end{figure}


\begin{figure}[htbp]
\begin{center}
$
{\rm ack}({\rm m}, {\rm n}) = 
\padcond*{${\rm m} = 0$}{%
  \padbox{return ${\rm n}+1$}
}
{%
  \padcond{${\rm n} = 0$}{%
    \padbox{return ${\rm ack}({\rm m}-1, 1)$}
  }
  {%
    \padbox{return ${\rm ack}({\rm m}-1, {\rm ack}({\rm m}, {\rm n}-1))$}
  }
}
$
\end{center}
\caption{Ackermann's function}
\label{ackermann}
\end{figure}


\section{Troubleshooting}

\subsection{Errors in pad.sty}

In this section, I'll explain how to deal with each error.

\begin{description}
\item[\rm ! TeX capacity exceeded, sorry {[}parameter stack size=$\ldots${]}.]
\mbox{}

This occurs when {\tt \bs padcase}s are nested too deeply. Save the PAD
in the most inner loop using {\tt \bs savepad} first, then draw the PAD
using {\tt \bs usepad}.

\item[\rm ! TeX capacity exceeded, sorry {[}semantic stack size=$\ldots${]}.]
\mbox{}

This also occurs by nesting too deeply. Deal with it in the same manner
as previous.

Use Big\TeX\ to process a file with complicated and/or many PADs,
because the current version of pad.sty does not maintain resources
well.

\item[\rm ! No room for a new $\ldots$.] \mbox{}

This occurs when there are too much PADs or switching alternatives to
{\tt \bs padcase}. I'm sorry that there is no way to deal with it but to
reduce the number of PADs or divide the input file.
\end{description}

\subsection{Trouble with pad2tex}

Now, I'll explain how to deal with troubles and errors occurred when
using pad2tex\footnote{written by Seiichi Yoshida
(seiichi@muraoka.info.waseda.ac.jp)}. 

\begin{description}
\item[\rm PAD sticks out to the right] \mbox{}

Fold lines manually because pad.sty does not fold lines automatically
when PAD juts out. For example, fold the condition of {\tt \bs
padwhile}, {\tt \bs padrepeat} or {\tt \bs padcond} using {\tt \bs
shortstack}.

\item[\rm PAD sticks out to below] \mbox{}

Current version of pad.sty does not support page break in the middle of
PAD. Collect procedures into a subroutine to fit it into one page.

\item[\rm ! TeX capacity exceeded, sorry {[}main memory size=$\ldots${]}.]
\mbox{}

This occurs when there are too many unprocessed figures. Insert {\tt \bs 
clearpage} just before the place where the error occurs. 
\end{description}


\section{Known Problems}

\begin{itemize}
\item When minus value is specified in optional argument of a \verb|\\|
in {\tt \bs padseq}, the flow line on the left won't be eliminated.

\item When using {\tt \bs padmessage} in the last of {\tt \bs padseq},
the flow line on the left won't be eliminated. 

\item The height of the box of {\tt \bs padcomment} is ignored. 

\item Resources are poorly managed.
\end{itemize}


\section{Things to do}

\begin{itemize}
\item Optimize the usage of resources. 

\item Support page break in the middle of {\tt \bs padseq}. 

\item Support design customization of PAD. 
\end{itemize}


\section{Credit}

My E-mail address is \mbox{\tt satoshi@ueda.info.waseda.ac.jp}. The
latest version of pad.sty will be found at 
\mbox{\tt
http://www.ueda.info.waseda.ac.jp/\~{}satoshi/padsty/padsty-e.html}. 



\begin{thebibliography}{1}

\bibitem{program_gihou}
Yoshihiko Futamura.
\newblock {\em Program Techniques 
{\small\rm --- Structured Programming Using PAD ---}}. 
\newblock Ohm, 1984.

\bibitem{latex-j}
Leslie Lamport. 
\newblock {\em {\LaTeX \rm:} {A} Document Preparation System}.
\newblock ASCII, 1990. \\
\newblock (The Original: Leslie Lamport. {\em {\LaTeX \rm:} {A} Document
Preparation System}. Addison-Wesley, 1986.).

\bibitem{SA:TeX}
Hideaki Togashi.
\newblock {ASCII} Japanese {\TeX}.
\newblock  Super ASCII. ASCII, August 1992--August 1993.
\end{thebibliography}

%\bibliography{temp}
%\bibliographystyle{jplain}
%\nocite{latex-j}
%\nocite{program_gihou}
%\nocite{SA:TeX}


\begin{table}[h]
\caption{List of the format of macros}
\label{tab:format}
\begin{center}
\begin{tabular}{|c|l|c|}
\hline
macro & \multicolumn{1}{|c|}{format} & PAD \\ \hline\hline
%%%%%%%%%%%%%%%%%%%%
procedure 
& \tt \bs padbox\{{\em text}\} 
\rule[-2ex]{0pt}{5ex} 
& \padbox*{proc} \\ \hline
%%%%%%%%%%%%%%%%%%%%
pre-conditional loop
& \tt \bs padwhile\{{\em cond\/}\}\{{\em proc\/}\} 
\rule[-1.5ex]{0pt}{5ex}
& \padwhile*{cond}{\padbox{proc}} \\ \hline
%%%%%%%%%%%%%%%%%%%%
\lower2ex\hbox{\shortstack{general loop\\(post-conditional loop)}}
& \tt \bs padrepeat\{{\em cond\/}\}\{{\em proc\/}\} 
\rule[-1.5ex]{0pt}{5ex}
& \padrepeat*{cond}{\padbox{proc}} \\ \hline
%%%%%%%%%%%%%%%%%%%%
selection 
& \tt \bs padcond\{{\em cond\/}\}\{{\em proc1\/}\}\{{\em proc2\/}\} 
\rule[-5ex]{0pt}{11ex}
& \padcond*{cond}{\padbox{true}}{\padbox{false}} \\ \hline
%%%%%%%%%%%%%%%%%%%%
\lower2ex\hbox{\shortstack{selection\\(has 2 or more conditions)}} 
& \tt \bs padcase\{{\em expr\/}\}\{{\em cases\/}\} 
\rule[-8ex]{0pt}{16ex}
& \padcase*{${\rm var } = \mbox{}$}{1:\padbox{proc1},2:\padbox{proc2},3:\padbox{proc3}} \\ \hline
%%%%%%%%%%%%%%%%%%%%
subroutine
& \tt \bs padsub\{{\em text\/}\} 
\rule[-2ex]{0pt}{5ex}
& \padsub*{proc} \\ \hline
%%%%%%%%%%%%%%%%%%%%
sequence
& \tt \bs padseq\{{\em procs\/}\} 
\rule[-5ex]{0pt}{11ex}
& \padseq*{\padbox{proc1} \\ \padbox{proc2}} \\ \hline
%%%%%%%%%%%%%%%%%%%%
label
& \tt \bs padlabel\{{\em label\/}\}
\rule[-2ex]{0pt}{6ex}
& \padlabel*{label} \\ \hline
%%%%%%%%%%%%%%%%%%%%
reference to label
& \tt \bs padref\{{\em label\/}\}
\rule[-4ex]{0pt}{9ex}
& \lower2.5ex\hbox{\padbox{goto\ \padref{label}}} \\ \hline
%%%%%%%%%%%%%%%%%%%%
procedure (multiple lines)
& \tt \bs padboxss\{{\em texts\/}\}
\rule[-4ex]{0pt}{9ex}
& \lower2.5ex\hbox{\padboxss{proc1\\proc2}} \\ \hline
%%%%%%%%%%%%%%%%%%%%
subroutine (multiple lines)
& \tt \bs padsubss\{{\em texts\/}\}
\rule[-4ex]{0pt}{9ex}
& \lower2.5ex\hbox{\padsubss{proc1\\proc2}} \\ \hline
%%%%%%%%%%%%%%%%%%%%
message
& \tt \bs padmessage\{{\em message\/}\}
\rule[-6ex]{0pt}{13ex}
& \padseq*{%
    \padbox{proc1} \\
    \padmessage{message} \\
    \padbox{proc2}
} \\ \hline
%%%%%%%%%%%%%%%%%%%%
comment
& \tt \bs padcomment\{{\em comment\/}\}
\rule[-5ex]{0pt}{11ex}
& \padseq*{%
    \padbox{proc1} \padcomment{comment} \\
    \padbox{proc2}
} \\ \hline
%%%%%%%%%%%%%%%%%%%%
save PAD
& \tt \bs savepad\{{\em name\/}\}\{{\em pad\/}\}
& \\ \hline
%%%%%%%%%%%%%%%%%%%%
use PAD
& \tt \bs usepad\{{\em name\/}\}
& \\ \hline
\end{tabular}
\end{center}
\end{table}


\end{document}
