General ⇒ Warm up Command
Warm up Command
I am trying to create a latex book to use as notes for the classes i am teaching. I would like to have at the start of each section a warmup. I would like to create a command that would put a box around the questions and title it as a warm up. And then add all the answers to the warmups in an appendix. i have attached a PDF of what i am thinking the final product will look like.
- Attachments
-
- Algebra2Notes.pdf
- (90.49 KiB) Downloaded 251 times
NEW: TikZ book now 40% off at Amazon.com for a short time.
-
- Posts: 126
- Joined: Sun Feb 13, 2011 8:36 pm
Warm up Command
This will involve some TeX programming. Assuming that you know at least some basics about it, you should be able to achieve your goal by inspecting the example I've made. Hope this helps.
Best
Best
Code: Select all
\documentclass{book}
\usepackage[T1]{fontenc}
\author{Your friendly math teacher}
\title{Calculus Summer School}
\date{2011}
% Create an output handle to write code to the file *.sol which we
% later \input in the appendix.
\newwrite\solutionstream
\immediate\openout\solutionstream=\jobname.sol
% Define the environment for the "warming up".
\newsavebox{\warmupbox}
\newenvironment
{WarmingUp}
{
% Write the current chapter number to the solutions file. This
% is just an example. One should add a check here if we are in
% a \chapter, a \section or a \subsection and write the
% appropriate information. Maybe you just want to introduce a
% counter for the `WarmingUp's instead and reference them by it.
\immediate\write\solutionstream{\noexpand\SectionInSolutions{\thesection}}
% We collect all the contents of the environment in a \savebox
% and typeset it later.
\begin{lrbox}{\warmupbox}
\begin{minipage}{\textwidth}
\begin{center}
\scshape Warming Up
\end{center}\par
\begin{enumerate}
}
{
\end{enumerate}
\end{minipage}
\end{lrbox}
\par\noindent
\fbox{\usebox{\warmupbox}}
}
% Define a command that takes the question as its first and the answer
% at its second argument. The question will be typeset as an \item
% immediately. Question and answer will be written to the *.sol file.
\newcommand
{\WarmingUpExercise}[2]
{%
\item#1%
\immediate\write\solutionstream{\noexpand\SolutionsEntry{\theenumi}{#1}{#2}}%
}
% The following two commands specify how a solution entry is typeset.
\newcommand{\SectionInSolutions}[1]{\subsubsection*{Section #1}}
\newcommand{\SolutionsEntry}[3]
{%
\noindent\textsc{Question #1}
\par\noindent Q:\quad#2
\par\noindent A:\quad#3
\par\vspace{1ex}
}
% calling this command will typeset the solutions. It will only work
% for `WarmingUp's that have occured BEFORE this command.
\newcommand
{\WarmingUpSolutions}
{
\immediate\closeout\solutionstream
\input{\jobname.sol}
}
\begin{document}
\maketitle
\chapter{Elementary Operations}
\section{Adding Natural Numbers}
\begin{WarmingUp}
\WarmingUpExercise{How much is $1+2$?}{3}
\WarmingUpExercise{And what about $6+8$?}{14}
\end{WarmingUp}
Now you are ready to dive into the math.
\section{Real Numbers}
\begin{WarmingUp}
\WarmingUpExercise{Compute $12.4 + 9.6$.}{22.0}
\WarmingUpExercise{Use your pocket calulator to evaluate $3.0\times(1.0/3.0)$.}{0.99999}
\end{WarmingUp}
Enjoy computing with real numbers. Soon we'll introduce $i$\dots
\appendix
\chapter{Solutions}
\WarmingUpSolutions
\end{document}
- Attachments
-
- SummerSchool.pdf
- PDF output of the example code.
- (142.33 KiB) Downloaded 251 times
I'm using pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian).