LaTeX forum ⇒ GeneralWarm up Command

LaTeX specific issues not fitting into one of the other forums of this category.
Mikerada6
Posts: 42
Joined: Fri Oct 17, 2008 5:55 pm

Warm up Command

Postby Mikerada6 » Mon Jul 04, 2011 7:55 pm

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 81 times

5gon12eder
Posts: 126
Joined: Sun Feb 13, 2011 8:36 pm

Postby 5gon12eder » Tue Jul 05, 2011 11:46 pm

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

  1. \documentclass{book}
  2. \usepackage[T1]{fontenc}
  3.  
  4. \author{Your friendly math teacher}
  5. \title{Calculus Summer School}
  6. \date{2011}
  7.  
  8. % Create an output handle to write code to the file *.sol which we
  9. % later \input in the appendix.
  10. \newwrite\solutionstream
  11. \immediate\openout\solutionstream=\jobname.sol
  12.  
  13. % Define the environment for the "warming up".
  14. \newsavebox{\warmupbox}
  15. \newenvironment
  16. {WarmingUp}
  17. {
  18. % Write the current chapter number to the solutions file. This
  19. % is just an example. One should add a check here if we are in
  20. % a \chapter, a \section or a \subsection and write the
  21. % appropriate information. Maybe you just want to introduce a
  22. % counter for the `WarmingUp's instead and reference them by it.
  23. \immediate\write\solutionstream{\noexpand\SectionInSolutions{\thesection}}
  24. % We collect all the contents of the environment in a \savebox
  25. % and typeset it later.
  26. \begin{lrbox}{\warmupbox}
  27. \begin{minipage}{\textwidth}
  28. \begin{center}
  29. \scshape Warming Up
  30. \end{center}\par
  31. \begin{enumerate}
  32. }
  33. {
  34. \end{enumerate}
  35. \end{minipage}
  36. \end{lrbox}
  37. \par\noindent
  38. \fbox{\usebox{\warmupbox}}
  39. }
  40.  
  41. % Define a command that takes the question as its first and the answer
  42. % at its second argument. The question will be typeset as an \item
  43. % immediately. Question and answer will be written to the *.sol file.
  44. \newcommand
  45. {\WarmingUpExercise}[2]
  46. {%
  47. \item#1%
  48. \immediate\write\solutionstream{\noexpand\SolutionsEntry{\theenumi}{#1}{#2}}%
  49. }
  50.  
  51. % The following two commands specify how a solution entry is typeset.
  52. \newcommand{\SectionInSolutions}[1]{\subsubsection*{Section #1}}
  53. \newcommand{\SolutionsEntry}[3]
  54. {%
  55. \noindent\textsc{Question #1}
  56. \par\noindent Q:\quad#2
  57. \par\noindent A:\quad#3
  58. \par\vspace{1ex}
  59. }
  60.  
  61. % calling this command will typeset the solutions. It will only work
  62. % for `WarmingUp's that have occured BEFORE this command.
  63. \newcommand
  64. {\WarmingUpSolutions}
  65. {
  66. \immediate\closeout\solutionstream
  67. \input{\jobname.sol}
  68. }
  69.  
  70. \begin{document}
  71. \maketitle
  72.  
  73. \chapter{Elementary Operations}
  74. \section{Adding Natural Numbers}
  75. \begin{WarmingUp}
  76. \WarmingUpExercise{How much is $1+2$?}{3}
  77. \WarmingUpExercise{And what about $6+8$?}{14}
  78. \end{WarmingUp}
  79.  
  80. Now you are ready to dive into the math.
  81.  
  82. \section{Real Numbers}
  83. \begin{WarmingUp}
  84. \WarmingUpExercise{Compute $12.4 + 9.6$.}{22.0}
  85. \WarmingUpExercise{Use your pocket calulator to evaluate $3.0\times(1.0/3.0)$.}{0.99999}
  86. \end{WarmingUp}
  87.  
  88. Enjoy computing with real numbers. Soon we'll introduce $i$\dots
  89.  
  90. \appendix
  91. \chapter{Solutions}
  92. \WarmingUpSolutions
  93. \end{document}
Attachments
SummerSchool.pdf
PDF output of the example code.
(142.33 KiB) Downloaded 78 times
I'm using pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian).


Return to “General”

Who is online

Users browsing this forum: No registered users and 6 guests