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