I am trying to typeset the grammars needed to describe the applied pi calculus. The outcome should look somewhat similar to the following attached example, especially concerning the alignment of the right hand side text.

the grammar of plain processes

To me, this does not seem to be solvable straightforward with the syntax package. Though i am fairly convinced this is the package to go with, i have no idea on how to typeset such a layout despite reading the documentation. The grammar-environement seems to be rather restrictive. Any ideas are thus highly appreciated.

  • Would there be a problem using a simple tabular? Commented Nov 11, 2015 at 11:43
  • I am not quite sure how i would be able to fit this into one tabular-enivoronement as of the indentation of the second line and following.
    – foobar
    Commented Nov 11, 2015 at 11:47
  • This question is strongly related to that one on BNF grammar, but egreg's solution is much more simpler (at last to me) than what was proposed earlier.
    – Clément
    Commented Nov 11, 2015 at 15:13
  • 1
    I would argue it is related, however not useful to the specific problem. There are - at least by skimming through the package's documentation - tight restrictions as to how a grammar looks that is typeset using the syntax package. The solution offered in the question you referenced does not address this issue and thus looks just like a grammar i had typeset before. Thus, i am glad egreg posted such a wonderful answer.
    – foobar
    Commented Nov 11, 2015 at 16:21
  • Let me rephrase my comment as "I'd like the expression BNF to appear in that post". When I tried to display BNF grammar nicely with latex, I encountered the same difficulties as you, and felt the packages mentioned in that topic were not very helpful.
    – Clément
    Commented Nov 11, 2015 at 16:34

1 Answer 1


This seems to replicate your example:




\begin{grammar}{P,Q,R\Coloneqq}{processes (or plain processes)}
\mathbf{0}                        & null process \\
P\mid Q                           & parallel composition \\
!P                                & replication \\
\nu n.P                           & name restriction (``new'') \\
\text{if $M=N$ then $P$ else $Q$} & conditional \\
u(x).P                            & message input \\
\bar{u}(N).P                      & message output


enter image description here

  • Thank you very much. Any easy way to get this centered and to add a little more space to top and bottom?
    – foobar
    Commented Nov 11, 2015 at 12:13
  • 1
    @foobar Just place the environment between \[ and \].
    – egreg
    Commented Nov 11, 2015 at 12:53
  • How would you extend this to multiple grammars? So that the text between grammars lines up.
    – user833970
    Commented Jan 21, 2022 at 21:01
  • @user833970 I wouldn't align different rules in different places.
    – egreg
    Commented Jan 21, 2022 at 21:18
  • I don't mean globally. But I might define mutual grammars in the same figure and then it looks strange when the explanation text is unaligned. (sorry if this is a dumb question, right now I'm just doing something dirty with tables)
    – user833970
    Commented Jan 21, 2022 at 21:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .