topnush
Here is my MWE:
```
\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\setbeamersize{text margin left=10mm,text margin right=5mm}
\setbeamertemplate{frametitle}[default][center]
\usepackage[many]{tcolorbox}
\usepackage{listings}
\usepackage{calc}
\begin{document}
\begin{frame}[fragile]{The tidemark algorithm}
\only<1>{
\begin{lstlisting}[ mathescape, name=tidemark, basewidth = {.3em}]
text
\end{lstlisting}
}
\end{frame}
\end{document}
```
This fails sadly. How can I get listings and \only to work together?
Top Answer
samcarter
The problem is that you can't have fragile stuff like code listings inside the argument of a macro. Luckily you can easily work around this by using an environment instead:
```
\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\setbeamersize{text margin left=10mm,text margin right=5mm}
\setbeamertemplate{frametitle}[default][center]
\usepackage[many]{tcolorbox}
\usepackage{listings}
\usepackage{calc}
\begin{document}
\begin{frame}[fragile]
\frametitle{The tidemark algorithm}
\begin{onlyenv}<1>
\begin{lstlisting}[ mathescape, name=tidemark, basewidth = {.3em}]
text
\end{lstlisting}
\end{onlyenv}
\only<2>{abc}
\end{frame}
\end{document}
```