
answer
私が準備することになっているテストの質問の回答を表示する という環境を定義しました。
アイデアとしては、答えが表示されるバージョンと、答えが表示されていないバージョン(生徒をテストするため)をコンパイルすることです。
環境を無効にするエレガントな方法はありますか?
もちろん、コマンドを定義して\ifanswer
、\ifanswer{\begin{answer}foo\end{answer}}
各環境に対して と記述することもできます。ただし、この方法の問題点は、このコマンドを毎回覚えて挿入する必要があることです。もちろん、これを一度でも忘れると恥ずかしいことになります。
MWE:
\documentclass{article}
\newenvironment{answer}{\textit{Answer} }{\textit{the end.}}
\begin{document}
Question: Bla
\begin{answer}
Foo
\end{answer}
\end{document}
答え1
David が言ったように、次のパッケージを使用できますcomment
:
\documentclass{article}
\usepackage{comment}
\newenvironment{answer}{\textit{Answer} }{\textit{the end.}}
\includecomment{answer} %%% comment out to show the answer
\begin{document}
Question: Bla
\begin{answer}
Foo answer
\end{answer}
\end{document}
難しい方法でやりたいなら -
\documentclass{article}
\usepackage{environ}
\usepackage{ifthen}
\newboolean{answers}
\setboolean{answers}{true} %%% uncomment to show answers properly
%\setboolean{answers}{false} %%% comment to show answers properly
\ifthenelse{\boolean{answers}}%
{%
\NewEnviron{answer}
{%
\textit{Answer}
\BODY{}
\textit{the end.}
}%
}%
{\NewEnviron{answer}
{%
\textit{Answer}
\textit{the end.}
}%
}%
\begin{document}
Question: Bla
\begin{answer}
Foo answer
\end{answer}
\end{document}