我正在为我的学生写一本物理学习指南。为了解决例子,我创建了一个新环境,它最多可以包含三个部分:问题、答案和之后要思考的内容。这些部分应该用一条细线隔开。
我需要一些帮助来调整它以符合我的喜好。我想修复的问题:
- 我可能只是想想,在这种情况下我不想要这个规则。
- 为了避免我自己的失误,示例环境必须包含一个问题和一个答案(以及可选的想法),或者只有一个想法。我不想只使用一个问题或答案的示例。
当然,我欢迎更好的方法来实现我的目标。
我的工作示例是
\documentclass{tufte-book}
\usepackage{amsmath}
\usepackage{siunitx}
\usepackage{framed}
\colorlet{shadecolor}{orange!8}
\newenvironment{example}{
\newcommand{\sep}{\hfill\rule[0.25em]{0.5\linewidth}{.7pt}\hfill\null\newline}
\newcommand{\question}{{\bfseries Question: }}
\newcommand{\answer}{\sep{\bfseries Answer: }}
\newcommand{\think}{\sep{\bfseries Think about: }}
\begin{shaded}\begin{quote}
}{\end{quote}\end{shaded}}
\begin{document}
I don't want the rule below if there's only a think about:
\begin{example}
\think Blah, blah, blah.
\end{example}
Where's the answer? I don't want questions without answers.
\begin{example}
\question When it first starts raining, will it be large or small
raindrops that hit the ground first?
\end{example}
What was the question?
\begin{example}
\answer Raindrops vary in size from 0.5~\si{mm} in diameter to
4~\si{mm}. Larger raindrops will split into smaller drops.
Blah, blah, blah.
\end{example}
My ideal for examples with question/answer/think parts:
\begin{example}
\question When it first starts raining, will it be large or small
raindrops that hit the ground first?
\answer Raindrops vary in size from 0.5~\si{mm} in diameter to
4~\si{mm}. Larger raindrops will split into smaller drops.
Raindrops reach terminal velocity $v_T$ almost immediately after
they start falling. This means that the drag force (pointing up)
becomes equal but opposite to the raindrop weight (pointing
down). Finding the terminal velocity will determine what sized
raindrops hit the ground first when the rain storm begins.
Blah, blah, blah ...
\think Give a physics explanation for why falling hailstones are
more dangerous than falling raindrops.
\end{example}
\end{document}
答案1
我不是程序员,但是这个可以满足你的需要
\documentclass{book}
\usepackage{amsmath}
\usepackage{siunitx}
\usepackage{framed,tikz}
\colorlet{shadecolor}{orange!8}
\newif\ifque\quefalse
\newif\ifans\ansfalse
\newcommand{\sep}{\hfill\rule[0.25em]{0.5\linewidth}{.7pt}\hfill\null\newline}
\newcommand{\question}{\quetrue{\bfseries Question: }}
\newcommand{\answer}{\ifque\anstrue\sep{\bfseries Answer: }\else\errmessage{You need question}\fi}
\newcommand{\think}{\ifans\sep\fi{\bfseries Think about: }}
\newenvironment{example}{%
\begin{shaded}\begin{quote}}{%
\ifque\ifans\else\errmessage{You need answer}\fi\fi%
\end{quote}\end{shaded}}
\begin{document}
I don't want the rule below if there's only a think about:
\begin{example}
\think Blah, blah, blah.
\end{example}
Where's the answer? I don't want questions without answers.
\begin{example}
\question When it first starts raining, will it be large or small
raindrops that hit the ground first?
\end{example}
What was the question?
\begin{example}
\answer Raindrops vary in size from 0.5~\si{mm} in diameter to
4~\si{mm}. Larger raindrops will split into smaller drops.
Blah, blah, blah.
\end{example}
My ideal for examples with question/answer/think parts:
\begin{example}
\question When it first starts raining, will it be large or small
raindrops that hit the ground first?
\answer Raindrops vary in size from 0.5~\si{mm} in diameter to
4~\si{mm}. Larger raindrops will split into smaller drops.
Raindrops reach terminal velocity $v_T$ almost immediately after
they start falling. This means that the drag force (pointing up)
becomes equal but opposite to the raindrop weight (pointing
down). Finding the terminal velocity will determine what sized
raindrops hit the ground first when the rain storm begins.
Blah, blah, blah ...
\think Give a physics explanation for why falling hailstones are
more dangerous than falling raindrops.
\end{example}
\end{document}
答案2
我结合了几个 TeX stackexchange 帖子中的想法,想出了以下代码片段。它似乎满足了我的要求。基本上是一个带有特殊命令 \question、\answer 和 \think 的描述环境。如果愿意,我仍然可以使用常用的 \item 命令,因此我可以在我的示例环境中使用常规列表。
\documentclass{tufte-book}
\usepackage{amsmath}
\usepackage{siunitx}
\usepackage{framed}
%% \newenvironment{example}{
%% \newcommand{\sep}{\hfill\rule[0.25em]{0.5\linewidth}{.7pt}\hfill\null\newline}
%% \newcommand{\question}{{\bfseries Question: }}
%% \newcommand{\answer}{\sep{\bfseries Answer: }}
%% \newcommand{\think}{\sep{\bfseries Think about: }}
%% \begin{shaded}\begin{quote}
%% }{\end{quote}\end{shaded}}
\usepackage{etoolbox}
\makeatletter
\let\myitem\@item
\patchcmd{\myitem}
{\addvspace\itemsep}
{\par\kern\dimexpr.7\itemsep-.7\parskip-.7\baselineskip\relax%
\hfill\rule{0.5\linewidth}{.7pt}\hfill\null%
\par\kern\dimexpr.3\itemsep-.3\parskip-.3\baselineskip\relax}
{}{}%
\makeatother
\newtoggle{question}
\newtoggle{answer}
\newtoggle{think}
\newenvironment{example}{
\togglefalse{question}
\togglefalse{answer}
\togglefalse{think}
\newcommand{\question}{\toggletrue{question}\myitem[\bfseries Question]}
\newcommand{\answer}{\toggletrue{answer}\myitem[\bfseries Answer]}
\newcommand{\think}{\toggletrue{think}\myitem[\bfseries Think about]}
\colorlet{shadecolor}{orange!8}
\begin{shaded}\begin{description}
}{
\ifboolexpr{togl {question} and togl {answer} or togl {think}}
{}
{\errmessage{You need both question AND answer items, or a think-about item}}
\end{description}\end{shaded}
}
\begin{document}
Must have both question and answer parts, or a think-about part:
\begin{example}
\think Ok, let's think about this.
\end{example}
Full example:
\begin{example}
\question When it first starts raining, will it be large or small
raindrops that hit the ground first?
\answer Raindrops vary in size from 0.5~\si{mm} in diameter to
4~\si{mm}. Larger raindrops will split into smaller drops.
Raindrops reach terminal velocity $v_T$ almost immediately after
they start falling. This means that the drag force (pointing up)
becomes equal but opposite to the raindrop weight (pointing
down). Finding the terminal velocity will determine what sized
raindrops hit the ground first when the rain storm begins.
Blah, blah, blah ...
\think Give a physics explanation for why falling hailstones are
more dangerous than falling raindrops.
\item[A regular description] can also be used.
The usual list environments are also ok to include:
\begin{itemize}
\item one
\item two
\item three
\end{itemize}
\end{example}
\end{document}