I'm working with formal grammar in LaTeX and would like to write some of the shorter rules in the same row in order to save space. The rules are aligned using the array
environment and I'd like to define some kind of optional columns to align the rules in the rows with multiple ones correctly.
Example mwe.tex:
\documentclass{article}
\begin{document}
\[\begin{array}{rl}
S \rightarrow& aaaaaABbbbbb | aaaaABbbbb | aaaABbbb | aaABbb | aABb | ab\\
A \rightarrow& aaCbb | aDb | ab, B \rightarrow aaEbb | aFb | ab\\
C \rightarrow& c, D \rightarrow d, E \rightarrow e, F \rightarrow f\\
\end{array}\]
\end{document}
The MWE currently produces this result:
The result I desire would be similar to the following:
I've found this relevant question, but it appears to be a rather ugly hack and also hard to auto-apply, as the actual work document uses a lot more rules than this MWE.
I also tried nesting the arrays, but compiling the file with three indented, nested arrays produced a damaged PDF that I'm both unable to view or delete