Path: utzoo!attcan!uunet!decwrl!ucbvax!prg.oxford.ac.uk!Damian.Cugley From: Damian.Cugley@prg.oxford.ac.uk (Damian Cugley) Newsgroups: comp.text.tex Subject: Re: Styles for lispcode and grammars wanted... Message-ID: <9007111834.AA04668@msc3.prg.ox.ac.uk> Date: 11 Jul 90 18:34:23 GMT References: <3074@gmdzi.UUCP> Sender: daemon@ucbvax.BERKELEY.EDU Lines: 75 > From: krey@gmdzi.UUCP (Juergen Krey) > Message-ID: <3074@gmdzi.UUCP> > Moreover i'm looking for a macro-set to pretty-print formal grammars like > (Extended) Backus-Naur Form with LaTeX/TeX. > Thanks for any help/hints > HjK Here's one I threw together for my own use. It does EBNF, in LaTeX, in the style I like - catagory names italicized in angle brackets, and `::=' introducing productions. Example of use: ------------------------------------------------------------------------ Generally glue is quoted using this notation~\TBcite[\p271]: \begin{EBNF} \item[glue] \ [~`plus' \~] [~`minus' \~]. \item[stretch] \ | \. \item[fil dimen] \ (~`fil' | `fill' | `filll'~). \end{EBNF} A \ which is a \ ... ------------------------------------------------------------------------ This is "list" environment in the style of "description" etc (Sec. 5.7). Thus, productions start with \item[LHS] which produces ::= in the document. (This was so I can alter the ::= to something else if I really want to.) Each production is in LR (horizontal) mode. The whole thing is indented to \parindent, with turnover lines indented a further 2 em. `|' produces a vertical line. \ or \Cat{FOO} produces , with FOO italicized. You might prefer {\tt plus} instead of `plus' etc. Here's the code: ------------------------------------------------------------------------ % Damian Cugley Wed 11 Jul 1990 \begingroup \catcode`\|=13 \gdef\EBNF {\list{???}% {% \catcode`\|=13 \def|{$\mid$}% \def\makelabel##1{\<##1> ::=}% \parsep=0pt \itemsep=\smallskipamount \leftmargin=\parindent \advance\leftmargin+2em \labelsep=0.5em \labelwidth=1.5em \raggedright }% } \endgroup \let\endEBNF\endlist \def\Cat#1{\hbox{$\langle${\it #1\/}$\rangle$}} \def\<#1>{Cat{#1}} ------------------------------------------------------------------------ /--------------------------------------------------------------------\ | Damian Cugley, Programming Research Group, 11 Keble Rd, Oxford, UK | | Damian.Cugley@prg.oxford.ac.uk =or= ...@oxford.prg in UK | \--------------------------------------------------------------------/