使用答案包时将枚举练习与其答案进行匹配

使用答案包时将枚举练习与其答案进行匹配

我正在使用该answers软件包编写一些练习表。我编写的一些问题包含枚举列表(例如从部分 (a) 到 (h) 及以后)。我遇到的问题是每个枚举项所附带的答案的位置。当枚举列表很短时,我可以轻松地手动编写答案,如下所示:

\begin{sol} 
(a) Here (b) Next (c) The one after next
\end{sol}

但是,对于较长的枚举列表,我经常会回去添加新问题、删除其他问题或者只是更改它们的顺序,而且由于答案只是“手工编码”的,所以我现在必须回去尝试跟踪答案顺序的所有更改,这对于非常长的列表来说真的很痛苦。

有没有什么方法answers可以将使用该包的枚举列表中每个问题的答案在源头“绑定”在一起,但在打印时仍会出现在同一个练习下(比如练习 2)?

举个例子,在我的 MWE 中,是否可以不必像我从 (a) 到 (h) 那样手动编码答案,而是将每个答案与问题一起放在源头,并且仍然可以将一个练习中的所有答案打印在同一练习标题下(在我的情况下是练习 2)?

\documentclass{memoir}

\usepackage{amsmath}
\usepackage{enumitem}
\usepackage{xcolor}
\usepackage{ntheorem}
\theorembodyfont{\upshape}
\theoremseparator{.}

