src/Tools/isac/Doc/railsetup.sty
author Walther Neuper <walther.neuper@jku.at>
Wed, 11 Mar 2020 15:25:52 +0100
changeset 59827 168abe8dd1e3
permissions -rw-r--r--
start formally checked documentation with Lucas_Interpreter

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