包裹答案中有错误吗?

包裹答案中有错误吗?

我有这个来自答案包的示例的轻微变化

\documentclass[12pt,a4paper]{article}
\usepackage{ifthen}
\usepackage{answers}
\Newassociation{sol}{Solution}{ans}
\newboolean{InSol}\setboolean{InSol}{False}
\newenvironment{Sol}
% Need to know whether we are in a solution or not
% So we set a defined boolean to test this
{\setboolean{InSol}{True}\begin{sol}}
%
{\end{sol}\setboolean{InSol}{False}}

\begin{document}
\Opensolutionfile{ans}[ans1]

First exercise

\begin{Sol}
  First solution.
\end{Sol}

Second exercise

\begin{Sol}
  Second solution.
\end{Sol}
 \Closesolutionfile{ans}
 \section{Solutions}
 \input{ans1}
 \end{document}

它生成以下应答文件

\begin{Solution}{}

First solution.

\end{Sol}

Second exercise

\begin{Sol}

Second solution.

\end{Sol}
 \Closesolutionfile{ans}
 \section{Solutions}
 \input{ans1}
 \end{document}

这是一个错误还是我做了一些愚蠢的事情?

答案1

您不应该在环境定义中使用\begin{sol}和,而应该使用和。无需将条件重置为 false,因为环境提供的分组会执行此操作。\end{sol}\sol\endsol

\documentclass[12pt,a4paper]{article}
\usepackage{ifthen}
\usepackage{answers}

\Newassociation{sol}{Solution}{ans}

\newboolean{InSol}\setboolean{InSol}{false}
\newenvironment{Sol}
% Need to know whether we are in a solution or not
% So we set a defined boolean to test this
  {\setboolean{InSol}{true}\sol}
  {\endsol}

\begin{document}
\Opensolutionfile{ans}[\jobname ans]

First exercise

\begin{Sol}
  First solution.
\end{Sol}

Second exercise

\begin{Sol}
  Second solution.
\end{Sol}
 \Closesolutionfile{ans}
 \section{Solutions}
 \input{\jobname ans}
 \end{document}

答案文件的内容

\begin{Solution}{}
  First solution.
\end{Solution}
\begin{Solution}{}
  Second solution.
\end{Solution}

相关内容