Good day,
I'm trying to check for the solution environment and close it if it's open.
I have tried this answer and checking directly for the @insolution toggle that is set by solution environment when exam document class is used, but both return false.
I'm pretty sure that I'm making some very stupid mistake, but can not find it.
Here's a minimal working example:
\documentclass{exam}
\printanswerstrue
\begin{document}
\begin{questions}
\question
\emph{TEST QUESTION}
\end{questions}
\begin{solution}
% Use @currenvir to check if we are in the solution environment
\ifx\@currenvir\@solution
currenvir is solution
\else
currenvir is not solution
\fi
% Use @insolutiontrue to check if we are in the solution environment
\if@insolution
in solution is TRUE
\else
in solution is FALSE
\fi
\emph{TEST SOLUTION}
\end{solution}
\end{document}
And here is what it produces:
As one can see, both checks return FALSE, while they should instead return TRUE.
What am I doing wrong here?


\makeatletterbefore trying to use commands with@in their name (see: https://tex.stackexchange.com/q/8351/134574). – Phelype Oleinik Feb 06 '20 at 14:44\makeatotherwhen you're finished making changes (ideally)! – rbrignall Feb 06 '20 at 15:11\makeatletteras I copied them with some of the code. – Eichhorn Feb 06 '20 at 19:54