doc-src/rail.sty
author nipkow
Sun Mar 02 15:02:06 2008 +0100 (2008-03-02)
changeset 26191 ae537f315b34
parent 13044 c049910774cb
permissions -rw-r--r--
Generalized Zorn and added well-ordering theorem
wenzelm@2658
     1
% rail.sty - style file to support railroad diagrams
wenzelm@2658
     2
%
wenzelm@2658
     3
% 09-Jul-90 L. Rooijakkers
paulson@13044
     4
% 08-Oct-90 L. Rooijakkers	fixed centering bug when \rail@tmpc<0.
paulson@13044
     5
% 07-Feb-91 L. Rooijakkers	added \railoptions command, indexing
paulson@13044
     6
% 08-Feb-91 L. Rooijakkers	minor fixes
paulson@13044
     7
% 28-Jun-94 K. Barthelmann	turned into LaTeX2e package
paulson@13044
     8
% 08-Dec-96 K. Barthelmann	replaced \@writefile
paulson@13044
     9
% 13-Dec-96 K. Barthelmann	cleanup
paulson@13044
    10
% 22-Feb-98 K. Barthelmann	fixed catcodes of special characters
paulson@13044
    11
% 18-Apr-98 K. Barthelmann	fixed \par handling
paulson@13044
    12
% 19-May-98 J. Olsson		Added new macros to support arrow heads.
paulson@13044
    13
% 26-Jul-98 K. Barthelmann	changed \par to output newlines
wenzelm@2658
    14
%
wenzelm@2658
    15
% This style file needs to be used in conjunction with the 'rail'
wenzelm@2658
    16
% program. Running LaTeX as 'latex file' produces file.rai, which should be
wenzelm@2658
    17
% processed by Rail with 'rail file'. This produces file.rao, which will
wenzelm@2658
    18
% be picked up by LaTeX on the next 'latex file' run.
wenzelm@2658
    19
%
wenzelm@2658
    20
% LaTeX will warn if there is no file.rao or it's out of date.
wenzelm@2658
    21
%
wenzelm@2658
    22
% The macros in this file thus consist of two parts: those that read and
wenzelm@2658
    23
% write the .rai and .rao files, and those that do the actual formatting
wenzelm@2658
    24
% of the railroad diagrams.
wenzelm@2658
    25
berghofe@3097
    26
\NeedsTeXFormat{LaTeX2e}
paulson@13044
    27
\ProvidesPackage{rail}[1998/05/19]
wenzelm@2658
    28
wenzelm@2658
    29
% railroad diagram formatting parameters (user level)
wenzelm@2658
    30
% all of these are copied into their internal versions by \railinit
wenzelm@2658
    31
%
wenzelm@2658
    32
% \railunit : \unitlength within railroad diagrams
wenzelm@2658
    33
% \railextra : extra length at outside of diagram
wenzelm@2658
    34
% \railboxheight : height of ovals and frames
wenzelm@2658
    35
% \railboxskip : vertical space between lines
wenzelm@2658
    36
% \railboxleft : space to the left of a box
wenzelm@2658
    37
% \railboxright : space to the right of a box
wenzelm@2658
    38
% \railovalspace : extra space around contents of oval
wenzelm@2658
    39
% \railframespace : extra space around contents of frame
wenzelm@2658
    40
% \railtextleft : space to the left of text
wenzelm@2658
    41
% \railtextright : space to the right of text
wenzelm@2658
    42
% \railtextup : space to lift text up
wenzelm@2658
    43
% \railjoinsize : circle size of join/split arcs
wenzelm@2658
    44
% \railjoinadjust : space to adjust join
wenzelm@2658
    45
%
wenzelm@2658
    46
% \railnamesep : separator between name and rule body
wenzelm@2658
    47
berghofe@3097
    48
\newlength\railunit
berghofe@3097
    49
\newlength\railextra
berghofe@3097
    50
\newlength\railboxheight
berghofe@3097
    51
\newlength\railboxskip
berghofe@3097
    52
\newlength\railboxleft
berghofe@3097
    53
\newlength\railboxright
berghofe@3097
    54
\newlength\railovalspace
berghofe@3097
    55
\newlength\railframespace
berghofe@3097
    56
\newlength\railtextleft
berghofe@3097
    57
\newlength\railtextright
berghofe@3097
    58
\newlength\railtextup
berghofe@3097
    59
\newlength\railjoinsize
berghofe@3097
    60
\newlength\railjoinadjust
berghofe@3097
    61
\newlength\railnamesep
berghofe@3097
    62
berghofe@3097
    63
% initialize the parameters
berghofe@3097
    64
berghofe@3097
    65
\setlength\railunit{1sp}
berghofe@3097
    66
\setlength\railextra{4ex}
berghofe@3097
    67
\setlength\railboxleft{1ex}
berghofe@3097
    68
\setlength\railboxright{1ex}
berghofe@3097
    69
\setlength\railovalspace{2ex}
berghofe@3097
    70
\setlength\railframespace{2ex}
berghofe@3097
    71
\setlength\railtextleft{1ex}
berghofe@3097
    72
\setlength\railtextright{1ex}
berghofe@3097
    73
\setlength\railjoinadjust{0pt}
berghofe@3097
    74
\setlength\railnamesep{1ex}
berghofe@3097
    75
berghofe@3097
    76
\DeclareOption{10pt}{
berghofe@3097
    77
  \setlength\railboxheight{16pt}
berghofe@3097
    78
  \setlength\railboxskip{24pt}
berghofe@3097
    79
  \setlength\railtextup{5pt}
berghofe@3097
    80
  \setlength\railjoinsize{16pt}
berghofe@3097
    81
}
berghofe@3097
    82
\DeclareOption{11pt}{
berghofe@3097
    83
  \setlength\railboxheight{16pt}
berghofe@3097
    84
  \setlength\railboxskip{24pt}
berghofe@3097
    85
  \setlength\railtextup{5pt}
berghofe@3097
    86
  \setlength\railjoinsize{16pt}
berghofe@3097
    87
}
berghofe@3097
    88
\DeclareOption{12pt}{
berghofe@3097
    89
  \setlength\railboxheight{20pt}
berghofe@3097
    90
  \setlength\railboxskip{28pt}
berghofe@3097
    91
  \setlength\railtextup{6pt}
berghofe@3097
    92
  \setlength\railjoinsize{20pt}
berghofe@3097
    93
}
berghofe@3097
    94
berghofe@3097
    95
\ExecuteOptions{10pt}
berghofe@3097
    96
\ProcessOptions
wenzelm@2658
    97
wenzelm@2658
    98
% internal versions of the formatting parameters
wenzelm@2658
    99
%
wenzelm@2658
   100
% \rail@extra   : \railextra
wenzelm@2658
   101
% \rail@boxht   : \railboxheight
wenzelm@2658
   102
% \rail@boxsp   : \railboxskip
wenzelm@2658
   103
% \rail@boxlf   : \railboxleft
wenzelm@2658
   104
% \rail@boxrt   : \railboxright
wenzelm@2658
   105
% \rail@boxhht  : \railboxheight / 2
wenzelm@2658
   106
% \rail@ovalsp  : \railovalspace
wenzelm@2658
   107
% \rail@framesp : \railframespace
wenzelm@8591
   108
% \rail@textlf  : \railtextleft
wenzelm@8591
   109
% \rail@textrt  : \railtextright
wenzelm@8591
   110
% \rail@textup  : \railtextup
wenzelm@2658
   111
% \rail@joinsz  : \railjoinsize
wenzelm@2658
   112
% \rail@joinhsz : \railjoinsize / 2
wenzelm@2658
   113
% \rail@joinadj : \railjoinadjust
wenzelm@2658
   114
%
wenzelm@2658
   115
% \railinit : internalize all of the parameters.
wenzelm@2658
   116
wenzelm@2658
   117
\newcount\rail@extra
wenzelm@2658
   118
\newcount\rail@boxht
wenzelm@2658
   119
\newcount\rail@boxsp
wenzelm@2658
   120
\newcount\rail@boxlf
wenzelm@2658
   121
\newcount\rail@boxrt
wenzelm@2658
   122
\newcount\rail@boxhht
wenzelm@2658
   123
\newcount\rail@ovalsp
wenzelm@2658
   124
\newcount\rail@framesp
wenzelm@2658
   125
\newcount\rail@textlf
wenzelm@2658
   126
\newcount\rail@textrt
wenzelm@2658
   127
\newcount\rail@textup
wenzelm@2658
   128
\newcount\rail@joinsz
wenzelm@2658
   129
\newcount\rail@joinhsz
wenzelm@2658
   130
\newcount\rail@joinadj
wenzelm@2658
   131
berghofe@3097
   132
