4

This recent question tickled my curiosity on etoolbox (that looks great but that I have actually never used).

After a quick check, I don't read any notorious incompatibility between etoolbox and beamer.

Where am I wrong when I try this ? Must be silly...

%\documentclass{memoir}
%\documentclass{article}
\documentclass{beamer}

\usepackage{etoolbox} \usepackage{tikz}

% This works fine %\BeforeBeginEnvironment{tikzpicture}{\begin{center}} %\AfterEndEnvironment{tikzpicture}{\end{center}}

% It generates an error %\BeforeBeginEnvironment{tikzpicture}{\begin{frame}} \BeforeBeginEnvironment{tikzpicture}{ \begin{frame} \frametitle{My TikZ} } \AfterEndEnvironment{tikzpicture}{ \end{frame} }

\begin{document} \begin{tikzpicture} \node[circle,draw=red] {Test}; \end{tikzpicture} \end{document}

David Carlisle
  • 757,742
JeT
  • 3,020
  • 3
    beamer frames are grabbed as a whole so the code needs to see \end{frame} explicitly in the document – David Carlisle Dec 08 '21 at 20:34
  • @DavidCarlisle mmm... thanks boss :) So probably no by-pass to that I presume. – JeT Dec 08 '21 at 20:36
  • 1
    @JeT Try changing your definition to \BeforeBeginEnvironment{tikzpicture}{\begin{frame}[environment=tikzpicture]\frametitle{My TikZ}} (though I'm not sure it's a good idea to make all tikzpictures do a frame...) – Phelype Oleinik Dec 08 '21 at 21:26
  • @PhelypeOleinik obrigado. You're right, bad idea but the example was simple enough as an exercise to try to understand this package. – JeT Dec 08 '21 at 21:39
  • @PhelypeOleinik is it just me or I know get an error Incomplete \ifx ? – JeT Dec 08 '21 at 22:22
  • @JeT As I said, not sure if it's a good idea :) the environment option works when you do \newenvironment{myenv}{\begin{frame}[environment=myenv]}. It doesn't work when you use environment hooks (and I think it's not possible to make it work). – Phelype Oleinik Dec 08 '21 at 23:53

1 Answers1

1

beamer frames are grabbed as a whole so the code needs to see \end{frame} explicitly in the document otherwise it will parse ahead past the end of the frame looking for \end{frame}.

David Carlisle
  • 757,742