I want to add an EBNF grammar to my document and following the answers here and here, it seems that the most popular package for this is syntax.
However, in the documentation it is not clear how to support constructs such as optional items enclosed in square brackets on multiple lines. I tried to use both [ and \[ directly but both do not work inside the \begin{grammar} block. Inserting [ after a \\ outputs an error, while \[ puts the line centered and adds a lot of vertical space before and after it.
Is there a proper way to include optional items in EBNF using syntax?
I would also like to change the font to use typewriter font throughout, and not have this continuous changing of typewriter and normal font. Not sure what is the right way to achieve this. The syntax documentation is a bit confusing in this regard.
I've included a minimal example below where I have the first rule including the [ which works, but it is on the same line, the second rule including a line break, which works, but does not start with [, while the third one which includes both, and reports a strange error Missing number, treated as zero.
\documentclass[]{article}
\usepackage{times}
\usepackage{syntax}
\begin{document}
\begin{grammar}
<a> ::= "a" [<b>]
<b> ::= "b" \\ <c>
%this does not work
<c> ::= "c" \\ [<d>]
\end{grammar}
\end{document}
I would like to know what is the right way to put the optional parameter on the new line with the [ and how to change the font of BNF grammars to typewriter font throughout. (Not the rest of the document of course).


