doc-src/rail.sty
changeset 3097 ae362c99a635
parent 2658 13ba951a4572
child 8591 9d660fc42916
equal deleted inserted replaced
3096:ccc2c92bb232 3097:ae362c99a635
     2 %
     2 %
     3 % 09-Jul-90 L. Rooijakkers
     3 % 09-Jul-90 L. Rooijakkers
     4 % 08-Oct-90 L. Rooijakkers	fixed centering bug when \rail@tmpc<0.
     4 % 08-Oct-90 L. Rooijakkers	fixed centering bug when \rail@tmpc<0.
     5 % 07-Feb-91 L. Rooijakkers	added \railoptions command, indexing
     5 % 07-Feb-91 L. Rooijakkers	added \railoptions command, indexing
     6 % 08-Feb-91 L. Rooijakkers	minor fixes
     6 % 08-Feb-91 L. Rooijakkers	minor fixes
       
     7 % 28-Jun-94 K. Barthelmann	turned into LaTeX2e package
       
     8 % 08-Dec-96 K. Barthelmann	replaced \@writefile
       
     9 % 13-Dec-96 K. Barthelmann	cleanup
     7 %
    10 %
     8 % This style file needs to be used in conjunction with the 'rail'
    11 % This style file needs to be used in conjunction with the 'rail'
     9 % program. Running LaTeX as 'latex file' produces file.rai, which should be
    12 % program. Running LaTeX as 'latex file' produces file.rai, which should be
    10 % processed by Rail with 'rail file'. This produces file.rao, which will
    13 % processed by Rail with 'rail file'. This produces file.rao, which will
    11 % be picked up by LaTeX on the next 'latex file' run.
    14 % be picked up by LaTeX on the next 'latex file' run.
    14 %
    17 %
    15 % The macros in this file thus consist of two parts: those that read and
    18 % The macros in this file thus consist of two parts: those that read and
    16 % write the .rai and .rao files, and those that do the actual formatting
    19 % write the .rai and .rao files, and those that do the actual formatting
    17 % of the railroad diagrams.
    20 % of the railroad diagrams.
    18 
    21 
    19 % railroad read/write macros
    22 \NeedsTeXFormat{LaTeX2e}
    20 %
    23 \ProvidesPackage{rail}[1996/12/13]
    21 % \begin{rail} TEXT \end{rail} : TEXT is written out to the .rai file,
       
    22 %                                as \rail@i{NR}{TEXT}. Then the matching
       
    23 %                                \rail@o{NR}{FMT} from the .rao file is
       
    24 %                                executed (if defined).
       
    25 %
       
    26 % \railoptions{OPTIONS} : OPTIONS are written out to the .rai file,
       
    27 %                         as \rail@p{OPTIONS}.
       
    28 %
       
    29 % \railterm{IDENT,IDENT,...} : format IDENT as terminals. writes out
       
    30 %                              \rail@t{IDENT} to the .rai file and
       
    31 %                              defines \rail@t@IDENT as \rail@termfont IDENT.
       
    32 %
       
    33 % \railtoken{IDENT}{TEXT} : format IDENT as terminal TEXT. writes out
       
    34 %                           \rail@t{IDENT} to the .rai file and defines
       
    35 %                           \rail@t@IDENT as TEXT.
       
    36 %
       
    37 % \rail@nr : railroad diagram counter, starts at 1
       
    38 %
       
    39 % \ifrail@match : current \rail@i{NR}{TEXT} matches
       
    40 %
       
    41 % \rail@first :	actions to be done first. read in .rao file,
       
    42 %               open .rai file if \@filesw true, undefine \rail@first.
       
    43 %               executed from \begin{rail} and \railtoken.
       
    44 %
       
    45 % \rail@i{NR}{TEXT} : defines \rail@i@NR as TEXT. written to the .rai
       
    46 %                     file by \rail, read from the .rao file by
       
    47 %                     \rail@first
       
    48 %
       
    49 % \rail@t{IDENT} : tells Rail that IDENT is to be custom formatted,
       
    50 %                  written to the .rai file by \railterm and \railtoken.
       
    51 %
       
    52 % \rail@o{NR}{TEXT} : defines \rail@o@NR as TEXT, read from the .rao
       
    53 %                     file by \rail@first.
       
    54 %
       
    55 % \rail@p{OPTIONS} : pass options to rail, written to the .rai file by
       
    56 %                    \railoptions
       
    57 %
       
    58 % \rail@warn : warn user for mismatching diagrams
       
    59 %
       
    60 % \rail@endwarn : either \relax or \rail@warn
       
    61 %
       
    62 % \rail@enddocument : original \enddocument
       
    63 %
       
    64 % \enddocument : checks \ifrail@all
       
    65 
       
    66 \newcount\rail@nr
       
    67 \rail@nr=1
       
    68 
       
    69 \newif\ifrail@all
       
    70 \rail@alltrue
       
    71 
       
    72 \newif\ifrail@match
       
    73 
       
    74 \def\rail@first{
       
    75 \makeatletter
       
    76 \@input{\jobname.rao}
       
    77 \makeatother
       
    78 \if@filesw
       
    79 \newwrite\tf@rai
       
    80 \immediate\openout\tf@rai\jobname.rai\relax
       
    81 \fi
       
    82 \global\let\rail@first=\relax
       
    83 }
       
    84 
       
    85 \long\def\rail#1\end#2{
       
    86 \end{#2}
       
    87 \rail@first
       
    88 \begingroup
       
    89 \let\\=\relax
       
    90 \global\edef\rail@i@{#1}
       
    91 \endgroup
       
    92 \@ifundefined{tf@rai}{}{
       
    93 \begingroup
       
    94 \let\\=\relax
       
    95 \immediate\write\tf@rai{\noexpand\rail@i{\number\rail@nr}{\rail@i@}}
       
    96 \endgroup
       
    97 }
       
    98 \rail@matchtrue
       
    99 \@ifundefined{rail@o@\number\rail@nr}{\rail@matchfalse}{}
       
   100 \expandafter\ifx\csname rail@i@\number\rail@nr\endcsname\rail@i@
       
   101 \else
       
   102 \rail@matchfalse
       
   103 \fi
       
   104 \ifrail@match
       
   105 \expandafter\relax\csname rail@o@\number\rail@nr\endcsname
       
   106 \else
       
   107 \@warning{Railroad diagram {\number\rail@nr} doesn't match}
       
   108 \global\let\rail@endwarn=\rail@warn
       
   109 \rail@begin{1}{}
       
   110 \rail@setbox{\bf ???}
       
   111 \rail@oval
       
   112 \rail@end
       
   113 \fi
       
   114 \global\advance\rail@nr by 1
       
   115 }
       
   116 
       
   117 \def\railoptions#1{
       
   118 \rail@first
       
   119 \@writefile{rai}{\noexpand\rail@p{#1}}
       
   120 }
       
   121 
       
   122 \def\railterm#1{
       
   123 \rail@first
       
   124 \@for\rail@i@:=#1\do{
       
   125 \@writefile{rai}{\noexpand\rail@t{\rail@i@}}
       
   126 }
       
   127 }
       
   128 
       
   129 \def\railtoken#1#2{
       
   130 \rail@first
       
   131 \@writefile{rai}{\noexpand\rail@t{#1}}
       
   132 \expandafter\def\csname rail@t@#1\endcsname{#2}
       
   133 }
       
   134 
       
   135 \long\def\rail@i#1#2{
       
   136 \expandafter\gdef\csname rail@i@#1\endcsname{#2}
       
   137 }
       
   138 
       
   139 \def\rail@o#1#2{
       
   140 \expandafter\gdef\csname rail@o@#1\endcsname{#2}
       
   141 }
       
   142 
       
   143 \def\rail@t#1{}
       
   144 
       
   145 \def\rail@p#1{}
       
   146 
       
   147 \def\rail@warn{
       
   148 \@warning{Railroad diagram(s) may have changed. Use 'rail' and rerun}
       
   149 }
       
   150 
       
   151 \let\rail@endwarn=\relax
       
   152 
       
   153 \let\rail@enddocument=\enddocument
       
   154 
       
   155 \def\enddocument{
       
   156 \rail@endwarn
       
   157 \rail@enddocument
       
   158 }
       
   159 
       
   160 % index entry macro
       
   161 %
       
   162 % \rail@index{IDENT} : add index entry for IDENT
       
   163 
       
   164 \def\rail@index#1{
       
   165 \index{\rail@indexfont#1}
       
   166 }
       
   167 
    24 
   168 % railroad diagram formatting parameters (user level)
    25 % railroad diagram formatting parameters (user level)
   169 % all of these are copied into their internal versions by \railinit
    26 % all of these are copied into their internal versions by \railinit
   170 %
    27 %
   171 % \railunit : \unitlength within railroad diagrams
    28 % \railunit : \unitlength within railroad diagrams
   182 % \railjoinsize : circle size of join/split arcs
    39 % \railjoinsize : circle size of join/split arcs
   183 % \railjoinadjust : space to adjust join
    40 % \railjoinadjust : space to adjust join
   184 %
    41 %
   185 % \railnamesep : separator between name and rule body
    42 % \railnamesep : separator between name and rule body
   186 
    43 
   187 \newdimen\railunit
    44 \newlength\railunit
   188 \newdimen\railextra
    45 \newlength\railextra
   189 \newdimen\railboxheight
    46 \newlength\railboxheight
   190 \newdimen\railboxskip
    47 \newlength\railboxskip
   191 \newdimen\railboxleft
    48 \newlength\railboxleft
   192 \newdimen\railboxright
    49 \newlength\railboxright
   193 \newdimen\railovalspace
    50 \newlength\railovalspace
   194 \newdimen\railframespace
    51 \newlength\railframespace
   195 \newdimen\railtextleft
    52 \newlength\railtextleft
   196 \newdimen\railtextright
    53 \newlength\railtextright
   197 \newdimen\railtextup
    54 \newlength\railtextup
   198 \newdimen\railjoinsize
    55 \newlength\railjoinsize
   199 \newdimen\railjoinadjust
    56 \newlength\railjoinadjust
   200 \newdimen\railnamesep
    57 \newlength\railnamesep
       
    58 
       
    59 % initialize the parameters
       
    60 
       
    61 \setlength\railunit{1sp}
       
    62 \setlength\railextra{4ex}
       
    63 \setlength\railboxleft{1ex}
       
    64 \setlength\railboxright{1ex}
       
    65 \setlength\railovalspace{2ex}
       
    66 \setlength\railframespace{2ex}
       
    67 \setlength\railtextleft{1ex}
       
    68 \setlength\railtextright{1ex}
       
    69 \setlength\railjoinadjust{0pt}
       
    70 \setlength\railnamesep{1ex}
       
    71 
       
    72 \DeclareOption{10pt}{
       
    73   \setlength\railboxheight{16pt}
       
    74   \setlength\railboxskip{24pt}
       
    75   \setlength\railtextup{5pt}
       
    76   \setlength\railjoinsize{16pt}
       
    77 }
       
    78 \DeclareOption{11pt}{
       
    79   \setlength\railboxheight{16pt}
       
    80   \setlength\railboxskip{24pt}
       
    81   \setlength\railtextup{5pt}
       
    82   \setlength\railjoinsize{16pt}
       
    83 }
       
    84 \DeclareOption{12pt}{
       
    85   \setlength\railboxheight{20pt}
       
    86   \setlength\railboxskip{28pt}
       
    87   \setlength\railtextup{6pt}
       
    88   \setlength\railjoinsize{20pt}
       
    89 }
       
    90 
       
    91 \ExecuteOptions{10pt}
       
    92 \ProcessOptions
   201 
    93 
   202 % internal versions of the formatting parameters
    94 % internal versions of the formatting parameters
   203 %
    95 %
   204 % \rail@extra   : \railextra
    96 % \rail@extra   : \railextra
   205 % \rail@boxht   : \railboxheight
    97 % \rail@boxht   : \railboxheight
   231 \newcount\rail@textup
   123 \newcount\rail@textup
   232 \newcount\rail@joinsz
   124 \newcount\rail@joinsz
   233 \newcount\rail@joinhsz
   125 \newcount\rail@joinhsz
   234 \newcount\rail@joinadj
   126 \newcount\rail@joinadj
   235 
   127 
   236 \def\railinit{
   128 \newcommand\railinit{
   237 \rail@extra=\railextra
   129 \rail@extra=\railextra
   238 \divide\rail@extra by \railunit
   130 \divide\rail@extra by \railunit
   239 \rail@boxht=\railboxheight
   131 \rail@boxht=\railboxheight
   240 \divide\rail@boxht by \railunit
   132 \divide\rail@boxht by \railunit
   241 \rail@boxsp=\railboxskip
   133 \rail@boxsp=\railboxskip
   264 \divide\rail@joinhsz by 2
   156 \divide\rail@joinhsz by 2
   265 \rail@joinadj=\railjoinadjust
   157 \rail@joinadj=\railjoinadjust
   266 \divide\rail@joinadj by \railunit
   158 \divide\rail@joinadj by \railunit
   267 }
   159 }
   268 
   160 
   269 % initialize the parameters
   161 \AtBeginDocument{\railinit}
   270 
   162 
   271 \railunit=1sp
   163 % \rail@param : declarations for list environment
   272 \railextra=4ex
   164 %
   273 \railboxleft=1ex
   165 % \railparam{TEXT} : sets \rail@param to TEXT
   274 \railboxright=1ex
   166 
   275 \railovalspace=2ex
   167 \def\rail@param{}
   276 \railframespace=2ex
   168 
   277 \railtextleft=1ex
   169 \newcommand\railparam[1]{
   278 \railtextright=1ex
   170 \def\rail@param{#1}
   279 \railjoinadjust=0pt
   171 }
   280 \railnamesep=1ex
   172 
   281 
   173 % \rail@tokenfont : format setup for \railtoken identifiers
   282 \ifcase\@ptsize
   174 %
   283 % 10 pt
   175 % \rail@termfont : format setup for terminals
   284 \railboxheight=16pt
   176 %
   285 \railboxskip=24pt
   177 % \rail@nontfont : format setup for nonterminals
   286 \railtextup=5pt
   178 %
   287 \railjoinsize=16pt
   179 % \rail@annofont : format setup for annotations
   288 \or
   180 %
   289 % 11 pt
   181 % \rail@rulefont : format setup for rule names
   290 \railboxheight=16pt
   182 %
   291 \railboxskip=24pt
   183 % \rail@indexfont : format setup for index entry
   292 \railtextup=5pt
   184 %
   293 \railjoinsize=16pt
   185 % \railtermfont{TEXT} : set terminal format setup to TEXT
   294 \or
   186 %
   295 % 12 pt
   187 % \railnontermfont{TEXT} : set nonterminal format setup to TEXT
   296 \railboxheight=20pt
   188 %
   297 \railboxskip=28pt
   189 % \railannotatefont{TEXT} : set annotation format setup to TEXT
   298 \railtextup=6pt
   190 %
   299 \railjoinsize=20pt
   191 % \railnamefont{TEXT} : set rule name format setup to TEXT
   300 \fi
   192 %
   301 
   193 % \railindexfont{TEXT} : set index entry format setup to TEXT
   302 \railinit
   194 
       
   195 \def\rail@termfont{\ttfamily\upshape}
       
   196 \def\rail@nontfont{\rmfamily\upshape}
       
   197 \def\rail@annofont{\rmfamily\itshape}
       
   198 \def\rail@namefont{\rmfamily\itshape}
       
   199 \def\rail@indexfont{\rmfamily\itshape}
       
   200 
       
   201 \newcommand\railtermfont[1]{
       
   202 \def\rail@termfont{#1}
       
   203 }
       
   204 
       
   205 \newcommand\railnontermfont[1]{
       
   206 \def\rail@nontfont{#1}
       
   207 }
       
   208 
       
   209 \newcommand\railannotatefont[1]{
       
   210 \def\rail@annofont{#1}
       
   211 }
       
   212 
       
   213 \newcommand\railnamefont[1]{
       
   214 \def\rail@namefont{#1}
       
   215 }
       
   216 
       
   217 \newcommand\railindexfont[1]{
       
   218 \def\rail@indexfont{#1}
       
   219 }
       
   220 
       
   221 % railroad read/write macros
       
   222 %
       
   223 % \begin{rail} TEXT \end{rail} : TEXT is written out to the .rai file,
       
   224 %                                as \rail@i{NR}{TEXT}. Then the matching
       
   225 %                                \rail@o{NR}{FMT} from the .rao file is
       
   226 %                                executed (if defined).
       
   227 %
       
   228 % \railoptions{OPTIONS} : OPTIONS are written out to the .rai file,
       
   229 %                         as \rail@p{OPTIONS}.
       
   230 %
       
   231 % \railterm{IDENT,IDENT,...} : format IDENT as terminals. writes out
       
   232 %                              \rail@t{IDENT} to the .rai file
       
   233 %
       
   234 % \railalias{IDENT}{TEXT} : format IDENT as TEXT. defines \rail@t@IDENT as
       
   235 %                           TEXT.
       
   236 %
       
   237 % \rail@nr : railroad diagram counter
       
   238 %
       
   239 % \ifrail@match : current \rail@i{NR}{TEXT} matches
       
   240 %
       
   241 % \rail@first :	actions to be done first. read in .rao file,
       
   242 %               open .rai file if \@filesw true, undefine \rail@first.
       
   243 %               executed from \begin{rail} and \railtoken.
       
   244 %
       
   245 % \rail@i{NR}{TEXT} : defines \rail@i@NR as TEXT. written to the .rai
       
   246 %                     file by \rail, read from the .rao file by
       
   247 %                     \rail@first
       
   248 %
       
   249 % \rail@t{IDENT} : tells Rail that IDENT is to be custom formatted,
       
   250 %                  written to the .rai file by \railterm.
       
   251 %
       
   252 % \rail@o{NR}{TEXT} : defines \rail@o@NR as TEXT, read from the .rao
       
   253 %                     file by \rail@first.
       
   254 %
       
   255 % \rail@p{OPTIONS} : pass options to rail, written to the .rai file by
       
   256 %                    \railoptions
       
   257 %
       
   258 % \rail@write{TEXT} : write TEXT to the .rai file
       
   259 %
       
   260 % \rail@warn : warn user for mismatching diagrams
       
   261 %
       
   262 % \rail@endwarn : either \relax or \rail@warn
       
   263 %
       
   264 % \ifrail@all : checked at the end of the document
       
   265 
       
   266 \newcount\rail@nr
       
   267 
       
   268 \newif\ifrail@all
       
   269 \rail@alltrue
       
   270 
       
   271 \newif\ifrail@match
       
   272 
       
   273 \def\rail@first{
       
   274 \makeatletter
       
   275 \InputIfFileExists{\jobname.rao}{}{\PackageInfo{rail}{No file \jobname.rao}}
       
   276 \makeatother
       
   277 \if@filesw
       
   278 \newwrite\tf@rai
       
   279 \immediate\openout\tf@rai=\jobname.rai
       
   280 \fi
       
   281 \global\let\rail@first=\relax
       
   282 }
       
   283 
       
   284 \long\def\rail@body#1\end{
       
   285 \begingroup
       
   286 \let\\=\relax
       
   287 \xdef\rail@i@{#1}
       
   288 \rail@write{\string\rail@i{\number\rail@nr}{\rail@i@}}
       
   289 \endgroup
       
   290 \end
       
   291 }
       
   292 
       
   293 \newenvironment{rail}{
       
   294 \global\advance\rail@nr by 1
       
   295 \rail@first
       
   296 \rail@body
       
   297 }{
       
   298 \rail@matchtrue
       
   299 \@ifundefined{rail@o@\number\rail@nr}{\rail@matchfalse}{}
       
   300 \expandafter\ifx\csname rail@i@\number\rail@nr\endcsname\rail@i@
       
   301 \else
       
   302 \rail@matchfalse
       
   303 \fi
       
   304 \ifrail@match
       
   305 \csname rail@o@\number\rail@nr\endcsname
       
   306 \else
       
   307 \PackageWarning{rail}{Railroad diagram {\number\rail@nr} doesn't match}
       
   308 \global\let\rail@endwarn=\rail@warn
       
   309 \begin{list}{}{\rail@param}
       
   310 \rail@begin{1}{}
       
   311 \rail@setbox{\bfseries ???}
       
   312 \rail@oval
       
   313 \rail@end
       
   314 \end{list}
       
   315 \fi
       
   316 }
       
   317 
       
   318 \newcommand\railoptions[1]{
       
   319 \rail@first
       
   320 \rail@write{\string\rail@p{#1}}
       
   321 }
       
   322 
       
   323 \newcommand\railterm[1]{
       
   324 \rail@first
       
   325 \@for\rail@@:=#1\do{
       
   326 \rail@write{\string\rail@t{\rail@@}}
       
   327 }
       
   328 }
       
   329 
       
   330 \newcommand\railalias[2]{
       
   331 \expandafter\def\csname rail@t@#1\endcsname{#2}
       
   332 }
       
   333 
       
   334 \long\def\rail@i#1#2{
       
   335 \expandafter\gdef\csname rail@i@#1\endcsname{#2}
       
   336 }
       
   337 
       
   338 \def\rail@o#1#2{
       
   339 \expandafter\gdef\csname rail@o@#1\endcsname{
       
   340 \begin{list}{}{\rail@param}#2\end{list}
       
   341 }
       
   342 }
       
   343 
       
   344 \def\rail@t#1{}
       
   345 
       
   346 \def\rail@p#1{}
       
   347 
       
   348 \def\rail@write#1{\@ifundefined{tf@rai}{}{\immediate\write\tf@rai{#1}}}
       
   349 
       
   350 \def\rail@warn{
       
   351 \PackageWarningNoLine{rail}{Railroad diagram(s) may have changed.
       
   352                             Use 'rail' and rerun}
       
   353 }
       
   354 
       
   355 \let\rail@endwarn=\relax
       
   356 
       
   357 \AtEndDocument{\rail@endwarn}
       
   358 
       
   359 % index entry macro
       
   360 %
       
   361 % \rail@index{IDENT} : add index entry for IDENT
       
   362 
       
   363 \def\rail@index#1{
       
   364 \index{\rail@indexfont#1}
       
   365 }
   303 
   366 
   304 % railroad formatting primitives
   367 % railroad formatting primitives
   305 %
   368 %
   306 % \rail@x : current x
   369 % \rail@x : current x
   307 % \rail@y : current y
   370 % \rail@y : current y
   341 \rail@y=#1
   404 \rail@y=#1
   342 \multiply\rail@y by -\rail@boxsp
   405 \multiply\rail@y by -\rail@boxsp
   343 \advance\rail@y by -\rail@boxht
   406 \advance\rail@y by -\rail@boxht
   344 }
   407 }
   345 
   408 
   346 % \rail@list : declarations for list environment
       
   347 %
       
   348 % \railparam{TEXT} : sets \rail@list to TEXT
       
   349 %
       
   350 % \rail@begin{HEIGHT}{NAME} : begin a railroad diagram of height HEIGHT
   409 % \rail@begin{HEIGHT}{NAME} : begin a railroad diagram of height HEIGHT
   351 %
   410 %
   352 % \rail@end : end a railroad diagram
   411 % \rail@end : end a railroad diagram
   353 
   412 %
   354 \def\rail@list{}
   413 % \rail@expand{IDENT} : expand IDENT
   355 
       
   356 \def\railparam#1{
       
   357 \def\rail@list{#1}
       
   358 }
       
   359 
       
   360 \newbox\tempbox
       
   361 
   414 
   362 \def\rail@begin#1#2{
   415 \def\rail@begin#1#2{
   363 \medskip
       
   364 \begin{list}{}{\rail@list}
       
   365 \item[]
   416 \item[]
   366 \vbox\bgroup
   417 \begin{minipage}[t]{\linewidth}
   367 \ifx\@empty#2\else
   418 \ifx\@empty#2\else
   368 {\rail@namefont #2}
   419 {\rail@namefont \rail@expand{#2}}\\*[\railnamesep]
   369 \\*[\railnamesep]\nopagebreak
       
   370 \fi
   420 \fi
   371 \unitlength=\railunit
   421 \unitlength=\railunit
   372 \rail@tmpa=#1
   422 \rail@tmpa=#1
   373 \multiply\rail@tmpa by \rail@boxsp
   423 \multiply\rail@tmpa by \rail@boxsp
   374 \begin{picture}(0,\number\rail@tmpa)(0,-\number\rail@tmpa)
   424 \begin{picture}(0,\number\rail@tmpa)(0,-\number\rail@tmpa)
   381 
   431 
   382 \def\rail@end{
   432 \def\rail@end{
   383 \advance\rail@x by \rail@extra
   433 \advance\rail@x by \rail@extra
   384 \rail@eline
   434 \rail@eline
   385 \end{picture}
   435 \end{picture}
   386 \egroup
   436 \end{minipage}
   387 \end{list}
   437 }
   388 }
   438 
   389 
   439 \def\rail@expand#1{\@ifundefined{rail@t@#1}{#1}{\csname rail@t@#1\endcsname}}
   390 % \rail@tokenfont : format setup for \railtoken identifiers
   440 
   391 %
   441 % \rail@token{TEXT}[ANNOT] : format token TEXT with annotation
   392 % \rail@termfont : format setup for terminals
   442 %
   393 %
   443 % \rail@ctoken{TEXT}[ANNOT] : format token TEXT centered with annotation
   394 % \rail@nontfont : format setup for nonterminals
   444 %
   395 %
   445 % \rail@nont{TEXT}[ANNOT] : format nonterminal TEXT with annotation
   396 % \rail@annofont : format setup for annotations
   446 %
   397 %
   447 % \rail@cnont{TEXT}[ANNOT] : format nonterminal TEXT centered with annotation
   398 % \rail@rulefont : format setup for rule names
   448 %
   399 %
   449 % \rail@term{TEXT}[ANNOT] : format terminal TEXT with annotation
   400 % \rail@indexfont : format setup for index entry
   450 %
   401 %
   451 % \rail@cterm{TEXT}[ANNOT] : format terminal TEXT centered with annotation
   402 % \railtokenfont{TEXT} : set \railtoken format setup to TEXT
       
   403 %
       
   404 % \railtermfont{TEXT} : set terminal format setup to TEXT
       
   405 %
       
   406 % \railnontermfont{TEXT} : set nonterminal format setup to TEXT
       
   407 %
       
   408 % \railannotatefont{TEXT} : set annotation format setup to TEXT
       
   409 %
       
   410 % \railnamefont{TEXT} : set rule name format setup to TEXT
       
   411 %
       
   412 % \railindexfont{TEXT} : set index entry format setup to TEXT
       
   413 
       
   414 \let\rail@tokenfont=\tt
       
   415 \let\rail@termfont=\tt
       
   416 \let\rail@nontfont=\rm
       
   417 \let\rail@annofont=\it
       
   418 \let\rail@namefont=\it
       
   419 \let\rail@indexfont=\it
       
   420 
       
   421 \def\railtokenfont#1{
       
   422 \def\rail@tokenfont{#1}
       
   423 }
       
   424 
       
   425 \def\railtermfont#1{
       
   426 \def\rail@termfont{#1}
       
   427 }
       
   428 
       
   429 \def\railnontermfont#1{
       
   430 \def\rail@nontfont{#1}
       
   431 }
       
   432 
       
   433 \def\railannotatefont#1{
       
   434 \def\rail@annofont{#1}
       
   435 }
       
   436 
       
   437 \def\railnamefont#1{
       
   438 \def\rail@namefont{#1}
       
   439 }
       
   440 
       
   441 \def\railindexfont#1{
       
   442 \def\rail@indexfont{#1}
       
   443 }
       
   444 
       
   445 % \rail@token{TEXT} : format token TEXT
       
   446 %
       
   447 % \rail@ctoken{TEXT} : format token TEXT centered
       
   448 %
       
   449 % \rail@nont{TEXT} : format nonterminal TEXT
       
   450 %
       
   451 % \rail@cnont{TEXT} : format nonterminal TEXT centered
       
   452 %
       
   453 % \rail@cterm{TEXT} : format terminal TEXT
       
   454 %
       
   455 % \rail@cterm{TEXT} : format terminal TEXT centered
       
   456 %
   452 %
   457 % \rail@annote[TEXT] : format TEXT as annotation
   453 % \rail@annote[TEXT] : format TEXT as annotation
   458 %
   454 
   459 % \rail@annotebox[TEXT] : annotate box with TEXT
   455 \def\rail@token#1[#2]{
   460 
   456 \rail@setbox{%
   461 \def\rail@token#1{
   457 {\rail@termfont \rail@expand{#1}}\ifx\@empty#2\else\ {\rail@annofont #2}\fi
   462 \expandafter\@ifundefined{rail@t@#1}{
       
   463 \rail@setbox{\rail@termfont #1}
       
   464 }{
       
   465 \rail@setbox{\rail@tokenfont \csname rail@t@#1\endcsname}
       
   466 }
   458 }
   467 \rail@oval
   459 \rail@oval
   468 }
   460 }
   469 
   461 
   470 \def\rail@ctoken#1{
   462 \def\rail@ctoken#1[#2]{
   471 \rail@setbox{\rail@tokenfont \csname rail@t@#1\endcsname}
   463 \rail@setbox{%
       
   464 {\rail@termfont \rail@expand{#1}}\ifx\@empty#2\else\ {\rail@annofont #2}\fi
       
   465 }
   472 \rail@coval
   466 \rail@coval
   473 }
   467 }
   474 
   468 
   475 \def\rail@nont#1{
   469 \def\rail@nont#1[#2]{
   476 \rail@setbox{\rail@nontfont #1}
   470 \rail@setbox{%
       
   471 {\rail@nontfont \rail@expand{#1}}\ifx\@empty#2\else\ {\rail@annofont #2}\fi
       
   472 }
   477 \rail@frame
   473 \rail@frame
   478 }
   474 }
   479 
   475 
   480 \def\rail@cnont#1{
   476 \def\rail@cnont#1[#2]{
   481 \rail@setbox{\rail@nontfont #1}
   477 \rail@setbox{%
       
   478 {\rail@nontfont \rail@expand{#1}}\ifx\@empty#2\else\ {\rail@annofont #2}\fi
       
   479 }
   482 \rail@cframe
   480 \rail@cframe
   483 }
   481 }
   484 
   482 
   485 \def\rail@term#1{
   483 \def\rail@term#1[#2]{
   486 \rail@setbox{\rail@termfont #1}
   484 \rail@setbox{%
       
   485 {\rail@termfont #1}\ifx\@empty#2\else\ {\rail@annofont #2}\fi
       
   486 }
   487 \rail@oval
   487 \rail@oval
   488 }
   488 }
   489 
   489 
   490 \def\rail@cterm#1{
   490 \def\rail@cterm#1[#2]{
   491 \rail@setbox{\rail@termfont #1}
   491 \rail@setbox{%
       
   492 {\rail@termfont #1}\ifx\@empty#2\else\ {\rail@annofont #2}\fi
       
   493 }
   492 \rail@coval
   494 \rail@coval
   493 }
   495 }
   494 
   496 
   495 \def\rail@annote[#1]{
   497 \def\rail@annote[#1]{
   496 \rail@setbox{\rail@annofont #1}
   498 \rail@setbox{\rail@annofont #1}
   497 \rail@text
   499 \rail@text
   498 }
       
   499 
       
   500 \def\rail@annotebox[#1]{
       
   501 \ \rail@annofont #1
       
   502 }
   500 }
   503 
   501 
   504 % \rail@box : temporary box for \rail@oval and \rail@frame
   502 % \rail@box : temporary box for \rail@oval and \rail@frame
   505 %
   503 %
   506 % \rail@setbox{TEXT} : set \rail@box to TEXT, set \rail@tmpa to width
   504 % \rail@setbox{TEXT} : set \rail@box to TEXT, set \rail@tmpa to width