我想创建一个问题集合,每个问题由问题本身、可选提示和可选解决方案组成。我想知道最好的方法是什么?
我可以使用一些帮助来定义一个界面,让我把问题放在一个地方,并分别在不同部分(或章节)打印相应的提示和解决方案。
有人暗示我,这个方案exsheets
可能已经解决了一半的问题。
\documentclass{report}
\usepackage[english]{babel}
\usepackage{mathtools}
\usepackage{blindtext}
\numberwithin{equation}{section}
\numberwithin{figure}{section}
\numberwithin{table}{section}
\newcounter{problem}
\newenvironment{problem}[1]{
{\bfseries\large{#1}\par}
}{}
\begin{document}
\part{Problems}
\section{Puzzle 1}
\begin{problem}{Pythagoras}
\blindtext
%\begin{hints}
% \blindtext
%\end{hints}
%\begin{solution}
% \blindtext
%\end{solution}
\end{problem}
\section{Puzzle 2}
\part{Hints}
\section{Puzzle 1 hint}
\section{Puzzle 2 hint}
\part{Solutions}
\section{Puzzle 1 solution}
\section{Puzzle 2 solution}
\end{document}
我也在LaTeX 社区。
答案1
就像你在问题中说的那样:这是可行的exsheets
:
\documentclass{article}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{exsheets}
\SetupExSheets{ headings = block-subtitle }
% new property `hint':
\DeclareQuestionProperty{hint}
% a command to print all given hints
\NewDocumentCommand\printquestionhints{}{%
\ForEachQuestion
{%
\IfQuestionPropertyT{hint}{##1}{%
\ExSheetsHeading
{block} % headings style
{Hint} % heading
{\QuestionNumber{##1}}% number
{0} % points -- need to be zero here
{0} % bonus points -- need to be zero here
{##1}% % ID
\GetQuestionProperty{hint}{##1}%
\par
\medskip
}%
}%
}
\begin{document}
\section{Problems}
\begin{question}[subtitle=Pythagoras]
This is the first problem.
\SetQuestionProperties{ hint = This is a hint to the first problem. }
\end{question}
\begin{solution}
This is the solution to the first problem.
\end{solution}
\begin{question}[subtitle=Another Problem]
This is the second problem.
\end{question}
\begin{solution}
This is the solution to the second problem.
\end{solution}
\begin{question}[subtitle=Yet Another Problem]
This is the third problem.
\SetQuestionProperties{ hint = This is a hint to the third problem. }
\end{question}
\begin{solution}
This is the solution to the third problem.
\end{solution}
\section{Hints}
\printquestionhints
\section{Solutions}
\printsolutions
\end{document}
可以进行定制(标题的字体形状/大小,...)
答案2
将提示和解决方案存储在储物箱中。
\documentclass{article}
\usepackage[english]{babel}
\usepackage{mathtools}
\usepackage{environ}
\numberwithin{equation}{section}
\numberwithin{figure}{section}
\numberwithin{table}{section}
\newcounter{problem}
\newenvironment{problem}[1]
{\refstepcounter{problem}%
{\textbf{Problem \theproblem\ (#1)}\par}\nopagebreak\noindent\ignorespaces}
{}
\makeatletter
\newtoks\late@hintstoks
\newtoks\late@solutiontoks
\NewEnviron{hints}{%
\toks@=\expandafter{\BODY}%
\protected@edef\@tempa{%
\the\late@hintstoks % the previous contents
\noexpand\late@hint{\theproblem}{\the\toks@}%
}%
\global\late@hintstoks=\expandafter{\@tempa}%
}
\NewEnviron{solution}{%
\toks@=\expandafter{\BODY}%
\protected@edef\@tempa{%
\the\late@solutiontoks % the previous contents
\noexpand\late@solution{\theproblem}{\the\toks@}%
}%
\global\late@solutiontoks=\expandafter{\@tempa}%
}
\newcommand{\late@hint}[2]{%
\paragraph*{Hints for problem #1}#2%
}
\newcommand{\late@solution}[2]{%
\subsubsection*{Solution for problem #1}#2%
}
\newcommand{\printhints}{%
\part{Hints}
\the\late@hintstoks
}
\newcommand{\printsolutions}{%
\part{Solutions}
\the\late@solutiontoks
}
\makeatother
\begin{document}
\part{Problems}
\section{Puzzle 1}
\begin{problem}{Pythagoras}
This problem is about Pythagoras' theorem
\begin{hints}
These are the hints about Pythagoras.
\end{hints}
\begin{solution}
Pythagoras' theorem is easy!
\end{solution}
\end{problem}
\section{Puzzle 2}
\begin{problem}{Riemann}
Prove the zeros of the $\zeta$ functions are on the critical line.
\begin{hints}
Try first with a few cases.
\end{hints}
\begin{solution}
Oh, well!
\end{solution}
\end{problem}
\printhints
\printsolutions
\end{document}
答案3
tcolorbox
并非专门用于创建问题+解决方案集合,但可以用于此。
下一个代码几乎是从文档中复制而来。它展示了使用和记录工具的tcolorbox
示例: ,,,。savelowerto
record
\tcbstartrecording
\tcbstoprecording
\tcbinputrecords
savelowerto
保存lower
框部分以供进一步处理。在这种情况下,所有解决方案都分lower
部分声明,这些部分将被记录下来,然后使用 读取\tcbinputrecords
。
\documentclass{article}
\usepackage{lipsum}
\usepackage[most]{tcolorbox}
\NewTColorBox[auto counter,number within=section]{exercise}{+O{}}{ %
enhanced,colframe=green!20!black,colback=yellow!10!white,coltitle=green!40!black,
fonttitle=\bfseries,
underlay={\begin{tcbclipinterior}
\shade[inner color=green!80!yellow,outer color=yellow!10!white]
(interior.north west) circle (2cm);
\draw[help lines,step=5mm,yellow!80!black,shift={(interior.north west)}]
(interior.south west) grid (interior.north east);
\end{tcbclipinterior}},
title={Exercise~\thetcbcounter:},
label={exercise@\thetcbcounter},
attach title to upper=\quad,
after upper={\par\hfill\textcolor{green!40!black} %
{\itshape Solution on page~\pageref{solution@\thetcbcounter}}},
lowerbox=ignored,
savelowerto=solutions/exercise-\thetcbcounter.tex,
record={\string\solution{\thetcbcounter}{solutions/exercise-\thetcbcounter.tex}},
#1
}
\NewTotalTColorBox{\solution}{mm}{ %
enhanced,colframe=red!20!black,colback=yellow!10!white,coltitle=red!40!black,
fonttitle=\bfseries,
underlay={\begin{tcbclipinterior}
\shade[inner color=red!50!yellow,outer color=yellow!10!white]
(interior.north west) circle (2cm);
\draw[help lines,step=5mm,yellow!80!black,shift={(interior.north west)}]
(interior.south west) grid (interior.north east);
\end{tcbclipinterior}},
title={Solution of Exercise~\ref{exercise@#1} on page~\pageref{exercise@#1}:},
phantomlabel={solution@#1},
attach title to upper=\par,
}{\input{#2}}
\tcbset{no solution/.style={no recording,after upper=}}
\begin{document}
\section{Some problems}
\tcbstartrecording
\lipsum[1]
\begin{exercise}
Compute the derivative of the following function:
\begin{equation*}
f(x)=\sin((\sin x)^2)
\end{equation*}
\tcblower
The derivative is:
\begin{align*}
f’(x) &= \left( \sin((\sin x)^2) \right)’
=\cos((\sin x)^2) 2\sin x \cos x.
\end{align*}
100\end{exercise}
\lipsum[2]
\begin{exercise}[no solution]
It holds:
\begin{equation*}
\frac{d}{dx}\left(\ln|x|\right) = \frac{1}{x}.
\end{equation*}
\end{exercise}
\lipsum[3]
\begin{exercise}
Compute the derivative of the following function:
\begin{equation*}
f(x)=(\sin(\sin x))^2
\end{equation*}
\tcblower
The derivative is:
\begin{align*}
f’(x) &= \left( (\sin(\sin x))^2 \right)’
=2\sin(\sin x)\cos(\sin x)\cos x.
\end{align*}
\end{exercise}
\tcbstoprecording
\section{Some solutions to previous problems}
\tcbinputrecords
\end{document}