![экзаменационный класс: определить новую среду, которая зависит от \printanswers](https://rvso.com/image/370296/%D1%8D%D0%BA%D0%B7%D0%B0%D0%BC%D0%B5%D0%BD%D0%B0%D1%86%D0%B8%D0%BE%D0%BD%D0%BD%D1%8B%D0%B9%20%D0%BA%D0%BB%D0%B0%D1%81%D1%81%3A%20%D0%BE%D0%BF%D1%80%D0%B5%D0%B4%D0%B5%D0%BB%D0%B8%D1%82%D1%8C%20%D0%BD%D0%BE%D0%B2%D1%83%D1%8E%20%D1%81%D1%80%D0%B5%D0%B4%D1%83%2C%20%D0%BA%D0%BE%D1%82%D0%BE%D1%80%D0%B0%D1%8F%20%D0%B7%D0%B0%D0%B2%D0%B8%D1%81%D0%B8%D1%82%20%D0%BE%D1%82%20%5Cprintanswers.png)
У меня возникли проблемы с определением новой среды, которая зависит от опции \printanswers экзаменационного класса.
\documentclass{exam}
\usepackage{framed}
\printanswers
%\noprintanswers
\newenvironment{note}{\ifprintanswers\begin{framed}\noindent\textbf{Note:}\par\noindent}{\end{framed}\fi}
\begin{document}
\begin{questions}
\question
question
\begin{solution}
this is the solution
\end{solution}
\begin{note}
this is a note
\end{note}
\end{questions}
\end{document}
Когда я использую \printanswers, все выглядит нормально, но когда я использую \noprintanswers, я получаю ошибку:
! Incomplete \iffalse; all text was ignored after line 17.
Я хочу, чтобы среда заметок была скрыта при использовании \noprintanswers.
решение1
Чтобы подавить среду, один из методов — сделать ее эквивалентной среде, {comment}
определенной пакетом verbatim. Другой — поместить тело команды в \vbox
и выбросить \vbox
, что является решением, используемым средой экзамена. Вот подход \vbox
:
\documentclass{exam}
\usepackage{framed}
\newenvironment{note}{%
\ifprintanswers
\begin{framed}\noindent\textbf{Note:}\par\noindent
\else
\setbox0\vbox\bgroup
\fi
}{%
\ifprintanswers
\end{framed}%
\else
\egroup
\fi%
}
\printanswers
%\noprintanswers
\begin{document}
\begin{questions}
\question
question
\begin{solution}
this is the solution
\end{solution}
\begin{note}
this is a note
\end{note}
\end{questions}
\end{document}