# Add command at the beginning of all frames

I need to add a command \setRTL from the bidi package to write right-to-left text, at the beginning of every frame.

Another answer does not solve the issue; any suggestions?

\documentclass{beamer}
\usefonttheme{serif}

\usepackage{etoolbox}  % no longer needed; loaded by Beamer from v3.36

\usepackage{bidi}

\AtBeginEnvironment{frame}{\setRTL}

\begin{document}
\begin{frame}{frame title}
hello world

\begin{enumerate}
\item first item
\item second item
\end{enumerate}
\end{frame}
\end{document}


You cannot directly hook into the begin of Beamer's frame environment with the usual etoolbox \AtBeginEnvironment, as hinted at elsewhere.

Replacing your \AtBeginEnvironment with \BeforeBeginEnvironment, is actually sufficient. That is:

\BeforeBeginEnvironment{frame}{\setRTL}


This may, however, have undesirable side-effects, since it hooks in prior to the environment's definition.

One alternative is the following (hooking into @checkframetitle), adapted from another similar answer, however it will not affect the slide's title:

\makeatletter
\pretocmd\beamer@checkframetitle{\setRTL}
\makeatother


Finally, you could instead hook into the earlier @framenotesbegin, which would affect the slide title (obtaining an equivalent result to the \BeforeBeginEnvironment approach):

\makeatletter
\pretocmd\beamer@framenotesbegin{\setRTL}
\makeatother