\newcommand\railinit{
wenzelm@2658
   133
\rail@extra=\railextra
wenzelm@2658
   134
\divide\rail@extra by \railunit
wenzelm@2658
   135
\rail@boxht=\railboxheight
wenzelm@2658
   136
\divide\rail@boxht by \railunit
wenzelm@2658
   137
\rail@boxsp=\railboxskip
wenzelm@2658
   138
\divide\rail@boxsp by \railunit
wenzelm@2658
   139
\rail@boxlf=\railboxleft
wenzelm@2658
   140
\divide\rail@boxlf by \railunit
wenzelm@2658
   141
\rail@boxrt=\railboxright
wenzelm@2658
   142
\divide\rail@boxrt by \railunit
wenzelm@2658
   143
\rail@boxhht=\railboxheight
wenzelm@2658
   144
\divide\rail@boxhht by \railunit
wenzelm@2658
   145
\divide\rail@boxhht by 2
wenzelm@2658
   146
\rail@ovalsp=\railovalspace
wenzelm@2658
   147
\divide\rail@ovalsp by \railunit
wenzelm@2658
   148
\rail@framesp=\railframespace
wenzelm@2658
   149
\divide\rail@framesp by \railunit
wenzelm@2658
   150
\rail@textlf=\railtextleft
wenzelm@2658
   151
\divide\rail@textlf by \railunit
wenzelm@2658
   152
\rail@textrt=\railtextright
wenzelm@2658
   153
\divide\rail@textrt by \railunit
wenzelm@2658
   154
\rail@textup=\railtextup
wenzelm@2658
   155
\divide\rail@textup by \railunit
wenzelm@2658
   156
\rail@joinsz=\railjoinsize
wenzelm@2658
   157
\divide\rail@joinsz by \railunit
wenzelm@2658
   158
\rail@joinhsz=\railjoinsize
wenzelm@2658
   159
\divide\rail@joinhsz by \railunit
wenzelm@2658
   160
\divide\rail@joinhsz by 2
wenzelm@2658
   161
\rail@joinadj=\railjoinadjust
wenzelm@2658
   162
\divide\rail@joinadj by \railunit
wenzelm@2658
   163
}
wenzelm@2658
   164
berghofe@3097
   165
\AtBeginDocument{\railinit}
berghofe@3097
   166
berghofe@3097
   167
% \rail@param : declarations for list environment
berghofe@3097
   168
%
berghofe@3097
   169
% \railparam{TEXT} : sets \rail@param to TEXT
paulson@13044
   170
%
paulson@13044
   171
% \rail@reserved : characters reserved for grammar
berghofe@3097
   172
berghofe@3097
   173
\newcommand\railparam[1]{
paulson@13044
   174
\def\rail@param{
paulson@13044
   175
  \setlength\leftmargin{0pt}\setlength\rightmargin{0pt}
paulson@13044
   176
  \setlength\labelwidth{0pt}\setlength\labelsep{0pt}
paulson@13044
   177
  \setlength\itemindent{0pt}\setlength\listparindent{0pt}
paulson@13044
   178
  #1
berghofe@3097
   179
}
paulson@13044
   180
}
paulson@13044
   181
\railparam{}
wenzelm@2658
   182
paulson@13044
   183
\newtoks\rail@reserved
paulson@13044
   184