\usepackage{answers}
\Newassociation{sol}{Solution}{ans}
\renewcommand{\Solutionlabel}[1]{\small{#1.}}
\newtheorem{ex}{}[section]
\renewcommand{\theex}{\arabic{ex}}
\newenvironment{Ex}[1]{\begin{trivlist}\item \textsc{#1} %
\renewcommand{\Currentlabel}{#1}}{\end{trivlist}}

\usepackage{multicol}
\newenvironment{mtmulticols}[1]{%
\Writetofile{ans}{\string\begin{multicols}{#1}}
\begin{multicols}{#1}}{\end{multicols}%
\Writetofile{ans}{\string\end{multicols}}}

\begin{document}
\chapter{Polynomials}
\section{Partial fractions}
\label{sec:partial-fractions}

\Opensolutionfile{ans}[partial-fractions]
\section*{Exercises for Section \ref{sec:partial-fractions}}
\vspace{-0.6cm}
\hrulefill
\begin{Ex}{Warm-ups}
\end{Ex}
\begin{ex}
Who is the most famous mathematician of all time?
\begin{sol}
Euler
\end{sol}
\end{ex}
\begin{ex}
Resolve each of the following proper rational expressions (some filler
here) into partial fractions. 
\begin{mtmulticols}{3}
\begin{enumerate}[label=(\alph*)]
\item $\displaystyle{\frac{1}{(x - 1)(x - 2)}}$
\item $\displaystyle{\frac{5x + 4}{x^2 + x - 2}}$
\item $\displaystyle{\frac{7x - 1}{2x^2 - x - 1}}$
\item $\displaystyle{\frac{25}{18x^3 - 9x^2 - 11x + 2}}$
\item $\displaystyle{\frac{x^2 + 15x - 4}{(x + 1)(x + 2)(x - 8)}}$
\item $\displaystyle{\frac{48}{(x^2 - 1)(x^2 - 9)}}$
\item $\displaystyle{\frac{1}{x^3 + 10x^2 + 25x}}$
\item $\displaystyle{\frac{x}{(x + 4)^3}}$
\item $\displaystyle{\frac{11x + 18}{(x^2 - 4)(x + 3)}}$
\end{enumerate}
\end{mtmulticols}
\begin{sol}
(a) $\displaystyle{\frac{1}{x - 2} - \frac{1}{x - 1}}$ \quad 
(b) $\displaystyle{\frac{2}{x + 2} + \frac{3}{x - 1}}$ \quad 
(c) $\displaystyle{\frac{3}{2x + 1} + \frac{2}{x - 1}}$ \quad 
(d) $\displaystyle{\frac{3}{3x + 2} - \frac{12}{6x - 1} + \frac{1}{x -
      1}}$ \quad  
(e) $\displaystyle{\frac{2}{x - 8} + \frac{2}{x + 1} - \frac{3}{x +
      2}}$ \quad  
(f) $\displaystyle{\frac{3}{x - 1} + \frac{3}{x + 1} - \frac{1}{x + 3}
    + \frac{1}{x - 3}}$ \quad  
(g) $\displaystyle{\frac{1}{25(x + 5)} - \frac{1}{5(x + 5)^2} +
      \frac{1}{25 x}}$ \quad 
(h) $\displaystyle{\frac{2}{x - 2} + \frac{1}{x + 2} - \frac{3}{x +
      3}}$ 
\end{sol}
\end{ex}

\Closesolutionfile{ans}
\section*{Answers for Section \ref{sec:partial-fractions}}
\input{partial-fractions}

\end{document}

答案1

您应该尝试设计一个方案,让每个问题的答案与相应的问题保持一致。这里有一个建议,引入一个Solutionsublist' environment to contain the question and the list of“solitem”,其中包含每个问题的单独解决方案。

示例输出

\documentclass{memoir}

\usepackage{amsmath}
\usepackage[inline]{enumitem}
\usepackage{xcolor}
\usepackage{ntheorem}
\theorembodyfont{\upshape}
\theoremseparator{.}

\usepackage{answers}
\Newassociation{sol}{Solution}{ans}
\renewcommand{\Solutionlabel}[1]{\small{#1.}}
\newtheorem{ex}{}[section]
\renewcommand{\theex}{\arabic{ex}}
\newenvironment{Ex}[1]{\begin{trivlist}\item \textsc{#1} %
\renewcommand{\Currentlabel}{#1}}{\end{trivlist}}

\usepackage{multicol}
\newenvironment{mtmulticols}[1]{%
\Writetofile{ans}{\string\begin{multicols}{#1}}
\begin{multicols}{#1}}{\end{multicols}%
\Writetofile{ans}{\string\end{multicols}}}

\Newassociation{solitem}{Solutionsubitem}{ans}
\renewcommand{\Solutionsubitemlabel}[1]{#1}
\newenvironment{Solutionsublist}{\Writetofile{ans}{\string\begin{Solution}{\theex}}}{\Writetofile{ans}{\string\end{Solution}}}

\begin{document}
\chapter{Polynomials}
\section{Partial fractions}
\label{sec:partial-fractions}
\tracingmacros=1
\Opensolutionfile{ans}[partial-fractions]
\section*{Exercises for Section \ref{sec:partial-fractions}}
\vspace{-0.6cm}
\hrulefill
\begin{Ex}{Warm-ups}
\end{Ex}
\begin{ex}
Who is the most famous mathematician of all time?
\begin{sol}
Euler
\end{sol}
\end{ex}
\begin{ex}
Resolve each of the following proper rational expressions (some filler
here) into partial fractions.
\begin{multicols}{3}
\begin{Solutionsublist}
\begin{enumerate}[label=(\alph*)]
\item $\displaystyle{\frac{1}{(x - 1)(x - 2)}}$
  \begin{solitem}
    $\displaystyle{\frac{1}{x - 2} - \frac{1}{x - 1}}$
  \end{solitem}
\item $\displaystyle{\frac{5x + 4}{x^2 + x - 2}}$
  \begin{solitem}
    $\displaystyle{\frac{2}{x + 2} + \frac{3}{x - 1}}$
  \end{solitem}
\item $\displaystyle{\frac{7x - 1}{2x^2 - x - 1}}$
  \begin{solitem}
    $\displaystyle{\frac{3}{2x + 1} + \frac{2}{x - 1}}$
  \end{solitem}
\item $\displaystyle{\frac{25}{18x^3 - 9x^2 - 11x + 2}}$
  \begin{solitem}
    $\displaystyle{\frac{3}{3x + 2} - \frac{12}{6x - 1} + \frac{1}{x -
      1}}$
  \end{solitem}
\item $\displaystyle{\frac{x^2 + 15x - 4}{(x + 1)(x + 2)(x - 8)}}$
  \begin{solitem}
    $\displaystyle{\frac{2}{x - 8} + \frac{2}{x + 1} - \frac{3}{x +
      2}}$
  \end{solitem}
\item $\displaystyle{\frac{48}{(x^2 - 1)(x^2 - 9)}}$
  \begin{solitem}
    $\displaystyle{\frac{3}{x - 1} + \frac{3}{x + 1} - \frac{1}{x + 3}
    + \frac{1}{x - 3}}$
  \end{solitem}
\end{enumerate}
\end{Solutionsublist}
\end{multicols}
\end{ex}

\Closesolutionfile{ans}
\section*{Answers for Section \ref{sec:partial-fractions}}
\input{partial-fractions}

\end{document}

就像在原始代码中一样,您以多列格式编写解决方案,但随后您必须确保每个解决方案都比给定的列窄。相反,我只是让它们每行打印一次。

相关内容