doc-src/rail.sty
changeset 3097 ae362c99a635
parent 2658 13ba951a4572
child 8591 9d660fc42916
--- a/doc-src/rail.sty	Fri May 02 16:18:49 1997 +0200
+++ b/doc-src/rail.sty	Fri May 02 16:21:04 1997 +0200
@@ -4,6 +4,9 @@
 % 08-Oct-90 L. Rooijakkers	fixed centering bug when \rail@tmpc<0.
 % 07-Feb-91 L. Rooijakkers	added \railoptions command, indexing
 % 08-Feb-91 L. Rooijakkers	minor fixes
+% 28-Jun-94 K. Barthelmann	turned into LaTeX2e package
+% 08-Dec-96 K. Barthelmann	replaced \@writefile
+% 13-Dec-96 K. Barthelmann	cleanup
 %
 % This style file needs to be used in conjunction with the 'rail'
 % program. Running LaTeX as 'latex file' produces file.rai, which should be
@@ -16,154 +19,8 @@
 % write the .rai and .rao files, and those that do the actual formatting
 % of the railroad diagrams.
 
-% railroad read/write macros
-%
-% \begin{rail} TEXT \end{rail} : TEXT is written out to the .rai file,
-%                                as \rail@i{NR}{TEXT}. Then the matching
-%                                \rail@o{NR}{FMT} from the .rao file is
-%                                executed (if defined).
-%
-% \railoptions{OPTIONS} : OPTIONS are written out to the .rai file,
-%                         as \rail@p{OPTIONS}.
-%
-% \railterm{IDENT,IDENT,...} : format IDENT as terminals. writes out
-%                              \rail@t{IDENT} to the .rai file and
-%                              defines \rail@t@IDENT as \rail@termfont IDENT.
-%
-% \railtoken{IDENT}{TEXT} : format IDENT as terminal TEXT. writes out
-%                           \rail@t{IDENT} to the .rai file and defines
-%                           \rail@t@IDENT as TEXT.
-%
-% \rail@nr : railroad diagram counter, starts at 1
-%
-% \ifrail@match : current \rail@i{NR}{TEXT} matches
-%
-% \rail@first :	actions to be done first. read in .rao file,
-%               open .rai file if \@filesw true, undefine \rail@first.
-%               executed from \begin{rail} and \railtoken.
-%
-% \rail@i{NR}{TEXT} : defines \rail@i@NR as TEXT. written to the .rai
-%                     file by \rail, read from the .rao file by
-%                     \rail@first
-%
-% \rail@t{IDENT} : tells Rail that IDENT is to be custom formatted,
-%                  written to the .rai file by \railterm and \railtoken.
-%
-% \rail@o{NR}{TEXT} : defines \rail@o@NR as TEXT, read from the .rao
-%                     file by \rail@first.
-%
-% \rail@p{OPTIONS} : pass options to rail, written to the .rai file by
-%                    \railoptions
-%
-% \rail@warn : warn user for mismatching diagrams
-%
-% \rail@endwarn : either \relax or \rail@warn
-%
-% \rail@enddocument : original \enddocument
-%
-% \enddocument : checks \ifrail@all
-
-\newcount\rail@nr
-\rail@nr=1
-
-\newif\ifrail@all
-\rail@alltrue
-
-\newif\ifrail@match
-
-\def\rail@first{
-\makeatletter
-\@input{\jobname.rao}
-\makeatother
-\if@filesw
-\newwrite\tf@rai
-\immediate\openout\tf@rai\jobname.rai\relax
-\fi
-\global\let\rail@first=\relax
-}
-
-\long\def\rail#1\end#2{
-\end{#2}
-\rail@first
-\begingroup
-\let\\=\relax
-\global\edef\rail@i@{#1}
-\endgroup
-\@ifundefined{tf@rai}{}{
-\begingroup
-\let\\=\relax
-\immediate\write\tf@rai{\noexpand\rail@i{\number\rail@nr}{\rail@i@}}
-\endgroup
-}
-\rail@matchtrue
-\@ifundefined{rail@o@\number\rail@nr}{\rail@matchfalse}{}
-\expandafter\ifx\csname rail@i@\number\rail@nr\endcsname\rail@i@
-\else
-\rail@matchfalse
-\fi
-\ifrail@match
-\expandafter\relax\csname rail@o@\number\rail@nr\endcsname
-\else
-\@warning{Railroad diagram {\number\rail@nr} doesn't match}
-\global\let\rail@endwarn=\rail@warn
-\rail@begin{1}{}
-\rail@setbox{\bf ???}
-\rail@oval
-\rail@end
-\fi
-\global\advance\rail@nr by 1
-}
-
-\def\railoptions#1{
-\rail@first
-\@writefile{rai}{\noexpand\rail@p{#1}}
-}
-
-\def\railterm#1{
-\rail@first
-\@for\rail@i@:=#1\do{
-\@writefile{rai}{\noexpand\rail@t{\rail@i@}}
-}
-}
-
-\def\railtoken#1#2{
-\rail@first
-\@writefile{rai}{\noexpand\rail@t{#1}}
-\expandafter\def\csname rail@t@#1\endcsname{#2}
-}
-
-\long\def\rail@i#1#2{
-\expandafter\gdef\csname rail@i@#1\endcsname{#2}
-}
-
-\def\rail@o#1#2{
-\expandafter\gdef\csname rail@o@#1\endcsname{#2}
-}
-
-\def\rail@t#1{}
-
-\def\rail@p#1{}
-
-\def\rail@warn{
-\@warning{Railroad diagram(s) may have changed. Use 'rail' and rerun}
-}
-
-\let\rail@endwarn=\relax
-
-\let\rail@enddocument=\enddocument
-
-\def\enddocument{
-\rail@endwarn
-\rail@enddocument
-}
-
-% index entry macro
-%
-% \rail@index{IDENT} : add index entry for IDENT
-
-\def\rail@index#1{
-\index{\rail@indexfont#1}
-}
+\NeedsTeXFormat{LaTeX2e}
+\ProvidesPackage{rail}[1996/12/13]
 
 % railroad diagram formatting parameters (user level)
 % all of these are copied into their internal versions by \railinit
