New version of rail.sty for LaTeX 2e
authorberghofe
Fri May 02 16:21:04 1997 +0200 (1997-05-02)
changeset 3097ae362c99a635
parent 3096 ccc2c92bb232
child 3098 a31170b67367
New version of rail.sty for LaTeX 2e
doc-src/rail.sty
     1.1 --- a/doc-src/rail.sty	Fri May 02 16:18:49 1997 +0200
     1.2 +++ b/doc-src/rail.sty	Fri May 02 16:21:04 1997 +0200
     1.3 @@ -4,6 +4,9 @@
     1.4  % 08-Oct-90 L. Rooijakkers	fixed centering bug when \rail@tmpc<0.
     1.5  % 07-Feb-91 L. Rooijakkers	added \railoptions command, indexing
     1.6  % 08-Feb-91 L. Rooijakkers	minor fixes
     1.7 +% 28-Jun-94 K. Barthelmann	turned into LaTeX2e package
     1.8 +% 08-Dec-96 K. Barthelmann	replaced \@writefile
     1.9 +% 13-Dec-96 K. Barthelmann	cleanup
    1.10  %
    1.11  % This style file needs to be used in conjunction with the 'rail'
    1.12  % program. Running LaTeX as 'latex file' produces file.rai, which should be
    1.13 @@ -16,154 +19,8 @@
    1.14  % write the .rai and .rao files, and those that do the actual formatting
    1.15  % of the railroad diagrams.
    1.16  
    1.17 -% railroad read/write macros
    1.18 -%
    1.19 -% \begin{rail} TEXT \end{rail} : TEXT is written out to the .rai file,
    1.20 -%                                as \rail@i{NR}{TEXT}. Then the matching
    1.21 -%                                \rail@o{NR}{FMT} from the .rao file is
    1.22 -%                                executed (if defined).
    1.23 -%
    1.24 -% \railoptions{OPTIONS} : OPTIONS are written out to the .rai file,
    1.25 -%                         as \rail@p{OPTIONS}.
    1.26 -%
    1.27 -% \railterm{IDENT,IDENT,...} : format IDENT as terminals. writes out
    1.28 -%                              \rail@t{IDENT} to the .rai file and
    1.29 -%                              defines \rail@t@IDENT as \rail@termfont IDENT.
    1.30 -%
    1.31 -% \railtoken{IDENT}{TEXT} : format IDENT as terminal TEXT. writes out
    1.32 -%                           \rail@t{IDENT} to the .rai file and defines
    1.33 -%                           \rail@t@IDENT as TEXT.
    1.34 -%
    1.35 -% \rail@nr : railroad diagram counter, starts at 1
    1.36 -%
    1.37 -% \ifrail@match : current \rail@i{NR}{TEXT} matches
    1.38 -%
    1.39 -% \rail@first :	actions to be done first. read in .rao file,
    1.40 -%               open .rai file if \@filesw true, undefine \rail@first.
    1.41 -%               executed from \begin{rail} and \railtoken.
    1.42 -%
    1.43 -% \rail@i{NR}{TEXT} : defines \rail@i@NR as TEXT. written to the .rai
    1.44 -%                     file by \rail, read from the .rao file by
    1.45 -%                     \rail@first
    1.46 -%
    1.47 -% \rail@t{IDENT} : tells Rail that IDENT is to be custom formatted,
    1.48 -%                  written to the .rai file by \railterm and \railtoken.
    1.49 -%
    1.50 -% \rail@o{NR}{TEXT} : defines \rail@o@NR as TEXT, read from the .rao
    1.51 -%                     file by \rail@first.
    1.52 -%
    1.53 -% \rail@p{OPTIONS} : pass options to rail, written to the .rai file by
    1.54 -%                    \railoptions
    1.55 -%
    1.56 -% \rail@warn : warn user for mismatching diagrams
    1.57 -%
    1.58 -% \rail@endwarn : either \relax or \rail@warn
    1.59 -%
    1.60 -% \rail@enddocument : original \enddocument
    1.61 -%
    1.62 -% \enddocument : checks \ifrail@all
    1.63 -
    1.64 -\newcount\rail@nr
    1.65 -\rail@nr=1
    1.66 -
    1.67 -\newif\ifrail@all
    1.68 -\rail@alltrue
    1.69 -
    1.70 -\newif\ifrail@match
    1.71 -
    1.72 -\def\rail@first{
    1.73 -\makeatletter
    1.74 -\@input{\jobname.rao}
    1.75 -\makeatother
    1.76 -\if@filesw
    1.77 -\newwrite\tf@rai
    1.78 -\immediate\openout\tf@rai\jobname.rai\relax
    1.79 -\fi
    1.80 -\global\let\rail@first=\relax
    1.81 -}
    1.82 -
    1.83 -\long\def\rail#1\end#2{
    1.84 -\end{#2}
    1.85 -\rail@first
    1.86 -\begingroup
    1.87 -\let\\=\relax
    1.88 -\global\edef\rail@i@{#1}
    1.89 -\endgroup
    1.90 -\@ifundefined{tf@rai}{}{
    1.91 -\begingroup
    1.92 -\let\\=\relax
    1.93 -\immediate\write\tf@rai{\noexpand\rail@i{\number\rail@nr}{\rail@i@}}
    1.94 -\endgroup
    1.95 -}
    1.96 -\rail@matchtrue
    1.97 -\@ifundefined{rail@o@\number\rail@nr}{\rail@matchfalse}{}
    1.98 -\expandafter\ifx\csname rail@i@\number\rail@nr\endcsname\rail@i@
    1.99 -\else
   1.100 -\rail@matchfalse
   1.101 -\fi
   1.102 -\ifrail@match
   1.103 -\expandafter\relax\csname rail@o@\number\rail@nr\endcsname
   1.104 -\else
   1.105 -\@warning{Railroad diagram {\number\rail@nr} doesn't match}
   1.106 -\global\let\rail@endwarn=\rail@warn
   1.107 -\rail@begin{1}{}
   1.108 -\rail@setbox{\bf ???}
   1.109 -\rail@oval
   1.110 -\rail@end
   1.111 -\fi
   1.112 -\global\advance\rail@nr by 1
   1.113 -}
   1.114 -
   1.115 -\def\railoptions#1{
   1.116 -\rail@first
   1.117 -\@writefile{rai}{\noexpand\rail@p{#1}}
   1.118 -}
   1.119 -
   1.120 -\def\railterm#1{
   1.121 -\rail@first
   1.122 -\@for\rail@i@:=#1\do{
   1.123 -\@writefile{rai}{\noexpand\rail@t{\rail@i@}}
   1.124 -}
   1.125 -}
   1.126 -
   1.127 -\def\railtoken#1#2{
   1.128 -\rail@first
   1.129 -\@writefile{rai}{\noexpand\rail@t{#1}}
   1.130 -\expandafter\def\csname rail@t@#1\endcsname{#2}
   1.131 -}
   1.132 -
   1.133 -\long\def\rail@i#1#2{
   1.134 -\expandafter\gdef\csname rail@i@#1\endcsname{#2}
   1.135 -}
   1.136 -
   1.137 -\def\rail@o#1#2{
   1.138 -\expandafter\gdef\csname rail@o@#1\endcsname{#2}
   1.139 -}
   1.140 -
   1.141 -\def\rail@t#1{}
   1.142 -
   1.143 -\def\rail@p#1{}
   1.144 -
   1.145 -\def\rail@warn{
   1.146 -\@warning{Railroad diagram(s) may have changed. Use 'rail' and rerun}
   1.147 -}
   1.148 -
   1.149 -\let\rail@endwarn=\relax
   1.150 -
   1.151 -\let\rail@enddocument=\enddocument
   1.152 -
   1.153 -\def\enddocument{
   1.154 -\rail@endwarn
   1.155 -\rail@enddocument
   1.156 -}
   1.157 -
   1.158 -% index entry macro
   1.159 -%
   1.160 -% \rail@index{IDENT} : add index entry for IDENT
   1.161 -
   1.162 -\def\rail@index#1{
   1.163 -\index{\rail@indexfont#1}
   1.164 -}
   1.165 +\NeedsTeXFormat{LaTeX2e}
   1.166 +\ProvidesPackage{rail}[1996/12/13]
   1.167  
   1.168  % railroad diagram formatting parameters (user level)
   1.169  % all of these are copied into their internal versions by \railinit
   1.170 @@ -184,20 +41,55 @@
   1.171  %
   1.172  % \railnamesep : separator between name and rule body
   1.173  
   1.174 -\newdimen\railunit
   1.175 -\newdimen\railextra
   1.176 -\newdimen\railboxheight
   1.177 -\newdimen\railboxskip
   1.178 -\newdimen\railboxleft
   1.179 -\newdimen\railboxright
   1.180 -\newdimen\railovalspace
   1.181 -\newdimen\railframespace
   1.182 -\newdimen\railtextleft
   1.183 -\newdimen\railtextright
   1.184 -\newdimen\railtextup
   1.185 -\newdimen\railjoinsize
   1.186 -\newdimen\railjoinadjust
   1.187 -\newdimen\railnamesep
   1.188 +\newlength\railunit
   1.189 +\newlength\railextra
   1.190 +\newlength\railboxheight
   1.191 +\newlength\railboxskip
   1.192 +\newlength\railboxleft
   1.193 +\newlength\railboxright
   1.194 +\newlength\railovalspace
   1.195 +\newlength\railframespace
   1.196 +\newlength\railtextleft
   1.197 +\newlength\railtextright
   1.198 +\newlength\railtextup
   1.199 +\newlength\railjoinsize
   1.200 +\newlength\railjoinadjust
   1.201 +\newlength\railnamesep
   1.202 +
   1.203 +% initialize the parameters
   1.204 +
   1.205 +\setlength\railunit{1sp}
   1.206 +\setlength\railextra{4ex}
   1.207 +\setlength\railboxleft{1ex}
   1.208 +\setlength\railboxright{1ex}
   1.209 +\setlength\railovalspace{2ex}
   1.210 +\setlength\railframespace{2ex}
   1.211 +\setlength\railtextleft{1ex}
   1.212 +\setlength\railtextright{1ex}
   1.213 +\setlength\railjoinadjust{0pt}
   1.214 +\setlength\railnamesep{1ex}
   1.215 +
   1.216 +\DeclareOption{10pt}{
   1.217 +  \setlength\railboxheight{16pt}
   1.218 +  \setlength\railboxskip{24pt}
   1.219 +  \setlength\railtextup{5pt}
   1.220 +  \setlength\railjoinsize{16pt}
   1.221 +}
   1.222 +\DeclareOption{11pt}{
   1.223 +  \setlength\railboxheight{16pt}
   1.224 +  \setlength\railboxskip{24pt}
   1.225 +  \setlength\railtextup{5pt}
   1.226 +  \setlength\railjoinsize{16pt}
   1.227 +}
   1.228 +\DeclareOption{12pt}{
   1.229 +  \setlength\railboxheight{20pt}
   1.230 +  \setlength\railboxskip{28pt}
   1.231 +  \setlength\railtextup{6pt}
   1.232 +  \setlength\railjoinsize{20pt}
   1.233 +}
   1.234 +
   1.235 +\ExecuteOptions{10pt}
   1.236 +\ProcessOptions
   1.237  
   1.238  % internal versions of the formatting parameters
   1.239  %
   1.240 @@ -233,7 +125,7 @@
   1.241  \newcount\rail@joinhsz
   1.242  \newcount\rail@joinadj
   1.243  
   1.244 -\def\railinit{
   1.245 +\newcommand\railinit{
   1.246  \rail@extra=\railextra
   1.247  \divide\rail@extra by \railunit
   1.248  \rail@boxht=\railboxheight
   1.249 @@ -266,40 +158,211 @@
   1.250  \divide\rail@joinadj by \railunit
   1.251  }
   1.252  
   1.253 -% initialize the parameters
   1.254 +\AtBeginDocument{\railinit}
   1.255 +
   1.256 +% \rail@param : declarations for list environment
   1.257 +%
   1.258 +% \railparam{TEXT} : sets \rail@param to TEXT
   1.259 +
   1.260 +\def\rail@param{}
   1.261 +
   1.262 +\newcommand\railparam[1]{
   1.263 +\def\rail@param{#1}
   1.264 +}
   1.265  
   1.266 -\railunit=1sp
   1.267 -\railextra=4ex
   1.268 -\railboxleft=1ex
   1.269 -\railboxright=1ex
   1.270 -\railovalspace=2ex
   1.271 -\railframespace=2ex
   1.272 -\railtextleft=1ex
   1.273 -\railtextright=1ex
   1.274 -\railjoinadjust=0pt
   1.275 -\railnamesep=1ex
   1.276 +% \rail@tokenfont : format setup for \railtoken identifiers
   1.277 +%
   1.278 +% \rail@termfont : format setup for terminals
   1.279 +%
   1.280 +% \rail@nontfont : format setup for nonterminals
   1.281 +%
   1.282 +% \rail@annofont : format setup for annotations
   1.283 +%
   1.284 +% \rail@rulefont : format setup for rule names
   1.285 +%
   1.286 +% \rail@indexfont : format setup for index entry
   1.287 +%
   1.288 +% \railtermfont{TEXT} : set terminal format setup to TEXT
   1.289 +%
   1.290 +% \railnontermfont{TEXT} : set nonterminal format setup to TEXT
   1.291 +%
   1.292 +% \railannotatefont{TEXT} : set annotation format setup to TEXT
   1.293 +%
   1.294 +% \railnamefont{TEXT} : set rule name format setup to TEXT
   1.295 +%
   1.296 +% \railindexfont{TEXT} : set index entry format setup to TEXT
   1.297 +
   1.298 +\def\rail@termfont{\ttfamily\upshape}
   1.299 +\def\rail@nontfont{\rmfamily\upshape}
   1.300 +\def\rail@annofont{\rmfamily\itshape}
   1.301 +\def\rail@namefont{\rmfamily\itshape}
   1.302 +\def\rail@indexfont{\rmfamily\itshape}
   1.303 +
   1.304 +\newcommand\railtermfont[1]{
   1.305 +\def\rail@termfont{#1}
   1.306 +}
   1.307 +
   1.308 +\newcommand\railnontermfont[1]{
   1.309 +\def\rail@nontfont{#1}
   1.310 +}
   1.311 +
   1.312 +\newcommand\railannotatefont[1]{
   1.313 +\def\rail@annofont{#1}
   1.314 +}
   1.315 +
   1.316 +\newcommand\railnamefont[1]{
   1.317 +\def\rail@namefont{#1}
   1.318 +}
   1.319 +
   1.320 +\newcommand\railindexfont[1]{
   1.321 +\def\rail@indexfont{#1}
   1.322 +}
   1.323  
   1.324 -\ifcase\@ptsize
   1.325 -% 10 pt
   1.326 -\railboxheight=16pt
   1.327 -\railboxskip=24pt
   1.328 -\railtextup=5pt
   1.329 -\railjoinsize=16pt
   1.330 -\or
   1.331 -% 11 pt
   1.332 -\railboxheight=16pt
   1.333 -\railboxskip=24pt
   1.334 -\railtextup=5pt
   1.335 -\railjoinsize=16pt
   1.336 -\or
   1.337 -% 12 pt
   1.338 -\railboxheight=20pt
   1.339 -\railboxskip=28pt
   1.340 -\railtextup=6pt
   1.341 -\railjoinsize=20pt
   1.342 +% railroad read/write macros
   1.343 +%
   1.344 +% \begin{rail} TEXT \end{rail} : TEXT is written out to the .rai file,
   1.345 +%                                as \rail@i{NR}{TEXT}. Then the matching
   1.346 +%                                \rail@o{NR}{FMT} from the .rao file is
   1.347 +%                                executed (if defined).
   1.348 +%
   1.349 +% \railoptions{OPTIONS} : OPTIONS are written out to the .rai file,
   1.350 +%                         as \rail@p{OPTIONS}.
   1.351 +%
   1.352 +% \railterm{IDENT,IDENT,...} : format IDENT as terminals. writes out
   1.353 +%                              \rail@t{IDENT} to the .rai file
   1.354 +%
   1.355 +% \railalias{IDENT}{TEXT} : format IDENT as TEXT. defines \rail@t@IDENT as
   1.356 +%                           TEXT.
   1.357 +%
   1.358 +% \rail@nr : railroad diagram counter
   1.359 +%
   1.360 +% \ifrail@match : current \rail@i{NR}{TEXT} matches
   1.361 +%
   1.362 +% \rail@first :	actions to be done first. read in .rao file,
   1.363 +%               open .rai file if \@filesw true, undefine \rail@first.
   1.364 +%               executed from \begin{rail} and \railtoken.
   1.365 +%
   1.366 +% \rail@i{NR}{TEXT} : defines \rail@i@NR as TEXT. written to the .rai
   1.367 +%                     file by \rail, read from the .rao file by
   1.368 +%                     \rail@first
   1.369 +%
   1.370 +% \rail@t{IDENT} : tells Rail that IDENT is to be custom formatted,
   1.371 +%                  written to the .rai file by \railterm.
   1.372 +%
   1.373 +% \rail@o{NR}{TEXT} : defines \rail@o@NR as TEXT, read from the .rao
   1.374 +%                     file by \rail@first.
   1.375 +%
   1.376 +% \rail@p{OPTIONS} : pass options to rail, written to the .rai file by
   1.377 +%                    \railoptions
   1.378 +%
   1.379 +% \rail@write{TEXT} : write TEXT to the .rai file
   1.380 +%
   1.381 +% \rail@warn : warn user for mismatching diagrams
   1.382 +%
   1.383 +% \rail@endwarn : either \relax or \rail@warn
   1.384 +%
   1.385 +% \ifrail@all : checked at the end of the document
   1.386 +
   1.387 +\newcount\rail@nr
   1.388 +
   1.389 +\newif\ifrail@all
   1.390 +\rail@alltrue
   1.391 +
   1.392 +\newif\ifrail@match
   1.393 +
   1.394 +\def\rail@first{
   1.395 +\makeatletter
   1.396 +\InputIfFileExists{\jobname.rao}{}{\PackageInfo{rail}{No file \jobname.rao}}
   1.397 +\makeatother
   1.398 +\if@filesw
   1.399 +\newwrite\tf@rai
   1.400 +\immediate\openout\tf@rai=\jobname.rai
   1.401  \fi
   1.402 +\global\let\rail@first=\relax
   1.403 +}
   1.404  
   1.405 -\railinit
   1.406 +\long\def\rail@body#1\end{
   1.407 +\begingroup
   1.408 +\let\\=\relax
   1.409 +\xdef\rail@i@{#1}
   1.410 +\rail@write{\string\rail@i{\number\rail@nr}{\rail@i@}}
   1.411 +\endgroup
   1.412 +\end
   1.413 +}
   1.414 +
   1.415 +\newenvironment{rail}{
   1.416 +\global\advance\rail@nr by 1
   1.417 +\rail@first
   1.418 +\rail@body
   1.419 +}{
   1.420 +\rail@matchtrue
   1.421 +\@ifundefined{rail@o@\number\rail@nr}{\rail@matchfalse}{}
   1.422 +\expandafter\ifx\csname rail@i@\number\rail@nr\endcsname\rail@i@
   1.423 +\else
   1.424 +\rail@matchfalse
   1.425 +\fi
   1.426 +\ifrail@match
   1.427 +\csname rail@o@\number\rail@nr\endcsname
   1.428 +\else
   1.429 +\PackageWarning{rail}{Railroad diagram {\number\rail@nr} doesn't match}
   1.430 +\global\let\rail@endwarn=\rail@warn
   1.431 +\begin{list}{}{\rail@param}
   1.432 +\rail@begin{1}{}
   1.433 +\rail@setbox{\bfseries ???}
   1.434 +\rail@oval
   1.435 +\rail@end
   1.436 +\end{list}
   1.437 +\fi
   1.438 +}
   1.439 +
   1.440 +\newcommand\railoptions[1]{
   1.441 +\rail@first
   1.442 +\rail@write{\string\rail@p{#1}}
   1.443 +}
   1.444 +
   1.445 +\newcommand\railterm[1]{
   1.446 +\rail@first
   1.447 +\@for\rail@@:=#1\do{
   1.448 +\rail@write{\string\rail@t{\rail@@}}
   1.449 +}
   1.450 +}
   1.451 +
   1.452 +\newcommand\railalias[2]{
   1.453 +\expandafter\def\csname rail@t@#1\endcsname{#2}
   1.454 +}
   1.455 +
   1.456 +\long\def\rail@i#1#2{
   1.457 +\expandafter\gdef\csname rail@i@#1\endcsname{#2}
   1.458 +}
   1.459 +
   1.460 +\def\rail@o#1#2{
   1.461 +\expandafter\gdef\csname rail@o@#1\endcsname{
   1.462 +\begin{list}{}{\rail@param}#2\end{list}
   1.463 +}
   1.464 +}
   1.465 +
   1.466 +\def\rail@t#1{}
   1.467 +
   1.468 +\def\rail@p#1{}
   1.469 +
   1.470 +\def\rail@write#1{\@ifundefined{tf@rai}{}{\immediate\write\tf@rai{#1}}}
   1.471 +
   1.472 +\def\rail@warn{
   1.473 +\PackageWarningNoLine{rail}{Railroad diagram(s) may have changed.
   1.474 +                            Use 'rail' and rerun}
   1.475 +}
   1.476 +
   1.477 +\let\rail@endwarn=\relax
   1.478 +
   1.479 +\AtEndDocument{\rail@endwarn}
   1.480 +
   1.481 +% index entry macro
   1.482 +%
   1.483 +% \rail@index{IDENT} : add index entry for IDENT
   1.484 +
   1.485 +\def\rail@index#1{
   1.486 +\index{\rail@indexfont#1}
   1.487 +}
   1.488  
   1.489  % railroad formatting primitives
   1.490  %
   1.491 @@ -343,30 +406,17 @@
   1.492  \advance\rail@y by -\rail@boxht
   1.493  }
   1.494  
   1.495 -% \rail@list : declarations for list environment
   1.496 -%
   1.497 -% \railparam{TEXT} : sets \rail@list to TEXT
   1.498 -%
   1.499  % \rail@begin{HEIGHT}{NAME} : begin a railroad diagram of height HEIGHT
   1.500  %
   1.501  % \rail@end : end a railroad diagram
   1.502 -
   1.503 -\def\rail@list{}
   1.504 -
   1.505 -\def\railparam#1{
   1.506 -\def\rail@list{#1}
   1.507 -}
   1.508 -
   1.509 -\newbox\tempbox
   1.510 +%
   1.511 +% \rail@expand{IDENT} : expand IDENT
   1.512  
   1.513  \def\rail@begin#1#2{
   1.514 -\medskip
   1.515 -\begin{list}{}{\rail@list}
   1.516  \item[]
   1.517 -\vbox\bgroup
   1.518 +\begin{minipage}[t]{\linewidth}
   1.519  \ifx\@empty#2\else
   1.520 -{\rail@namefont #2}
   1.521 -\\*[\railnamesep]\nopagebreak
   1.522 +{\rail@namefont \rail@expand{#2}}\\*[\railnamesep]
   1.523  \fi
   1.524  \unitlength=\railunit
   1.525  \rail@tmpa=#1
   1.526 @@ -383,112 +433,64 @@
   1.527  \advance\rail@x by \rail@extra
   1.528  \rail@eline
   1.529  \end{picture}
   1.530 -\egroup
   1.531 -\end{list}
   1.532 -}
   1.533 -
   1.534 -% \rail@tokenfont : format setup for \railtoken identifiers
   1.535 -%
   1.536 -% \rail@termfont : format setup for terminals
   1.537 -%
   1.538 -% \rail@nontfont : format setup for nonterminals
   1.539 -%
   1.540 -% \rail@annofont : format setup for annotations
   1.541 -%
   1.542 -% \rail@rulefont : format setup for rule names
   1.543 -%
   1.544 -% \rail@indexfont : format setup for index entry
   1.545 -%
   1.546 -% \railtokenfont{TEXT} : set \railtoken format setup to TEXT
   1.547 -%
   1.548 -% \railtermfont{TEXT} : set terminal format setup to TEXT
   1.549 -%
   1.550 -% \railnontermfont{TEXT} : set nonterminal format setup to TEXT
   1.551 -%
   1.552 -% \railannotatefont{TEXT} : set annotation format setup to TEXT
   1.553 -%
   1.554 -% \railnamefont{TEXT} : set rule name format setup to TEXT
   1.555 -%
   1.556 -% \railindexfont{TEXT} : set index entry format setup to TEXT
   1.557 -
   1.558 -\let\rail@tokenfont=\tt
   1.559 -\let\rail@termfont=\tt
   1.560 -\let\rail@nontfont=\rm
   1.561 -\let\rail@annofont=\it
   1.562 -\let\rail@namefont=\it
   1.563 -\let\rail@indexfont=\it
   1.564 -
   1.565 -\def\railtokenfont#1{
   1.566 -\def\rail@tokenfont{#1}
   1.567 +\end{minipage}
   1.568  }
   1.569  
   1.570 -\def\railtermfont#1{
   1.571 -\def\rail@termfont{#1}
   1.572 -}
   1.573 -
   1.574 -\def\railnontermfont#1{
   1.575 -\def\rail@nontfont{#1}
   1.576 -}
   1.577 -
   1.578 -\def\railannotatefont#1{
   1.579 -\def\rail@annofont{#1}
   1.580 -}
   1.581 -
   1.582 -\def\railnamefont#1{
   1.583 -\def\rail@namefont{#1}
   1.584 -}
   1.585 +\def\rail@expand#1{\@ifundefined{rail@t@#1}{#1}{\csname rail@t@#1\endcsname}}
   1.586  
   1.587 -\def\railindexfont#1{
   1.588 -\def\rail@indexfont{#1}
   1.589 -}
   1.590 -
   1.591 -% \rail@token{TEXT} : format token TEXT
   1.592 +% \rail@token{TEXT}[ANNOT] : format token TEXT with annotation
   1.593  %
   1.594 -% \rail@ctoken{TEXT} : format token TEXT centered
   1.595 +% \rail@ctoken{TEXT}[ANNOT] : format token TEXT centered with annotation
   1.596 +%
   1.597 +% \rail@nont{TEXT}[ANNOT] : format nonterminal TEXT with annotation
   1.598  %
   1.599 -% \rail@nont{TEXT} : format nonterminal TEXT
   1.600 -%
   1.601 -% \rail@cnont{TEXT} : format nonterminal TEXT centered
   1.602 +% \rail@cnont{TEXT}[ANNOT] : format nonterminal TEXT centered with annotation
   1.603  %
   1.604 -% \rail@cterm{TEXT} : format terminal TEXT
   1.605 +% \rail@term{TEXT}[ANNOT] : format terminal TEXT with annotation
   1.606  %
   1.607 -% \rail@cterm{TEXT} : format terminal TEXT centered
   1.608 +% \rail@cterm{TEXT}[ANNOT] : format terminal TEXT centered with annotation
   1.609  %
   1.610  % \rail@annote[TEXT] : format TEXT as annotation
   1.611 -%
   1.612 -% \rail@annotebox[TEXT] : annotate box with TEXT
   1.613  
   1.614 -\def\rail@token#1{
   1.615 -\expandafter\@ifundefined{rail@t@#1}{
   1.616 -\rail@setbox{\rail@termfont #1}
   1.617 -}{
   1.618 -\rail@setbox{\rail@tokenfont \csname rail@t@#1\endcsname}
   1.619 +\def\rail@token#1[#2]{
   1.620 +\rail@setbox{%
   1.621 +{\rail@termfont \rail@expand{#1}}\ifx\@empty#2\else\ {\rail@annofont #2}\fi
   1.622  }
   1.623  \rail@oval
   1.624  }
   1.625  
   1.626 -\def\rail@ctoken#1{
   1.627 -\rail@setbox{\rail@tokenfont \csname rail@t@#1\endcsname}
   1.628 +\def\rail@ctoken#1[#2]{
   1.629 +\rail@setbox{%
   1.630 +{\rail@termfont \rail@expand{#1}}\ifx\@empty#2\else\ {\rail@annofont #2}\fi
   1.631 +}
   1.632  \rail@coval
   1.633  }
   1.634  
   1.635 -\def\rail@nont#1{
   1.636 -\rail@setbox{\rail@nontfont #1}
   1.637 +\def\rail@nont#1[#2]{
   1.638 +\rail@setbox{%
   1.639 +{\rail@nontfont \rail@expand{#1}}\ifx\@empty#2\else\ {\rail@annofont #2}\fi
   1.640 +}
   1.641  \rail@frame
   1.642  }
   1.643  
   1.644 -\def\rail@cnont#1{
   1.645 -\rail@setbox{\rail@nontfont #1}
   1.646 +\def\rail@cnont#1[#2]{
   1.647 +\rail@setbox{%
   1.648 +{\rail@nontfont \rail@expand{#1}}\ifx\@empty#2\else\ {\rail@annofont #2}\fi
   1.649 +}
   1.650  \rail@cframe
   1.651  }
   1.652  
   1.653 -\def\rail@term#1{
   1.654 -\rail@setbox{\rail@termfont #1}
   1.655 +\def\rail@term#1[#2]{
   1.656 +\rail@setbox{%
   1.657 +{\rail@termfont #1}\ifx\@empty#2\else\ {\rail@annofont #2}\fi
   1.658 +}
   1.659  \rail@oval
   1.660  }
   1.661  
   1.662 -\def\rail@cterm#1{
   1.663 -\rail@setbox{\rail@termfont #1}
   1.664 +\def\rail@cterm#1[#2]{
   1.665 +\rail@setbox{%
   1.666 +{\rail@termfont #1}\ifx\@empty#2\else\ {\rail@annofont #2}\fi
   1.667 +}
   1.668  \rail@coval
   1.669  }
   1.670  
   1.671 @@ -497,10 +499,6 @@
   1.672  \rail@text
   1.673  }
   1.674  
   1.675 -\def\rail@annotebox[#1]{
   1.676 -\ \rail@annofont #1
   1.677 -}
   1.678 -
   1.679  % \rail@box : temporary box for \rail@oval and \rail@frame
   1.680  %
   1.681  % \rail@setbox{TEXT} : set \rail@box to TEXT, set \rail@tmpa to width