Hi all!
I would like to define an environment "bnfgrammar" to typeset
grammars in BNF format. What I thought is that you could type
\startbnfgrammar
t \BNFis x\in X \BNFcomment{(variable)}
\BNFor f(t_1,\dots,t_n) \BNFcomment{(function term)}
\stopbnfgrammar
and get a properly formatted grammar:
t ::= x\in X (variable)
| f(t_1,\dots,t_n) (function term)
My first try was to use a self-defined tabulate environment:
\definetabulate
[bnfgrammar]
[|lm|cm|lm|]
\setuptabulate
[bnfgrammar]
[inner=\@bnfgrammarsetup]
\def\@bnfgrammarsetup{%
\def\BNFdf{\NC}
\def\BNFis{\NC \mathrel{:=} \NC}
\def\BNFor{\NC \NR \NC \NC \mathrel{|} \NC}}
This got me quite far, as I can now type:
\startbnfgrammar
\BNFdf t
\BNFis x\in X
\BNFor f(t_1,\dots,t_n)
\stopbnfgrammar
However, the following problems remain:
1. Pagebreaks should not be allowed in the grammar. (Is there an
equivalent to the samepage environment for LaTeX?)
2. I would like to get rid of the \BNFdf command. Unfortunately,
I was not able to write something like
\def\startbnfgrammar{%
\start@bnfgrammar \NC}
with @bnfgrammar being bnfgrammar from above. I guess this has
to do with that the tabulation scans in everything until the
next \stoptabulate command and gets confused.
3. How should I implement the \BNFcomment command? I want the
comment to be placed in a \hbox of a given width, which then
should be aligned on the right text margin. Normally, I would
just use \hfill to flush that box to the right, but this does
not work with tabulate, as all the widths are calculated on
demand.
Does anyone has a neat solution to this problem? Is there
something better than tabulate for this purpose?
Cheers,
Marco
--
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net