\rail@reserved={:;|*+?[]()'"}
paulson@13044
   185
berghofe@3097
   186
% \rail@termfont : format setup for terminals
berghofe@3097
   187
%
berghofe@3097
   188
% \rail@nontfont : format setup for nonterminals
berghofe@3097
   189
%
berghofe@3097
   190
% \rail@annofont : format setup for annotations
berghofe@3097
   191
%
berghofe@3097
   192
% \rail@rulefont : format setup for rule names
berghofe@3097
   193
%
berghofe@3097
   194
% \rail@indexfont : format setup for index entry
berghofe@3097
   195
%
berghofe@3097
   196
% \railtermfont{TEXT} : set terminal format setup to TEXT
berghofe@3097
   197
%
berghofe@3097
   198
% \railnontermfont{TEXT} : set nonterminal format setup to TEXT
berghofe@3097
   199
%
berghofe@3097
   200
% \railannotatefont{TEXT} : set annotation format setup to TEXT
berghofe@3097
   201
%
berghofe@3097
   202
% \railnamefont{TEXT} : set rule name format setup to TEXT
berghofe@3097
   203
%
berghofe@3097
   204
% \railindexfont{TEXT} : set index entry format setup to TEXT
berghofe@3097
   205
berghofe@3097
   206
\def\rail@termfont{\ttfamily\upshape}
berghofe@3097
   207
\def\rail@nontfont{\rmfamily\upshape}
berghofe@3097
   208
\def\rail@annofont{\rmfamily\itshape}
berghofe@3097
   209
\def\rail@namefont{\rmfamily\itshape}
berghofe@3097
   210
\def\rail@indexfont{\rmfamily\itshape}
berghofe@3097
   211
berghofe@3097
   212
\newcommand\railtermfont[1]{
berghofe@3097
   213
\def\rail@termfont{#1}
berghofe@3097
   214
}
berghofe@3097
   215
berghofe@3097
   216
\newcommand\railnontermfont[1]{
berghofe@3097
   217
\def\rail@nontfont{#1}
berghofe@3097
   218
}
berghofe@3097
   219
berghofe@3097
   220
\newcommand\railannotatefont[1]{
berghofe@3097
   221
\def\rail@annofont{#1}
berghofe@3097
   222
}
berghofe@3097
   223
berghofe@3097
   224
\newcommand\railnamefont[1]{
berghofe@3097
   225
\def\rail@namefont{#1}
berghofe@3097
   226
}
berghofe@3097
   227
berghofe@3097
   228
\newcommand\railindexfont[1]{
berghofe@3097
   229
\def\rail@indexfont{#1}
berghofe@3097
   230
}
wenzelm@2658
   231
berghofe@3097
   232
% railroad read/write macros
berghofe@3097
   233
%
berghofe@3097
   234
% \begin{rail} TEXT \end{rail} : TEXT is written out to the .rai file,
berghofe@3097
   235
%                                as \rail@i{NR}{TEXT}. Then the matching
berghofe@3097
   236
%                                \rail@o{NR}{FMT} from the .rao file is
berghofe@3097
   237
%                                executed (if defined).
berghofe@3097
   238
%
berghofe@3097
   239
% \railoptions{OPTIONS} : OPTIONS are written out to the .rai file,
berghofe@3097
   240
%                         as \rail@p{OPTIONS}.
berghofe@3097
   241
%
berghofe@3097
   242
% \railterm{IDENT,IDENT,...} : format IDENT as terminals. writes out
berghofe@3097
   243
%                              \rail@t{IDENT} to the .rai file
berghofe@3097
   244
%
berghofe@3097
   245
% \railalias{IDENT}{TEXT} : format IDENT as TEXT. defines \rail@t@IDENT as
berghofe@3097
   246
%                           TEXT.
berghofe@3097
   247
%
paulson@13044
   248
% \railtoken{IDENT}{TEXT} : abbreviates \railalias{IDENT}{TEXT}\railterm{IDENT}
paulson@13044
   249
%                           (for backward compatibility)
paulson@13044
   250
%
paulson@13044
   251
% \rail@setcodes : guards special characters
paulson@13044
   252
%
paulson@13044
   253
% \rail@makeother{CHARACTER} : sets \catcode of CHARACTER to "other"
paulson@13044
   254
%                              used inside a loop for \rail@setcodes
paulson@13044
   255
%
berghofe@3097
   256
% \rail@nr : railroad diagram counter
berghofe@3097
   257
%
berghofe@3097
   258
% \ifrail@match : current \rail@i{NR}{TEXT} matches
berghofe@3097
   259
%
wenzelm@8591
   260
% \rail@first : actions to be done first. read in .rao file,
berghofe@3097
   261
%               open .rai file if \@filesw true, undefine \rail@first.
paulson@13044
   262
%               executed from \begin{rail}, \railoptions and \railterm.
berghofe@3097
   263
%
berghofe@3097
   264
% \rail@i{NR}{TEXT} : defines \rail@i@NR as TEXT. written to the .rai
berghofe@3097
   265
%                     file by \rail, read from the .rao file by
berghofe@3097
   266
%                     \rail@first
berghofe@3097
   267
%
berghofe@3097
   268
% \rail@t{IDENT} : tells Rail that IDENT is to be custom formatted,
berghofe@3097
   269
%                  written to the .rai file by \railterm.
berghofe@3097
   270
%
berghofe@3097
   271
% \rail@o{NR}{TEXT} : defines \rail@o@NR as TEXT, read from the .rao
berghofe@3097
   272
%                     file by \rail@first.
berghofe@3097
   273
%
berghofe@3097
   274
% \rail@p{OPTIONS} : pass options to rail, written to the .rai file by
berghofe@3097
   275
%                    \railoptions
berghofe@3097
   276
%
berghofe@3097
   277
% \rail@write{TEXT} : write TEXT to the .rai file
berghofe@3097
   278
%
berghofe@3097
   279
% \rail@warn : warn user for mismatching diagrams
berghofe@3097
   280
%
berghofe@3097
   281
% \rail@endwarn : either \relax or \rail@warn
berghofe@3097
   282
%
berghofe@3097
   283
% \ifrail@all : checked at the end of the document
berghofe@3097
   284
paulson@13044
   285
\def\rail@makeother#1{
paulson@13044
   286
  \expandafter\catcode\expandafter`\csname\string #1\endcsname=12
paulson@13044
   287
}
paulson@13044
   288
paulson@13044
   289
\def\rail@setcodes{
paulson@13044
   290
\let\par=\relax
paulson@13044
   291
\let\\=\relax
paulson@13044
   292
\expandafter\@tfor\expandafter\rail@symbol\expandafter:\expandafter=%
paulson@13044
   293
  \the\rail@reserved
paulson@13044
   294
\do{\expandafter\rail@makeother\rail@symbol}
paulson@13044
   295
}
paulson@13044
   296
berghofe@3097
   297
\newcount\rail@nr
berghofe@3097
   298
berghofe@3097
   299
\newif\ifrail@all
berghofe@3097
   300
\rail@alltrue
berghofe@3097
   301
berghofe@3097
   302
\newif\ifrail@match
berghofe@3097
   303
berghofe@3097
   304
\def\rail@first{
paulson@13044
   305
\begingroup
berghofe@3097
   306
\makeatletter
paulson@13044
   307
\rail@setcodes
berghofe@3097
   308
\InputIfFileExists{\jobname.rao}{}{\PackageInfo{rail}{No file \jobname.rao}}
berghofe@3097
   309
\makeatother
paulson@13044
   310
\endgroup
berghofe@3097
   311
\if@filesw
berghofe@3097
   312
\newwrite\tf@rai
berghofe@3097
   313
\immediate\openout\tf@rai=\jobname.rai
wenzelm@2658
   314
\fi
berghofe@3097
   315
\global\let\rail@first=\relax
berghofe@3097
   316
}
wenzelm@2658
   317
berghofe@3097
   318
\long\def\rail@body#1\end{
paulson@13044
   319
{
paulson@13044
   320
\newlinechar=`^^J
paulson@13044
   321
\def\par{\string\par^^J}
paulson@13044
   322
\rail@write{\string\rail@i{\number\rail@nr}{#1}}
paulson@13044
   323
}
berghofe@3097
   324
\xdef\rail@i@{#1}
berghofe@3097
   325
\end
berghofe@3097
   326
}
berghofe@3097
   327
berghofe@3097
   328
\newenvironment{rail}{
berghofe@3097
   329
\global\advance\rail@nr by 1
berghofe@3097
   330
\rail@first
paulson@13044
   331
\begingroup
paulson@13044
   332
\rail@setcodes
berghofe@3097
   333
\rail@body
berghofe@3097
   334
}{
paulson@13044
   335
\endgroup
berghofe@3097
   336
\rail@matchtrue
berghofe@3097
   337
\@ifundefined{rail@o@\number\rail@nr}{\rail@matchfalse}{}
berghofe@3097
   338
\expandafter\ifx\csname rail@i@\number\rail@nr\endcsname\rail@i@
berghofe@3097
   339
\else
berghofe@3097
   340
\rail@matchfalse
berghofe@3097
   341
\fi
berghofe@3097
   342
\ifrail@match
berghofe@3097
   343
\csname rail@o@\number\rail@nr\endcsname
berghofe@3097
   344
\else
berghofe@3097
   345
\PackageWarning{rail}{Railroad diagram {\number\rail@nr} doesn't match}
berghofe@3097
   346
\global\let\rail@endwarn=\rail@warn
berghofe@3097
   347
\begin{list}{}{\rail@param}
berghofe@3097
   348
\rail@begin{1}{}
berghofe@3097
   349
\rail@setbox{\bfseries ???}
berghofe@3097
   350
\rail@oval
berghofe@3097
   351
\rail@end
berghofe@3097
   352
\end{list}
berghofe@3097
   353
\fi
berghofe@3097
   354
}
berghofe@3097
   355
berghofe@3097
   356
\newcommand\railoptions[1]{
berghofe@3097
   357
\rail@first
berghofe@3097
   358
\rail@write{\string\rail@p{#1}}
berghofe@3097
   359
}
berghofe@3097
   360
berghofe@3097
   361
\newcommand\railterm[1]{
berghofe@3097
   362
\rail@first
berghofe@3097
   363
\@for\rail@@:=#1\do{
berghofe@3097
   364
\rail@write{\string\rail@t{\rail@@}}
berghofe@3097
   365
}
berghofe@3097
   366
}
berghofe@3097
   367
berghofe@3097
   368
\newcommand\railalias[2]{
berghofe@3097
   369
\expandafter\def\csname rail@t@#1\endcsname{#2}
berghofe@3097
   370
}
berghofe@3097
   371
paulson@13044
   372
\newcommand\railtoken[2]{\railalias{#1}{#2}\railterm{#1}}
paulson@13044
   373
berghofe@3097
   374
\long\def\rail@i#1#2{
berghofe@3097
   375
\expandafter\gdef\csname rail@i@#1\endcsname{#2}
berghofe@3097
   376
}
berghofe@3097
   377
berghofe@3097
   378
\def\rail@o#1#2{
berghofe@3097
   379
\expandafter\gdef\csname rail@o@#1\endcsname{
paulson@13044
   380
\begin{list}{}{\rail@param}
paulson@13044
   381
#2
paulson@13044
   382
\end{list}
berghofe@3097
   383
}
berghofe@3097
   384
}
berghofe@3097
   385
berghofe@3097
   386
\def\rail@t#1{}
berghofe@3097
   387
berghofe@3097
   388
\def\rail@p#1{}
berghofe@3097
   389
paulson@13044
   390
\long\def\rail@write#1{\@ifundefined{tf@rai}{}{\immediate\write\tf@rai{#1}}}
berghofe@3097
   391
berghofe@3097
   392
\def\rail@warn{
berghofe@3097
   393
\PackageWarningNoLine{rail}{Railroad diagram(s) may have changed.
berghofe@3097
   394
                            Use 'rail' and rerun}
berghofe@3097
   395
}
berghofe@3097
   396
berghofe@3097
   397
\let\rail@endwarn=\relax
berghofe@3097
   398
berghofe@3097
   399
\AtEndDocument{\rail@endwarn}
berghofe@3097
   400
berghofe@3097
   401
% index entry macro
berghofe@3097
   402
%
berghofe@3097
   403
% \rail@index{IDENT} : add index entry for IDENT
berghofe@3097
   404
berghofe@3097
   405
\def\rail@index#1{
berghofe@3097
   406
\index{\rail@indexfont#1}
berghofe@3097
   407
}
wenzelm@2658
   408
wenzelm@2658
   409
% railroad formatting primitives
wenzelm@2658
   410
%
wenzelm@2658
   411
% \rail@x : current x
wenzelm@2658
   412
% \rail@y : current y
wenzelm@2658
   413
% \rail@ex : current end x
wenzelm@2658
   414
% \rail@sx : starting x for \rail@cr
wenzelm@2658
   415
% \rail@rx : rightmost previous x for \rail@cr
wenzelm@2658
   416
%
wenzelm@2658
   417
% \rail@tmpa : temporary count
wenzelm@2658
   418
% \rail@tmpb : temporary count
wenzelm@2658
   419
% \rail@tmpc : temporary count
wenzelm@2658
   420
%
wenzelm@2658
   421
% \rail@put : put at (\rail@x,\rail@y)
paulson@13044
   422
% \rail@vput : put vector at (\rail@x,\rail@y)
wenzelm@2658
   423
%
wenzelm@2658
   424
% \rail@eline : end line by drawing from \rail@ex to \rail@x
wenzelm@2658
   425
%
paulson@13044
   426
% \rail@vreline : end line by drawing a vector from \rail@x to \rail@ex
paulson@13044
   427
%
paulson@13044
   428
% \rail@vleline : end line by drawing a vector from \rail@ex to \rail@x
paulson@13044
   429
%
wenzelm@2658
   430
% \rail@sety{LEVEL} : set \rail@y to level LEVEL
wenzelm@2658
   431
wenzelm@2658
   432
\newcount\rail@x
wenzelm@2658
   433
\newcount\rail@y
wenzelm@2658
   434
\newcount\rail@ex
wenzelm@2658
   435
\newcount\rail@sx
wenzelm@2658
   436
\newcount\rail@rx
wenzelm@2658
   437
wenzelm@2658
   438
\newcount\rail@tmpa
wenzelm@2658
   439
\newcount\rail@tmpb
wenzelm@2658
   440
\newcount\rail@tmpc
wenzelm@2658
   441
wenzelm@2658
   442
\def\rail@put{\put(\number\rail@x,\number\rail@y)}
wenzelm@2658
   443
paulson@13044
   444
\def\rail@vput{\put(\number\rail@ex,\number\rail@y)}
paulson@13044
   445
wenzelm@2658
   446
\def\rail@eline{
wenzelm@2658
   447
\rail@tmpb=\rail@x
wenzelm@2658
   448
\advance\rail@tmpb by -\rail@ex
wenzelm@2658
   449
\rail@put{\line(-1,0){\number\rail@tmpb}}
wenzelm@2658
   450
}
wenzelm@2658
   451
paulson@13044
   452
\def\rail@vreline{
paulson@13044
   453
\rail@tmpb=\rail@x
paulson@13044
   454
\advance\rail@tmpb by -\rail@ex
paulson@13044
   455
\rail@vput{\vector(1,0){\number\rail@tmpb}}
paulson@13044
   456
}
paulson@13044
   457
paulson@13044
   458
\def\rail@vleline{
paulson@13044
   459
\rail@tmpb=\rail@x
paulson@13044
   460
\advance\rail@tmpb by -\rail@ex
paulson@13044
   461
\rail@put{\vector(-1,0){\number\rail@tmpb}}
paulson@13044
   462
}
paulson@13044
   463
wenzelm@2658
   464
\def\rail@sety#1{
wenzelm@2658
   465
\rail@y=#1
wenzelm@2658
   466
\multiply\rail@y by -\rail@boxsp
wenzelm@2658
   467
\advance\rail@y by -\rail@boxht
wenzelm@2658
   468
}
wenzelm@2658
   469
wenzelm@2658
   470
% \rail@begin{HEIGHT}{NAME} : begin a railroad diagram of height HEIGHT
wenzelm@2658
   471
%
wenzelm@2658
   472
% \rail@end : end a railroad diagram
berghofe@3097
   473
%
berghofe@3097
   474
% \rail@expand{IDENT} : expand IDENT
wenzelm@2658
   475
wenzelm@2658
   476
\def\rail@begin#1#2{
paulson@13044
   477
\item
berghofe@3097
   478
\begin{minipage}[t]{\linewidth}
wenzelm@2658
   479
\ifx\@empty#2\else
berghofe@3097
   480
{\rail@namefont \rail@expand{#2}}\\*[\railnamesep]
wenzelm@2658
   481
\fi
wenzelm@2658
   482
\unitlength=\railunit
wenzelm@2658
   483
\rail@tmpa=#1
wenzelm@2658
   484
\multiply\rail@tmpa by \rail@boxsp
wenzelm@2658
   485
\begin{picture}(0,\number\rail@tmpa)(0,-\number\rail@tmpa)
wenzelm@2658
   486
\rail@ex=0
wenzelm@2658
   487
\rail@rx=0
wenzelm@2658
   488
\rail@x=\rail@extra
wenzelm@2658
   489
\rail@sx=\rail@x
wenzelm@2658
   490
\rail@sety{0}
wenzelm@2658
   491
}
wenzelm@2658
   492
wenzelm@2658
   493
\def\rail@end{
wenzelm@2658
   494
\advance\rail@x by \rail@extra
wenzelm@2658
   495
\rail@eline
wenzelm@2658
   496
\end{picture}
berghofe@3097
   497
\end{minipage}
wenzelm@2658
   498
}
wenzelm@2658
   499
paulson@13044
   500
\def\rail@vend{
paulson@13044
   501
\advance\rail@x by \rail@extra
paulson@13044
   502
\rail@vreline
paulson@13044
   503
\end{picture}
paulson@13044
   504
\end{minipage}
paulson@13044
   505
}
paulson@13044
   506
berghofe@3097
   507
\def\rail@expand#1{\@ifundefined{rail@t@#1}{#1}{\csname rail@t@#1\endcsname}}
wenzelm@2658
   508
berghofe@3097
   509
% \rail@token{TEXT}[ANNOT] : format token TEXT with annotation
paulson@13044
   510
% \rail@ltoken{TEXT}[ANNOT] : format token TEXT with annotation, arrow left
paulson@13044
   511
% \rail@rtoken{TEXT}[ANNOT] : format token TEXT with annotation, arrow right
wenzelm@2658
   512
%
berghofe@3097
   513
% \rail@ctoken{TEXT}[ANNOT] : format token TEXT centered with annotation
paulson@13044
   514
% \rail@lctoken{TEXT}[ANNOT] : format token TEXT centered with annotation, arrow left
paulson@13044
   515
% \rail@rctoken{TEXT}[ANNOT] : format token TEXT centered with annotation, arrow right
berghofe@3097
   516
%
berghofe@3097
   517
% \rail@nont{TEXT}[ANNOT] : format nonterminal TEXT with annotation
paulson@13044
   518
% \rail@lnont{TEXT}[ANNOT] : format nonterminal TEXT with annotation, arrow left
paulson@13044
   519
% \rail@rnont{TEXT}[ANNOT] : format nonterminal TEXT with annotation. arrow right
wenzelm@2658
   520
%
berghofe@3097
   521
% \rail@cnont{TEXT}[ANNOT] : format nonterminal TEXT centered with annotation
paulson@13044
   522
% \rail@lcnont{TEXT}[ANNOT] : format nonterminal TEXT centered with annotation,
paulson@13044
   523
%                             arrow left
paulson@13044
   524
% \rail@rcnont{TEXT}[ANNOT] : format nonterminal TEXT centered with annotation,
paulson@13044
   525
%                             arrow right
wenzelm@2658
   526
%
berghofe@3097
   527
% \rail@term{TEXT}[ANNOT] : format terminal TEXT with annotation
paulson@13044
   528
% \rail@lterm{TEXT}[ANNOT] : format terminal TEXT with annotation, arrow left
paulson@13044
   529
% \rail@rterm{TEXT}[ANNOT] : format terminal TEXT with annotation, arrow right
wenzelm@2658
   530
%
berghofe@3097
   531
% \rail@cterm{TEXT}[ANNOT] : format terminal TEXT centered with annotation
paulson@13044
   532
% \rail@lcterm{TEXT}[ANNOT] : format terminal TEXT centered with annotation, arrow left
paulson@13044
   533
% \rail@rcterm{TEXT}[ANNOT] : format terminal TEXT centered with annotation,
paulson@13044
   534
%                             arrow right
wenzelm@2658
   535
%
wenzelm@2658
   536
% \rail@annote[TEXT] : format TEXT as annotation
wenzelm@2658
   537
berghofe@3097
   538
\def\rail@token#1[#2]{
berghofe@3097
   539
\rail@setbox{%
paulson@13044
   540
{\rail@termfont \rail@expand{#1}}\ifx\@empty#2\else\ {\rail@annofont #2}\fi
wenzelm@2658
   541
}
wenzelm@2658
   542
\rail@oval
wenzelm@2658
   543
}
wenzelm@2658
   544
paulson@13044
   545
\def\rail@ltoken#1[#2]{
paulson@13044
   546
\rail@setbox{%
paulson@13044
   547
{\rail@termfont \rail@expand{#1}}\ifx\@empty#2\else\ {\rail@annofont #2}\fi
paulson@13044
   548
}
paulson@13044
   549
\rail@vloval
paulson@13044
   550
}
paulson@13044
   551
paulson@13044
   552
\def\rail@rtoken#1[#2]{
paulson@13044
   553
\rail@setbox{%
paulson@13044
   554
{\rail@termfont \rail@expand{#1}}\ifx\@empty#2\else\ {\rail@annofont #2}\fi
paulson@13044
   555
}
paulson@13044
   556
\rail@vroval
paulson@13044
   557
}
paulson@13044
   558
berghofe@3097
   559
\def\rail@ctoken#1[#2]{
berghofe@3097
   560
\rail@setbox{%
paulson@13044
   561
{\rail@termfont \rail@expand{#1}}\ifx\@empty#2\else\ {\rail@annofont #2}\fi
berghofe@3097
   562
}
wenzelm@2658
   563
\rail@coval
wenzelm@2658
   564
}
wenzelm@2658
   565
paulson@13044
   566
\def\rail@lctoken#1[#2]{
paulson@13044
   567
\rail@setbox{%
paulson@13044
   568
{\rail@termfont \rail@expand{#1}}\ifx\@empty#2\else\ {\rail@annofont #2}\fi
paulson@13044
   569
}
paulson@13044
   570
\rail@vlcoval
paulson@13044
   571
}
paulson@13044
   572
paulson@13044
   573
\def\rail@rctoken#1[#2]{
paulson@13044
   574
\rail@setbox{%
paulson@13044
   575
{\rail@termfont \rail@expand{#1}}\ifx\@empty#2\else\ {\rail@annofont #2}\fi
paulson@13044
   576
}
paulson@13044
   577
\rail@vrcoval
paulson@13044
   578
}
paulson@13044
   579
berghofe@3097
   580
\def\rail@nont#1[#2]{
berghofe@3097
   581
\rail@setbox{%
berghofe@3097
   582
{\rail@nontfont \rail@expand{#1}}\ifx\@empty#2\else\ {\rail@annofont #2}\fi
berghofe@3097
   583
}
wenzelm@2658
   584
\rail@frame
wenzelm@2658
   585
}
wenzelm@2658
   586
paulson@13044
   587
\def\rail@lnont#1[#2]{
paulson@13044
   588
\rail@setbox{%
paulson@13044
   589
{\rail@nontfont \rail@expand{#1}}\ifx\@empty#2\else\ {\rail@annofont #2}\fi
paulson@13044
   590
}
paulson@13044
   591
\rail@vlframe
paulson@13044
   592
}
paulson@13044
   593
paulson@13044
   594
\def\rail@rnont#1[#2]{
paulson@13044
   595
\rail@setbox{%
paulson@13044
   596
{\rail@nontfont \rail@expand{#1}}\ifx\@empty#2\else\ {\rail@annofont #2}\fi
paulson@13044
   597
}
paulson@13044
   598
\rail@vrframe
paulson@13044
   599
}
paulson@13044
   600
berghofe@3097
   601
\def\rail@cnont#1[#2]{
berghofe@3097
   602
\rail@setbox{%
berghofe@3097
   603
{\rail@nontfont \rail@expand{#1}}\ifx\@empty#2\else\ {\rail@annofont #2}\fi
berghofe@3097
   604
}
wenzelm@2658
   605
\rail@cframe
wenzelm@2658
   606
}
wenzelm@2658
   607
paulson@13044
   608
\def\rail@lcnont#1[#2]{
paulson@13044
   609
\rail@setbox{%
paulson@13044
   610
{\rail@nontfont \rail@expand{#1}}\ifx\@empty#2\else\ {\rail@annofont #2}\fi
paulson@13044
   611
}
paulson@13044
   612
\rail@vlcframe
paulson@13044
   613
}
paulson@13044
   614
paulson@13044
   615
\def\rail@rcnont#1[#2]{
paulson@13044
   616
\rail@setbox{%
paulson@13044
   617
{\rail@nontfont \rail@expand{#1}}\ifx\@empty#2\else\ {\rail@annofont #2}\fi
paulson@13044
   618
}
paulson@13044
   619
\rail@vrcframe
paulson@13044
   620
}
paulson@13044
   621
berghofe@3097
   622
\def\rail@term#1[#2]{
berghofe@3097
   623
\rail@setbox{%
berghofe@3097
   624
{\rail@termfont #1}\ifx\@empty#2\else\ {\rail@annofont #2}\fi
berghofe@3097
   625
}
wenzelm@2658
   626
\rail@oval
wenzelm@2658
   627
}
wenzelm@2658
   628
paulson@13044
   629
\def\rail@lterm#1[#2]{
paulson@13044
   630
\rail@setbox{%
paulson@13044
   631
{\rail@termfont #1}\ifx\@empty#2\else\ {\rail@annofont #2}\fi
paulson@13044
   632
}
paulson@13044
   633
\rail@vloval
paulson@13044
   634
}
paulson@13044
   635
paulson@13044
   636
\def\rail@rterm#1[#2]{
paulson@13044
   637
\rail@setbox{%
paulson@13044
   638
{\rail@termfont #1}\ifx\@empty#2\else\ {\rail@annofont #2}\fi
paulson@13044
   639
}
paulson@13044
   640
\rail@vroval
paulson@13044
   641
}
paulson@13044
   642
berghofe@3097
   643
\def\rail@cterm#1[#2]{
berghofe@3097
   644
\rail@setbox{%
berghofe@3097
   645
{\rail@termfont #1}\ifx\@empty#2\else\ {\rail@annofont #2}\fi
berghofe@3097
   646
}
wenzelm@2658
   647
\rail@coval
wenzelm@2658
   648
}
wenzelm@2658
   649
paulson@13044
   650
\def\rail@lcterm#1[#2]{
paulson@13044
   651
\rail@setbox{%
paulson@13044
   652
{\rail@termfont #1}\ifx\@empty#2\else\ {\rail@annofont #2}\fi
paulson@13044
   653
}
paulson@13044
   654
\rail@vlcoval
paulson@13044
   655
}
paulson@13044
   656
paulson@13044
   657
\def\rail@rcterm#1[#2]{
paulson@13044
   658
\rail@setbox{%
paulson@13044
   659
{\rail@termfont #1}\ifx\@empty#2\else\ {\rail@annofont #2}\fi
paulson@13044
   660
}
paulson@13044
   661
\rail@vrcoval
paulson@13044
   662
}
paulson@13044
   663
wenzelm@2658
   664
\def\rail@annote[#1]{
wenzelm@2658
   665
\rail@setbox{\rail@annofont #1}
wenzelm@2658
   666
\rail@text
wenzelm@2658
   667
}
wenzelm@2658
   668
wenzelm@2658
   669
% \rail@box : temporary box for \rail@oval and \rail@frame
wenzelm@2658
   670
%
wenzelm@2658
   671
% \rail@setbox{TEXT} : set \rail@box to TEXT, set \rail@tmpa to width
wenzelm@2658
   672
%
wenzelm@2658
   673
% \rail@oval : format \rail@box of width \rail@tmpa inside an oval
paulson@13044
   674
% \rail@vloval : format \rail@box of width \rail@tmpa inside an oval, vector left
paulson@13044
   675
% \rail@vroval : format \rail@box of width \rail@tmpa inside an oval, vector right
wenzelm@2658
   676
%
wenzelm@2658
   677
% \rail@coval : same as \rail@oval, but centered between \rail@x and
wenzelm@2658
   678
%               \rail@mx
paulson@13044
   679
% \rail@vlcoval : same as \rail@oval, but centered between \rail@x and
paulson@13044
   680
%                 \rail@mx, vector left
paulson@13044
   681
% \rail@vrcoval : same as \rail@oval, but centered between \rail@x and
paulson@13044
   682
%                 \rail@mx, vector right
wenzelm@2658
   683
%
wenzelm@2658
   684
% \rail@frame : format \rail@box of width \rail@tmpa inside a frame
paulson@13044
   685
% \rail@vlframe : format \rail@box of width \rail@tmpa inside a frame, vector left
paulson@13044
   686
% \rail@vrframe : format \rail@box of width \rail@tmpa inside a frame, vector right
wenzelm@2658
   687
%
wenzelm@2658
   688
% \rail@cframe : same as \rail@frame, but centered between \rail@x and
wenzelm@2658
   689
%                \rail@mx
paulson@13044
   690
% \rail@vlcframe : same as \rail@frame, but centered between \rail@x and
paulson@13044
   691
%                  \rail@mx, vector left
paulson@13044
   692
% \rail@vrcframe : same as \rail@frame, but centered between \rail@x and
paulson@13044
   693
%                  \rail@mx, vector right
wenzelm@2658
   694
%
wenzelm@2658
   695
% \rail@text : format \rail@box of width \rail@tmpa above the line
wenzelm@2658
   696
wenzelm@2658
   697
\newbox\rail@box
wenzelm@2658
   698
wenzelm@2658
   699
\def\rail@setbox#1{
wenzelm@2658
   700
\setbox\rail@box\hbox{\strut#1}
wenzelm@2658
   701
\rail@tmpa=\wd\rail@box
wenzelm@2658
   702
\divide\rail@tmpa by \railunit
wenzelm@2658
   703
}
wenzelm@2658
   704
wenzelm@2658
   705
\def\rail@oval{
wenzelm@2658
   706
\advance\rail@x by \rail@boxlf
wenzelm@2658
   707
\rail@eline
wenzelm@2658
   708
\advance\rail@tmpa by \rail@ovalsp
wenzelm@2658
   709
\ifnum\rail@tmpa<\rail@boxht\rail@tmpa=\rail@boxht\fi
wenzelm@2658
   710
\rail@tmpb=\rail@tmpa
wenzelm@2658
   711
\divide\rail@tmpb by 2
wenzelm@2658
   712
\advance\rail@y by -\rail@boxhht
wenzelm@2658
   713
\rail@put{\makebox(\number\rail@tmpa,\number\rail@boxht){\box\rail@box}}
wenzelm@2658
   714
\advance\rail@y by \rail@boxhht
wenzelm@2658
   715
\advance\rail@x by \rail@tmpb
wenzelm@2658
   716
\rail@put{\oval(\number\rail@tmpa,\number\rail@boxht)}
wenzelm@2658
   717
\advance\rail@x by \rail@tmpb
wenzelm@2658
   718
\rail@ex=\rail@x
wenzelm@2658
   719
\advance\rail@x by \rail@boxrt
wenzelm@2658
   720
}
wenzelm@2658
   721
paulson@13044
   722
\def\rail@vloval{
paulson@13044
   723
\advance\rail@x by \rail@boxlf
paulson@13044
   724
\rail@eline
paulson@13044
   725
\advance\rail@tmpa by \rail@ovalsp
paulson@13044
   726
\ifnum\rail@tmpa<\rail@boxht\rail@tmpa=\rail@boxht\fi
paulson@13044
   727
\rail@tmpb=\rail@tmpa
paulson@13044
   728
\divide\rail@tmpb by 2
paulson@13044
   729
\advance\rail@y by -\rail@boxhht
paulson@13044
   730
\rail@put{\makebox(\number\rail@tmpa,\number\rail@boxht){\box\rail@box}}
paulson@13044
   731
\advance\rail@y by \rail@boxhht
paulson@13044
   732
\advance\rail@x by \rail@tmpb
paulson@13044
   733
\rail@put{\oval(\number\rail@tmpa,\number\rail@boxht)}
paulson@13044
   734
\advance\rail@x by \rail@tmpb
paulson@13044
   735
\rail@ex=\rail@x
paulson@13044
   736
\advance\rail@x by \rail@boxrt
paulson@13044
   737
\rail@vleline
paulson@13044
   738
}
paulson@13044
   739
paulson@13044
   740
\def\rail@vroval{
paulson@13044
   741
\advance\rail@x by \rail@boxlf
paulson@13044
   742
\rail@vreline
paulson@13044
   743
\advance\rail@tmpa by \rail@ovalsp
paulson@13044
   744
\ifnum\rail@tmpa<\rail@boxht\rail@tmpa=\rail@boxht\fi
paulson@13044
   745
\rail@tmpb=\rail@tmpa
paulson@13044
   746
\divide\rail@tmpb by 2
paulson@13044
   747
\advance\rail@y by -\rail@boxhht
paulson@13044
   748
\rail@put{\makebox(\number\rail@tmpa,\number\rail@boxht){\box\rail@box}}
paulson@13044
   749
\advance\rail@y by \rail@boxhht
paulson@13044
   750
\advance\rail@x by \rail@tmpb
paulson@13044
   751
\rail@put{\oval(\number\rail@tmpa,\number\rail@boxht)}
paulson@13044
   752
\advance\rail@x by \rail@tmpb
paulson@13044
   753
\rail@ex=\rail@x
paulson@13044
   754
\advance\rail@x by \rail@boxrt
paulson@13044
   755
}
paulson@13044
   756
wenzelm@2658
   757
\def\rail@coval{
wenzelm@2658
   758
\rail@tmpb=\rail@tmpa
wenzelm@2658
   759
\advance\rail@tmpb by \rail@ovalsp
wenzelm@2658
   760
\ifnum\rail@tmpb<\rail@boxht\rail@tmpb=\rail@boxht\fi
wenzelm@2658
   761
\advance\rail@tmpb by \rail@boxlf
wenzelm@2658
   762
\advance\rail@tmpb by \rail@boxrt
wenzelm@2658
   763
\rail@tmpc=\rail@mx
wenzelm@2658
   764
\advance\rail@tmpc by -\rail@x
wenzelm@2658
   765
\advance\rail@tmpc by -\rail@tmpb
wenzelm@2658
   766
\divide\rail@tmpc by 2
wenzelm@2658
   767
\ifnum\rail@tmpc>0
wenzelm@2658
   768
\advance\rail@x by \rail@tmpc
wenzelm@2658
   769
\fi
wenzelm@2658
   770
\rail@oval
wenzelm@2658
   771
}
wenzelm@2658
   772
paulson@13044
   773
\def\rail@vlcoval{
paulson@13044
   774
\rail@tmpb=\rail@tmpa
paulson@13044
   775
\advance\rail@tmpb by \rail@ovalsp
paulson@13044
   776
\ifnum\rail@tmpb<\rail@boxht\rail@tmpb=\rail@boxht\fi
paulson@13044
   777
\advance\rail@tmpb by \rail@boxlf
paulson@13044
   778
\advance\rail@tmpb by \rail@boxrt
paulson@13044
   779
\rail@tmpc=\rail@mx
paulson@13044
   780
\advance\rail@tmpc by -\rail@x
paulson@13044
   781
\advance\rail@tmpc by -\rail@tmpb
paulson@13044
   782
\divide\rail@tmpc by 2
paulson@13044
   783
\ifnum\rail@tmpc>0
paulson@13044
   784
\advance\rail@x by \rail@tmpc
paulson@13044
   785
\fi
paulson@13044
   786
\rail@vloval
paulson@13044
   787
}
paulson@13044
   788
paulson@13044
   789
\def\rail@vrcoval{
paulson@13044
   790
\rail@tmpb=\rail@tmpa
paulson@13044
   791
\advance\rail@tmpb by \rail@ovalsp
paulson@13044
   792
\ifnum\rail@tmpb<\rail@boxht\rail@tmpb=\rail@boxht\fi
paulson@13044
   793
\advance\rail@tmpb by \rail@boxlf
paulson@13044
   794
\advance\rail@tmpb by \rail@boxrt
paulson@13044
   795
\rail@tmpc=\rail@mx
paulson@13044
   796
\advance\rail@tmpc by -\rail@x
paulson@13044
   797
\advance\rail@tmpc by -\rail@tmpb
paulson@13044
   798
\divide\rail@tmpc by 2
paulson@13044
   799
\ifnum\rail@tmpc>0
paulson@13044
   800
\advance\rail@x by \rail@tmpc
paulson@13044
   801
\fi
paulson@13044
   802
\rail@vroval
paulson@13044
   803
}
paulson@13044
   804
wenzelm@2658
   805
\def\rail@frame{
wenzelm@2658
   806
\advance\rail@x by \rail@boxlf
wenzelm@2658
   807
\rail@eline
wenzelm@2658
   808
\advance\rail@tmpa by \rail@framesp
wenzelm@2658
   809
\ifnum\rail@tmpa<\rail@boxht\rail@tmpa=\rail@boxht\fi
wenzelm@2658
   810
\advance\rail@y by -\rail@boxhht
wenzelm@2658
   811
\rail@put{\framebox(\number\rail@tmpa,\number\rail@boxht){\box\rail@box}}
wenzelm@2658
   812
\advance\rail@y by \rail@boxhht
wenzelm@2658
   813
\advance\rail@x by \rail@tmpa
wenzelm@2658
   814
\rail@ex=\rail@x
wenzelm@2658
   815
\advance\rail@x by \rail@boxrt
wenzelm@2658
   816
}
wenzelm@2658
   817
paulson@13044
   818
\def\rail@vlframe{
paulson@13044
   819
\advance\rail@x by \rail@boxlf
paulson@13044
   820
\rail@eline
paulson@13044
   821
\advance\rail@tmpa by \rail@framesp
paulson@13044
   822
\ifnum\rail@tmpa<\rail@boxht\rail@tmpa=\rail@boxht\fi
paulson@13044
   823
\advance\rail@y by -\rail@boxhht
paulson@13044
   824
\rail@put{\framebox(\number\rail@tmpa,\number\rail@boxht){\box\rail@box}}
paulson@13044
   825
\advance\rail@y by \rail@boxhht
paulson@13044
   826
\advance\rail@x by \rail@tmpa
paulson@13044
   827
\rail@ex=\rail@x
paulson@13044
   828
\advance\rail@x by \rail@boxrt
paulson@13044
   829
\rail@vleline
paulson@13044
   830
}
paulson@13044
   831
paulson@13044
   832
\def\rail@vrframe{
paulson@13044
   833
\advance\rail@x by \rail@boxlf
paulson@13044
   834
\rail@vreline
paulson@13044
   835
\advance\rail@tmpa by \rail@framesp
paulson@13044
   836
\ifnum\rail@tmpa<\rail@boxht\rail@tmpa=\rail@boxht\fi
paulson@13044
   837
\advance\rail@y by -\rail@boxhht
paulson@13044
   838
\rail@put{\framebox(\number\rail@tmpa,\number\rail@boxht){\box\rail@box}}
paulson@13044
   839
\advance\rail@y by \rail@boxhht
paulson@13044
   840
\advance\rail@x by \rail@tmpa
paulson@13044
   841
\rail@ex=\rail@x
paulson@13044
   842
\advance\rail@x by \rail@boxrt
paulson@13044
   843
}
paulson@13044
   844
wenzelm@2658
   845
\def\rail@cframe{
wenzelm@2658
   846
\rail@tmpb=\rail@tmpa
wenzelm@2658
   847
\advance\rail@tmpb by \rail@framesp
wenzelm@2658
   848
\ifnum\rail@tmpb<\rail@boxht\rail@tmpb=\rail@boxht\fi
wenzelm@2658
   849
\advance\rail@tmpb by \rail@boxlf
wenzelm@2658
   850
\advance\rail@tmpb by \rail@boxrt
wenzelm@2658
   851
\rail@tmpc=\rail@mx
wenzelm@2658
   852
\advance\rail@tmpc by -\rail@x
wenzelm@2658
   853
\advance\rail@tmpc by -\rail@tmpb
wenzelm@2658
   854
\divide\rail@tmpc by 2
wenzelm@2658
   855
\ifnum\rail@tmpc>0
wenzelm@2658
   856
\advance\rail@x by \rail@tmpc
wenzelm@2658
   857
\fi
wenzelm@2658
   858
\rail@frame
wenzelm@2658
   859
}
wenzelm@2658
   860
paulson@13044
   861
\def\rail@vlcframe{
paulson@13044
   862
\rail@tmpb=\rail@tmpa
paulson@13044
   863
\advance\rail@tmpb by \rail@framesp
paulson@13044
   864
\ifnum\rail@tmpb<\rail@boxht\rail@tmpb=\rail@boxht\fi
paulson@13044
   865
\advance\rail@tmpb by \rail@boxlf
paulson@13044
   866
\advance\rail@tmpb by \rail@boxrt
paulson@13044
   867
\rail@tmpc=\rail@mx
paulson@13044
   868
\advance\rail@tmpc by -\rail@x
paulson@13044
   869
\advance\rail@tmpc by -\rail@tmpb
paulson@13044
   870
\divide\rail@tmpc by 2
paulson@13044
   871
\ifnum\rail@tmpc>0
paulson@13044
   872
\advance\rail@x by \rail@tmpc
paulson@13044
   873
\fi
paulson@13044
   874
\rail@vlframe
paulson@13044
   875
}
paulson@13044
   876
paulson@13044
   877
\def\rail@vrcframe{
paulson@13044
   878
\rail@tmpb=\rail@tmpa
paulson@13044
   879
\advance\rail@tmpb by \rail@framesp
paulson@13044
   880
\ifnum\rail@tmpb<\rail@boxht\rail@tmpb=\rail@boxht\fi
paulson@13044
   881
\advance\rail@tmpb by \rail@boxlf
paulson@13044
   882
\advance\rail@tmpb by \rail@boxrt
paulson@13044
   883
\rail@tmpc=\rail@mx
paulson@13044
   884
\advance\rail@tmpc by -\rail@x
paulson@13044
   885
\advance\rail@tmpc by -\rail@tmpb
paulson@13044
   886
\divide\rail@tmpc by 2
paulson@13044
   887
\ifnum\rail@tmpc>0
paulson@13044
   888
\advance\rail@x by \rail@tmpc
paulson@13044
   889
\fi
paulson@13044
   890
\rail@vrframe
paulson@13044
   891
}
paulson@13044
   892
wenzelm@2658
   893
\def\rail@text{
wenzelm@2658
   894
\advance\rail@x by \rail@textlf
wenzelm@2658
   895
\advance\rail@y by \rail@textup
wenzelm@2658
   896
\rail@put{\box\rail@box}
wenzelm@2658
   897
\advance\rail@y by -\rail@textup
wenzelm@2658
   898
\advance\rail@x by \rail@tmpa
wenzelm@2658
   899
\advance\rail@x by \rail@textrt
wenzelm@2658
   900
}
wenzelm@2658
   901
wenzelm@2658
   902
% alternatives
wenzelm@2658
   903
%
wenzelm@2658
   904
% \rail@jx \rail@jy : current join point
wenzelm@2658
   905
%
wenzelm@2658
   906
% \rail@gx \rail@gy \rail@gex \rail@grx : global versions of \rail@x etc,
wenzelm@2658
   907
%                                         to pass values over group closings
wenzelm@2658
   908
%
wenzelm@2658
   909
% \rail@mx : maximum x so far
wenzelm@2658
   910
%
wenzelm@2658
   911
% \rail@sy : starting \rail@y for alternatives
wenzelm@2658
   912
%
wenzelm@2658
   913
% \rail@jput : put at (\rail@jx,\rail@jy)
wenzelm@2658
   914
%
wenzelm@2658
   915
% \rail@joval[PART] : put \oval[PART] with adjust
wenzelm@2658
   916
wenzelm@2658
   917
\newcount\rail@jx
wenzelm@2658
   918
\newcount\rail@jy
wenzelm@2658
   919
wenzelm@2658
   920
\newcount\rail@gx
wenzelm@2658
   921
\newcount\rail@gy
wenzelm@2658
   922
\newcount\rail@gex
wenzelm@2658
   923
\newcount\rail@grx
wenzelm@2658
   924
wenzelm@2658
   925
\newcount\rail@sy
wenzelm@2658
   926
\newcount\rail@mx
wenzelm@2658
   927
wenzelm@2658
   928
\def\rail@jput{
wenzelm@2658
   929
\put(\number\rail@jx,\number\rail@jy)
wenzelm@2658
   930
}
wenzelm@2658
   931
wenzelm@2658
   932
\def\rail@joval[#1]{
wenzelm@2658
   933
\advance\rail@jx by \rail@joinadj
wenzelm@2658
   934
\rail@jput{\oval(\number\rail@joinsz,\number\rail@joinsz)[#1]}
wenzelm@2658
   935
\advance\rail@jx by -\rail@joinadj
wenzelm@2658
   936
}
wenzelm@2658
   937
wenzelm@2658
   938
% \rail@barsplit : incoming split for '|'
wenzelm@2658
   939
%
wenzelm@2658
   940
% \rail@plussplit : incoming split for '+'
wenzelm@2658
   941
%
wenzelm@2658
   942
wenzelm@2658
   943
\def\rail@barsplit{
wenzelm@2658
   944
\advance\rail@jy by -\rail@joinhsz
wenzelm@2658
   945
\rail@joval[tr]
wenzelm@2658
   946
\advance\rail@jx by \rail@joinhsz
wenzelm@2658
   947
}
wenzelm@2658
   948
wenzelm@2658
   949
\def\rail@plussplit{
wenzelm@2658
   950
\advance\rail@jy by -\rail@joinhsz
wenzelm@2658
   951
\advance\rail@jx by \rail@joinsz
wenzelm@2658
   952
\rail@joval[tl]
wenzelm@2658
   953
\advance\rail@jx by -\rail@joinhsz
wenzelm@2658
   954
}
wenzelm@2658
   955
wenzelm@2658
   956
% \rail@alt{SPLIT} : start alternatives with incoming split SPLIT
wenzelm@2658
   957
%
wenzelm@2658
   958
wenzelm@2658
   959
\def\rail@alt#1{
wenzelm@2658
   960
\rail@sy=\rail@y
wenzelm@2658
   961
\rail@jx=\rail@x
wenzelm@2658
   962
\rail@jy=\rail@y
wenzelm@2658
   963
\advance\rail@x by \rail@joinsz
wenzelm@2658
   964
\rail@mx=0
wenzelm@2658
   965
\let\rail@list=\@empty
wenzelm@2658
   966
\let\rail@comma=\@empty
wenzelm@2658
   967
\let\rail@split=#1
wenzelm@2658
   968
\begingroup
wenzelm@2658
   969
\rail@sx=\rail@x
wenzelm@2658
   970
\rail@rx=0
wenzelm@2658
   971
}
wenzelm@2658
   972
wenzelm@2658
   973
% \rail@nextalt{FIX}{Y} : start next alternative at vertical position Y
wenzelm@2658
   974
%                         and fix-up FIX
wenzelm@2658
   975
%
wenzelm@2658
   976
wenzelm@2658
   977
\def\rail@nextalt#1#2{
wenzelm@2658
   978
\global\rail@gx=\rail@x
wenzelm@2658
   979
\global\rail@gy=\rail@y
wenzelm@2658
   980
\global\rail@gex=\rail@ex
wenzelm@2658
   981
\global\rail@grx=\rail@rx
wenzelm@2658
   982
\endgroup
wenzelm@2658
   983
#1
wenzelm@2658
   984
\ifnum\rail@gx>\rail@mx\rail@mx=\rail@gx\fi
wenzelm@2658
   985
\ifnum\rail@grx>\rail@mx\rail@mx=\rail@grx\fi
wenzelm@2658
   986
\edef\rail@list{\rail@list\rail@comma\number\rail@gex:\number\rail@gy}
wenzelm@2658
   987
\def\rail@comma{,}
wenzelm@2658
   988
\rail@split
wenzelm@2658
   989
\let\rail@split=\@empty
wenzelm@2658
   990
\rail@sety{#2}
wenzelm@2658
   991
\rail@tmpa=\rail@jy
wenzelm@2658
   992
\advance\rail@tmpa by -\rail@y
wenzelm@2658
   993
\advance\rail@tmpa by -\rail@joinhsz
wenzelm@2658
   994
\rail@jput{\line(0,-1){\number\rail@tmpa}}
wenzelm@2658
   995
\rail@jy=\rail@y
wenzelm@2658
   996
\advance\rail@jy by \rail@joinhsz
wenzelm@2658
   997
\advance\rail@jx by \rail@joinhsz
wenzelm@2658
   998
\rail@joval[bl]
wenzelm@2658
   999
\advance\rail@jx by -\rail@joinhsz
wenzelm@2658
  1000
\rail@ex=\rail@x
wenzelm@2658
  1001
\begingroup
wenzelm@2658
  1002
\rail@sx=\rail@x
wenzelm@2658
  1003
\rail@rx=0
wenzelm@2658
  1004
}
wenzelm@2658
  1005
wenzelm@2658
  1006
% \rail@barjoin : outgoing join for first '|' alternative
wenzelm@2658
  1007
%
wenzelm@2658
  1008
% \rail@plusjoin : outgoing join for first '+' alternative
wenzelm@2658
  1009
%
wenzelm@2658
  1010
% \rail@altjoin : join for subsequent alternative
wenzelm@2658
  1011
%
wenzelm@2658
  1012
wenzelm@2658
  1013
\def\rail@barjoin{
wenzelm@2658
  1014
\ifnum\rail@y<\rail@sy
wenzelm@2658
  1015
\global\rail@gex=\rail@jx
wenzelm@2658
  1016
\else
wenzelm@2658
  1017
\global\rail@gex=\rail@ex
wenzelm@2658
  1018
\fi
wenzelm@2658
  1019
\advance\rail@jy by -\rail@joinhsz
wenzelm@2658
  1020
\rail@joval[tl]
wenzelm@2658
  1021
\advance\rail@jx by -\rail@joinhsz
wenzelm@2658
  1022
\ifnum\rail@y<\rail@sy
wenzelm@2658
  1023
\rail@altjoin
wenzelm@2658
  1024
\fi
wenzelm@2658
  1025
}
wenzelm@2658
  1026
wenzelm@2658
  1027
\def\rail@plusjoin{
wenzelm@2658
  1028
\global\rail@gex=\rail@ex
wenzelm@2658
  1029
\advance\rail@jy by -\rail@joinhsz
wenzelm@2658
  1030
\advance\rail@jx by -\rail@joinsz
wenzelm@2658
  1031
\rail@joval[tr]
wenzelm@2658
  1032
\advance\rail@jx by \rail@joinhsz
wenzelm@2658
  1033
}
wenzelm@2658
  1034
wenzelm@2658
  1035
\def\rail@altjoin{
wenzelm@2658
  1036
\rail@eline
wenzelm@2658
  1037
\rail@tmpa=\rail@jy
wenzelm@2658
  1038
\advance\rail@tmpa by -\rail@y
wenzelm@2658
  1039
\advance\rail@tmpa by -\rail@joinhsz
wenzelm@2658
  1040
\rail@jput{\line(0,-1){\number\rail@tmpa}}
wenzelm@2658
  1041
\rail@jy=\rail@y
wenzelm@2658
  1042
\advance\rail@jy by \rail@joinhsz
wenzelm@2658
  1043
\advance\rail@jx by -\rail@joinhsz
wenzelm@2658
  1044
\rail@joval[br]
wenzelm@2658
  1045
\advance\rail@jx by \rail@joinhsz
wenzelm@2658
  1046
}
wenzelm@2658
  1047
wenzelm@2658
  1048
% \rail@eltsplit EX:Y; : split EX:Y into \rail@ex \rail@y
wenzelm@2658
  1049
%
wenzelm@2658
  1050
% \rail@endalt{JOIN} : end alternatives with outgoing join JOIN
wenzelm@2658
  1051
wenzelm@2658
  1052
\def\rail@eltsplit#1:#2;{\rail@ex=#1\rail@y=#2}
wenzelm@2658
  1053
wenzelm@2658
  1054
\def\rail@endalt#1{
wenzelm@2658
  1055
\global\rail@gx=\rail@x
wenzelm@2658
  1056
\global\rail@gy=\rail@y
wenzelm@2658
  1057
\global\rail@gex=\rail@ex
wenzelm@2658
  1058
\global\rail@grx=\rail@rx
wenzelm@2658
  1059
\endgroup
wenzelm@2658
  1060
\ifnum\rail@gx>\rail@mx\rail@mx=\rail@gx\fi
wenzelm@2658
  1061
\ifnum\rail@grx>\rail@mx\rail@mx=\rail@grx\fi
wenzelm@2658
  1062
\edef\rail@list{\rail@list\rail@comma\number\rail@gex:\number\rail@gy}
wenzelm@2658
  1063
\rail@x=\rail@mx
wenzelm@2658
  1064
\rail@jx=\rail@x
wenzelm@2658
  1065
\rail@jy=\rail@sy
wenzelm@2658
  1066
\advance\rail@jx by \rail@joinsz
wenzelm@2658
  1067
\let\rail@join=#1
wenzelm@2658
  1068
\@for\rail@elt:=\rail@list\do{
wenzelm@2658
  1069
\expandafter\rail@eltsplit\rail@elt;
wenzelm@2658
  1070
\rail@join
wenzelm@2658
  1071
\let\rail@join=\rail@altjoin
wenzelm@2658
  1072
}
wenzelm@2658
  1073
\rail@x=\rail@mx
wenzelm@2658
  1074
\rail@y=\rail@sy
wenzelm@2658
  1075
\rail@ex=\rail@gex
wenzelm@2658
  1076
\advance\rail@x by \rail@joinsz
wenzelm@2658
  1077
}
wenzelm@2658
  1078
wenzelm@2658
  1079
% \rail@bar : start '|' alternatives
wenzelm@2658
  1080
%
wenzelm@2658
  1081
% \rail@nextbar : next '|' alternative
wenzelm@2658
  1082
%
wenzelm@2658
  1083
% \rail@endbar : end '|' alternatives
wenzelm@2658
  1084
%
wenzelm@2658
  1085
wenzelm@2658
  1086
\def\rail@bar{
wenzelm@2658
  1087
\rail@alt\rail@barsplit
wenzelm@2658
  1088
}
wenzelm@2658
  1089
wenzelm@2658
  1090
\def\rail@nextbar{
wenzelm@2658
  1091
\rail@nextalt\relax
wenzelm@2658
  1092
}
wenzelm@2658
  1093
wenzelm@2658
  1094
\def\rail@endbar{
wenzelm@2658
  1095
\rail@endalt\rail@barjoin
wenzelm@2658
  1096
}
wenzelm@2658
  1097
wenzelm@2658
  1098
% \rail@plus : start '+' alternatives
wenzelm@2658
  1099
%
wenzelm@2658
  1100
% \rail@nextplus: next '+' alternative
wenzelm@2658
  1101
%
wenzelm@2658
  1102
% \rail@endplus : end '+' alternatives
wenzelm@2658
  1103
%
wenzelm@2658
  1104
wenzelm@2658
  1105
\def\rail@plus{
wenzelm@2658
  1106
\rail@alt\rail@plussplit
wenzelm@2658
  1107
}
wenzelm@2658
  1108
wenzelm@2658
  1109
\def\rail@nextplus{
wenzelm@2658
  1110
\rail@nextalt\rail@fixplus
wenzelm@2658
  1111
}
wenzelm@2658
  1112
wenzelm@2658
  1113
\def\rail@fixplus{
wenzelm@2658
  1114
\ifnum\rail@gy<\rail@sy
wenzelm@2658
  1115
\begingroup
wenzelm@2658
  1116
\rail@x=\rail@gx
wenzelm@2658
  1117
\rail@y=\rail@gy
wenzelm@2658
  1118
\rail@ex=\rail@gex
wenzelm@2658
  1119
\rail@rx=\rail@grx
wenzelm@2658
  1120
\ifnum\rail@x<\rail@rx
wenzelm@2658
  1121
\rail@x=\rail@rx
wenzelm@2658
  1122
\fi
wenzelm@2658
  1123
\rail@eline
wenzelm@2658
  1124
\rail@jx=\rail@x
wenzelm@2658
  1125
\rail@jy=\rail@y
wenzelm@2658
  1126
\advance\rail@jy by \rail@joinhsz
wenzelm@2658
  1127
\rail@joval[br]
wenzelm@2658
  1128
\advance\rail@jx by \rail@joinhsz
wenzelm@2658
  1129
\rail@tmpa=\rail@sy
wenzelm@2658
  1130
\advance\rail@tmpa by -\rail@joinhsz
wenzelm@2658
  1131
\advance\rail@tmpa by -\rail@jy
wenzelm@2658
  1132
\rail@jput{\line(0,1){\number\rail@tmpa}}
wenzelm@2658
  1133
\rail@jy=\rail@sy
wenzelm@2658
  1134
\advance\rail@jy by -\rail@joinhsz
wenzelm@2658
  1135
\advance\rail@jx by \rail@joinhsz
wenzelm@2658
  1136
\rail@joval[tl]
wenzelm@2658
  1137
\advance\rail@jy by \rail@joinhsz
wenzelm@2658
  1138
\global\rail@gx=\rail@jx
wenzelm@2658
  1139
\global\rail@gy=\rail@jy
wenzelm@2658
  1140
\global\rail@gex=\rail@gx
wenzelm@2658
  1141
\global\rail@grx=\rail@rx
wenzelm@2658
  1142
\endgroup
wenzelm@2658
  1143
\fi
wenzelm@2658
  1144
}
wenzelm@2658
  1145
wenzelm@2658
  1146
\def\rail@endplus{
wenzelm@2658
  1147
\rail@endalt\rail@plusjoin
wenzelm@2658
  1148
}
wenzelm@2658
  1149
wenzelm@2658
  1150
% \rail@cr{Y} : carriage return to vertical position Y
wenzelm@2658
  1151
wenzelm@2658
  1152
\def\rail@cr#1{
wenzelm@2658
  1153
\rail@tmpa=\rail@sx
wenzelm@2658
  1154
\advance\rail@tmpa by \rail@joinsz
wenzelm@2658
  1155
\ifnum\rail@x<\rail@tmpa\rail@x=\rail@tmpa\fi
wenzelm@2658
  1156
\rail@eline
wenzelm@2658
  1157
\rail@jx=\rail@x
wenzelm@2658
  1158
\rail@jy=\rail@y
wenzelm@2658
  1159
\advance\rail@x by \rail@joinsz
wenzelm@2658
  1160
\ifnum\rail@x>\rail@rx\rail@rx=\rail@x\fi
wenzelm@2658
  1161
\advance\rail@jy by -\rail@joinhsz
wenzelm@2658
  1162
\rail@joval[tr]
wenzelm@2658
  1163
\advance\rail@jx by \rail@joinhsz
wenzelm@2658
  1164
\rail@sety{#1}
wenzelm@2658
  1165
\rail@tmpa=\rail@jy
wenzelm@2658
  1166
\advance\rail@tmpa by -\rail@y
wenzelm@2658
  1167
\advance\rail@tmpa by -\rail@boxsp
wenzelm@2658
  1168
\advance\rail@tmpa by -\rail@joinhsz
wenzelm@2658
  1169
\rail@jput{\line(0,-1){\number\rail@tmpa}}
wenzelm@2658
  1170
\rail@jy=\rail@y
wenzelm@2658
  1171
\advance\rail@jy by \rail@boxsp
wenzelm@2658
  1172
\advance\rail@jy by \rail@joinhsz
wenzelm@2658
  1173
\advance\rail@jx by -\rail@joinhsz
wenzelm@2658
  1174
\rail@joval[br]
wenzelm@2658
  1175
\advance\rail@jy by -\rail@joinhsz
wenzelm@2658
  1176
\rail@tmpa=\rail@jx
wenzelm@2658
  1177
\advance\rail@tmpa by -\rail@sx
wenzelm@2658
  1178
\advance\rail@tmpa by -\rail@joinhsz
wenzelm@2658
  1179
\rail@jput{\line(-1,0){\number\rail@tmpa}}
wenzelm@2658
  1180
\rail@jx=\rail@sx
wenzelm@2658
  1181
\advance\rail@jx by \rail@joinhsz
wenzelm@2658
  1182
\advance\rail@jy by -\rail@joinhsz
wenzelm@2658
  1183
\rail@joval[tl]
wenzelm@2658
  1184
\advance\rail@jx by -\rail@joinhsz
wenzelm@2658
  1185
\rail@tmpa=\rail@boxsp
wenzelm@2658
  1186
\advance\rail@tmpa by -\rail@joinsz
wenzelm@2658
  1187
\rail@jput{\line(0,-1){\number\rail@tmpa}}
wenzelm@2658
  1188
\advance\rail@jy by -\rail@tmpa
wenzelm@2658
  1189
\advance\rail@jx by \rail@joinhsz
wenzelm@2658
  1190
\rail@joval[bl]
wenzelm@2658
  1191
\rail@x=\rail@jx
wenzelm@2658
  1192
\rail@ex=\rail@x
wenzelm@2658
  1193
}