시험 수업: \printanswers에 의존하는 새로운 환경 정의

시험 수업: \printanswers에 의존하는 새로운 환경 정의

시험 클래스의 \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를 사용할 때 Notes 환경을 숨기고 싶습니다.

답변1

{comment}환경을 억제하는 한 가지 기술은 해당 환경을 축어 패키지에 정의된 환경 과 동일하게 만드는 것입니다 . 또 다른 방법은 명령 본문을 a에 넣고 시험 환경에서 사용하는 솔루션인 를 \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} 

관련 정보