@@ -184,20 +41,55 @@
 %
 % \railnamesep : separator between name and rule body
 
-\newdimen\railunit
-\newdimen\railextra
-\newdimen\railboxheight
-\newdimen\railboxskip
-\newdimen\railboxleft
-\newdimen\railboxright
-\newdimen\railovalspace
-\newdimen\railframespace
-\newdimen\railtextleft
-\newdimen\railtextright
-\newdimen\railtextup
-\newdimen\railjoinsize
-\newdimen\railjoinadjust
-\newdimen\railnamesep
+\newlength\railunit
+\newlength\railextra
+\newlength\railboxheight
+\newlength\railboxskip
+\newlength\railboxleft
+\newlength\railboxright
+\newlength\railovalspace
+\newlength\railframespace
+\newlength\railtextleft
+\newlength\railtextright
+\newlength\railtextup
+\newlength\railjoinsize
+\newlength\railjoinadjust
+\newlength\railnamesep
+
+% initialize the parameters
+
+\setlength\railunit{1sp}
+\setlength\railextra{4ex}
+\setlength\railboxleft{1ex}
+\setlength\railboxright{1ex}
+\setlength\railovalspace{2ex}
+\setlength\railframespace{2ex}
+\setlength\railtextleft{1ex}
+\setlength\railtextright{1ex}
+\setlength\railjoinadjust{0pt}
+\setlength\railnamesep{1ex}
+
+\DeclareOption{10pt}{
+  \setlength\railboxheight{16pt}
+  \setlength\railboxskip{24pt}
+  \setlength\railtextup{5pt}
+  \setlength\railjoinsize{16pt}
+}
+\DeclareOption{11pt}{
+  \setlength\railboxheight{16pt}
+  \setlength\railboxskip{24pt}
+  \setlength\railtextup{5pt}
+  \setlength\railjoinsize{16pt}
+}
+\DeclareOption{12pt}{
+  \setlength\railboxheight{20pt}
+  \setlength\railboxskip{28pt}
+  \setlength\railtextup{6pt}
+  \setlength\railjoinsize{20pt}
+}
+
+\ExecuteOptions{10pt}
+\ProcessOptions
 
 % internal versions of the formatting parameters
 %
@@ -233,7 +125,7 @@
 \newcount\rail@joinhsz
 \newcount\rail@joinadj
 
-\def\railinit{
+\newcommand\railinit{
 \rail@extra=\railextra
 \divide\rail@extra by \railunit
 \rail@boxht=\railboxheight
@@ -266,40 +158,211 @@
 \divide\rail@joinadj by \railunit
 }
 
-% initialize the parameters
+\AtBeginDocument{\railinit}
+
+% \rail@param : declarations for list environment
+%
+% \railparam{TEXT} : sets \rail@param to TEXT
+
+\def\rail@param{}
+
+\newcommand\railparam[1]{
+\def\rail@param{#1}
+}
 
-\railunit=1sp
-\railextra=4ex
-\railboxleft=1ex
-\railboxright=1ex
-\railovalspace=2ex
-\railframespace=2ex
-\railtextleft=1ex
-\railtextright=1ex
-\railjoinadjust=0pt
-\railnamesep=1ex
+% \rail@tokenfont : format setup for \railtoken identifiers
+%
+% \rail@termfont : format setup for terminals
+%
+% \rail@nontfont : format setup for nonterminals
+%
+% \rail@annofont : format setup for annotations
+%
+% \rail@rulefont : format setup for rule names
+%
+% \rail@indexfont : format setup for index entry
+%
+% \railtermfont{TEXT} : set terminal format setup to TEXT
+%
+% \railnontermfont{TEXT} : set nonterminal format setup to TEXT
+%
+% \railannotatefont{TEXT} : set annotation format setup to TEXT
+%
+% \railnamefont{TEXT} : set rule name format setup to TEXT
+%
+% \railindexfont{TEXT} : set index entry format setup to TEXT
+
+\def\rail@termfont{\ttfamily\upshape}
+\def\rail@nontfont{\rmfamily\upshape}
+\def\rail@annofont{\rmfamily\itshape}
+\def\rail@namefont{\rmfamily\itshape}
+\def\rail@indexfont{\rmfamily\itshape}
+
+\newcommand\railtermfont[1]{
+\def\rail@termfont{#1}
+}
+
+\newcommand\railnontermfont[1]{
+\def\rail@nontfont{#1}
+}
+
+\newcommand\railannotatefont[1]{
+\def\rail@annofont{#1}
+}
+