General ⇒ Warm up Command
Warm up Command
- Attachments
-
- Algebra2Notes.pdf
- (90.49 KiB) Downloaded 259 times
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
-
- Posts: 126
- Joined: Sun Feb 13, 2011 8:36 pm
Warm up Command
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 265 times