added this file;
authorwenzelm
Thu Feb 20 15:15:17 1997 +0100 (1997-02-20)
changeset 265813ba951a4572
parent 2657 448bb82c4003
child 2659 f50eb863599e
added this file;
doc-src/rail.sty
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/doc-src/rail.sty	Thu Feb 20 15:15:17 1997 +0100
     1.3 @@ -0,0 +1,890 @@
     1.4 +% rail.sty - style file to support railroad diagrams
     1.5 +%
     1.6 +% 09-Jul-90 L. Rooijakkers
     1.7 +% 08-Oct-90 L. Rooijakkers	fixed centering bug when \rail@tmpc<0.
     1.8 +% 07-Feb-91 L. Rooijakkers	added \railoptions command, indexing
     1.9 +% 08-Feb-91 L. Rooijakkers	minor fixes
    1.10 +%
    1.11 +% This style file needs to be used in conjunction with the 'rail'
    1.12 +% program. Running LaTeX as 'latex file' produces file.rai, which should be
    1.13 +% processed by Rail with 'rail file'. This produces file.rao, which will
    1.14 +% be picked up by LaTeX on the next 'latex file' run.
    1.15 +%
    1.16 +% LaTeX will warn if there is no file.rao or it's out of date.
    1.17 +%
    1.18 +% The macros in this file thus consist of two parts: those that read and
    1.19 +% write the .rai and .rao files, and those that do the actual formatting
    1.20 +% of the railroad diagrams.
    1.21 +
    1.22 +% railroad read/write macros
    1.23 +%
    1.24 +% \begin{rail} TEXT \end{rail} : TEXT is written out to the .rai file,
    1.25 +%                                as \rail@i{NR}{TEXT}. Then the matching
    1.26 +%                                \rail@o{NR}{FMT} from the .rao file is
    1.27 +%                                executed (if defined).
    1.28 +%
    1.29 +% \railoptions{OPTIONS} : OPTIONS are written out to the .rai file,
    1.30 +%                         as \rail@p{OPTIONS}.
    1.31 +%
    1.32 +% \railterm{IDENT,IDENT,...} : format IDENT as terminals. writes out
    1.33 +%                              \rail@t{IDENT} to the .rai file and
    1.34 +%                              defines \rail@t@IDENT as \rail@termfont IDENT.
    1.35 +%
    1.36 +% \railtoken{IDENT}{TEXT} : format IDENT as terminal TEXT. writes out
    1.37 +%                           \rail@t{IDENT} to the .rai file and defines
    1.38 +%                           \rail@t@IDENT as TEXT.
    1.39 +%
    1.40 +% \rail@nr : railroad diagram counter, starts at 1
    1.41 +%
    1.42 +% \ifrail@match : current \rail@i{NR}{TEXT} matches
    1.43 +%
    1.44 +% \rail@first :	actions to be done first. read in .rao file,
    1.45 +%               open .rai file if \@filesw true, undefine \rail@first.
    1.46 +%               executed from \begin{rail} and \railtoken.
    1.47 +%
    1.48 +% \rail@i{NR}{TEXT} : defines \rail@i@NR as TEXT. written to the .rai
    1.49 +%                     file by \rail, read from the .rao file by
    1.50 +%                     \rail@first
    1.51 +%
    1.52 +% \rail@t{IDENT} : tells Rail that IDENT is to be custom formatted,
    1.53 +%                  written to the .rai file by \railterm and \railtoken.
    1.54 +%
    1.55 +% \rail@o{NR}{TEXT} : defines \rail@o@NR as TEXT, read from the .rao
    1.56 +%                     file by \rail@first.
    1.57 +%
    1.58 +% \rail@p{OPTIONS} : pass options to rail, written to the .rai file by
    1.59 +%                    \railoptions
    1.60 +%
    1.61 +% \rail@warn : warn user for mismatching diagrams
    1.62 +%
    1.63 +% \rail@endwarn : either \relax or \rail@warn
    1.64 +%
    1.65 +% \rail@enddocument : original \enddocument
    1.66 +%
    1.67 +% \enddocument : checks \ifrail@all
    1.68 +
    1.69 +\newcount\rail@nr
    1.70 +\rail@nr=1
    1.71 +
    1.72 +\newif\ifrail@all
    1.73 +\rail@alltrue
    1.74 +
    1.75 +\newif\ifrail@match
    1.76 +
    1.77 +\def\rail@first{
    1.78 +\makeatletter
    1.79 +\@input{\jobname.rao}
    1.80 +\makeatother
    1.81 +\if@filesw
    1.82 +\newwrite\tf@rai
    1.83 +\immediate\openout\tf@rai\jobname.rai\relax
    1.84 +\fi
    1.85 +\global\let\rail@first=\relax
    1.86 +}
    1.87 +
    1.88 +\long\def\rail#1\end#2{
    1.89 +\end{#2}
    1.90 +\rail@first
    1.91 +\begingroup
    1.92 +\let\\=\relax
    1.93 +\global\edef\rail@i@{#1}
    1.94 +\endgroup
    1.95 +\@ifundefined{tf@rai}{}{
    1.96 +\begingroup
    1.97 +\let\\=\relax
    1.98 +\immediate\write\tf@rai{\noexpand\rail@i{\number\rail@nr}{\rail@i@}}
    1.99 +\endgroup
   1.100 +}
   1.101 +\rail@matchtrue
   1.102 +\@ifundefined{rail@o@\number\rail@nr}{\rail@matchfalse}{}
   1.103 +\expandafter\ifx\csname rail@i@\number\rail@nr\endcsname\rail@i@
   1.104 +\else
   1.105 +\rail@matchfalse
   1.106 +\fi
   1.107 +\ifrail@match
   1.108 +\expandafter\relax\csname rail@o@\number\rail@nr\endcsname
   1.109 +\else
   1.110 +\@warning{Railroad diagram {\number\rail@nr} doesn't match}
   1.111 +\global\let\rail@endwarn=\rail@warn
   1.112 +\rail@begin{1}{}
   1.113 +\rail@setbox{\bf ???}
   1.114 +\rail@oval
   1.115 +\rail@end
   1.116 +\fi
   1.117 +\global\advance\rail@nr by 1
   1.118 +}
   1.119 +
   1.120 +\def\railoptions#1{
   1.121 +\rail@first
   1.122 +\@writefile{rai}{\noexpand\rail@p{#1}}
   1.123 +}
   1.124 +
   1.125 +\def\railterm#1{
   1.126 +\rail@first
   1.127 +\@for\rail@i@:=#1\do{
   1.128 +\@writefile{rai}{\noexpand\rail@t{\rail@i@}}
   1.129 +}
   1.130 +}
   1.131 +
   1.132 +\def\railtoken#1#2{
   1.133 +\rail@first
   1.134 +\@writefile{rai}{\noexpand\rail@t{#1}}
   1.135 +\expandafter\def\csname rail@t@#1\endcsname{#2}
   1.136 +}
   1.137 +
   1.138 +\long\def\rail@i#1#2{
   1.139 +\expandafter\gdef\csname rail@i@#1\endcsname{#2}
   1.140 +}
   1.141 +
   1.142 +\def\rail@o#1#2{
   1.143 +\expandafter\gdef\csname rail@o@#1\endcsname{#2}
   1.144 +}
   1.145 +
   1.146 +\def\rail@t#1{}
   1.147 +
   1.148 +\def\rail@p#1{}
   1.149 +
   1.150 +\def\rail@warn{
   1.151 +\@warning{Railroad diagram(s) may have changed. Use 'rail' and rerun}
   1.152 +}
   1.153 +
   1.154 +\let\rail@endwarn=\relax
   1.155 +
   1.156 +\let\rail@enddocument=\enddocument
   1.157 +
   1.158 +\def\enddocument{
   1.159 +\rail@endwarn
   1.160 +\rail@enddocument
   1.161 +}
   1.162 +
   1.163 +% index entry macro
   1.164 +%
   1.165 +% \rail@index{IDENT} : add index entry for IDENT
   1.166 +
   1.167 +\def\rail@index#1{
   1.168 +\index{\rail@indexfont#1}
   1.169 +}
   1.170 +
   1.171 +% railroad diagram formatting parameters (user level)
   1.172 +% all of these are copied into their internal versions by \railinit
   1.173 +%
   1.174 +% \railunit : \unitlength within railroad diagrams
   1.175 +% \railextra : extra length at outside of diagram
   1.176 +% \railboxheight : height of ovals and frames
   1.177 +% \railboxskip : vertical space between lines
   1.178 +% \railboxleft : space to the left of a box
   1.179 +% \railboxright : space to the right of a box
   1.180 +% \railovalspace : extra space around contents of oval
   1.181 +% \railframespace : extra space around contents of frame
   1.182 +% \railtextleft : space to the left of text
   1.183 +% \railtextright : space to the right of text
   1.184 +% \railtextup : space to lift text up
   1.185 +% \railjoinsize : circle size of join/split arcs
   1.186 +% \railjoinadjust : space to adjust join
   1.187 +%
   1.188 +% \railnamesep : separator between name and rule body
   1.189 +
   1.190 +\newdimen\railunit
   1.191 +\newdimen\railextra
   1.192 +\newdimen\railboxheight
   1.193 +\newdimen\railboxskip
   1.194 +\newdimen\railboxleft
   1.195 +\newdimen\railboxright
   1.196 +\newdimen\railovalspace
   1.197 +\newdimen\railframespace
   1.198 +\newdimen\railtextleft
   1.199 +\newdimen\railtextright
   1.200 +\newdimen\railtextup
   1.201 +\newdimen\railjoinsize
   1.202 +\newdimen\railjoinadjust
   1.203 +\newdimen\railnamesep
   1.204 +
   1.205 +% internal versions of the formatting parameters
   1.206 +%
   1.207 +% \rail@extra   : \railextra
   1.208 +% \rail@boxht   : \railboxheight
   1.209 +% \rail@boxsp   : \railboxskip
   1.210 +% \rail@boxlf   : \railboxleft
   1.211 +% \rail@boxrt   : \railboxright
   1.212 +% \rail@boxhht  : \railboxheight / 2
   1.213 +% \rail@ovalsp  : \railovalspace
   1.214 +% \rail@framesp : \railframespace
   1.215 +% \rail@textlf	: \railtextleft
   1.216 +% \rail@textrt	: \railtextright
   1.217 +% \rail@textup	: \railtextup
   1.218 +% \rail@joinsz  : \railjoinsize
   1.219 +% \rail@joinhsz : \railjoinsize / 2
   1.220 +% \rail@joinadj : \railjoinadjust
   1.221 +%
   1.222 +% \railinit : internalize all of the parameters.
   1.223 +
   1.224 +\newcount\rail@extra
   1.225 +\newcount\rail@boxht
   1.226 +\newcount\rail@boxsp
   1.227 +\newcount\rail@boxlf
   1.228 +\newcount\rail@boxrt
   1.229 +\newcount\rail@boxhht
   1.230 +\newcount\rail@ovalsp
   1.231 +\newcount\rail@framesp
   1.232 +\newcount\rail@textlf
   1.233 +\newcount\rail@textrt
   1.234 +\newcount\rail@textup
   1.235 +\newcount\rail@joinsz
   1.236 +\newcount\rail@joinhsz
   1.237 +\newcount\rail@joinadj
   1.238 +
   1.239 +\def\railinit{
   1.240 +\rail@extra=\railextra
   1.241 +\divide\rail@extra by \railunit
   1.242 +\rail@boxht=\railboxheight
   1.243 +\divide\rail@boxht by \railunit
   1.244 +\rail@boxsp=\railboxskip
   1.245 +\divide\rail@boxsp by \railunit
   1.246 +\rail@boxlf=\railboxleft
   1.247 +\divide\rail@boxlf by \railunit
   1.248 +\rail@boxrt=\railboxright
   1.249 +\divide\rail@boxrt by \railunit
   1.250 +\rail@boxhht=\railboxheight
   1.251 +\divide\rail@boxhht by \railunit
   1.252 +\divide\rail@boxhht by 2
   1.253 +\rail@ovalsp=\railovalspace
   1.254 +\divide\rail@ovalsp by \railunit
   1.255 +\rail@framesp=\railframespace
   1.256 +\divide\rail@framesp by \railunit
   1.257 +\rail@textlf=\railtextleft
   1.258 +\divide\rail@textlf by \railunit
   1.259 +\rail@textrt=\railtextright
   1.260 +\divide\rail@textrt by \railunit
   1.261 +\rail@textup=\railtextup
   1.262 +\divide\rail@textup by \railunit
   1.263 +\rail@joinsz=\railjoinsize
   1.264 +\divide\rail@joinsz by \railunit
   1.265 +\rail@joinhsz=\railjoinsize
   1.266 +\divide\rail@joinhsz by \railunit
   1.267 +\divide\rail@joinhsz by 2
   1.268 +\rail@joinadj=\railjoinadjust
   1.269 +\divide\rail@joinadj by \railunit
   1.270 +}
   1.271 +
   1.272 +% initialize the parameters
   1.273 +
   1.274 +\railunit=1sp
   1.275 +\railextra=4ex
   1.276 +\railboxleft=1ex
   1.277 +\railboxright=1ex
   1.278 +\railovalspace=2ex
   1.279 +\railframespace=2ex
   1.280 +\railtextleft=1ex
   1.281 +\railtextright=1ex
   1.282 +\railjoinadjust=0pt
   1.283 +\railnamesep=1ex
   1.284 +
   1.285 +\ifcase\@ptsize
   1.286 +% 10 pt
   1.287 +\railboxheight=16pt
   1.288 +\railboxskip=24pt
   1.289 +\railtextup=5pt
   1.290 +\railjoinsize=16pt
   1.291 +\or
   1.292 +% 11 pt
   1.293 +\railboxheight=16pt
   1.294 +\railboxskip=24pt
   1.295 +\railtextup=5pt
   1.296 +\railjoinsize=16pt
   1.297 +\or
   1.298 +% 12 pt
   1.299 +\railboxheight=20pt
   1.300 +\railboxskip=28pt
   1.301 +\railtextup=6pt
   1.302 +\railjoinsize=20pt
   1.303 +\fi
   1.304 +
   1.305 +\railinit
   1.306 +
   1.307 +% railroad formatting primitives
   1.308 +%
   1.309 +% \rail@x : current x
   1.310 +% \rail@y : current y
   1.311 +% \rail@ex : current end x
   1.312 +% \rail@sx : starting x for \rail@cr
   1.313 +% \rail@rx : rightmost previous x for \rail@cr
   1.314 +%
   1.315 +% \rail@tmpa : temporary count
   1.316 +% \rail@tmpb : temporary count
   1.317 +% \rail@tmpc : temporary count
   1.318 +%
   1.319 +% \rail@put : put at (\rail@x,\rail@y)
   1.320 +%
   1.321 +% \rail@eline : end line by drawing from \rail@ex to \rail@x
   1.322 +%
   1.323 +% \rail@sety{LEVEL} : set \rail@y to level LEVEL
   1.324 +
   1.325 +\newcount\rail@x
   1.326 +\newcount\rail@y
   1.327 +\newcount\rail@ex
   1.328 +\newcount\rail@sx
   1.329 +\newcount\rail@rx
   1.330 +
   1.331 +\newcount\rail@tmpa
   1.332 +\newcount\rail@tmpb
   1.333 +\newcount\rail@tmpc
   1.334 +
   1.335 +\def\rail@put{\put(\number\rail@x,\number\rail@y)}
   1.336 +
   1.337 +\def\rail@eline{
   1.338 +\rail@tmpb=\rail@x
   1.339 +\advance\rail@tmpb by -\rail@ex
   1.340 +\rail@put{\line(-1,0){\number\rail@tmpb}}
   1.341 +}
   1.342 +
   1.343 +\def\rail@sety#1{
   1.344 +\rail@y=#1
   1.345 +\multiply\rail@y by -\rail@boxsp
   1.346 +\advance\rail@y by -\rail@boxht
   1.347 +}
   1.348 +
   1.349 +% \rail@list : declarations for list environment
   1.350 +%
   1.351 +% \railparam{TEXT} : sets \rail@list to TEXT
   1.352 +%
   1.353 +% \rail@begin{HEIGHT}{NAME} : begin a railroad diagram of height HEIGHT
   1.354 +%
   1.355 +% \rail@end : end a railroad diagram
   1.356 +
   1.357 +\def\rail@list{}
   1.358 +
   1.359 +\def\railparam#1{
   1.360 +\def\rail@list{#1}
   1.361 +}
   1.362 +
   1.363 +\newbox\tempbox
   1.364 +
   1.365 +\def\rail@begin#1#2{
   1.366 +\medskip
   1.367 +\begin{list}{}{\rail@list}
   1.368 +\item[]
   1.369 +\vbox\bgroup
   1.370 +\ifx\@empty#2\else
   1.371 +{\rail@namefont #2}
   1.372 +\\*[\railnamesep]\nopagebreak
   1.373 +\fi
   1.374 +\unitlength=\railunit
   1.375 +\rail@tmpa=#1
   1.376 +\multiply\rail@tmpa by \rail@boxsp
   1.377 +\begin{picture}(0,\number\rail@tmpa)(0,-\number\rail@tmpa)
   1.378 +\rail@ex=0
   1.379 +\rail@rx=0
   1.380 +\rail@x=\rail@extra
   1.381 +\rail@sx=\rail@x
   1.382 +\rail@sety{0}
   1.383 +}
   1.384 +
   1.385 +\def\rail@end{
   1.386 +\advance\rail@x by \rail@extra
   1.387 +\rail@eline
   1.388 +\end{picture}
   1.389 +\egroup
   1.390 +\end{list}
   1.391 +}
   1.392 +
   1.393 +% \rail@tokenfont : format setup for \railtoken identifiers
   1.394 +%
   1.395 +% \rail@termfont : format setup for terminals
   1.396 +%
   1.397 +% \rail@nontfont : format setup for nonterminals
   1.398 +%
   1.399 +% \rail@annofont : format setup for annotations
   1.400 +%
   1.401 +% \rail@rulefont : format setup for rule names
   1.402 +%
   1.403 +% \rail@indexfont : format setup for index entry
   1.404 +%
   1.405 +% \railtokenfont{TEXT} : set \railtoken format setup to TEXT
   1.406 +%
   1.407 +% \railtermfont{TEXT} : set terminal format setup to TEXT
   1.408 +%
   1.409 +% \railnontermfont{TEXT} : set nonterminal format setup to TEXT
   1.410 +%
   1.411 +% \railannotatefont{TEXT} : set annotation format setup to TEXT
   1.412 +%
   1.413 +% \railnamefont{TEXT} : set rule name format setup to TEXT
   1.414 +%
   1.415 +% \railindexfont{TEXT} : set index entry format setup to TEXT
   1.416 +
   1.417 +\let\rail@tokenfont=\tt
   1.418 +\let\rail@termfont=\tt
   1.419 +\let\rail@nontfont=\rm
   1.420 +\let\rail@annofont=\it
   1.421 +\let\rail@namefont=\it
   1.422 +\let\rail@indexfont=\it
   1.423 +
   1.424 +\def\railtokenfont#1{
   1.425 +\def\rail@tokenfont{#1}
   1.426 +}
   1.427 +
   1.428 +\def\railtermfont#1{
   1.429 +\def\rail@termfont{#1}
   1.430 +}
   1.431 +
   1.432 +\def\railnontermfont#1{
   1.433 +\def\rail@nontfont{#1}
   1.434 +}
   1.435 +
   1.436 +\def\railannotatefont#1{
   1.437 +\def\rail@annofont{#1}
   1.438 +}
   1.439 +
   1.440 +\def\railnamefont#1{
   1.441 +\def\rail@namefont{#1}
   1.442 +}
   1.443 +
   1.444 +\def\railindexfont#1{
   1.445 +\def\rail@indexfont{#1}
   1.446 +}
   1.447 +
   1.448 +% \rail@token{TEXT} : format token TEXT
   1.449 +%
   1.450 +% \rail@ctoken{TEXT} : format token TEXT centered
   1.451 +%
   1.452 +% \rail@nont{TEXT} : format nonterminal TEXT
   1.453 +%
   1.454 +% \rail@cnont{TEXT} : format nonterminal TEXT centered
   1.455 +%
   1.456 +% \rail@cterm{TEXT} : format terminal TEXT
   1.457 +%
   1.458 +% \rail@cterm{TEXT} : format terminal TEXT centered
   1.459 +%
   1.460 +% \rail@annote[TEXT] : format TEXT as annotation
   1.461 +%
   1.462 +% \rail@annotebox[TEXT] : annotate box with TEXT
   1.463 +
   1.464 +\def\rail@token#1{
   1.465 +\expandafter\@ifundefined{rail@t@#1}{
   1.466 +\rail@setbox{\rail@termfont #1}
   1.467 +}{
   1.468 +\rail@setbox{\rail@tokenfont \csname rail@t@#1\endcsname}
   1.469 +}
   1.470 +\rail@oval
   1.471 +}
   1.472 +
   1.473 +\def\rail@ctoken#1{
   1.474 +\rail@setbox{\rail@tokenfont \csname rail@t@#1\endcsname}
   1.475 +\rail@coval
   1.476 +}
   1.477 +
   1.478 +\def\rail@nont#1{
   1.479 +\rail@setbox{\rail@nontfont #1}
   1.480 +\rail@frame
   1.481 +}
   1.482 +
   1.483 +\def\rail@cnont#1{
   1.484 +\rail@setbox{\rail@nontfont #1}
   1.485 +\rail@cframe
   1.486 +}
   1.487 +
   1.488 +\def\rail@term#1{
   1.489 +\rail@setbox{\rail@termfont #1}
   1.490 +\rail@oval
   1.491 +}
   1.492 +
   1.493 +\def\rail@cterm#1{
   1.494 +\rail@setbox{\rail@termfont #1}
   1.495 +\rail@coval
   1.496 +}
   1.497 +
   1.498 +\def\rail@annote[#1]{
   1.499 +\rail@setbox{\rail@annofont #1}
   1.500 +\rail@text
   1.501 +}
   1.502 +
   1.503 +\def\rail@annotebox[#1]{
   1.504 +\ \rail@annofont #1
   1.505 +}
   1.506 +
   1.507 +% \rail@box : temporary box for \rail@oval and \rail@frame
   1.508 +%
   1.509 +% \rail@setbox{TEXT} : set \rail@box to TEXT, set \rail@tmpa to width
   1.510 +%
   1.511 +% \rail@oval : format \rail@box of width \rail@tmpa inside an oval
   1.512 +%
   1.513 +% \rail@coval : same as \rail@oval, but centered between \rail@x and
   1.514 +%               \rail@mx
   1.515 +%
   1.516 +% \rail@frame : format \rail@box of width \rail@tmpa inside a frame
   1.517 +%
   1.518 +% \rail@cframe : same as \rail@frame, but centered between \rail@x and
   1.519 +%                \rail@mx
   1.520 +%
   1.521 +% \rail@text : format \rail@box of width \rail@tmpa above the line
   1.522 +
   1.523 +\newbox\rail@box
   1.524 +
   1.525 +\def\rail@setbox#1{
   1.526 +\setbox\rail@box\hbox{\strut#1}
   1.527 +\rail@tmpa=\wd\rail@box
   1.528 +\divide\rail@tmpa by \railunit
   1.529 +}
   1.530 +
   1.531 +\def\rail@oval{
   1.532 +\advance\rail@x by \rail@boxlf
   1.533 +\rail@eline
   1.534 +\advance\rail@tmpa by \rail@ovalsp
   1.535 +\ifnum\rail@tmpa<\rail@boxht\rail@tmpa=\rail@boxht\fi
   1.536 +\rail@tmpb=\rail@tmpa
   1.537 +\divide\rail@tmpb by 2
   1.538 +\advance\rail@y by -\rail@boxhht
   1.539 +\rail@put{\makebox(\number\rail@tmpa,\number\rail@boxht){\box\rail@box}}
   1.540 +\advance\rail@y by \rail@boxhht
   1.541 +\advance\rail@x by \rail@tmpb
   1.542 +\rail@put{\oval(\number\rail@tmpa,\number\rail@boxht)}
   1.543 +\advance\rail@x by \rail@tmpb
   1.544 +\rail@ex=\rail@x
   1.545 +\advance\rail@x by \rail@boxrt
   1.546 +}
   1.547 +
   1.548 +\def\rail@coval{
   1.549 +\rail@tmpb=\rail@tmpa
   1.550 +\advance\rail@tmpb by \rail@ovalsp
   1.551 +\ifnum\rail@tmpb<\rail@boxht\rail@tmpb=\rail@boxht\fi
   1.552 +\advance\rail@tmpb by \rail@boxlf
   1.553 +\advance\rail@tmpb by \rail@boxrt
   1.554 +\rail@tmpc=\rail@mx
   1.555 +\advance\rail@tmpc by -\rail@x
   1.556 +\advance\rail@tmpc by -\rail@tmpb
   1.557 +\divide\rail@tmpc by 2
   1.558 +\ifnum\rail@tmpc>0
   1.559 +\advance\rail@x by \rail@tmpc
   1.560 +\fi
   1.561 +\rail@oval
   1.562 +}
   1.563 +
   1.564 +\def\rail@frame{
   1.565 +\advance\rail@x by \rail@boxlf
   1.566 +\rail@eline
   1.567 +\advance\rail@tmpa by \rail@framesp
   1.568 +\ifnum\rail@tmpa<\rail@boxht\rail@tmpa=\rail@boxht\fi
   1.569 +\advance\rail@y by -\rail@boxhht
   1.570 +\rail@put{\framebox(\number\rail@tmpa,\number\rail@boxht){\box\rail@box}}
   1.571 +\advance\rail@y by \rail@boxhht
   1.572 +\advance\rail@x by \rail@tmpa
   1.573 +\rail@ex=\rail@x
   1.574 +\advance\rail@x by \rail@boxrt
   1.575 +}
   1.576 +
   1.577 +\def\rail@cframe{
   1.578 +\rail@tmpb=\rail@tmpa
   1.579 +\advance\rail@tmpb by \rail@framesp
   1.580 +\ifnum\rail@tmpb<\rail@boxht\rail@tmpb=\rail@boxht\fi
   1.581 +\advance\rail@tmpb by \rail@boxlf
   1.582 +\advance\rail@tmpb by \rail@boxrt
   1.583 +\rail@tmpc=\rail@mx
   1.584 +\advance\rail@tmpc by -\rail@x
   1.585 +\advance\rail@tmpc by -\rail@tmpb
   1.586 +\divide\rail@tmpc by 2
   1.587 +\ifnum\rail@tmpc>0
   1.588 +\advance\rail@x by \rail@tmpc
   1.589 +\fi
   1.590 +\rail@frame
   1.591 +}
   1.592 +
   1.593 +\def\rail@text{
   1.594 +\advance\rail@x by \rail@textlf
   1.595 +\advance\rail@y by \rail@textup
   1.596 +\rail@put{\box\rail@box}
   1.597 +\advance\rail@y by -\rail@textup
   1.598 +\advance\rail@x by \rail@tmpa
   1.599 +\advance\rail@x by \rail@textrt
   1.600 +}
   1.601 +
   1.602 +% alternatives
   1.603 +%
   1.604 +% \rail@jx \rail@jy : current join point
   1.605 +%
   1.606 +% \rail@gx \rail@gy \rail@gex \rail@grx : global versions of \rail@x etc,
   1.607 +%                                         to pass values over group closings
   1.608 +%
   1.609 +% \rail@mx : maximum x so far
   1.610 +%
   1.611 +% \rail@sy : starting \rail@y for alternatives
   1.612 +%
   1.613 +% \rail@jput : put at (\rail@jx,\rail@jy)
   1.614 +%
   1.615 +% \rail@joval[PART] : put \oval[PART] with adjust
   1.616 +
   1.617 +\newcount\rail@jx
   1.618 +\newcount\rail@jy
   1.619 +
   1.620 +\newcount\rail@gx
   1.621 +\newcount\rail@gy
   1.622 +\newcount\rail@gex
   1.623 +\newcount\rail@grx
   1.624 +
   1.625 +\newcount\rail@sy
   1.626 +\newcount\rail@mx
   1.627 +
   1.628 +\def\rail@jput{
   1.629 +\put(\number\rail@jx,\number\rail@jy)
   1.630 +}
   1.631 +
   1.632 +\def\rail@joval[#1]{
   1.633 +\advance\rail@jx by \rail@joinadj
   1.634 +\rail@jput{\oval(\number\rail@joinsz,\number\rail@joinsz)[#1]}
   1.635 +\advance\rail@jx by -\rail@joinadj
   1.636 +}
   1.637 +
   1.638 +% \rail@barsplit : incoming split for '|'
   1.639 +%
   1.640 +% \rail@plussplit : incoming split for '+'
   1.641 +%
   1.642 +
   1.643 +\def\rail@barsplit{
   1.644 +\advance\rail@jy by -\rail@joinhsz
   1.645 +\rail@joval[tr]
   1.646 +\advance\rail@jx by \rail@joinhsz
   1.647 +}
   1.648 +
   1.649 +\def\rail@plussplit{
   1.650 +\advance\rail@jy by -\rail@joinhsz
   1.651 +\advance\rail@jx by \rail@joinsz
   1.652 +\rail@joval[tl]
   1.653 +\advance\rail@jx by -\rail@joinhsz
   1.654 +}
   1.655 +
   1.656 +% \rail@alt{SPLIT} : start alternatives with incoming split SPLIT
   1.657 +%
   1.658 +
   1.659 +\def\rail@alt#1{
   1.660 +\rail@sy=\rail@y
   1.661 +\rail@jx=\rail@x
   1.662 +\rail@jy=\rail@y
   1.663 +\advance\rail@x by \rail@joinsz
   1.664 +\rail@mx=0
   1.665 +\let\rail@list=\@empty
   1.666 +\let\rail@comma=\@empty
   1.667 +\let\rail@split=#1
   1.668 +\begingroup
   1.669 +\rail@sx=\rail@x
   1.670 +\rail@rx=0
   1.671 +}
   1.672 +
   1.673 +% \rail@nextalt{FIX}{Y} : start next alternative at vertical position Y
   1.674 +%                         and fix-up FIX
   1.675 +%
   1.676 +
   1.677 +\def\rail@nextalt#1#2{
   1.678 +\global\rail@gx=\rail@x
   1.679 +\global\rail@gy=\rail@y
   1.680 +\global\rail@gex=\rail@ex
   1.681 +\global\rail@grx=\rail@rx
   1.682 +\endgroup
   1.683 +#1
   1.684 +\ifnum\rail@gx>\rail@mx\rail@mx=\rail@gx\fi
   1.685 +\ifnum\rail@grx>\rail@mx\rail@mx=\rail@grx\fi
   1.686 +\edef\rail@list{\rail@list\rail@comma\number\rail@gex:\number\rail@gy}
   1.687 +\def\rail@comma{,}
   1.688 +\rail@split
   1.689 +\let\rail@split=\@empty
   1.690 +\rail@sety{#2}
   1.691 +\rail@tmpa=\rail@jy
   1.692 +\advance\rail@tmpa by -\rail@y
   1.693 +\advance\rail@tmpa by -\rail@joinhsz
   1.694 +\rail@jput{\line(0,-1){\number\rail@tmpa}}
   1.695 +\rail@jy=\rail@y
   1.696 +\advance\rail@jy by \rail@joinhsz
   1.697 +\advance\rail@jx by \rail@joinhsz
   1.698 +\rail@joval[bl]
   1.699 +\advance\rail@jx by -\rail@joinhsz
   1.700 +\rail@ex=\rail@x
   1.701 +\begingroup
   1.702 +\rail@sx=\rail@x
   1.703 +\rail@rx=0
   1.704 +}
   1.705 +
   1.706 +% \rail@barjoin : outgoing join for first '|' alternative
   1.707 +%
   1.708 +% \rail@plusjoin : outgoing join for first '+' alternative
   1.709 +%
   1.710 +% \rail@altjoin : join for subsequent alternative
   1.711 +%
   1.712 +
   1.713 +\def\rail@barjoin{
   1.714 +\ifnum\rail@y<\rail@sy
   1.715 +\global\rail@gex=\rail@jx
   1.716 +\else
   1.717 +\global\rail@gex=\rail@ex
   1.718 +\fi
   1.719 +\advance\rail@jy by -\rail@joinhsz
   1.720 +\rail@joval[tl]
   1.721 +\advance\rail@jx by -\rail@joinhsz
   1.722 +\ifnum\rail@y<\rail@sy
   1.723 +\rail@altjoin
   1.724 +\fi
   1.725 +}
   1.726 +
   1.727 +\def\rail@plusjoin{
   1.728 +\global\rail@gex=\rail@ex
   1.729 +\advance\rail@jy by -\rail@joinhsz
   1.730 +\advance\rail@jx by -\rail@joinsz
   1.731 +\rail@joval[tr]
   1.732 +\advance\rail@jx by \rail@joinhsz
   1.733 +}
   1.734 +
   1.735 +\def\rail@altjoin{
   1.736 +\rail@eline
   1.737 +\rail@tmpa=\rail@jy
   1.738 +\advance\rail@tmpa by -\rail@y
   1.739 +\advance\rail@tmpa by -\rail@joinhsz
   1.740 +\rail@jput{\line(0,-1){\number\rail@tmpa}}
   1.741 +\rail@jy=\rail@y
   1.742 +\advance\rail@jy by \rail@joinhsz
   1.743 +\advance\rail@jx by -\rail@joinhsz
   1.744 +\rail@joval[br]
   1.745 +\advance\rail@jx by \rail@joinhsz
   1.746 +}
   1.747 +
   1.748 +% \rail@eltsplit EX:Y; : split EX:Y into \rail@ex \rail@y
   1.749 +%
   1.750 +% \rail@endalt{JOIN} : end alternatives with outgoing join JOIN
   1.751 +
   1.752 +\def\rail@eltsplit#1:#2;{\rail@ex=#1\rail@y=#2}
   1.753 +
   1.754 +\def\rail@endalt#1{
   1.755 +\global\rail@gx=\rail@x
   1.756 +\global\rail@gy=\rail@y
   1.757 +\global\rail@gex=\rail@ex
   1.758 +\global\rail@grx=\rail@rx
   1.759 +\endgroup
   1.760 +\ifnum\rail@gx>\rail@mx\rail@mx=\rail@gx\fi
   1.761 +\ifnum\rail@grx>\rail@mx\rail@mx=\rail@grx\fi
   1.762 +\edef\rail@list{\rail@list\rail@comma\number\rail@gex:\number\rail@gy}
   1.763 +\rail@x=\rail@mx
   1.764 +\rail@jx=\rail@x
   1.765 +\rail@jy=\rail@sy
   1.766 +\advance\rail@jx by \rail@joinsz
   1.767 +\let\rail@join=#1
   1.768 +\@for\rail@elt:=\rail@list\do{
   1.769 +\expandafter\rail@eltsplit\rail@elt;
   1.770 +\rail@join
   1.771 +\let\rail@join=\rail@altjoin
   1.772 +}
   1.773 +\rail@x=\rail@mx
   1.774 +\rail@y=\rail@sy
   1.775 +\rail@ex=\rail@gex
   1.776 +\advance\rail@x by \rail@joinsz
   1.777 +}
   1.778 +
   1.779 +% \rail@bar : start '|' alternatives
   1.780 +%
   1.781 +% \rail@nextbar : next '|' alternative
   1.782 +%
   1.783 +% \rail@endbar : end '|' alternatives
   1.784 +%
   1.785 +
   1.786 +\def\rail@bar{
   1.787 +\rail@alt\rail@barsplit
   1.788 +}
   1.789 +
   1.790 +\def\rail@nextbar{
   1.791 +\rail@nextalt\relax
   1.792 +}
   1.793 +
   1.794 +\def\rail@endbar{
   1.795 +\rail@endalt\rail@barjoin
   1.796 +}
   1.797 +
   1.798 +% \rail@plus : start '+' alternatives
   1.799 +%
   1.800 +% \rail@nextplus: next '+' alternative
   1.801 +%
   1.802 +% \rail@endplus : end '+' alternatives
   1.803 +%
   1.804 +
   1.805 +\def\rail@plus{
   1.806 +\rail@alt\rail@plussplit
   1.807 +}
   1.808 +
   1.809 +\def\rail@nextplus{
   1.810 +\rail@nextalt\rail@fixplus
   1.811 +}
   1.812 +
   1.813 +\def\rail@fixplus{
   1.814 +\ifnum\rail@gy<\rail@sy
   1.815 +\begingroup
   1.816 +\rail@x=\rail@gx
   1.817 +\rail@y=\rail@gy
   1.818 +\rail@ex=\rail@gex
   1.819 +\rail@rx=\rail@grx
   1.820 +\ifnum\rail@x<\rail@rx
   1.821 +\rail@x=\rail@rx
   1.822 +\fi
   1.823 +\rail@eline
   1.824 +\rail@jx=\rail@x
   1.825 +\rail@jy=\rail@y
   1.826 +\advance\rail@jy by \rail@joinhsz
   1.827 +\rail@joval[br]
   1.828 +\advance\rail@jx by \rail@joinhsz
   1.829 +\rail@tmpa=\rail@sy
   1.830 +\advance\rail@tmpa by -\rail@joinhsz
   1.831 +\advance\rail@tmpa by -\rail@jy
   1.832 +\rail@jput{\line(0,1){\number\rail@tmpa}}
   1.833 +\rail@jy=\rail@sy
   1.834 +\advance\rail@jy by -\rail@joinhsz
   1.835 +\advance\rail@jx by \rail@joinhsz
   1.836 +\rail@joval[tl]
   1.837 +\advance\rail@jy by \rail@joinhsz
   1.838 +\global\rail@gx=\rail@jx
   1.839 +\global\rail@gy=\rail@jy
   1.840 +\global\rail@gex=\rail@gx
   1.841 +\global\rail@grx=\rail@rx
   1.842 +\endgroup
   1.843 +\fi
   1.844 +}
   1.845 +
   1.846 +\def\rail@endplus{
   1.847 +\rail@endalt\rail@plusjoin
   1.848 +}
   1.849 +
   1.850 +% \rail@cr{Y} : carriage return to vertical position Y
   1.851 +
   1.852 +\def\rail@cr#1{
   1.853 +\rail@tmpa=\rail@sx
   1.854 +\advance\rail@tmpa by \rail@joinsz
   1.855 +\ifnum\rail@x<\rail@tmpa\rail@x=\rail@tmpa\fi
   1.856 +\rail@eline
   1.857 +\rail@jx=\rail@x
   1.858 +\rail@jy=\rail@y
   1.859 +\advance\rail@x by \rail@joinsz
   1.860 +\ifnum\rail@x>\rail@rx\rail@rx=\rail@x\fi
   1.861 +\advance\rail@jy by -\rail@joinhsz
   1.862 +\rail@joval[tr]
   1.863 +\advance\rail@jx by \rail@joinhsz
   1.864 +\rail@sety{#1}
   1.865 +\rail@tmpa=\rail@jy
   1.866 +\advance\rail@tmpa by -\rail@y
   1.867 +\advance\rail@tmpa by -\rail@boxsp
   1.868 +\advance\rail@tmpa by -\rail@joinhsz
   1.869 +\rail@jput{\line(0,-1){\number\rail@tmpa}}
   1.870 +\rail@jy=\rail@y
   1.871 +\advance\rail@jy by \rail@boxsp
   1.872 +\advance\rail@jy by \rail@joinhsz
   1.873 +\advance\rail@jx by -\rail@joinhsz
   1.874 +\rail@joval[br]
   1.875 +\advance\rail@jy by -\rail@joinhsz
   1.876 +\rail@tmpa=\rail@jx
   1.877 +\advance\rail@tmpa by -\rail@sx
   1.878 +\advance\rail@tmpa by -\rail@joinhsz
   1.879 +\rail@jput{\line(-1,0){\number\rail@tmpa}}
   1.880 +\rail@jx=\rail@sx
   1.881 +\advance\rail@jx by \rail@joinhsz
   1.882 +\advance\rail@jy by -\rail@joinhsz
   1.883 +\rail@joval[tl]
   1.884 +\advance\rail@jx by -\rail@joinhsz
   1.885 +\rail@tmpa=\rail@boxsp
   1.886 +\advance\rail@tmpa by -\rail@joinsz
   1.887 +\rail@jput{\line(0,-1){\number\rail@tmpa}}
   1.888 +\advance\rail@jy by -\rail@tmpa
   1.889 +\advance\rail@jx by \rail@joinhsz
   1.890 +\rail@joval[bl]
   1.891 +\rail@x=\rail@jx
   1.892 +\rail@ex=\rail@x
   1.893 +}