# How to type a Backus-Naur form in LaTeX [duplicate]

I need to type Backus-Naur form in LaTeX document. I found several packages on CTAN:

• ebnf seems to not work with TeXLive 2009
• latex-bnf does not align the declaration, etc.
• There is a module for ConTeXt, context-bnf

Is there a package for modern LaTeX, or should I just use hand-formatting via verbatim?

• Not `verbatim`, for goodness sake. If everything else fails, use an `itemize` or something like that. I hope someone comes up with a better solution. Oct 23, 2010 at 14:27
• Please note that I mentioned `verbatim` as last resort. Probably `tabular` would be closer to what I have in mind but neither of those solution is IMHO LaTeX-like (i.e. type the document and let computer to figure out how to format it). Oct 23, 2010 at 14:35
• – knut
Aug 30, 2012 at 20:19
• I have found the `syntax` package very easy to use, thanks to this detailed answer. May 3, 2014 at 17:13
• The simplebnf package (github.com/Zeta611/simplebnf) is straightforward to use. Disclaimer: I'm the author of the package. May 12 at 7:09

I stumbled across the `syntax-mdw` package the other day. It looks like it might typeset BNFs and syntax diagrams nicely. See the documentation (PDF) to get an idea of its capabilities.
• If the package's underscore hack causes problems then try `\usepackage[nounderscore]{syntax}`. May 28, 2012 at 14:39
• I needed to use `[nounderscore]` otherwise I got the error `! Missing \endcsname inserted.`
Try the `bnf.tex` at http://dante.ctan.org/tex-archive/macros/plain/contrib/bnf/ . It is simple enough that can form the basis of what you are looking and expand as you wish.