![问题与解决方案书](https://linux22.com/image/455319/%E9%97%AE%E9%A2%98%E4%B8%8E%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88%E4%B9%A6.png)
我正在写一本包含问题和解决方案的书。我正在尝试找到获得 pdf 输出的最佳方法,如下所示
第一章 问题集
- 问题:等等等等....
- 问题:等等....
- 问题:等等等等......
第二章:解决方案
- 问题 1 的解决方案
- 问题 2 的解决方案
- 问题 3 的解决方案......
但我想避免手动引用并希望我的代码按照以下方式
\begin{enumerate}
\item Problem 1
\item Solution to problem 1
\item Problem 1
\item Solution to problem 1
\end{enumerate}
是否可以?
答案1
这和你想要的一样吗?
\documentclass{article}
\usepackage{xsim}
\usepackage{blindtext}
\xsimsetup{collect}
\begin{document}
\section*{Set of problems}
\begin{exercise}[ID=A]
$1+1=$
\end{exercise}
\begin{solution}
$2$
\end{solution}
\begin{exercise}[ID=B]
$10\div2=$
\end{exercise}
\begin{solution}
5
\end{solution}
\begin{exercise}[ID=C]
Who has a red nosed reindeer?
\end{exercise}
\begin{solution}
santa
\end{solution}
\section*{Exercises}
\printrandomexercises[collection=all exercises,exclude=D]{3}
\newpage
\printsolutions
\end{document}
您必须运行代码两次才能使练习和解决方案出现在单独的页面上。
答案2
这是数学书吗?如果是的话,也许下面的内容更合适。
\documentclass[a4paper]{book}
\usepackage[margin=0.75in]{geometry}
\usepackage{xsim}
\usepackage[english]{babel}
\usepackage{blindtext}
\DeclareExerciseEnvironmentTemplate{number-only}{%
\par\noindent
\textbf{\GetExerciseProperty{counter}}%
\GetExercisePropertyT{subtitle}{ \textit{#1}} %
}{\par}
\newcommand\printsectionexercises{%
\ForEachUsedExerciseByType{%
\ifnum\ExercisePropertyGet{##1}{##2}{chapter- value}=\value{chapter}
\noindent\ExercisePropertyGet{##1}{##2}{instruction}\par
\XSIMprint{exercise}{##1}{##2}%
\fi
}%
}
\renewcommand\printsolutions{%
\def\currentchapter{}%
\def\lastchapter{}%
\ForEachUsedExerciseByType{%
\let\lastchapter\currentchapter
\edef\currentchapter{\ExercisePropertyGet{##1}{##2}{chapter- value}}%
\ifx\lastchapter\currentchapter\else
\section*{Chapter \ExercisePropertyGet{##1}{##2}{chapter}}
\fi
\XSIMprint{solution}{##1}{##2}%
}%
}
\DeclareExerciseProperty{instruction}
\newcommand\ExerciseRef[1]{%
\expanded{%
\noexpand
\ExercisePropertyGet{exercise}{\GetExerciseIdForProperty{ID}{#1}}. {counter-value}%
}%
}
\newcommand\This{\GetExerciseProperty{counter-value}}
\xsimsetup{
exercise/template = number-only ,
solution/template = number-only ,
exercise/within = section ,
exercise/the-counter = \arabic{exercise}. ,
exercise/print = false
}
\begin{document}
\chapter{ChapterOne}
\section{Solving for an unknown}
\blindtext
\begin{exercise}[instruction={In Exercises \This-- \ExerciseRef{last:x}, solve for \(x\).}]
\(x - 1 = 0\)
\end{exercise}
\begin{solution}
\(x = 1\)
\end{solution}
\begin{exercise}
\(3x - 12 = 0\)
\end{exercise}
\begin{solution}
\(x = 4\)
\end{solution}
\begin{exercise}[ID=last:x]
\(x^2 - 3x + 2 = 0\)
\end{exercise}
\begin{solution}
\(x = 1, 2\)
\end{solution}
\begin{exercise}[instruction={In Exercises \This-- \ExerciseRef{last:y}, solve for \(y\).}]
\(y^3 - 6 y^2 + 11 y - 6 = 0\)
\end{exercise}
\begin{solution}
\(y = 1, 2, 3\)
\end{solution}
\begin{exercise}[ID=last:y]
\(y^4 - 10 y^3 + 35 y^2 - 50 y + 24 = 0\)
\end{exercise}
\begin{solution}
\(y = 1, 2, 3, 4\)
\end{solution}
\subsection*{Exercises}
\printsectionexercises
\newpage
\chapter*{Solutions to the exercises}
\printsolutions
\end{document}
这就是你想要的东西吗?