-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtesttext.sty
191 lines (168 loc) · 6.55 KB
/
testtext.sty
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
% ========================================
% Page layout
\RequirePackage[left=1.45in,right=1.45in,top=1in,bottom=1in]{geometry}
% fancyhdr
\fancypagestyle{bodypage}{%
\fancyhf{}% clear all six fields
\fancyhead[RE,LO]{\small \textit{Introduction to Proofs}, Hef{}feron, version~\version}
\fancyhead[LE,RO]{\small page \thepage}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0pt}
}
\pagestyle{prefacepage}
\AtBeginDocument{\thispagestyle{firstpage}}
% ========================================
% Answers
% This has to go in this .sty because it opens and empties answers.tex,
% which would be bad if you ran pdflatex answers.
\usepackage{answers}
\Newassociation{ans}{solution}{answers}
\Opensolutionfile{answers}[answersbody]
% \begin{Filesave}{answers}
% \documentclass{ibl}
% \begin{document}
% \begin{answerlist}
% \end{Filesave}
\AtEndDocument{%
\Closesolutionfile{answers}}
% Exercises and answers that do not appear in this file are put into
% another .tex file for "Other exercises."
\newcommand{\otherfilename}{otherbody}
\Newassociation{otherproblems}{otherproblem}{otherex}
\Opensolutionfile{otherex}[\otherfilename]
\Newassociation{otherexercises}{otherexercise}{otherex}
% \Opensolutionfile{otherex}[\otherfilename]
\Newassociation{otheranswers}{otheranswer}{otherex}
% \Opensolutionfile{otherans}[\otherfilename]
\AtEndDocument{%
\Closesolutionfile{otherex}}
% ========================================
% Title-ing of chapters and sections
% Uses titlesec.
% If making compact version then put chapter start on same page
\ifbool{optioncompact}{\titleclass{\chapter}{straight}}{} % possibilities are: straight, part, top, page
% Format the chapter and section heads
\titleformat{\chapter}[block]{\color{darki}\Large\scshape}{Chapter \thechapter}{1em}{}[\thispagestyle{firstpage}]
\titlespacing*{\chapter}{0em}{4ex}{2ex}
\titleformat{\section}[block]{\color{darki}\large\scshape}{}{0em}{}[]
\titlespacing*{\section}{0em}{4ex}{1ex}
% Here is the interaction with answers package.
% Need to write the name of the chapter or section to the answer file.
% But that I can tell, I can't get \thetitle into titlesec's
% \titleformat after-code. So I write a new \chapter and \section
% that grab those, write the material to answers, and then run the command
% that titlesec has defined.
% Grab the name of the chapter, write it to the answers file, then
% invoke the titlesec \chapter command.
\let\chapterholder\chapter
\renewcommand{\chapter}{\@ifstar % look out for \chapter*{Preface}
\jhchapterStar%
\jhchapterNoStar%
}
\newcommand{\jhchapterStar}[1]{\chapterholder{#1}}
\newcommand{\jhchapterNoStar}[1]{\ifbool{inappendix}{\relax}{%
\Writetofile{answers}{\protect\chapter{#1}}\Writetofile{otherex}{\protect\chapter{#1}}}\chapterholder{#1}}
% Same thing for the \section command
\let\sectionholder\section
\renewcommand{\section}{\@ifstar
\jhsectionStar%
\jhsectionNoStar%
}
\newcommand{\jhsectionStar}[1]{\sectionholder{#1}}
\newcommand{\jhsectionNoStar}[1]{%
\Writetofile{answers}{\protect\section{#1}}\Writetofile{otherex}{\protect\section{#1}}\sectionholder{#1}}
% ++++++++++++
% Problems
\newcounter{exercisescount}
\AtEndDocument{\typeout{Total number of exercises: \theexercisescount.}}
% A problem consists of a number of exercise items.
% optional argument: A number that determines if this gets printed
\gdef\problem@booklengthvalue{0} % default value, for testing
\newenvironment{problem}[1][\defaultbooklength]{%
\gdef\problem@booklengthvalue{#1} % remember #1
\ifnumgreater{\problem@booklengthvalue}{\booklength}{
\typeout{About to turn on otherproblems macro}
\otherproblems
}{%
\addtocounter{exercisescount}{1} % some exercises are just a problem env, no exes
\begin{ex}
\Writetofile{answers}{\protect\begin{answer}{\Currentlabel}}
}
}{%
\ifnumgreater{\problem@booklengthvalue}{\booklength}{
\endotherproblems
}{%
\Writetofile{answers}{\protect\end{answer}}
\Writetofile{answers}{} % blank line for human readability
\end{ex}
}
}
\newenvironment{exercise}[1][\problem@booklengthvalue]{%
\gdef\exercise@booklengthvalue{#1} % remember #1
% \typeout{Exercise book length value \exercise@booklengthvalue}
\ifnumgreater{\exercise@booklengthvalue}{\booklength}{%
% \typeout{ Writing exercise to other file}
\otherexercises
}{
% \typeout{ Writing exercise to main file}
\addtocounter{exercisescount}{1} % each exercise adds 1 to total
\item
}
}{%
\ifnumgreater{\exercise@booklengthvalue}{\booklength}{%
\endotherexercises
}{%
}
}
\newenvironment{answer}{%
\ifnumgreater{\exercise@booklengthvalue}{\booklength}{%
\otheranswers
}{%
\ans
}
}{%
\ifnumgreater{\exercise@booklengthvalue}{\booklength}{%
\endotheranswers
}{
\endans
}
}
% ++++++++++++
% Exercises sometimes have multiple parts.
% For these exercises, when done on the board, I have separate students
% do separate parts
\newlength{\exesindent}\setlength{\exesindent}{1.25em}
\newenvironment{exlist}{% used in appendix as well as in exercises
\begin{enumerate}[topsep=0.15ex,partopsep=0ex,parsep=0ex,
beginpenalty=150, % Prevent page break after newline start
itemsep=.25ex plus .03ex minus .01ex,
leftmargin=\exesindent,rightmargin=0em,
align=left,label={\textsc{\alph*}.}]
}{%
\end{enumerate}
}
\newenvironment{exes}{%
% \typeout{exes: problem book length value \problem@booklengthvalue}
\ifnumgreater{\problem@booklengthvalue}{\booklength}{}{%
\addtocounter{exercisescount}{-1} % got +1 for problem env, so cancel that
\Writetofile{answers}{\protect\begin{exes}}
}
\begin{exlist}
% \begin{enumerate}[topsep=0.15ex,partopsep=0ex,parsep=0ex,
% beginpenalty=150, % Prevent page break after newline start
% itemsep=.25ex plus .03ex minus .01ex,
% leftmargin=\exesindent,rightmargin=0em,
% align=left,label={\textsc{\alph*}.\protect\addtocounter{exercisepartscount}{1}}]
}{%
\ifnumgreater{\problem@booklengthvalue}{\booklength}{}{%
\Writetofile{answers}{\protect\end{exes}}
}
% \end{enumerate}
\end{exlist}
}
% Each individual exercise has two main arguments, the exercise and
% the answer. There is also an optional argument, a number that
% determines if the exercise gets printed in the various length
% books.
\newcommand{\exer}[3][\defaultbooklength]{\item #2 %
\Writetofile{answers}{\protect\item\space #3}}