Please see the following MWE.
\documentclass{exam}
\usepackage{etoolbox}
% The following does not have any effect on the output
\AtBeginEnvironment{questions}{\setcounter{question}{4}}
\begin{document}
\begin{questions}
% The following works fine
% \setcounter{question}{4}
\question What is the answer?
\end{questions}
\end{document}
When only the \AtBeginEnvironment
command is retained, the question number in the output does not change.
However, it works fine when the \setcounter{question}{4}
is explicitly used inside the environment.
As per the manual of etoolbox
, the first approach was supposed to work.
\AtBeginEnvironment{<environment>}{<code>}
Appends arbitrary<code>
to a hook executed by the\begin
command at the beginning of a given<environment>
, immediately before\<environment>
, inside the group opened by\begin
.
mmediately before \<environment>
, that is not the same as inside thequestions
env. It might be doable using the kernel env hooks (haven't checked)