2

I'd like to use Beamer overlays inside a grammar definition:

\documentclass{beamer}

\usepackage{syntax}

\begin{document}
\begin{frame}[fragile]{}
  \begin{grammar}
  <term>
    ::=  <term1>
  \only<2>{
    \alt <term2>
  }
  \end{grammar}
\end{frame}
\end{document}

but this results in

<term> ::= <term1> <2>
    | <term2>

(note how <2> is, seemingly, picked up by grammar instead of \only!)

I've also tried \visible<2> and \uncover<2> (both result in an error ! Argument of \beamer@fakeinvisible has an extra }.), and \begin{onlyenv}<2> (results in Runaway argument? {onlyenv> \end {grammar} ! File ended while scanning use of \end.).

Cactus
  • 1,107
  • http://tex.stackexchange.com/a/18217/36296 might help โ€“ samcarter_is_at_topanswers.xyz May 24 '16 at 13:19
  • @samcarter: if I understand it right, that answer all hinges on being able to redefine lstlisting's escape character to ยง. But that's "inside out"; here I imagine I'd need to redefine Beamer's <> characters so that they don't clash with grammar? โ€“ Cactus May 24 '16 at 13:33
  • 1
    My idea was to just cover up the parts you want to hide with a white tikz shape. I don't know how many of these overlays you intent to have, but if they are not too many, this could just be done by hand. โ€“ samcarter_is_at_topanswers.xyz May 24 '16 at 14:39

1 Answers1

3

I think what I would do is abandon the grammar environment. Aside from requiring fragile and consuming the <> syntax, it also redefines \alt. This is essentially death to overlays in Beamer. Everything uses \alt so the fact that this is redefined to output a vertical bar and a bit of space is fatal.

The grammar environment also looks rather odd in a Beamer slide as it doesn't seem to get placed correctly in terms of spacing. But perhaps that's just me.

Would something like this work?

\documentclass{beamer}
\usepackage{syntax}
\begin{document}
\begin{frame}
  \begin{tabular}{lcl}
    \synt{term} & ::= & \synt{term1}\\
    \onslide<2->
    & \textbar & \synt{term2}\\
  \end{tabular}
\end{frame}
\end{document}

syntax with overlay specification

cfr
  • 198,882