我正在编写一本包含章节和小节的教科书,其中一些小节专门用于练习。
\documentclass[12pt]{book}
\begin{document}
\section{First!}
\subsection{Some theorems}
Theorem I guess...
\subsection{Exercises}
\begin{enumerate}
\item How much is 1+1?
\item How much is 2+3?
\end{enumerate}
\section{Second!}
\subsection{Let's define something}
A natural number is a number different from a fraction.
\subsection{More theorems}
I like fractions.
\subsection{Exercises}
\begin{enumerate}
\item Is $\pi$ a natural number?
\item Do you like natural numbers?
\end{enumerate}
\end{document}
我想在代码中添加解决方案,并将它们收集到解决方案文件中。我知道像answers
和这样的软件包exsheets
可以做得很好,但我想保留问题的布局,同时拥有一个带有自动编号的大型解决方案文件(其中可以清楚地看到哪个答案与哪个问题相对应)。
最好是类似
请记住每个小节的练习数量可能超过 10,所以我想将我的解决方案(以代码形式)保持在靠近问题的位置。
答案1
我一直在修改一些设置和answers
包,并决定采用以下解决方案:
\documentclass[12pt]{article}
\usepackage{answers}
\Newassociation{opdr}{Opdrachten}{ans}
\Newassociation{opl}{Oplossing}{ans}
\renewenvironment{Opdrachten}[1]{\begin{trivlist}\item \bfseries \large #1}{\end{trivlist}}
\renewenvironment{Oplossing}[1]{\begin{enumerate}\item[\bfseries #1.]}{\end{enumerate}}
\begin{document}
\Opensolutionfile{ans}[ans]
\section{First!}
\subsection{Some theorems}
Theorem I guess...
\subsection{Opdrachten}\label{Opdr_First1}
\begin{opdr}p.\pageref{Opdr_First1}\end{opdr}
\begin{enumerate}
\item How much is 1+1?
\begin{opl}
2
\end{opl}
\item How much is 2+3?
\begin{opl}
5
\end{opl}
\end{enumerate}
\section{Second!}
\subsection{Let's define something}
A natural number is a number different from a fraction.
\subsection{More theorems}
I like fractions.
\subsection{Opdrachten}\label{Opdr_Second1}
\begin{opdr}p.\pageref{Opdr_Second1}\end{opdr}
\begin{enumerate}
\item Is $\pi$ a natural number?
\begin{opl}
Yes.
\end{opl}
\item Do you like natural numbers?
\begin{opl}
No.
\end{opl}
\item This question doesn't have an answer.
\item This question does.
\begin{opl}
Yeah.
\end{opl}
\end{enumerate}
\Closesolutionfile{ans}
\newpage
\section*{Oplossingen}
\input{ans}
\end{document}
我喜欢这种布局,而且我还可以添加页码。